Search in sources :

Example 1 with FBManagedConnectionFactory

use of org.firebirdsql.jaybird.xca.FBManagedConnectionFactory in project jaybird by FirebirdSQL.

the class FBDriver method connect.

@Override
public FirebirdConnection connect(FirebirdConnectionProperties properties) throws SQLException {
    GDSType type = GDSType.getType(properties.getType());
    if (type == null) {
        type = GDSFactory.getDefaultGDSType();
    }
    FBManagedConnectionFactory mcf = new FBManagedConnectionFactory(type, (FBConnectionProperties) properties).canonicalize();
    FBDataSource dataSource = createDataSource(mcf);
    return (FirebirdConnection) dataSource.getConnection(mcf.getUser(), mcf.getPassword());
}
Also used : FBManagedConnectionFactory(org.firebirdsql.jaybird.xca.FBManagedConnectionFactory) GDSType(org.firebirdsql.gds.impl.GDSType)

Example 2 with FBManagedConnectionFactory

use of org.firebirdsql.jaybird.xca.FBManagedConnectionFactory in project jaybird by FirebirdSQL.

the class JDBCUrlPrefixTest method verifyUrl.

@Test
public void verifyUrl() throws SQLException {
    String url = getUrl();
    try (Connection connection = DriverManager.getConnection(url, getDefaultPropertiesForConnection())) {
        assertTrue("connection isValid", connection.isValid(500));
        FBConnection fbConnection = connection.unwrap(FBConnection.class);
        FBManagedConnectionFactory fbManagedConnectionFactory = (FBManagedConnectionFactory) fbConnection.getManagedConnection().getManagedConnectionFactory();
        String actualType = fbManagedConnectionFactory.getType();
        assertEquals("unexpected GDS type", expectedType, actualType);
    }
}
Also used : FBManagedConnectionFactory(org.firebirdsql.jaybird.xca.FBManagedConnectionFactory) Connection(java.sql.Connection) FBTestProperties.getDefaultPropertiesForConnection(org.firebirdsql.common.FBTestProperties.getDefaultPropertiesForConnection) Test(org.junit.Test)

Example 3 with FBManagedConnectionFactory

use of org.firebirdsql.jaybird.xca.FBManagedConnectionFactory in project jaybird by FirebirdSQL.

the class FBSimpleDataSourceTest method cannotChangeConfigAfterConnectionCreation_usingSharedMCF.

@Test
public void cannotChangeConfigAfterConnectionCreation_usingSharedMCF() throws Exception {
    FBManagedConnectionFactory mcf = new FBManagedConnectionFactory();
    FBSimpleDataSource ds = new FBSimpleDataSource(mcf);
    ds.setDatabaseName(FBTestProperties.DB_DATASOURCE_URL);
    ds.setUser(FBTestProperties.DB_USER);
    ds.setPassword(FBTestProperties.DB_PASSWORD);
    ds.setType(FBTestProperties.getGdsType().toString());
    // possible before connecting
    ds.setBlobBufferSize(1024);
    try (Connection connection = ds.getConnection()) {
        assertTrue(connection.isValid(1000));
    }
    expectedException.expect(IllegalStateException.class);
    // not possible after creating a connection
    ds.setBlobBufferSize(2048);
}
Also used : FBManagedConnectionFactory(org.firebirdsql.jaybird.xca.FBManagedConnectionFactory) Connection(java.sql.Connection) FirebirdConnection(org.firebirdsql.jdbc.FirebirdConnection) Test(org.junit.Test)

Example 4 with FBManagedConnectionFactory

use of org.firebirdsql.jaybird.xca.FBManagedConnectionFactory in project jaybird by FirebirdSQL.

the class FBDriver method connect.

@Override
public Connection connect(String url, final Properties info) throws SQLException {
    if (url == null) {
        throw new SQLException("url is null");
    }
    final GDSType type = GDSFactory.getTypeForProtocol(url);
    if (type == null) {
        return null;
    }
    final Map<String, String> mergedProperties = mergeProperties(url, info);
    try {
        int qMarkIndex = url.indexOf('?');
        if (qMarkIndex != -1) {
            url = url.substring(0, qMarkIndex);
        }
        FBManagedConnectionFactory mcf = new FBManagedConnectionFactory(type);
        String databaseURL = GDSFactory.getDatabasePath(type, url);
        // NOTE: occurrence of an explicit connection property may override this
        mcf.setDatabaseName(databaseURL);
        for (Map.Entry<String, String> entry : mergedProperties.entrySet()) {
            try {
                mcf.setProperty(entry.getKey(), entry.getValue());
            } catch (InvalidPropertyValueException e) {
                throw e.asSQLException();
            }
        }
        FBTpbMapper.processMapping(mcf, mergedProperties);
        mcf = mcf.canonicalize();
        FBDataSource dataSource = createDataSource(mcf);
        return dataSource.getConnection(mcf.getUser(), mcf.getPassword());
    } catch (GDSException e) {
        throw new FBSQLException(e);
    }
}
Also used : FBManagedConnectionFactory(org.firebirdsql.jaybird.xca.FBManagedConnectionFactory) InvalidPropertyValueException(org.firebirdsql.jaybird.props.InvalidPropertyValueException) GDSException(org.firebirdsql.gds.GDSException) GDSType(org.firebirdsql.gds.impl.GDSType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with FBManagedConnectionFactory

use of org.firebirdsql.jaybird.xca.FBManagedConnectionFactory in project jaybird by FirebirdSQL.

the class TestUseFirebirdAutocommit method checkFirebirdAutocommitValue.

private void checkFirebirdAutocommitValue(String url, boolean expectedUseFirebirdAutocommit) throws SQLException {
    try (FBConnection connection = (FBConnection) DriverManager.getConnection(url, FBTestProperties.DB_USER, FBTestProperties.DB_PASSWORD)) {
        FBManagedConnectionFactory managedConnectionFactory = connection.getManagedConnection().getManagedConnectionFactory();
        assertEquals("useFirebirdAutocommit", expectedUseFirebirdAutocommit, managedConnectionFactory.isUseFirebirdAutocommit());
    }
}
Also used : FBManagedConnectionFactory(org.firebirdsql.jaybird.xca.FBManagedConnectionFactory)

Aggregations

FBManagedConnectionFactory (org.firebirdsql.jaybird.xca.FBManagedConnectionFactory)7 GDSType (org.firebirdsql.gds.impl.GDSType)3 Connection (java.sql.Connection)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 FBTestProperties.getDefaultPropertiesForConnection (org.firebirdsql.common.FBTestProperties.getDefaultPropertiesForConnection)1 GDSException (org.firebirdsql.gds.GDSException)1 InvalidPropertyValueException (org.firebirdsql.jaybird.props.InvalidPropertyValueException)1 FirebirdConnection (org.firebirdsql.jdbc.FirebirdConnection)1