* Open and return database index
*/
final int openDatabase(String alias, String datapath) {
if (!isRemoteOpen) {
HsqlException e = Error.error(ErrorCode.GENERAL_ERROR,
"remote open not allowed");
printError("Remote database open not allowed");
setServerError(e);
throw e;
}
int i = getFirstEmptyDatabaseIndex();
if (i < -1) {
i = closeOldestDatabase();
if (i < -1) {
HsqlException e =
Error.error(ErrorCode.GENERAL_ERROR,
"limit of open databases reached");
printError("limit of open databases reached");
setServerError(e);
throw e;
}
}
HsqlProperties newprops = DatabaseURL.parseURL(datapath, false, false);
if (newprops == null) {
HsqlException e = Error.error(ErrorCode.GENERAL_ERROR,
"invalid database path");
printError("invalid database path");
setServerError(e);
throw e;
}
String path = newprops.getProperty(DatabaseURL.url_database);
String type = newprops.getProperty(DatabaseURL.url_connection_type);
try {
int dbid = DatabaseManager.getDatabase(type, path, this, newprops);
dbID[i] = dbid;
dbActionSequence[i] = actionSequence;
dbAlias[i] = alias;
dbPath[i] = path;
dbType[i] = type;
dbProps[i] = newprops;
return i;
} catch (HsqlException e) {
printError("Database [index=" + i + ", db=" + dbType[i]
+ dbPath[i] + ", alias=" + dbAlias[i]
+ "] did not open: " + e.toString());
setServerError(e);
throw e;
}
}