本文整理汇总了Java中org.apache.commons.dbcp.DelegatingConnection类的典型用法代码示例。如果您正苦于以下问题:Java DelegatingConnection类的具体用法?Java DelegatingConnection怎么用?Java DelegatingConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DelegatingConnection类属于org.apache.commons.dbcp包,在下文中一共展示了DelegatingConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: equals
import org.apache.commons.dbcp.DelegatingConnection; //导入依赖的package包/类
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
Connection conn = super.getInnermostDelegate();
if (conn == null) {
return false;
}
if (obj instanceof DelegatingConnection) {
DelegatingConnection c = (DelegatingConnection) obj;
return c.innermostDelegateEquals(conn);
} else {
return conn.equals(obj);
}
}
示例2: getGoodConnection
import org.apache.commons.dbcp.DelegatingConnection; //导入依赖的package包/类
/**
* This method gets a {@link Connection} from the {@link DataSource} and checks if it is a {@link oracle.jdbc.driver.OracleConnection}.
* There is a bug with commons-dbcp 1.4: if you want to create a {@link oracle.sql.BLOB} or a {@link java.sql.Clob} than you must get the inner {@link Connection} but you get another {@link Connection}.
* This is fixed in this method.
* @param connection
* @param dataSource
* @return
*/
public static Connection getGoodConnection(Connection connection, DataSource dataSource) {
if (dataSource instanceof BasicDataSource) {
BasicDataSource tempDataSource = (BasicDataSource) dataSource;
if (tempDataSource.getDriverClassName().toLowerCase().contains("oracle") && connection instanceof DelegatingConnection) {
boolean canAccess = tempDataSource.isAccessToUnderlyingConnectionAllowed();
if (!canAccess) {
tempDataSource.setAccessToUnderlyingConnectionAllowed(true);
}
DelegatingConnection tempConnection = (DelegatingConnection) connection;
Connection innermostDelegate = tempConnection.getInnermostDelegate();
if (!canAccess) {
tempDataSource.setAccessToUnderlyingConnectionAllowed(false);
}
return innermostDelegate;
}
}
return connection;
}
示例3: getProxyConnection
import org.apache.commons.dbcp.DelegatingConnection; //导入依赖的package包/类
/**
* returns a proxy database connection.
*
* @param ds
* @param dataId
* @return
* @throws SQLException
*/
public static Connection getProxyConnection(DataSource ds,
DataIdentifier dataId) throws SQLException {
Connection conn = ds.getConnection();
//for OracleConnection
if (((DelegatingConnection) conn).getInnermostDelegate() instanceof OracleConnection) {
Properties properties = getOracleProxyConnectionProperties(dataId);
OracleConnection oracleConnection = (OracleConnection) ((DelegatingConnection) conn).getInnermostDelegate();
oracleConnection.openProxySession(OracleConnection.PROXYTYPE_USER_NAME,
properties);
conn = oracleConnection;
}
return conn;
}
示例4: executeApp
import org.apache.commons.dbcp.DelegatingConnection; //导入依赖的package包/类
@Override
public void executeApp() throws Exception {
Connection connection = Connections.createConnection();
delegatingConnection = new DelegatingConnection(connection) {
@Override
public Statement createStatement() throws SQLException {
return new DelegatingStatement(this, super.createStatement()) {
@Override
public boolean execute(String sql) throws SQLException {
return super.execute("select 1 from employee");
}
};
}
};
try {
transactionMarker();
} finally {
Connections.closeConnection(connection);
}
}
示例5: executeApp
import org.apache.commons.dbcp.DelegatingConnection; //导入依赖的package包/类
@Override
public void executeApp() throws Exception {
Connection connection = Connections.createConnection();
delegatingConnection = new DelegatingConnection(connection) {
@Override
public Statement createStatement() throws SQLException {
return new DelegatingStatement(this, super.createStatement()) {
@Override
public void addBatch(String sql) throws SQLException {
super.addBatch("insert into employee (name) values ('1')");
}
};
}
};
try {
transactionMarker();
} finally {
Connections.closeConnection(connection);
}
}
示例6: executeApp
import org.apache.commons.dbcp.DelegatingConnection; //导入依赖的package包/类
@Override
public void executeApp() throws Exception {
connection = new DelegatingConnection(Connections.createConnection()) {
@Override
public void commit() throws SQLException {
throw new SQLException("A commit failure");
}
@Override
public void rollback() throws SQLException {
throw new SQLException("A rollback failure");
}
};
connection.setAutoCommit(false);
try {
transactionMarker();
} finally {
Connections.closeConnection(connection);
}
}
示例7: executeApp
import org.apache.commons.dbcp.DelegatingConnection; //导入依赖的package包/类
@Override
public void executeApp() throws Exception {
Connection connection = Connections.createConnection();
delegatingConnection = new DelegatingConnection(connection) {
@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {
return new DelegatingPreparedStatement(this, super.prepareStatement(sql)) {
@Override
public boolean execute() throws SQLException {
throw new SQLException("An execute failure");
}
};
}
};
try {
transactionMarker();
} finally {
Connections.closeConnection(connection);
}
}
示例8: testManagedConnectionEqualsSameDelegateNoUnderlyingAccess
import org.apache.commons.dbcp.DelegatingConnection; //导入依赖的package包/类
public void testManagedConnectionEqualsSameDelegateNoUnderlyingAccess() throws Exception {
// Get a maximal set of connections from the pool
Connection[] c = new Connection[getMaxActive()];
for (int i = 0; i < c.length; i++) {
c[i] = newConnection();
}
// Close the delegate of one wrapper in the pool
((DelegatingConnection) c[0]).getDelegate().close();
// Disable access for the new connection
ds.setAccessToUnderlyingConnectionAllowed(false);
// Grab a new connection - should get c[0]'s closed connection
// so should be delegate-equivalent, so equal
Connection con = newConnection();
assertTrue(c[0].equals(con));
assertTrue(con.equals(c[0]));
for (int i = 0; i < c.length; i++) {
c[i].close();
}
ds.setAccessToUnderlyingConnectionAllowed(true);
}
示例9: testManagedConnectionEqualsSameDelegate
import org.apache.commons.dbcp.DelegatingConnection; //导入依赖的package包/类
public void testManagedConnectionEqualsSameDelegate() throws Exception {
// Get a maximal set of connections from the pool
Connection[] c = new Connection[getMaxActive()];
for (int i = 0; i < c.length; i++) {
c[i] = newConnection();
}
// Close the delegate of one wrapper in the pool
((DelegatingConnection) c[0]).getDelegate().close();
// Grab a new connection - should get c[0]'s closed connection
// so should be delegate-equivalent, so equal
Connection con = newConnection();
assertTrue(c[0].equals(con));
assertTrue(con.equals(c[0]));
for (int i = 0; i < c.length; i++) {
c[i].close();
}
}
示例10: SphexDelegatingPreparedStatement
import org.apache.commons.dbcp.DelegatingConnection; //导入依赖的package包/类
public SphexDelegatingPreparedStatement(DelegatingConnection c, PreparedStatement s,
String sql, String url, List<Interceptor> interceptors) {
super(c, s);
this.sql = sql;
this.url = url;
this.interceptors = interceptors;
}
示例11: executeApp
import org.apache.commons.dbcp.DelegatingConnection; //导入依赖的package包/类
@Override
public void executeApp() throws Exception {
dataSource = new BasicDataSource() {
private boolean first = true;
@Override
public Connection getConnection() throws SQLException {
if (first) {
// BasicDataSource opens and closes a test connection on first
// getConnection()
first = false;
return super.getConnection();
}
return new DelegatingConnection(super.getConnection()) {
@Override
public void close() throws SQLException {
throw new SQLException("A close failure");
}
};
}
};
dataSource.setDriverClassName("org.hsqldb.jdbc.JDBCDriver");
dataSource.setUrl("jdbc:hsqldb:mem:test");
// BasicDataSource opens and closes a test connection on first getConnection(),
// so just getting that out of the way before starting transaction
dataSource.getConnection().close();
transactionMarker();
}
示例12: PooledConnectionImpl
import org.apache.commons.dbcp.DelegatingConnection; //导入依赖的package包/类
/**
* Wrap the real connection.
* @param connection the connection to be wrapped
* @param pool the pool to use
*/
PooledConnectionImpl(Connection connection, KeyedObjectPool pool) {
this.connection = connection;
if (connection instanceof DelegatingConnection) {
this.delegatingConnection = (DelegatingConnection) connection;
} else {
this.delegatingConnection = new DelegatingConnection(connection);
}
eventListeners = new Vector();
isClosed = false;
if (pool != null) {
pstmtPool = pool;
pstmtPool.setFactory(this);
}
}
示例13: testSharedConnection
import org.apache.commons.dbcp.DelegatingConnection; //导入依赖的package包/类
/**
* Verify that conection sharing is working (or not working) as expected.
*/
public void testSharedConnection() throws Exception {
DelegatingConnection connectionA = (DelegatingConnection) newConnection();
DelegatingConnection connectionB = (DelegatingConnection) newConnection();
assertFalse(connectionA.equals(connectionB));
assertFalse(connectionB.equals(connectionA));
assertFalse(connectionA.innermostDelegateEquals(connectionB.getInnermostDelegate()));
assertFalse(connectionB.innermostDelegateEquals(connectionA.getInnermostDelegate()));
connectionA.close();
connectionB.close();
}
示例14: testManagedConnectionEqualInnermost
import org.apache.commons.dbcp.DelegatingConnection; //导入依赖的package包/类
public void testManagedConnectionEqualInnermost() throws Exception {
ds.setAccessToUnderlyingConnectionAllowed(true);
DelegatingConnection con = (DelegatingConnection) ds.getConnection();
Connection inner = con.getInnermostDelegate();
ds.setAccessToUnderlyingConnectionAllowed(false);
DelegatingConnection con2 = new DelegatingConnection(inner);
assertTrue(con2.equals(con));
assertTrue(con.innermostDelegateEquals(con2.getInnermostDelegate()));
assertTrue(con2.innermostDelegateEquals(inner));
assertTrue(con.equals(con2));
}
示例15: testSharedConnection
import org.apache.commons.dbcp.DelegatingConnection; //导入依赖的package包/类
public void testSharedConnection() throws Exception {
DelegatingConnection connectionA = (DelegatingConnection) newConnection();
DelegatingConnection connectionB = (DelegatingConnection) newConnection();
assertTrue(connectionA.equals(connectionB));
assertTrue(connectionB.equals(connectionA));
assertTrue(connectionA.innermostDelegateEquals(connectionB.getInnermostDelegate()));
assertTrue(connectionB.innermostDelegateEquals(connectionA.getInnermostDelegate()));
connectionA.close();
connectionB.close();
}