本文整理汇总了Java中java.sql.Connection.unwrap方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.unwrap方法的具体用法?Java Connection.unwrap怎么用?Java Connection.unwrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.Connection
的用法示例。
在下文中一共展示了Connection.unwrap方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDataSourceTest
import java.sql.Connection; //导入方法依赖的package包/类
@Test
public void createDataSourceTest() throws SQLException
{
CloudSpannerDataSource subject = new CloudSpannerDataSource();
subject.setProjectId("helpful-adroit-123456");
subject.setInstanceId("test-instance");
subject.setDatabase("test");
subject.setPvtKeyPath("C:\\Users\\MyUserName\\Documents\\CloudSpannerKeys\\cloudspanner-key.json");
subject.setPvtKeyPath(null);
subject.setOauthAccessToken("TEST");
subject.setSimulateProductName("PostgreSQL");
subject.setAllowExtendedMode(true);
subject.setLoginTimeout(10);
subject.setLogWriter(new PrintWriter(System.out));
Connection con = subject.getConnection();
Assert.assertNotNull(con);
Assert.assertTrue(con.isWrapperFor(CloudSpannerConnection.class));
CloudSpannerConnection connection = con.unwrap(CloudSpannerConnection.class);
Assert.assertEquals("jdbc:cloudspanner://localhost", connection.getUrl());
Assert.assertEquals("PostgreSQL", connection.getProductName());
Assert.assertEquals("helpful-adroit-123456", connection.getSuppliedProperties().getProperty("Project"));
Assert.assertEquals("test-instance", connection.getSuppliedProperties().getProperty("Instance"));
Assert.assertEquals("test", connection.getSuppliedProperties().getProperty("Database"));
Assert.assertEquals("TEST", connection.getSuppliedProperties().getProperty("OAuthAccessToken"));
Assert.assertTrue(connection.isAllowExtendedMode());
}
示例2: testSuspect
import java.sql.Connection; //导入方法依赖的package包/类
@Test
public void testSuspect() throws Exception {
this.datasource.setMaxActive(100);
this.datasource.setMaxIdle(100);
this.datasource.setInitialSize(0);
this.datasource.getPoolProperties().setAbandonWhenPercentageFull(0);
this.datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(100);
this.datasource.getPoolProperties().setRemoveAbandoned(true);
this.datasource.getPoolProperties().setRemoveAbandonedTimeout(100);
this.datasource.getPoolProperties().setSuspectTimeout(1);
this.datasource.getPoolProperties().setLogAbandoned(true);
Connection con = datasource.getConnection();
Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive());
Thread.sleep(3000);
PooledConnection pcon = con.unwrap(PooledConnection.class);
Assert.assertTrue("Connection should be marked suspect",pcon.isSuspect());
con.close();
}
示例3: executeStoredProcedure
import java.sql.Connection; //导入方法依赖的package包/类
protected void executeStoredProcedure(final Connection pooledConnection, final String userid) throws java.sql.SQLException {
CallableStatement cs = null;
final String localId = (String) ContextManagerFactory.instance().getProperty(LOCAL_ID);
Object[] roles = getUserRoles(userid).toArray();
ARRAY newArray = null;
Connection connection = null;
try {
// Extract the actual oracle connection
connection = pooledConnection.unwrap(oracle.jdbc.OracleConnection.class);
if (!(connection instanceof oracle.jdbc.OracleConnection)) {
throw new Exception(String.format("Not an Oracle Connection : %s",connection.getClass().getName()));
}
cs = connection.prepareCall(CALL_JAFFA_SEC_SET_USERID);
cs.setString(1,userid);
newArray = ((oracle.jdbc.OracleConnection)connection).createARRAY(ROLE,roles);
cs.setArray(2,newArray);
cs.setString(3,localId);
if (log.isDebugEnabled()) {
// Log the call to the stored procedure
debugStatement(userid, localId, roles, newArray);
}
if(log.isDebugEnabled()) log.debug("Calling the Stored Procedure to Set the Context");
cs.execute();
connection.commit();
}
catch (Exception exception) {
final String message = String.format(String.format(SET_THE_CONTEXT_ERROR_MESSAGE,exception.getMessage()));
log.error(message, exception);
if (connection != null)
connection.rollback();
throw new UOWSecurityException(message, exception);
}
finally {
roles = null;
if (newArray != null)
newArray.free();
if (cs != null) {
cs.clearParameters();
cs.close();
cs = null;
}
}
}
示例4: isSecurableConnection
import java.sql.Connection; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public boolean isSecurableConnection(Connection connection) {
try {
return connection != null && connection.unwrap(oracle.jdbc.OracleConnection.class) instanceof oracle.jdbc.OracleConnection;
}catch (SQLException e){
return false;
}
}
示例5: getPostgresConnection
import java.sql.Connection; //导入方法依赖的package包/类
private PGConnection getPostgresConnection(Connection conn) throws SQLException {
if (conn instanceof PGConnection) {
return PGConnection.class.cast(conn);
}
return conn.unwrap(PGConnection.class);
}
示例6: doGetNativeConnection
import java.sql.Connection; //导入方法依赖的package包/类
@Override
protected Connection doGetNativeConnection(Connection con) throws SQLException {
return con.unwrap(this.connectionType);
}