Java Code Examples for com.mysql.cj.conf.HostInfo#getDatabase()
The following examples show how to use
com.mysql.cj.conf.HostInfo#getDatabase() .
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: XProtocol.java From FoxTelem with GNU General Public License v3.0 | 6 votes |
public XProtocol(HostInfo hostInfo, PropertySet propertySet) { String host = hostInfo.getHost(); if (host == null || StringUtils.isEmptyOrWhitespaceOnly(host)) { host = "localhost"; } int port = hostInfo.getPort(); if (port < 0) { port = 33060; } this.defaultSchemaName = hostInfo.getDatabase(); // Override common connectTimeout with xdevapi.connect-timeout to provide unified logic in StandardSocketFactory RuntimeProperty<Integer> connectTimeout = propertySet.getIntegerProperty(PropertyKey.connectTimeout); RuntimeProperty<Integer> xdevapiConnectTimeout = propertySet.getIntegerProperty(PropertyKey.xdevapiConnectTimeout); if (xdevapiConnectTimeout.isExplicitlySet() || !connectTimeout.isExplicitlySet()) { connectTimeout.setValue(xdevapiConnectTimeout.getValue()); } SocketConnection socketConn = propertySet.getBooleanProperty(PropertyKey.xdevapiUseAsyncProtocol).getValue() ? new XAsyncSocketConnection() : new NativeSocketConnection(); socketConn.connect(host, port, propertySet, null, null, 0); init(null, socketConn, propertySet, null); }
Example 2
Source File: SessionImpl.java From lams with GNU General Public License v2.0 | 5 votes |
public SessionImpl(HostInfo hostInfo) { PropertySet pset = new DefaultPropertySet(); pset.initializeProperties(hostInfo.exposeAsProperties()); this.session = new MysqlxSession(hostInfo, pset); this.defaultSchemaName = hostInfo.getDatabase(); this.xbuilder = (XMessageBuilder) this.session.<XMessage> getMessageBuilder(); }
Example 3
Source File: SessionImpl.java From FoxTelem with GNU General Public License v3.0 | 5 votes |
/** * Constructor. * * @param hostInfo * {@link HostInfo} instance */ public SessionImpl(HostInfo hostInfo) { PropertySet pset = new DefaultPropertySet(); pset.initializeProperties(hostInfo.exposeAsProperties()); this.session = new MysqlxSession(hostInfo, pset); this.defaultSchemaName = hostInfo.getDatabase(); this.xbuilder = (XMessageBuilder) this.session.<XMessage> getMessageBuilder(); }
Example 4
Source File: BaseTestCase.java From FoxTelem with GNU General Public License v3.0 | 5 votes |
protected Connection getUnreliableMultiHostConnection(String haMode, String[] hostNames, Properties props, Set<String> downedHosts) throws Exception { if (downedHosts == null) { downedHosts = new HashSet<>(); } props = getHostFreePropertiesFromTestsuiteUrl(props); props.setProperty(PropertyKey.socketFactory.getKeyName(), "testsuite.UnreliableSocketFactory"); HostInfo defaultHost = mainConnectionUrl.getMainHost(); String db = defaultHost.getDatabase(); String port = String.valueOf(defaultHost.getPort()); String host = defaultHost.getHost(); UnreliableSocketFactory.flushAllStaticData(); StringBuilder hostString = new StringBuilder(); String delimiter = ""; for (String hostName : hostNames) { UnreliableSocketFactory.mapHost(hostName, host); hostString.append(delimiter); delimiter = ","; hostString.append(hostName + ":" + port); if (downedHosts.contains(hostName)) { UnreliableSocketFactory.downHost(hostName); } } if (haMode == null) { haMode = ""; } else if (haMode.length() > 0) { haMode += ":"; } return getConnectionWithProps(ConnectionUrl.Type.FAILOVER_CONNECTION.getScheme() + haMode + "//" + hostString.toString() + "/" + db, props); }
Example 5
Source File: BaseTestCase.java From FoxTelem with GNU General Public License v3.0 | 5 votes |
protected ReplicationConnection getUnreliableReplicationConnection(Set<MockConnectionConfiguration> configs, Properties props) throws Exception { props = getHostFreePropertiesFromTestsuiteUrl(props); props.setProperty(PropertyKey.socketFactory.getKeyName(), "testsuite.UnreliableSocketFactory"); HostInfo defaultHost = mainConnectionUrl.getMainHost(); String db = defaultHost.getDatabase(); String port = String.valueOf(defaultHost.getPort()); String host = defaultHost.getHost(); UnreliableSocketFactory.flushAllStaticData(); StringBuilder hostString = new StringBuilder(); String glue = ""; for (MockConnectionConfiguration config : configs) { UnreliableSocketFactory.mapHost(config.hostName, host); hostString.append(glue); glue = ","; if (config.port == null) { config.port = (port == null ? "3306" : port); } hostString.append(config.getAddress()); if (config.isDowned) { UnreliableSocketFactory.downHost(config.hostName); } } return (ReplicationConnection) getConnectionWithProps(ConnectionUrl.Type.REPLICATION_CONNECTION.getScheme() + "//" + hostString.toString() + "/" + db, props); }
Example 6
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 7
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 8
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 9
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(); }