use of org.apache.derby.iapi.jdbc.InternalDriver in project derby by apache.
the class SlaveDatabase method handleShutdown.
/**
* Used to shutdown this database.
*
* If an error occurs as part of the database boot process, we
* hand the exception that caused boot to fail to the client
* thread. The client thread will in turn shut down this database.
*
* If an error occurs at a later stage than during boot, we shut
* down the database by setting up a connection with the shutdown
* attribute. The internal connection is required because database
* shutdown requires EmbedConnection to do cleanup.
*
* @param shutdownCause the reason why the database needs to be
* shutdown
*/
private void handleShutdown(StandardException shutdownCause) {
if (inBoot) {
bootException = shutdownCause;
return;
}
try {
shutdownInitiated = true;
String conStr = "jdbc:derby:" + dbname + ";" + Attribute.REPLICATION_INTERNAL_SHUTDOWN_SLAVE + "=true";
InternalDriver driver = InternalDriver.activeDriver();
if (driver != null) {
driver.connect(conStr, (Properties) null, 0);
}
} catch (Exception e) {
// Todo: report error to derby.log if exception is not
// SQLState.SHUTDOWN_DATABASE
}
}
use of org.apache.derby.iapi.jdbc.InternalDriver in project derby by apache.
the class BasicEmbeddedDataSource40 method setupResourceAdapter.
/**
* Return a resource adapter. Use {@code ra} if non-null and active, else
* get the one for the data base.
*
* @param ds The data source
* @param ra The cached value if any
* @param user The user name
* @param password The password in clear text
* @param requestPassword If {@code true}, use the supplied user and
* password to boot the database if required
* @return the resource adapter
* @throws SQLException An error occurred
*/
protected static ResourceAdapter setupResourceAdapter(EmbeddedXADataSourceInterface ds, ResourceAdapter ra, String user, String password, boolean requestPassword) throws SQLException {
synchronized (ds) {
if (ra == null || !ra.isActive()) {
// If it is inactive, it is useless.
ra = null;
// DERBY-4907 make sure the database name sent to find service
// does not include attributes.
String dbName = ((BasicEmbeddedDataSource40) ds).getShortDatabaseName();
if (dbName != null) {
// see if database already booted, if it is, then
// don't make a connection.
Database database = null;
// has been booted.
if (getMonitor() != null) {
database = (Database) findService(Property.DATABASE_MODULE, dbName);
}
if (database == null) {
// database cannot be found, this throws SQLException.
if (requestPassword) {
ds.getConnection(user, password).close();
} else {
ds.getConnection().close();
}
// now try to find it again
database = (Database) findService(Property.DATABASE_MODULE, dbName);
}
if (database != null) {
ra = (ResourceAdapter) database.getResourceAdapter();
}
}
if (ra == null) {
throw new SQLException(MessageService.getTextMessage(MessageId.CORE_DATABASE_NOT_AVAILABLE), "08006", ExceptionSeverity.DATABASE_SEVERITY);
}
// If database is already up, we need to set up driver
// seperately.
InternalDriver driver = ((BasicEmbeddedDataSource40) ds).findDriver();
if (driver == null) {
throw new SQLException(MessageService.getTextMessage(MessageId.CORE_DRIVER_NOT_AVAILABLE), "08006", ExceptionSeverity.DATABASE_SEVERITY);
}
}
}
return ra;
}
use of org.apache.derby.iapi.jdbc.InternalDriver in project derby by apache.
the class BasicEmbeddedDataSource40 method findDriver.
/**
* Return a handle to the internal driver, possibly instantiating it first
* if it hasn't been booted or if it has been shut down.
*
* @return The internal driver handle
* @throws SQLException
*/
@SuppressWarnings("ResultOfObjectAllocationIgnored")
InternalDriver findDriver() throws SQLException {
String url = jdbcurl;
synchronized (this) {
// shutdown by a 'jdbc:derby:;shutdown=true'
if (driver == null || !driver.acceptsURL(url)) {
new org.apache.derby.jdbc.EmbeddedDriver();
// If we know the driver, we loaded it. Otherwise only
// work if DriverManager has already loaded it.
// DriverManager will throw an exception if driver is not found
Driver registerDriver = DriverManager.getDriver(url);
if (registerDriver instanceof AutoloadedDriver) {
driver = (InternalDriver) AutoloadedDriver.getDriverModule();
} else {
driver = (InternalDriver) registerDriver;
}
}
// else driver != null and driver can accept url
}
return driver;
}
Aggregations