Search in sources :

Example 1 with SQLServerConnectionPoolDataSource

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;
}
Also used : SQLServerConnectionPoolDataSource(com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource)

Example 2 with SQLServerConnectionPoolDataSource

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);
}
Also used : SQLServerConnectionPoolDataSource(com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource) PooledDataSource(com.cadenzauk.core.sql.testutil.PooledDataSource) Bean(org.springframework.context.annotation.Bean)

Example 3 with SQLServerConnectionPoolDataSource

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.
}
Also used : PooledConnection(javax.sql.PooledConnection) SQLServerConnectionPoolDataSource(com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource) Statement(java.sql.Statement) Connection(java.sql.Connection) PooledConnection(javax.sql.PooledConnection) SQLServerConnection(com.microsoft.sqlserver.jdbc.SQLServerConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) DBConnection(com.microsoft.sqlserver.testframework.DBConnection) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) Test(org.junit.jupiter.api.Test)

Example 4 with SQLServerConnectionPoolDataSource

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.");
}
Also used : PooledConnection(javax.sql.PooledConnection) SQLServerConnectionPoolDataSource(com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource) Statement(java.sql.Statement) Connection(java.sql.Connection) PooledConnection(javax.sql.PooledConnection) SQLServerConnection(com.microsoft.sqlserver.jdbc.SQLServerConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) DBConnection(com.microsoft.sqlserver.testframework.DBConnection) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) Test(org.junit.jupiter.api.Test)

Example 5 with SQLServerConnectionPoolDataSource

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");
}
Also used : SQLServerConnectionPoolDataSource(com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource) ISQLServerDataSource(com.microsoft.sqlserver.jdbc.ISQLServerDataSource) SQLServerDataSource(com.microsoft.sqlserver.jdbc.SQLServerDataSource) ISQLServerDataSource(com.microsoft.sqlserver.jdbc.ISQLServerDataSource) SQLServerXADataSource(com.microsoft.sqlserver.jdbc.SQLServerXADataSource) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Aggregations

SQLServerConnectionPoolDataSource (com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource)5 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)3 Test (org.junit.jupiter.api.Test)3 ISQLServerConnection (com.microsoft.sqlserver.jdbc.ISQLServerConnection)2 SQLServerConnection (com.microsoft.sqlserver.jdbc.SQLServerConnection)2 DBConnection (com.microsoft.sqlserver.testframework.DBConnection)2 Connection (java.sql.Connection)2 Statement (java.sql.Statement)2 PooledConnection (javax.sql.PooledConnection)2 PooledDataSource (com.cadenzauk.core.sql.testutil.PooledDataSource)1 ISQLServerDataSource (com.microsoft.sqlserver.jdbc.ISQLServerDataSource)1 SQLServerDataSource (com.microsoft.sqlserver.jdbc.SQLServerDataSource)1 SQLServerXADataSource (com.microsoft.sqlserver.jdbc.SQLServerXADataSource)1 SQLException (java.sql.SQLException)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 Bean (org.springframework.context.annotation.Bean)1