Search in sources :

Example 1 with ISQLServerConnection

use of com.microsoft.sqlserver.jdbc.ISQLServerConnection in project mssql-jdbc by Microsoft.

the class ConnectionDriverTest method testIsWrapperFor.

@Test
public void testIsWrapperFor() throws SQLException, ClassNotFoundException {
    try (Connection conn = DriverManager.getConnection(connectionString);
        SQLServerConnection ssconn = (SQLServerConnection) conn) {
        boolean isWrapper;
        isWrapper = ssconn.isWrapperFor(ssconn.getClass());
        assertTrue(isWrapper, "SQLServerConnection supports unwrapping");
        assertEquals(ssconn.TRANSACTION_SNAPSHOT, ssconn.TRANSACTION_SNAPSHOT, "Cant access the TRANSACTION_SNAPSHOT ");
        isWrapper = ssconn.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerConnection"));
        assertTrue(isWrapper, "ISQLServerConnection supports unwrapping");
        ISQLServerConnection iSql = (ISQLServerConnection) ssconn.unwrap(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerConnection"));
        assertEquals(iSql.TRANSACTION_SNAPSHOT, iSql.TRANSACTION_SNAPSHOT, "Cant access the TRANSACTION_SNAPSHOT ");
        ssconn.unwrap(Class.forName("java.sql.Connection"));
    }
}
Also used : SQLServerConnection(com.microsoft.sqlserver.jdbc.SQLServerConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) 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 2 with ISQLServerConnection

use of com.microsoft.sqlserver.jdbc.ISQLServerConnection in project mssql-jdbc by Microsoft.

the class PoolingTest method testConnectionPoolClientConnectionId.

@Test
public void testConnectionPoolClientConnectionId() throws SQLException {
    SQLServerXADataSource ds = new SQLServerXADataSource();
    ds.setURL(connectionString);
    PooledConnection pc = ds.getPooledConnection();
    ISQLServerConnection con = (ISQLServerConnection) pc.getConnection();
    UUID Id1 = con.getClientConnectionId();
    assertTrue(Id1 != null, "Unexecepted: ClientConnectionId is null from Pool");
    con.close();
    // now reget the connection
    ISQLServerConnection con2 = (ISQLServerConnection) pc.getConnection();
    UUID Id2 = con2.getClientConnectionId();
    con2.close();
    assertEquals(Id1, Id2, "ClientConnection Ids from pool are not the same.");
}
Also used : PooledConnection(javax.sql.PooledConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) UUID(java.util.UUID) SQLServerXADataSource(com.microsoft.sqlserver.jdbc.SQLServerXADataSource) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) Test(org.junit.jupiter.api.Test)

Aggregations

ISQLServerConnection (com.microsoft.sqlserver.jdbc.ISQLServerConnection)2 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)2 PooledConnection (javax.sql.PooledConnection)2 Test (org.junit.jupiter.api.Test)2 SQLServerConnection (com.microsoft.sqlserver.jdbc.SQLServerConnection)1 SQLServerXADataSource (com.microsoft.sqlserver.jdbc.SQLServerXADataSource)1 DBConnection (com.microsoft.sqlserver.testframework.DBConnection)1 Connection (java.sql.Connection)1 UUID (java.util.UUID)1