Search in sources :

Example 1 with InternalDriver

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
    }
}
Also used : InternalDriver(org.apache.derby.iapi.jdbc.InternalDriver) StandardException(org.apache.derby.shared.common.error.StandardException) PrivilegedActionException(java.security.PrivilegedActionException) SQLException(java.sql.SQLException)

Example 2 with InternalDriver

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;
}
Also used : InternalDriver(org.apache.derby.iapi.jdbc.InternalDriver) SQLException(java.sql.SQLException) Database(org.apache.derby.iapi.db.Database)

Example 3 with InternalDriver

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;
}
Also used : InternalDriver(org.apache.derby.iapi.jdbc.InternalDriver) AutoloadedDriver(org.apache.derby.iapi.jdbc.AutoloadedDriver) Driver(java.sql.Driver) AutoloadedDriver(org.apache.derby.iapi.jdbc.AutoloadedDriver)

Aggregations

InternalDriver (org.apache.derby.iapi.jdbc.InternalDriver)3 SQLException (java.sql.SQLException)2 PrivilegedActionException (java.security.PrivilegedActionException)1 Driver (java.sql.Driver)1 Database (org.apache.derby.iapi.db.Database)1 AutoloadedDriver (org.apache.derby.iapi.jdbc.AutoloadedDriver)1 StandardException (org.apache.derby.shared.common.error.StandardException)1