use of com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource in project kafka-connect-cdc-mssql by jcustenborder.
the class MsSqlConnectionPoolDataSourceFactory method connectionPool.
@Override
public ConnectionPoolDataSource connectionPool(ConnectionKey connectionKey) throws SQLException {
SQLServerConnectionPoolDataSource dataSource = new SQLServerConnectionPoolDataSource();
dataSource.setServerName(this.config.serverName);
dataSource.setPortNumber(this.config.serverPort);
dataSource.setUser(this.config.jdbcUsername);
dataSource.setPassword(this.config.jdbcPassword);
dataSource.setMultiSubnetFailover(this.config.multiSubnetFailover);
if (Strings.isNullOrEmpty(connectionKey.databaseName)) {
dataSource.setDatabaseName(this.config.initialDatabase);
} else {
dataSource.setDatabaseName(connectionKey.databaseName);
}
return dataSource;
}
use of com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource in project siesta by cadenzauk.
the class SqlServerConfig method dataSource.
@Bean
public DataSource dataSource() throws SQLException {
SQLServerConnectionPoolDataSource pool = new SQLServerConnectionPoolDataSource();
pool.setServerName("localhost\\SQLEXPRESS");
pool.setDatabaseName("SIESTA");
pool.setIntegratedSecurity(true);
return new PooledDataSource(pool);
}
use of com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource in project mssql-jdbc by Microsoft.
the class ConnectionDriverTest method testConnectionEvents.
/**
* Attach the Event listener and listen for connection events, fatal errors should not close the pooled connection objects
*
* @throws SQLException
*/
@Test
public void testConnectionEvents() throws SQLException {
assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)), "Skipping test case on Azure SQL.");
SQLServerConnectionPoolDataSource mds = new SQLServerConnectionPoolDataSource();
mds.setURL(connectionString);
PooledConnection pooledConnection = mds.getPooledConnection();
// Attach the Event listener and listen for connection events.
MyEventListener myE = new MyEventListener();
// ConnectionListener implements ConnectionEventListener
pooledConnection.addConnectionEventListener(myE);
try (Connection con = pooledConnection.getConnection();
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) {
boolean exceptionThrown = false;
try {
// raise a severe exception and make sure that the connection is not
// closed.
stmt.executeUpdate("RAISERROR ('foo', 20,1) WITH LOG");
} catch (Exception e) {
exceptionThrown = true;
}
assertTrue(exceptionThrown, "Expected exception is not thrown.");
// Check to see if error occurred.
assertTrue(myE.errorOccurred, "Error occurred is not called.");
}
// make sure that connection is closed.
}
use of com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource in project mssql-jdbc by Microsoft.
the class ConnectionDriverTest method testConnectionPoolGetTwice.
@Test
public void testConnectionPoolGetTwice() throws SQLException {
assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)), "Skipping test case on Azure SQL.");
SQLServerConnectionPoolDataSource mds = new SQLServerConnectionPoolDataSource();
mds.setURL(connectionString);
PooledConnection pooledConnection = mds.getPooledConnection();
// Attach the Event listener and listen for connection events.
MyEventListener myE = new MyEventListener();
// ConnectionListener implements ConnectionEventListener
pooledConnection.addConnectionEventListener(myE);
Connection con = pooledConnection.getConnection();
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
// raise a non severe exception and make sure that the connection is not closed.
stmt.executeUpdate("RAISERROR ('foo', 3,1) WITH LOG");
// not a serious error there should not be any errors.
assertTrue(!myE.errorOccurred, "Error occurred is called.");
// check to make sure that connection is not closed.
assertTrue(!con.isClosed(), "Connection is closed.");
stmt.close();
con.close();
// check to make sure that connection is closed.
assertTrue(con.isClosed(), "Connection is not closed.");
}
use of com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource in project mssql-jdbc by Microsoft.
the class NativeMSSQLDataSourceTest method testInterfaceWrapping.
@Test
public void testInterfaceWrapping() throws ClassNotFoundException, SQLException {
SQLServerDataSource ds = new SQLServerDataSource();
assertEquals(true, ds.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerDataSource")));
assertEquals(true, ds.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDataSource")));
assertEquals(true, ds.isWrapperFor(Class.forName("javax.sql.CommonDataSource")));
ISQLServerDataSource ids = (ISQLServerDataSource) (ds.unwrap(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerDataSource")));
ids.setApplicationName("AppName");
SQLServerConnectionPoolDataSource poolDS = new SQLServerConnectionPoolDataSource();
assertEquals(true, poolDS.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerDataSource")));
assertEquals(true, poolDS.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDataSource")));
assertEquals(true, poolDS.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource")));
assertEquals(true, poolDS.isWrapperFor(Class.forName("javax.sql.CommonDataSource")));
ISQLServerDataSource ids2 = (ISQLServerDataSource) (poolDS.unwrap(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerDataSource")));
ids2.setApplicationName("AppName");
SQLServerXADataSource xaDS = new SQLServerXADataSource();
assertEquals(true, xaDS.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerDataSource")));
assertEquals(true, xaDS.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDataSource")));
assertEquals(true, xaDS.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource")));
assertEquals(true, xaDS.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerXADataSource")));
assertEquals(true, xaDS.isWrapperFor(Class.forName("javax.sql.CommonDataSource")));
ISQLServerDataSource ids3 = (ISQLServerDataSource) (xaDS.unwrap(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerDataSource")));
ids3.setApplicationName("AppName");
}
Aggregations