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());
}
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);
}
}
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);
}
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);
}
}
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());
}
}
Aggregations