use of org.apache.derby.iapi.jdbc.EngineConnection in project derby by apache.
the class Database method makeConnection.
/**
* Make a new connection using the database name and set
* the connection in the database
* @param p Properties for connection attributes to pass to connect
*/
void makeConnection(Properties p) throws SQLException {
p.put(Attribute.USERNAME_ATTR, userId);
// take care of case of SECMEC_USRIDONL
if (password != null)
p.put(Attribute.PASSWORD_ATTR, password);
// Contract between network server and embedded engine
// is that any connection returned implements EngineConnection.
EngineConnection conn = (EngineConnection) NetworkServerControlImpl.getDriver().connect(Attribute.PROTOCOL + shortDbName + attrString, p);
if (conn != null) {
conn.setAutoCommit(false);
}
setConnection(conn);
}
use of org.apache.derby.iapi.jdbc.EngineConnection in project derby by apache.
the class XADatabase method makeConnection.
/**
* Make a new connection using the database name and set
* the connection in the database
* @throws java.sql.SQLException
*/
@Override
synchronized void makeConnection(Properties p) throws SQLException {
if (xaDataSource == null) {
Class<?> clazz;
try {
if (JVMInfo.hasJNDI()) {
clazz = Class.forName("org.apache.derby.jdbc.EmbeddedXADataSource");
xaDataSource = (EmbeddedXADataSourceInterface) clazz.getConstructor().newInstance();
} else {
clazz = Class.forName("org.apache.derby.jdbc.BasicEmbeddedXADataSource40");
xaDataSource = (EmbeddedXADataSourceInterface) clazz.getConstructor().newInstance();
}
} catch (Exception e) {
SQLException ne = new SQLException(MessageService.getTextMessage(MessageId.CORE_DATABASE_NOT_AVAILABLE), "08006", ExceptionSeverity.DATABASE_SEVERITY);
ne.initCause(e);
throw ne;
}
}
xaDataSource.setDatabaseName(getShortDbName());
appendAttrString(p);
if (attrString != null)
xaDataSource.setConnectionAttributes(attrString);
EngineConnection conn = getConnection();
// If we have no existing connection. this is a brand new XAConnection.
if (conn == null) {
xaConnection = xaDataSource.getXAConnection(userId, password);
ra = xaDataSource.getResourceAdapter();
setXAResource(xaConnection.getXAResource());
} else // this is just a connection reset. Close the logical connection.
{
conn.close();
}
// Get a new logical connection.
// Contract between network server and embedded engine
// is that any connection returned implements EngineConnection.
conn = (EngineConnection) xaConnection.getConnection();
// Client will always drive the commits so connection should
// always be autocommit false on the server. DERBY-898/DERBY-899
conn.setAutoCommit(false);
setConnection(conn);
}
use of org.apache.derby.iapi.jdbc.EngineConnection in project derby by apache.
the class EmbedXAConnection method getRealConnection.
/**
* Override getRealConnection to create a a local connection
* when we are not associated with an XA transaction.
*
* This can occur if the application has a Connection object (conn)
* and the following sequence occurs.
*
* conn = xac.getConnection();
* xac.start(xid, ...)
*
* // do work with conn
*
* xac.end(xid, ...);
*
* // do local work with conn
* // need to create new connection here.
*/
public EngineConnection getRealConnection() throws SQLException {
EngineConnection rc = super.getRealConnection();
if (rc != null)
return rc;
openRealConnection();
// a new Connection, set its state according to the application's Connection handle
currentConnectionHandle.setState(true);
return realConnection;
}
use of org.apache.derby.iapi.jdbc.EngineConnection in project jackrabbit by apache.
the class ConnectionFactoryTest method testUnwrap.
public void testUnwrap() throws Exception {
DataSource ds = connectionFactory.getDataSource(DRIVER, DERBY_URL, "user", "password");
Connection wrappedCon = ds.getConnection();
assertNotNull(wrappedCon);
Connection con = ConnectionFactory.unwrap(wrappedCon);
assertTrue(con instanceof EngineConnection);
}
Aggregations