Java Code Examples for com.mysql.cj.conf.HostInfo#getPassword()
The following examples show how to use
com.mysql.cj.conf.HostInfo#getPassword() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatementImpl.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Cancels this Statement object if both the DBMS and driver support * aborting an SQL statement. This method can be used by one thread to * cancel a statement that is being executed by another thread. */ public void cancel() throws SQLException { if (!this.query.getStatementExecuting().get()) { return; } if (!this.isClosed && this.connection != null) { JdbcConnection cancelConn = null; java.sql.Statement cancelStmt = null; try { HostInfo hostInfo = this.session.getHostInfo(); String database = hostInfo.getDatabase(); String user = StringUtils.isNullOrEmpty(hostInfo.getUser()) ? "" : hostInfo.getUser(); String password = StringUtils.isNullOrEmpty(hostInfo.getPassword()) ? "" : hostInfo.getPassword(); NativeSession newSession = new NativeSession(this.session.getHostInfo(), this.session.getPropertySet()); newSession.connect(hostInfo, user, password, database, 30000, new TransactionEventHandler() { @Override public void transactionCompleted() { } public void transactionBegun() { } }); newSession.sendCommand(new NativeMessageBuilder().buildComQuery(newSession.getSharedSendPacket(), "KILL QUERY " + this.session.getThreadId()), false, 0); setCancelStatus(CancelStatus.CANCELED_BY_USER); } catch (IOException e) { throw SQLExceptionsMapping.translateException(e, this.exceptionInterceptor); } finally { if (cancelStmt != null) { cancelStmt.close(); } if (cancelConn != null) { cancelConn.close(); } } } }
Example 2
Source File: CancelQueryTaskImpl.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public void run() { Thread cancelThread = new Thread() { @Override public void run() { Query localQueryToCancel = CancelQueryTaskImpl.this.queryToCancel; if (localQueryToCancel == null) { return; } NativeSession session = (NativeSession) localQueryToCancel.getSession(); if (session == null) { return; } try { if (CancelQueryTaskImpl.this.queryTimeoutKillsConnection) { localQueryToCancel.setCancelStatus(CancelStatus.CANCELED_BY_TIMEOUT); session.invokeCleanupListeners(new OperationCancelledException(Messages.getString("Statement.ConnectionKilledDueToTimeout"))); } else { synchronized (localQueryToCancel.getCancelTimeoutMutex()) { long origConnId = session.getThreadId(); HostInfo hostInfo = session.getHostInfo(); String database = hostInfo.getDatabase(); String user = StringUtils.isNullOrEmpty(hostInfo.getUser()) ? "" : hostInfo.getUser(); String password = StringUtils.isNullOrEmpty(hostInfo.getPassword()) ? "" : hostInfo.getPassword(); NativeSession newSession = new NativeSession(hostInfo, session.getPropertySet()); newSession.connect(hostInfo, user, password, database, 30000, new TransactionEventHandler() { @Override public void transactionCompleted() { } public void transactionBegun() { } }); newSession.sendCommand(new NativeMessageBuilder().buildComQuery(newSession.getSharedSendPacket(), "KILL QUERY " + origConnId), false, 0); localQueryToCancel.setCancelStatus(CancelStatus.CANCELED_BY_TIMEOUT); } } // } catch (NullPointerException npe) { // Case when connection closed while starting to cancel. // We can't easily synchronise this, because then one thread can't cancel() a running query. // Ignore, we shouldn't re-throw this, because the connection's already closed, so the statement has been timed out. } catch (Throwable t) { CancelQueryTaskImpl.this.caughtWhileCancelling = t; } finally { setQueryToCancel(null); } } }; cancelThread.start(); }
Example 3
Source File: XDevAPIConnectionUrl.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Constructs an instance of {@link XDevAPIConnectionUrl}, performing all the required initializations. * * @param connStrParser * a {@link ConnectionUrlParser} instance containing the parsed version of the original connection string * @param info * the connection arguments map */ public XDevAPIConnectionUrl(ConnectionUrlParser connStrParser, Properties info) { super(connStrParser, info); this.type = Type.XDEVAPI_SESSION; /* * Validate the hosts list: * 1. Same user and password are required in all hosts. * 2. If the host property 'priority' is set for one host, then in needs to be set on all others too. * 3. 'Priority' value must be between 0 and 100. */ boolean first = true; String user = null; String password = null; boolean hasPriority = false; for (HostInfo hi : this.hosts) { if (first) { first = false; user = hi.getUser(); password = hi.getPassword(); hasPriority = hi.getHostProperties().containsKey(PRIORITY_PROPERTY_KEY); } else { if (!user.equals(hi.getUser()) || !password.equals(hi.getPassword())) { throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.14", new Object[] { Type.XDEVAPI_SESSION.getProtocol() })); } if (hasPriority ^ hi.getHostProperties().containsKey(PRIORITY_PROPERTY_KEY)) { throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.15", new Object[] { Type.XDEVAPI_SESSION.getProtocol() })); } } if (hasPriority) { try { int priority = Integer.parseInt(hi.getProperty(PRIORITY_PROPERTY_KEY)); if (priority < 0 || priority > 100) { throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.16", new Object[] { Type.XDEVAPI_SESSION.getProtocol() })); } } catch (NumberFormatException e) { throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.16", new Object[] { Type.XDEVAPI_SESSION.getProtocol() })); } } } // Sort the hosts list according to their priority settings. if (hasPriority) { this.hosts.sort(Comparator.<HostInfo, Integer> comparing(hi -> Integer.parseInt(hi.getHostProperties().get(PRIORITY_PROPERTY_KEY))).reversed()); } }
Example 4
Source File: StatementImpl.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
@Override public void cancel() throws SQLException { if (!this.query.getStatementExecuting().get()) { return; } if (!this.isClosed && this.connection != null) { JdbcConnection cancelConn = null; java.sql.Statement cancelStmt = null; try { HostInfo hostInfo = this.session.getHostInfo(); String database = hostInfo.getDatabase(); String user = StringUtils.isNullOrEmpty(hostInfo.getUser()) ? "" : hostInfo.getUser(); String password = StringUtils.isNullOrEmpty(hostInfo.getPassword()) ? "" : hostInfo.getPassword(); NativeSession newSession = new NativeSession(this.session.getHostInfo(), this.session.getPropertySet()); newSession.connect(hostInfo, user, password, database, 30000, new TransactionEventHandler() { @Override public void transactionCompleted() { } @Override public void transactionBegun() { } }); newSession.sendCommand(new NativeMessageBuilder().buildComQuery(newSession.getSharedSendPacket(), "KILL QUERY " + this.session.getThreadId()), false, 0); setCancelStatus(CancelStatus.CANCELED_BY_USER); } catch (IOException e) { throw SQLExceptionsMapping.translateException(e, this.exceptionInterceptor); } finally { if (cancelStmt != null) { cancelStmt.close(); } if (cancelConn != null) { cancelConn.close(); } } } }
Example 5
Source File: CancelQueryTaskImpl.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
@Override public void run() { Thread cancelThread = new Thread() { @Override public void run() { Query localQueryToCancel = CancelQueryTaskImpl.this.queryToCancel; if (localQueryToCancel == null) { return; } NativeSession session = (NativeSession) localQueryToCancel.getSession(); if (session == null) { return; } try { if (CancelQueryTaskImpl.this.queryTimeoutKillsConnection) { localQueryToCancel.setCancelStatus(CancelStatus.CANCELED_BY_TIMEOUT); session.invokeCleanupListeners(new OperationCancelledException(Messages.getString("Statement.ConnectionKilledDueToTimeout"))); } else { synchronized (localQueryToCancel.getCancelTimeoutMutex()) { long origConnId = session.getThreadId(); HostInfo hostInfo = session.getHostInfo(); String database = hostInfo.getDatabase(); String user = StringUtils.isNullOrEmpty(hostInfo.getUser()) ? "" : hostInfo.getUser(); String password = StringUtils.isNullOrEmpty(hostInfo.getPassword()) ? "" : hostInfo.getPassword(); NativeSession newSession = new NativeSession(hostInfo, session.getPropertySet()); newSession.connect(hostInfo, user, password, database, 30000, new TransactionEventHandler() { @Override public void transactionCompleted() { } public void transactionBegun() { } }); newSession.sendCommand(new NativeMessageBuilder().buildComQuery(newSession.getSharedSendPacket(), "KILL QUERY " + origConnId), false, 0); localQueryToCancel.setCancelStatus(CancelStatus.CANCELED_BY_TIMEOUT); } } // } catch (NullPointerException npe) { // Case when connection closed while starting to cancel. // We can't easily synchronise this, because then one thread can't cancel() a running query. // Ignore, we shouldn't re-throw this, because the connection's already closed, so the statement has been timed out. } catch (Throwable t) { CancelQueryTaskImpl.this.caughtWhileCancelling = t; } finally { setQueryToCancel(null); } } }; cancelThread.start(); }
Example 6
Source File: XDevAPIConnectionUrl.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
/** * Constructs an instance of {@link XDevAPIConnectionUrl}, performing all the required initializations. * * @param connStrParser * a {@link ConnectionUrlParser} instance containing the parsed version of the original connection string * @param info * the connection arguments map */ public XDevAPIConnectionUrl(ConnectionUrlParser connStrParser, Properties info) { super(connStrParser, info); this.type = Type.XDEVAPI_SESSION; /* * Validate the hosts list: * 1. Same user and password are required in all hosts. * 2. If the host property 'priority' is set for one host, then in needs to be set on all others too. * 3. 'Priority' value must be between 0 and 100. */ boolean first = true; String user = null; String password = null; boolean hasPriority = false; for (HostInfo hi : this.hosts) { if (first) { first = false; user = hi.getUser(); password = hi.getPassword(); hasPriority = hi.getHostProperties().containsKey(PropertyKey.PRIORITY.getKeyName()); } else { if (!user.equals(hi.getUser()) || !password.equals(hi.getPassword())) { throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.14", new Object[] { Type.XDEVAPI_SESSION.getScheme() })); } if (hasPriority ^ hi.getHostProperties().containsKey(PropertyKey.PRIORITY.getKeyName())) { throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.15", new Object[] { Type.XDEVAPI_SESSION.getScheme() })); } } if (hasPriority) { try { int priority = Integer.parseInt(hi.getProperty(PropertyKey.PRIORITY.getKeyName())); if (priority < 0 || priority > 100) { throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.16", new Object[] { Type.XDEVAPI_SESSION.getScheme() })); } } catch (NumberFormatException e) { throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.16", new Object[] { Type.XDEVAPI_SESSION.getScheme() })); } } } // Sort the hosts list according to their priority settings. if (hasPriority) { this.hosts.sort( Comparator.<HostInfo, Integer> comparing(hi -> Integer.parseInt(hi.getHostProperties().get(PropertyKey.PRIORITY.getKeyName()))).reversed()); } }