use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.DefaultPooledObject in project cuba by cuba-platform.
the class AbstractScripting method getPool.
private synchronized GenericKeyedObjectPool<String, Script> getPool() {
if (pool == null) {
GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
poolConfig.setMaxTotalPerKey(-1);
poolConfig.setMaxIdlePerKey(globalConfig.getGroovyEvaluationPoolMaxIdle());
pool = new GenericKeyedObjectPool<>(new BaseKeyedPooledObjectFactory<String, Script>() {
@Override
public Script create(String key) throws Exception {
return createScript(key);
}
@Override
public PooledObject<Script> wrap(Script value) {
return new DefaultPooledObject<>(value);
}
}, poolConfig);
}
return pool;
}
use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.DefaultPooledObject in project datanucleus-rdbms by datanucleus.
the class KeyedCPDSConnectionFactory method makeObject.
/**
* Creates a new {@link PooledConnectionAndInfo} from the given {@link UserPassKey}.
*
* @param upkey {@link UserPassKey} containing user credentials
* @throws SQLException if the connection could not be created.
* @see org.datanucleus.store.rdbms.datasource.dbcp2.pool2.KeyedPooledObjectFactory#makeObject(java.lang.Object)
*/
@Override
public synchronized PooledObject<PooledConnectionAndInfo> makeObject(UserPassKey upkey) throws Exception {
PooledConnectionAndInfo pci = null;
PooledConnection pc = null;
String username = upkey.getUsername();
String password = upkey.getPassword();
if (username == null) {
pc = _cpds.getPooledConnection();
} else {
pc = _cpds.getPooledConnection(username, password);
}
if (pc == null) {
throw new IllegalStateException("Connection pool data source returned null from getPooledConnection");
}
// should we add this object as a listener or the pool.
// consider the validateObject method in decision
pc.addConnectionEventListener(this);
pci = new PooledConnectionAndInfo(pc, username, password);
pcMap.put(pc, pci);
return new DefaultPooledObject<>(pci);
}
use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.DefaultPooledObject in project datanucleus-rdbms by datanucleus.
the class CPDSConnectionFactory method makeObject.
@Override
public synchronized PooledObject<PooledConnectionAndInfo> makeObject() {
PooledConnectionAndInfo pci;
try {
PooledConnection pc = null;
if (_username == null) {
pc = _cpds.getPooledConnection();
} else {
pc = _cpds.getPooledConnection(_username, _password);
}
if (pc == null) {
throw new IllegalStateException("Connection pool data source returned null from getPooledConnection");
}
// should we add this object as a listener or the pool.
// consider the validateObject method in decision
pc.addConnectionEventListener(this);
pci = new PooledConnectionAndInfo(pc, _username, _password);
pcMap.put(pc, pci);
} catch (SQLException e) {
throw new RuntimeException(e.getMessage());
}
return new DefaultPooledObject<>(pci);
}
use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.DefaultPooledObject in project x-pipe by ctripcorp.
the class NettyClientFactory method makeObject.
@Override
public PooledObject<NettyClient> makeObject() throws Exception {
ChannelFuture f = b.connect(address);
f.get(connectTimeoutMilli, TimeUnit.MILLISECONDS);
Channel channel = f.channel();
logger.info("[makeObject]{}", channel);
NettyClient nettyClient = new DefaultNettyClient(channel);
channel.attr(NettyClientHandler.KEY_CLIENT).set(nettyClient);
return new DefaultPooledObject<NettyClient>(nettyClient);
}
use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.DefaultPooledObject in project tomcat by apache.
the class PoolingConnection method makeObject.
/**
* {@link KeyedPooledObjectFactory} method for creating {@link PoolablePreparedStatement}s or
* {@link PoolableCallableStatement}s. The <code>stmtType</code> field in the key determines whether a
* PoolablePreparedStatement or PoolableCallableStatement is created.
*
* @param key
* the key for the {@link PreparedStatement} to be created
* @see #createKey(String, int, int, StatementType)
*/
@Override
public PooledObject<DelegatingPreparedStatement> makeObject(final PStmtKey key) throws Exception {
if (null == key) {
throw new IllegalArgumentException("Prepared statement key is null or invalid.");
}
if (key.getStmtType() == StatementType.PREPARED_STATEMENT) {
final PreparedStatement statement = (PreparedStatement) key.createStatement(getDelegate());
// Unable to find way to avoid this
@SuppressWarnings({ "rawtypes", "unchecked" }) final PoolablePreparedStatement pps = new PoolablePreparedStatement(statement, key, pstmtPool, this);
return new DefaultPooledObject<>(pps);
}
final CallableStatement statement = (CallableStatement) key.createStatement(getDelegate());
final PoolableCallableStatement pcs = new PoolableCallableStatement(statement, key, pstmtPool, this);
return new DefaultPooledObject<>(pcs);
}
Aggregations