Search in sources :

Example 1 with ConnectionPool

use of org.postgresql.jdbc2.optional.ConnectionPool in project pgjdbc by pgjdbc.

the class PGDataSourceFactory method createConnectionPoolDataSource.

public ConnectionPoolDataSource createConnectionPoolDataSource(Properties props) throws SQLException {
    props = new SingleUseProperties(props);
    ConnectionPool dataSource = new ConnectionPool();
    configureBaseDataSource(dataSource, props);
    return dataSource;
}
Also used : ConnectionPool(org.postgresql.jdbc2.optional.ConnectionPool)

Example 2 with ConnectionPool

use of org.postgresql.jdbc2.optional.ConnectionPool in project pgjdbc by pgjdbc.

the class ConnectionPoolTest method initializeDataSource.

/**
 * Creates and configures a ConnectionPool.
 */
@Override
protected void initializeDataSource() {
    if (bds == null) {
        bds = new ConnectionPool();
        setupDataSource(bds);
    }
}
Also used : ConnectionPool(org.postgresql.jdbc2.optional.ConnectionPool)

Example 3 with ConnectionPool

use of org.postgresql.jdbc2.optional.ConnectionPool in project pgjdbc by pgjdbc.

the class ConnectionPoolTest method testSerializable.

@Test
public void testSerializable() throws IOException, ClassNotFoundException {
    ConnectionPool pool = new ConnectionPool();
    pool.setDefaultAutoCommit(false);
    pool.setServerName("db.myhost.com");
    pool.setDatabaseName("mydb");
    pool.setUser("user");
    pool.setPassword("pass");
    pool.setPortNumber(1111);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(pool);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(bais);
    ConnectionPool pool2 = (ConnectionPool) ois.readObject();
    assertEquals(pool.isDefaultAutoCommit(), pool2.isDefaultAutoCommit());
    assertEquals(pool.getServerName(), pool2.getServerName());
    assertEquals(pool.getDatabaseName(), pool2.getDatabaseName());
    assertEquals(pool.getUser(), pool2.getUser());
    assertEquals(pool.getPassword(), pool2.getPassword());
    assertEquals(pool.getPortNumber(), pool2.getPortNumber());
}
Also used : ConnectionPool(org.postgresql.jdbc2.optional.ConnectionPool) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 4 with ConnectionPool

use of org.postgresql.jdbc2.optional.ConnectionPool in project pgjdbc by pgjdbc.

the class PGDataSourceFactoryTest method testCreateConnectionPoolDataSourceConfigured.

@Test
public void testCreateConnectionPoolDataSourceConfigured() throws Exception {
    Properties properties = new Properties();
    properties.put(DataSourceFactory.JDBC_DATABASE_NAME, "db");
    ConnectionPoolDataSource dataSource = dataSourceFactory.createConnectionPoolDataSource(properties);
    Assert.assertNotNull(dataSource);
    Assert.assertTrue(dataSource instanceof ConnectionPool);
    ConnectionPool connectionPoolDataSource = (ConnectionPool) dataSource;
    Assert.assertEquals("db", connectionPoolDataSource.getDatabaseName());
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) ConnectionPool(org.postgresql.jdbc2.optional.ConnectionPool) Properties(java.util.Properties) Test(org.junit.Test)

Example 5 with ConnectionPool

use of org.postgresql.jdbc2.optional.ConnectionPool in project openGauss-connector-jdbc by opengauss-mirror.

the class ConnectionPoolTest method testSerializable.

@Test
public void testSerializable() throws IOException, ClassNotFoundException {
    ConnectionPool pool = new ConnectionPool();
    pool.setDefaultAutoCommit(false);
    pool.setServerName("db.myhost.com");
    pool.setDatabaseName("mydb");
    pool.setUser("user");
    pool.setPassword("pass");
    pool.setPortNumber(1111);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(pool);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(bais);
    ConnectionPool pool2 = (ConnectionPool) ois.readObject();
    assertEquals(pool.isDefaultAutoCommit(), pool2.isDefaultAutoCommit());
    assertEquals(pool.getServerName(), pool2.getServerName());
    assertEquals(pool.getDatabaseName(), pool2.getDatabaseName());
    assertEquals(pool.getUser(), pool2.getUser());
    assertEquals(pool.getPassword(), pool2.getPassword());
    assertEquals(pool.getPortNumber(), pool2.getPortNumber());
}
Also used : ConnectionPool(org.postgresql.jdbc2.optional.ConnectionPool) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Aggregations

ConnectionPool (org.postgresql.jdbc2.optional.ConnectionPool)6 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 Properties (java.util.Properties)1 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)1