use of org.h2.command.Command in project h2database by h2database.
the class JdbcPreparedStatement method executeUpdateInternal.
private int executeUpdateInternal() throws SQLException {
closeOldResultSet();
synchronized (session) {
try {
setExecutingStatement(command);
ResultWithGeneratedKeys result = command.executeUpdate(generatedKeysRequest);
updateCount = result.getUpdateCount();
ResultInterface gk = result.getGeneratedKeys();
if (gk != null) {
int id = getNextId(TraceObject.RESULT_SET);
generatedKeys = new JdbcResultSet(conn, this, command, gk, id, false, true, false);
}
} finally {
setExecutingStatement(null);
}
}
return updateCount;
}
use of org.h2.command.Command in project h2database by h2database.
the class JdbcStatement method executeUpdateInternal.
private int executeUpdateInternal(String sql, Object generatedKeysRequest) throws SQLException {
checkClosedForWrite();
try {
closeOldResultSet();
sql = JdbcConnection.translateSQL(sql, escapeProcessing);
CommandInterface command = conn.prepareCommand(sql, fetchSize);
synchronized (session) {
setExecutingStatement(command);
try {
ResultWithGeneratedKeys result = command.executeUpdate(conn.scopeGeneratedKeys() ? false : generatedKeysRequest);
updateCount = result.getUpdateCount();
ResultInterface gk = result.getGeneratedKeys();
if (gk != null) {
int id = getNextId(TraceObject.RESULT_SET);
generatedKeys = new JdbcResultSet(conn, this, command, gk, id, false, true, false);
}
} finally {
setExecutingStatement(null);
}
}
command.close();
return updateCount;
} finally {
afterWriting();
}
}
use of org.h2.command.Command in project h2database by h2database.
the class JdbcStatement method executeQuery.
/**
* Executes a query (select statement) and returns the result set.
* If another result set exists for this statement, this will be closed
* (even if this statement fails).
*
* @param sql the SQL statement to execute
* @return the result set
*/
@Override
public ResultSet executeQuery(String sql) throws SQLException {
try {
int id = getNextId(TraceObject.RESULT_SET);
if (isDebugEnabled()) {
debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id, "executeQuery(" + quote(sql) + ")");
}
synchronized (session) {
checkClosed();
closeOldResultSet();
sql = JdbcConnection.translateSQL(sql, escapeProcessing);
CommandInterface command = conn.prepareCommand(sql, fetchSize);
ResultInterface result;
boolean lazy = false;
boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
setExecutingStatement(command);
try {
result = command.executeQuery(maxRows, scrollable);
lazy = result.isLazy();
} finally {
if (!lazy) {
setExecutingStatement(null);
}
}
if (!lazy) {
command.close();
}
resultSet = new JdbcResultSet(conn, this, command, result, id, closedByResultSet, scrollable, updatable);
}
return resultSet;
} catch (Exception e) {
throw logAndConvert(e);
}
}
use of org.h2.command.Command in project h2database by h2database.
the class TestView method testViewAlterAndCommandCache.
/**
* Make sure that when we change a view, that change in reflected in other
* sessions command cache.
*/
private void testViewAlterAndCommandCache() throws SQLException {
deleteDb("view");
Connection conn = getConnection("view");
Statement stat = conn.createStatement();
stat.execute("create table t0(id int primary key)");
stat.execute("create table t1(id int primary key)");
stat.execute("insert into t0 values(0)");
stat.execute("insert into t1 values(1)");
stat.execute("create view v1 as select * from t0");
ResultSet rs = stat.executeQuery("select * from v1");
assertTrue(rs.next());
assertEquals(0, rs.getInt(1));
stat.execute("create or replace view v1 as select * from t1");
rs = stat.executeQuery("select * from v1");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
conn.close();
deleteDb("view");
}
use of org.h2.command.Command in project nzbhydra2 by theotherp.
the class NzbHydra method main.
public static void main(String[] args) throws Exception {
LoggerFactory.getILoggerFactory();
String version = NzbHydra.class.getPackage().getImplementationVersion();
OptionParser parser = new OptionParser();
parser.accepts("datafolder", "Define path to main data folder. Must start with ./ for relative paths").withRequiredArg().defaultsTo("./data");
parser.accepts("host", "Run on this host").withOptionalArg();
parser.accepts("nobrowser", "Don't open browser to Hydra");
parser.accepts("port", "Run on this port (default: 5076)").withOptionalArg();
parser.accepts("baseurl", "Set base URL (e.g. /nzbhydra)").withOptionalArg();
parser.accepts("repairdb", "Repair database. Add database file path as argument").withRequiredArg();
parser.accepts("help", "Print help");
parser.accepts("version", "Print version");
OptionSet options = null;
try {
options = parser.parse(args);
} catch (OptionException e) {
logger.error("Invalid startup options detected: {}", e.getMessage());
System.exit(1);
}
if (System.getProperty("fromWrapper") == null && Arrays.stream(args).noneMatch(x -> x.equals("directstart"))) {
logger.info("NZBHydra 2 must be started using the wrapper for restart and updates to work. If for some reason you need to start it from the JAR directly provide the command line argument \"directstart\"");
} else if (options.has("help")) {
parser.printHelpOn(System.out);
} else if (options.has("version")) {
logger.info("NZBHydra 2 version: " + version);
} else if (options.has("repairdb")) {
String databaseFilePath = (String) options.valueOf("repairdb");
repairDb(databaseFilePath);
} else {
startup(args, options);
}
}
Aggregations