use of com.mysql.cj.conf.ConnectionUrl in project aws-mysql-jdbc by awslabs.
the class MysqlDataSource method getConnection.
/**
* Creates a connection using the specified properties.
*
* @param props
* the properties to connect with
*
* @return a connection to the database
*
* @throws SQLException
* if an error occurs
*/
protected java.sql.Connection getConnection(Properties props) throws SQLException {
String jdbcUrlToUse = this.explicitUrl ? this.url : getUrl();
//
// URL should take precedence over properties
//
ConnectionUrl connUrl = ConnectionUrl.getConnectionUrlInstance(jdbcUrlToUse, null);
Properties urlProps = connUrl.getConnectionArgumentsAsProperties();
urlProps.remove(PropertyKey.HOST.getKeyName());
urlProps.remove(PropertyKey.PORT.getKeyName());
urlProps.remove(PropertyKey.DBNAME.getKeyName());
urlProps.stringPropertyNames().stream().forEach(k -> props.setProperty(k, urlProps.getProperty(k)));
return mysqlDriver.connect(jdbcUrlToUse, props);
}
use of com.mysql.cj.conf.ConnectionUrl in project aws-mysql-jdbc by awslabs.
the class TestXDevAPIRequirements method testSessionCreation.
/**
* Session [11]
* Session.Connect.Single [6]
* Session.Connect.DataSource [7]
* Session.Connect.Mysqls [8] [9] - not supported in first version
*
* @throws Exception
*/
@Test
public void testSessionCreation() throws Exception {
if (!this.isSetForXTests) {
return;
}
Session sess;
String url = this.baseUrl;
sess = getSession(url);
sess.close();
// TODO test different URLs
ConnectionUrl conUrl = ConnectionUrl.getConnectionUrlInstance(url, null);
Properties props = conUrl.getMainHost().exposeAsProperties();
sess = getSession(props);
sess.close();
// test connection without port specification
if (props.getProperty(PropertyKey.PORT.getKeyName()).equals("33060")) {
props.remove(PropertyKey.PORT.getKeyName());
sess = getSession(props);
ConnectionUrl conUrl1 = ConnectionUrl.getConnectionUrlInstance(sess.getUri(), null);
assertEquals("33060", conUrl1.getMainHost().exposeAsProperties().getProperty(PropertyKey.PORT.getKeyName()));
sess.close();
}
// TODO test different properties
}
use of com.mysql.cj.conf.ConnectionUrl in project aws-mysql-jdbc by awslabs.
the class FailoverConnectionPlugin method createClusterInstanceTemplate.
private HostInfo createClusterInstanceTemplate(HostInfo hostInfo, String host, int port) {
// TODO: review whether we still need this method
Map<String, String> properties = new HashMap<>(this.initialConnectionProps);
properties.put(PropertyKey.connectTimeout.getKeyName(), String.valueOf(this.failoverConnectTimeoutMs));
properties.put(PropertyKey.socketTimeout.getKeyName(), String.valueOf(this.failoverSocketTimeoutMs));
if (!Objects.equals(hostInfo.getDatabase(), "")) {
properties.put(PropertyKey.DBNAME.getKeyName(), hostInfo.getDatabase());
}
final Properties connectionProperties = new Properties();
connectionProperties.putAll(this.initialConnectionProps);
final ConnectionUrl connectionUrl = ConnectionUrl.getConnectionUrlInstance(hostInfo.getDatabaseUrl(), connectionProperties);
return new HostInfo(connectionUrl, host, port, hostInfo.getUser(), hostInfo.getPassword(), hostInfo.isPasswordless(), properties);
}
use of com.mysql.cj.conf.ConnectionUrl in project aws-mysql-jdbc by awslabs.
the class AuroraTopologyService method createHost.
private HostInfo createHost(ResultSet resultSet) throws SQLException {
String hostEndpoint = getHostEndpoint(resultSet.getString(FIELD_SERVER_ID));
ConnectionUrl hostUrl = ConnectionUrl.getConnectionUrlInstance(getUrlFromEndpoint(hostEndpoint, this.clusterInstanceTemplate.getPort(), this.clusterInstanceTemplate.getDatabase()), new Properties());
return new HostInfo(hostUrl, hostEndpoint, this.clusterInstanceTemplate.getPort(), this.clusterInstanceTemplate.getUser(), this.clusterInstanceTemplate.getPassword(), this.clusterInstanceTemplate.isPasswordless(), getPropertiesFromTopology(resultSet));
}
use of com.mysql.cj.conf.ConnectionUrl in project aws-mysql-jdbc by awslabs.
the class AWSSecretsManagerPlugin method attemptConnectionWithSecrets.
private void attemptConnectionWithSecrets(Properties props, Secret secret, ConnectionUrl connectionUrl) throws SQLException {
updateConnectionProperties(props, secret);
final ConnectionUrl newConnectionUrl = ConnectionUrl.getConnectionUrlInstance(connectionUrl.getDatabaseUrl(), props);
this.nextPlugin.openInitialConnection(newConnectionUrl);
}
Aggregations