public MySqlDataSource(ServiceSelector serviceSelector, MySqlDataSourceConfig config) { super(config.getMaxConnections(), config.getMaxConnectionWait()); this.serviceSelector = serviceSelector; this.defaultFetchSize = config.getDefaultFetchSize(); }
@Override protected Connection createConnection() throws SQLException { assertNotDisposed(); // check for a pooled connection PooledConnection pooledConnection = pool.pollLast(); if (pooledConnection != null) { return prepareConnection(pooledConnection); } // otherwise create a new one return super.createConnection(); }
@Override public void close() throws SQLException { if (closed) { return; } closed = true; mockPooledConnection.closeOccurred(); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmptyFilenameThrows() throws Exception { H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() .setFilename("") .setInitScript("io/airlift/dbpool/h2.ddl") .setCipher(Cipher.AES) .setFilePassword("filePassword"); new H2EmbeddedDataSource(config); }
@Test(groups = "requiresTempFile", expectedExceptions = CreationException.class) public void testIncorrectConfigurationPrefixThrows() { final String configurationPrefix = "configuration"; final String constructionPrefix = "differentFromConfiguration"; Map<String, String> properties = createDefaultConfigurationProperties(configurationPrefix, temporaryFile.getAbsolutePath()); // Will throw because construction will fail due to the incorrect prefixing. createInjector(properties, new H2EmbeddedDataSourceModule(constructionPrefix, MainBinding.class)); }
@Test public void testConnectionException() throws Exception { ManagedDataSource dataSource = new MockManagedDataSource(1, new Duration(10, MILLISECONDS)); MockConnection connection = (MockConnection) dataSource.getConnection(); assertNotNull(connection); assertEquals(dataSource.getConnectionsActive(), 1); connection.errorOccurred(); assertEquals(dataSource.getConnectionsActive(), 0); }
@Inject public TwoObjectsHolder(@MainBinding DataSource mainDataSource, @AliasBinding DataSource aliasedDataSource) { this.mainDataSource = mainDataSource; this.aliasedDataSource = aliasedDataSource; } }
@Override protected PooledConnection createConnectionInternal() throws SQLException { return poolDataSource.getPooledConnection(); } }
public void errorOccurred() throws SQLException { if (closed) { return; } closed = true; mockPooledConnection.errorOccurred(); }
public MockManagedDataSource(int maxConnections, Duration maxConnectionWait) { this(new MockConnectionPoolDataSource(), maxConnections, maxConnectionWait); }
@Test(expectedExceptions = NullPointerException.class) public void testNullFilenameThrows() throws Exception { H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() // Filename left as null .setInitScript("io/airlift/dbpool/h2.ddl") .setCipher(Cipher.AES) .setFilePassword("filePassword"); new H2EmbeddedDataSource(config); }
public MySqlDataSource(ServiceSelector serviceSelector, MySqlDataSourceConfig config) { super(config.getMaxConnections(), config.getMaxConnectionWait()); this.serviceSelector = serviceSelector; this.defaultFetchSize = config.getDefaultFetchSize(); }
@Override protected Connection createConnection() throws SQLException { assertNotDisposed(); // check for a pooled connection PooledConnection pooledConnection = pool.pollLast(); if (pooledConnection != null) { return prepareConnection(pooledConnection); } // otherwise create a new one return super.createConnection(); }
@Inject public TwoObjectsHolder(@MainBinding DataSource mainDataSource, @AliasBinding DataSource aliasedDataSource) { this.mainDataSource = mainDataSource; this.aliasedDataSource = aliasedDataSource; } }
@Override public void close() throws SQLException { if (closed) { return; } closed = true; mockPooledConnection.closeOccurred(); }
@Override protected PooledConnection createConnectionInternal() throws SQLException { return poolDataSource.getPooledConnection(); } }
public void errorOccurred() throws SQLException { if (closed) { return; } closed = true; mockPooledConnection.errorOccurred(); }
public MockManagedDataSource(int maxConnections, Duration maxConnectionWait) { this(new MockConnectionPoolDataSource(), maxConnections, maxConnectionWait); }
@Test(expectedExceptions = NullPointerException.class) public void testNullFilenameThrows() throws Exception { H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() // Filename left as null .setInitScript("io/airlift/dbpool/h2.ddl") .setCipher(Cipher.AES) .setFilePassword("filePassword"); new H2EmbeddedDataSource(config); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmptyFilenameThrows() throws Exception { H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() .setFilename("") .setInitScript("io/airlift/dbpool/h2.ddl") .setCipher(Cipher.AES) .setFilePassword("filePassword"); new H2EmbeddedDataSource(config); }