use of org.apache.derby.iapi.db.Database in project derby by apache.
the class T_CreateConglomRet method isdbActive.
/**
* Check wheather the database is active or not
* @return {@code true} if the database is active, {@code false} otherwise
*/
public boolean isdbActive() {
LanguageConnectionContext lcc = (LanguageConnectionContext) getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
Database db = (Database) (lcc != null ? lcc.getDatabase() : null);
return (db != null ? db.isActive() : false);
}
use of org.apache.derby.iapi.db.Database 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.db.Database in project derby by apache.
the class EmbedConnection method bootDatabase.
/**
* Boot database.
*
* @param info boot properties
*
* @param softAuthenticationBoot If true, don't fail soft upgrade due
* to missing features (phase one of two phased hard upgrade boot).
*
* @return false iff the monitor cannot handle a service
* of the type indicated by the protocol within the name.
* If that's the case then we are the wrong driver.
*
* @throws Throwable if anything else is wrong.
*/
private boolean bootDatabase(Properties info, boolean softAuthenticationBoot) throws Throwable {
String dbname = tr.getDBName();
// boot database now
try {
info = filterProperties(info);
if (softAuthenticationBoot) {
info.setProperty(Attribute.SOFT_UPGRADE_NO_FEATURE_CHECK, "true");
} else {
info.remove(Attribute.SOFT_UPGRADE_NO_FEATURE_CHECK);
}
// try to start the service if it doesn't already exist
if (!startPersistentService(dbname, info)) {
// so just return null.
return false;
}
// clear these values as some modules hang onto
// the properties set corresponding to service.properties
// and they shouldn't be interested in these JDBC attributes.
info.clear();
Database database = (Database) findService(Property.DATABASE_MODULE, dbname);
tr.setDatabase(database);
} catch (StandardException mse) {
Throwable ne = mse.getCause();
SQLException nse;
/*
If there is a next exception, assume
that the first one is just a redundant "see the
next exception" message.
if it is a BEI, treat it as a database exception.
If there isn't a BEI, treat it as a java exception.
In general we probably want to walk the chain
and return all of them, but empirically, this
is all we need to do for now.
*/
if (ne instanceof StandardException)
nse = Util.generateCsSQLException((StandardException) ne);
else if (ne != null)
nse = Util.javaException(ne);
else
nse = Util.generateCsSQLException(mse);
throw Util.seeNextException(SQLState.BOOT_DATABASE_FAILED, nse, (ne == null ? mse : ne), dbname, getClass().getClassLoader());
}
// exception would have been thrown already.
return true;
}
Aggregations