use of org.h2.command.CommandInterface in project h2database by h2database.
the class JdbcConnection method getCatalog.
/**
* Gets the current catalog name.
*
* @return the catalog name
* @throws SQLException if the connection is closed
*/
@Override
public String getCatalog() throws SQLException {
try {
debugCodeCall("getCatalog");
checkClosed();
if (catalog == null) {
CommandInterface cat = prepareCommand("CALL DATABASE()", Integer.MAX_VALUE);
ResultInterface result = cat.executeQuery(0, false);
result.next();
catalog = result.currentRow()[0].getString();
cat.close();
}
return catalog;
} catch (Exception e) {
throw logAndConvert(e);
}
}
use of org.h2.command.CommandInterface in project h2database by h2database.
the class JdbcConnection method setSavepoint.
/**
* Creates a new unnamed savepoint.
*
* @return the new savepoint
*/
@Override
public Savepoint setSavepoint() throws SQLException {
try {
int id = getNextId(TraceObject.SAVEPOINT);
if (isDebugEnabled()) {
debugCodeAssign("Savepoint", TraceObject.SAVEPOINT, id, "setSavepoint()");
}
checkClosed();
CommandInterface set = prepareCommand("SAVEPOINT " + JdbcSavepoint.getName(null, savepointId), Integer.MAX_VALUE);
set.executeUpdate(false);
JdbcSavepoint savepoint = new JdbcSavepoint(this, savepointId, null, trace, id);
savepointId++;
return savepoint;
} catch (Exception e) {
throw logAndConvert(e);
}
}
use of org.h2.command.CommandInterface in project h2database by h2database.
the class Engine method openSession.
private synchronized Session openSession(ConnectionInfo ci) {
boolean ifExists = ci.removeProperty("IFEXISTS", false);
boolean ignoreUnknownSetting = ci.removeProperty("IGNORE_UNKNOWN_SETTINGS", false);
String cipher = ci.removeProperty("CIPHER", null);
String init = ci.removeProperty("INIT", null);
Session session;
for (int i = 0; ; i++) {
session = openSession(ci, ifExists, cipher);
if (session != null) {
break;
}
// wait a bit to avoid a busy loop (the method is synchronized)
if (i > 60 * 1000) {
// retry at most 1 minute
throw DbException.get(ErrorCode.DATABASE_ALREADY_OPEN_1, "Waited for database closing longer than 1 minute");
}
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// ignore
}
}
synchronized (session) {
session.setAllowLiterals(true);
DbSettings defaultSettings = DbSettings.getDefaultSettings();
for (String setting : ci.getKeys()) {
if (defaultSettings.containsKey(setting)) {
// database setting are only used when opening the database
continue;
}
String value = ci.getProperty(setting);
try {
CommandInterface command = session.prepareCommand("SET " + Parser.quoteIdentifier(setting) + " " + value, Integer.MAX_VALUE);
command.executeUpdate(false);
} catch (DbException e) {
if (e.getErrorCode() == ErrorCode.ADMIN_RIGHTS_REQUIRED) {
session.getTrace().error(e, "admin rights required; user: \"" + ci.getUserName() + "\"");
} else {
session.getTrace().error(e, "");
}
if (!ignoreUnknownSetting) {
session.close();
throw e;
}
}
}
if (init != null) {
try {
CommandInterface command = session.prepareCommand(init, Integer.MAX_VALUE);
command.executeUpdate(false);
} catch (DbException e) {
if (!ignoreUnknownSetting) {
session.close();
throw e;
}
}
}
session.setAllowLiterals(false);
session.commit(true);
}
return session;
}
use of org.h2.command.CommandInterface in project h2database by h2database.
the class SessionRemote method switchOffCluster.
private void switchOffCluster() {
CommandInterface ci = prepareCommand("SET CLUSTER ''", Integer.MAX_VALUE);
ci.executeUpdate(false);
}
use of org.h2.command.CommandInterface in project h2database by h2database.
the class SessionRemote method readSerializationSettings.
/**
* Read the serializer name from the persistent database settings.
*
* @return the serializer
*/
private String readSerializationSettings() {
String javaObjectSerializerFQN = null;
CommandInterface ci = prepareCommand("SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS " + " WHERE NAME='JAVA_OBJECT_SERIALIZER'", Integer.MAX_VALUE);
try {
ResultInterface result = ci.executeQuery(0, false);
if (result.next()) {
Value[] row = result.currentRow();
javaObjectSerializerFQN = row[0].getString();
}
} finally {
ci.close();
}
return javaObjectSerializerFQN;
}
Aggregations