990
// in src/main/org/h2/jdbcx/JdbcXAConnection.java
public void close() throws SQLException {
debugCodeCall("close");
Connection lastHandle = handleConn;
if (lastHandle != null) {
listeners.clear();
lastHandle.close();
}
if (physicalConn != null) {
try {
physicalConn.close();
} finally {
physicalConn = null;
}
}
}
// in src/main/org/h2/jdbcx/JdbcXAConnection.java
public Connection getConnection() throws SQLException {
debugCodeCall("getConnection");
Connection lastHandle = handleConn;
if (lastHandle != null) {
lastHandle.close();
}
// this will ensure the rollback command is cached
physicalConn.rollback();
handleConn = new PooledJdbcConnection(physicalConn);
return handleConn;
}
// in src/main/org/h2/jdbcx/JdbcXAConnection.java
public synchronized void close() throws SQLException {
if (!isClosed) {
try {
rollback();
setAutoCommit(true);
} catch (SQLException e) {
// ignore
}
closedHandle();
isClosed = true;
}
}
// in src/main/org/h2/jdbcx/JdbcXAConnection.java
public synchronized boolean isClosed() throws SQLException {
return isClosed || super.isClosed();
}
// in src/main/org/h2/jdbcx/JdbcConnectionPool.java
public Connection getConnection() throws SQLException {
long max = System.currentTimeMillis() + timeout * 1000;
do {
synchronized (this) {
if (activeConnections < maxConnections) {
return getConnectionNow();
}
try {
wait(1000);
} catch (InterruptedException e) {
// ignore
}
}
} while (System.currentTimeMillis() <= max);
throw new SQLException("Login timeout", "08001", 8001);
}
// in src/main/org/h2/jdbcx/JdbcConnectionPool.java
private Connection getConnectionNow() throws SQLException {
if (isDisposed) {
throw new IllegalStateException("Connection pool has been disposed.");
}
PooledConnection pc;
if (!recycledConnections.isEmpty()) {
pc = recycledConnections.remove(recycledConnections.size() - 1);
} else {
pc = dataSource.getPooledConnection();
}
Connection conn = pc.getConnection();
activeConnections++;
pc.addConnectionEventListener(this);
return conn;
}
// in src/main/org/h2/jdbcx/JdbcConnectionPool.java
public <T> T unwrap(Class<T> iface) throws SQLException {
throw DbException.getUnsupportedException("unwrap");
}
// in src/main/org/h2/jdbcx/JdbcConnectionPool.java
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw DbException.getUnsupportedException("isWrapperFor");
}
// in src/main/org/h2/jdbcx/JdbcDataSource.java
public Connection getConnection() throws SQLException {
debugCodeCall("getConnection");
return getJdbcConnection(userName, StringUtils.cloneCharArray(passwordChars));
}
// in src/main/org/h2/jdbcx/JdbcDataSource.java
public Connection getConnection(String user, String password) throws SQLException {
if (isDebugEnabled()) {
debugCode("getConnection("+quote(user)+", \"\");");
}
return getJdbcConnection(user, convertToCharArray(password));
}
// in src/main/org/h2/jdbcx/JdbcDataSource.java
private JdbcConnection getJdbcConnection(String user, char[] password) throws SQLException {
if (isDebugEnabled()) {
debugCode("getJdbcConnection("+quote(user)+", new char[0]);");
}
Properties info = new Properties();
info.setProperty("user", user);
info.put("password", password);
Connection conn = Driver.load().connect(url, info);
if (conn == null) {
throw new SQLException("No suitable driver found for " + url, "08001", 8001);
} else if (!(conn instanceof JdbcConnection)) {
throw new SQLException("Connecting with old version is not supported: " + url, "08001", 8001);
}
return (JdbcConnection) conn;
}
// in src/main/org/h2/jdbcx/JdbcDataSource.java
public XAConnection getXAConnection() throws SQLException {
debugCodeCall("getXAConnection");
int id = getNextId(XA_DATA_SOURCE);
return new JdbcXAConnection(factory, id, getJdbcConnection(userName, StringUtils.cloneCharArray(passwordChars)));
}
// in src/main/org/h2/jdbcx/JdbcDataSource.java
public XAConnection getXAConnection(String user, String password) throws SQLException {
if (isDebugEnabled()) {
debugCode("getXAConnection("+quote(user)+", \"\");");
}
int id = getNextId(XA_DATA_SOURCE);
return new JdbcXAConnection(factory, id, getJdbcConnection(user, convertToCharArray(password)));
}
// in src/main/org/h2/jdbcx/JdbcDataSource.java
public PooledConnection getPooledConnection() throws SQLException {
debugCodeCall("getPooledConnection");
return getXAConnection();
}
// in src/main/org/h2/jdbcx/JdbcDataSource.java
public PooledConnection getPooledConnection(String user, String password) throws SQLException {
if (isDebugEnabled()) {
debugCode("getPooledConnection("+quote(user)+", \"\");");
}
return getXAConnection(user, password);
}
// in src/main/org/h2/jdbcx/JdbcDataSource.java
public <T> T unwrap(Class<T> iface) throws SQLException {
throw unsupported("unwrap");
}
// in src/main/org/h2/jdbcx/JdbcDataSource.java
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw unsupported("isWrapperFor");
}
// in src/main/org/h2/message/TraceObject.java
protected SQLException unsupported(String message) throws SQLException {
try {
throw DbException.getUnsupportedException(message);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/tools/TriggerAdapter.java
public void init(Connection conn, String schemaName,
String triggerName, String tableName,
boolean before, int type) throws SQLException {
ResultSet rs = conn.getMetaData().getColumns(
null, schemaName, tableName, null);
oldSource = new TriggerRowSource();
newSource = new TriggerRowSource();
oldResultSet = new SimpleResultSet(oldSource);
newResultSet = new SimpleResultSet(newSource);
while (rs.next()) {
String column = rs.getString("COLUMN_NAME");
int dataType = rs.getInt("DATA_TYPE");
int precision = rs.getInt("COLUMN_SIZE");
int scale = rs.getInt("DECIMAL_DIGITS");
oldResultSet.addColumn(column, dataType, precision, scale);
newResultSet.addColumn(column, dataType, precision, scale);
}
this.schemaName = schemaName;
this.triggerName = triggerName;
this.tableName = tableName;
this.before = before;
this.type = type;
}
// in src/main/org/h2/tools/TriggerAdapter.java
public void fire(Connection conn, Object[] oldRow,
Object[] newRow) throws SQLException {
fire(conn, wrap(oldResultSet, oldSource, oldRow), wrap(newResultSet, newSource, newRow));
}
// in src/main/org/h2/tools/TriggerAdapter.java
private static SimpleResultSet wrap(SimpleResultSet rs, TriggerRowSource source, Object[] row) throws SQLException {
if (row == null) {
return null;
}
source.setRow(row);
rs.next();
return rs;
}
// in src/main/org/h2/tools/TriggerAdapter.java
public void remove() throws SQLException {
// do nothing by default
}
// in src/main/org/h2/tools/TriggerAdapter.java
public void close() throws SQLException {
// do nothing by default
}
// in src/main/org/h2/tools/Restore.java
public static void main(String... args) throws SQLException {
new Restore().runTool(args);
}
// in src/main/org/h2/tools/Restore.java
public void runTool(String... args) throws SQLException {
String zipFileName = "backup.zip";
String dir = ".";
String db = null;
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg.equals("-dir")) {
dir = args[++i];
} else if (arg.equals("-file")) {
zipFileName = args[++i];
} else if (arg.equals("-db")) {
db = args[++i];
} else if (arg.equals("-quiet")) {
// ignore
} else if (arg.equals("-help") || arg.equals("-?")) {
showUsage();
return;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
execute(zipFileName, dir, db, false);
}
// in src/main/org/h2/tools/Script.java
public static void main(String... args) throws SQLException {
new Script().runTool(args);
}
// in src/main/org/h2/tools/Script.java
public void runTool(String... args) throws SQLException {
String url = null;
String user = "sa";
String password = "";
String file = "backup.sql";
String options1 = null, options2 = null;
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg.equals("-url")) {
url = args[++i];
} else if (arg.equals("-user")) {
user = args[++i];
} else if (arg.equals("-password")) {
password = args[++i];
} else if (arg.equals("-script")) {
file = args[++i];
} else if (arg.equals("-options")) {
StringBuilder buff1 = new StringBuilder();
StringBuilder buff2 = new StringBuilder();
i++;
for (; i < args.length; i++) {
String a = args[i];
String upper = StringUtils.toUpperEnglish(a);
if ("SIMPLE".equals(upper) || upper.startsWith("NO") || "DROP".equals(upper)) {
buff1.append(' ');
buff1.append(args[i]);
} else {
buff2.append(' ');
buff2.append(args[i]);
}
}
options1 = buff1.toString();
options2 = buff2.toString();
} else if (arg.equals("-help") || arg.equals("-?")) {
showUsage();
return;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
if (url == null) {
showUsage();
throw new SQLException("URL not set");
}
if (options1 != null) {
processScript(url, user, password, file, options1, options2);
} else {
execute(url, user, password, file);
}
}
// in src/main/org/h2/tools/Script.java
private static void processScript(String url, String user, String password,
String fileName, String options1, String options2) throws SQLException {
Connection conn = null;
Statement stat = null;
try {
org.h2.Driver.load();
conn = DriverManager.getConnection(url, user, password);
stat = conn.createStatement();
String sql = "SCRIPT " + options1 + " TO '" + fileName + "' " + options2;
stat.execute(sql);
} finally {
JdbcUtils.closeSilently(stat);
JdbcUtils.closeSilently(conn);
}
}
// in src/main/org/h2/tools/Script.java
public static void execute(String url, String user, String password, String fileName) throws SQLException {
OutputStream o = null;
try {
o = FileUtils.newOutputStream(fileName, false);
execute(url, user, password, o);
} finally {
IOUtils.closeSilently(o);
}
}
// in src/main/org/h2/tools/Script.java
public static void execute(String url, String user, String password, OutputStream out) throws SQLException {
Connection conn = null;
try {
org.h2.Driver.load();
conn = DriverManager.getConnection(url, user, password);
process(conn, out);
} finally {
JdbcUtils.closeSilently(conn);
}
}
// in src/main/org/h2/tools/Script.java
static void process(Connection conn, OutputStream out) throws SQLException {
Statement stat = null;
try {
stat = conn.createStatement();
PrintWriter writer = new PrintWriter(IOUtils.getBufferedWriter(out));
ResultSet rs = stat.executeQuery("SCRIPT");
while (rs.next()) {
String s = rs.getString(1);
writer.println(s);
}
writer.flush();
} finally {
JdbcUtils.closeSilently(stat);
}
}
// in src/main/org/h2/tools/ChangeFileEncryption.java
public static void main(String... args) throws SQLException {
new ChangeFileEncryption().runTool(args);
}
// in src/main/org/h2/tools/ChangeFileEncryption.java
public void runTool(String... args) throws SQLException {
String dir = ".";
String cipher = null;
char[] decryptPassword = null;
char[] encryptPassword = null;
String db = null;
boolean quiet = false;
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg.equals("-dir")) {
dir = args[++i];
} else if (arg.equals("-cipher")) {
cipher = args[++i];
} else if (arg.equals("-db")) {
db = args[++i];
} else if (arg.equals("-decrypt")) {
decryptPassword = args[++i].toCharArray();
} else if (arg.equals("-encrypt")) {
encryptPassword = args[++i].toCharArray();
} else if (arg.equals("-quiet")) {
quiet = true;
} else if (arg.equals("-help") || arg.equals("-?")) {
showUsage();
return;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
if ((encryptPassword == null && decryptPassword == null) || cipher == null) {
showUsage();
throw new SQLException("Encryption or decryption password not set, or cipher not set");
}
try {
process(dir, db, cipher, decryptPassword, encryptPassword, quiet);
} catch (Exception e) {
throw DbException.toSQLException(e);
}
}
// in src/main/org/h2/tools/ChangeFileEncryption.java
public static void execute(String dir, String db, String cipher,
char[] decryptPassword, char[] encryptPassword, boolean quiet) throws SQLException {
try {
new ChangeFileEncryption().process(dir, db, cipher, decryptPassword, encryptPassword, quiet);
} catch (Exception e) {
throw DbException.toSQLException(e);
}
}
// in src/main/org/h2/tools/ChangeFileEncryption.java
private void process(String dir, String db, String cipher,
char[] decryptPassword, char[] encryptPassword, boolean quiet) throws SQLException {
dir = FileLister.getDir(dir);
ChangeFileEncryption change = new ChangeFileEncryption();
if (encryptPassword != null) {
for (char c : encryptPassword) {
if (c == ' ') {
throw new SQLException("The file password may not contain spaces");
}
}
}
change.out = out;
change.directory = dir;
change.cipherType = cipher;
change.decrypt = getFileEncryptionKey(decryptPassword);
change.encrypt = getFileEncryptionKey(encryptPassword);
ArrayList<String> files = FileLister.getDatabaseFiles(dir, db, true);
FileLister.tryUnlockDatabase(files, "encryption");
files = FileLister.getDatabaseFiles(dir, db, false);
if (files.size() == 0 && !quiet) {
printNoDatabaseFilesFound(dir, db);
}
// first, test only if the file can be renamed
// (to find errors with locked files early)
for (String fileName : files) {
String temp = dir + "/temp.db";
FileUtils.delete(temp);
FileUtils.moveTo(fileName, temp);
FileUtils.moveTo(temp, fileName);
}
// if this worked, the operation will (hopefully) be successful
// TODO changeFileEncryption: this is a workaround!
// make the operation atomic (all files or none)
for (String fileName : files) {
// Don't process a lob directory, just the files in the directory.
if (!FileUtils.isDirectory(fileName)) {
change.process(fileName);
}
}
}
// in src/main/org/h2/tools/ConvertTraceFile.java
public static void main(String... args) throws SQLException {
new ConvertTraceFile().runTool(args);
}
// in src/main/org/h2/tools/ConvertTraceFile.java
public void runTool(String... args) throws SQLException {
String traceFile = "test.trace.db";
String javaClass = "Test";
String script = "test.sql";
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg.equals("-traceFile")) {
traceFile = args[++i];
} else if (arg.equals("-javaClass")) {
javaClass = args[++i];
} else if (arg.equals("-script")) {
script = args[++i];
} else if (arg.equals("-help") || arg.equals("-?")) {
showUsage();
return;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
try {
convertFile(traceFile, javaClass, script);
} catch (IOException e) {
throw DbException.convertIOException(e, traceFile);
}
}
// in src/main/org/h2/tools/Backup.java
public static void main(String... args) throws SQLException {
new Backup().runTool(args);
}
// in src/main/org/h2/tools/Backup.java
public void runTool(String... args) throws SQLException {
String zipFileName = "backup.zip";
String dir = ".";
String db = null;
boolean quiet = false;
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg.equals("-dir")) {
dir = args[++i];
} else if (arg.equals("-db")) {
db = args[++i];
} else if (arg.equals("-quiet")) {
quiet = true;
} else if (arg.equals("-file")) {
zipFileName = args[++i];
} else if (arg.equals("-help") || arg.equals("-?")) {
showUsage();
return;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
try {
process(zipFileName, dir, db, quiet);
} catch (Exception e) {
throw DbException.toSQLException(e);
}
}
// in src/main/org/h2/tools/Backup.java
public static void execute(String zipFileName, String directory, String db, boolean quiet) throws SQLException {
try {
new Backup().process(zipFileName, directory, db, quiet);
} catch (Exception e) {
throw DbException.toSQLException(e);
}
}
// in src/main/org/h2/tools/Backup.java
private void process(String zipFileName, String directory, String db, boolean quiet) throws SQLException {
List<String> list;
boolean allFiles = db != null && db.length() == 0;
if (allFiles) {
list = FileUtils.newDirectoryStream(directory);
} else {
list = FileLister.getDatabaseFiles(directory, db, true);
}
if (list.size() == 0) {
if (!quiet) {
printNoDatabaseFilesFound(directory, db);
}
return;
}
if (!quiet) {
FileLister.tryUnlockDatabase(list, "backup");
}
zipFileName = FileUtils.toRealPath(zipFileName);
FileUtils.delete(zipFileName);
OutputStream fileOut = null;
try {
fileOut = FileUtils.newOutputStream(zipFileName, false);
ZipOutputStream zipOut = new ZipOutputStream(fileOut);
String base = "";
for (String fileName : list) {
if (fileName.endsWith(Constants.SUFFIX_PAGE_FILE) || allFiles) {
base = FileUtils.getParent(fileName);
break;
}
}
for (String fileName : list) {
String f = FileUtils.toRealPath(fileName);
if (!f.startsWith(base)) {
DbException.throwInternalError(f + " does not start with " + base);
}
if (f.endsWith(zipFileName)) {
continue;
}
if (FileUtils.isDirectory(fileName)) {
continue;
}
f = f.substring(base.length());
f = BackupCommand.correctFileName(f);
ZipEntry entry = new ZipEntry(f);
zipOut.putNextEntry(entry);
InputStream in = null;
try {
in = FileUtils.newInputStream(fileName);
IOUtils.copyAndCloseInput(in, zipOut);
} catch (FileNotFoundException e) {
// the file could have been deleted in the meantime
// ignore this (in this case an empty file is created)
} finally {
IOUtils.closeSilently(in);
}
zipOut.closeEntry();
if (!quiet) {
out.println("Processed: " + fileName);
}
}
zipOut.closeEntry();
zipOut.close();
} catch (IOException e) {
throw DbException.convertIOException(e, zipFileName);
} finally {
IOUtils.closeSilently(fileOut);
}
}
// in src/main/org/h2/tools/Csv.java
private int writeResultSet(ResultSet rs) throws SQLException {
try {
int rows = 0;
ResultSetMetaData meta = rs.getMetaData();
int columnCount = meta.getColumnCount();
String[] row = new String[columnCount];
int[] sqlTypes = new int[columnCount];
for (int i = 0; i < columnCount; i++) {
row[i] = meta.getColumnLabel(i + 1);
sqlTypes[i] = meta.getColumnType(i + 1);
}
if (writeColumnHeader) {
writeRow(row);
}
while (rs.next()) {
for (int i = 0; i < columnCount; i++) {
Object o;
switch (sqlTypes[i]) {
case Types.DATE:
o = rs.getDate(i + 1);
break;
case Types.TIME:
o = rs.getTime(i + 1);
break;
case Types.TIMESTAMP:
o = rs.getTimestamp(i + 1);
break;
default:
o = rs.getString(i + 1);
}
row[i] = o == null ? null : o.toString();
}
writeRow(row);
rows++;
}
output.close();
return rows;
} catch (IOException e) {
throw DbException.convertIOException(e, null);
} finally {
close();
JdbcUtils.closeSilently(rs);
}
}
// in src/main/org/h2/tools/Csv.java
public int write(Writer writer, ResultSet rs) throws SQLException {
this.output = writer;
return writeResultSet(rs);
}
// in src/main/org/h2/tools/Csv.java
public int write(String outputFileName, ResultSet rs, String charset) throws SQLException {
init(outputFileName, charset);
try {
initWrite();
return writeResultSet(rs);
} catch (IOException e) {
throw convertException("IOException writing " + outputFileName, e);
}
}
// in src/main/org/h2/tools/Csv.java
public int write(Connection conn, String outputFileName, String sql, String charset) throws SQLException {
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery(sql);
int rows = write(outputFileName, rs, charset);
stat.close();
return rows;
}
// in src/main/org/h2/tools/Csv.java
public ResultSet read(String inputFileName, String[] colNames, String charset) throws SQLException {
init(inputFileName, charset);
try {
return readResultSet(colNames);
} catch (IOException e) {
throw convertException("IOException reading " + inputFileName, e);
}
}
// in src/main/org/h2/tools/Csv.java
public Object[] readRow() throws SQLException {
if (input == null) {
return null;
}
String[] row = new String[columnNames.length];
try {
int i = 0;
while (true) {
String v = readValue();
if (v == null) {
if (endOfLine) {
if (i == 0) {
if (endOfFile) {
return null;
}
// empty line
continue;
}
break;
}
}
if (i < row.length) {
row[i++] = v;
}
if (endOfLine) {
break;
}
}
} catch (IOException e) {
throw convertException("IOException reading from " + fileName, e);
}
return row;
}
// in src/main/org/h2/tools/Csv.java
public void reset() throws SQLException {
throw new SQLException("Method is not supported", "CSV");
}
// in src/main/org/h2/tools/CreateCluster.java
public static void main(String... args) throws SQLException {
new CreateCluster().runTool(args);
}
// in src/main/org/h2/tools/CreateCluster.java
public void runTool(String... args) throws SQLException {
String urlSource = null;
String urlTarget = null;
String user = "sa";
String password = "";
String serverList = null;
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg.equals("-urlSource")) {
urlSource = args[++i];
} else if (arg.equals("-urlTarget")) {
urlTarget = args[++i];
} else if (arg.equals("-user")) {
user = args[++i];
} else if (arg.equals("-password")) {
password = args[++i];
} else if (arg.equals("-serverList")) {
serverList = args[++i];
} else if (arg.equals("-help") || arg.equals("-?")) {
showUsage();
return;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
if (urlSource == null || urlTarget == null || serverList == null) {
showUsage();
throw new SQLException("Source URL, target URL, or server list not set");
}
process(urlSource, urlTarget, user, password, serverList);
}
// in src/main/org/h2/tools/CreateCluster.java
public void execute(String urlSource, String urlTarget,
String user, String password, String serverList) throws SQLException {
process(urlSource, urlTarget, user, password, serverList);
}
// in src/main/org/h2/tools/CreateCluster.java
private void process(String urlSource, String urlTarget,
String user, String password, String serverList) throws SQLException {
Connection connSource = null, connTarget = null;
Statement statSource = null, statTarget = null;
String scriptFile = "backup.sql";
try {
org.h2.Driver.load();
// verify that the database doesn't exist,
// or if it exists (an old cluster instance), it is deleted
boolean exists = true;
try {
connTarget = DriverManager.getConnection(urlTarget +
";IFEXISTS=TRUE;CLUSTER=" + Constants.CLUSTERING_ENABLED,
user, password);
Statement stat = connTarget.createStatement();
stat.execute("DROP ALL OBJECTS DELETE FILES");
stat.close();
exists = false;
connTarget.close();
} catch (SQLException e) {
if (e.getErrorCode() == ErrorCode.DATABASE_NOT_FOUND_1) {
// database does not exists yet - ok
exists = false;
} else {
throw e;
}
}
if (exists) {
throw new SQLException("Target database must not yet exist. Please delete it first: " + urlTarget);
}
// use cluster='' so connecting is possible
// even if the cluster is enabled
connSource = DriverManager.getConnection(urlSource + ";CLUSTER=''", user, password);
statSource = connSource.createStatement();
// enable the exclusive mode and close other connections,
// so that data can't change while restoring the second database
statSource.execute("SET EXCLUSIVE 2");
try {
// backup
Script script = new Script();
script.setOut(out);
OutputStream scriptOut = null;
try {
scriptOut = FileUtils.newOutputStream(scriptFile, false);
Script.process(connSource, scriptOut);
} finally {
IOUtils.closeSilently(scriptOut);
}
// delete the target database and then restore
connTarget = DriverManager.getConnection(urlTarget + ";CLUSTER=''", user, password);
statTarget = connTarget.createStatement();
statTarget.execute("DROP ALL OBJECTS DELETE FILES");
connTarget.close();
RunScript runScript = new RunScript();
runScript.setOut(out);
runScript.process(urlTarget, user, password, scriptFile, null, false);
connTarget = DriverManager.getConnection(urlTarget, user, password);
statTarget = connTarget.createStatement();
// set the cluster to the serverList on both databases
statSource.executeUpdate("SET CLUSTER '" + serverList + "'");
statTarget.executeUpdate("SET CLUSTER '" + serverList + "'");
} finally {
// switch back to the regular mode
statSource.execute("SET EXCLUSIVE FALSE");
}
} finally {
FileUtils.delete(scriptFile);
JdbcUtils.closeSilently(statSource);
JdbcUtils.closeSilently(statTarget);
JdbcUtils.closeSilently(connSource);
JdbcUtils.closeSilently(connTarget);
}
}
// in src/main/org/h2/tools/Recover.java
public static void main(String... args) throws SQLException {
new Recover().runTool(args);
}
// in src/main/org/h2/tools/Recover.java
public void runTool(String... args) throws SQLException {
String dir = ".";
String db = null;
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if ("-dir".equals(arg)) {
dir = args[++i];
} else if ("-db".equals(arg)) {
db = args[++i];
} else if ("-removePassword".equals(arg)) {
remove = true;
} else if ("-trace".equals(arg)) {
trace = true;
} else if ("-transactionLog".equals(arg)) {
transactionLog = true;
} else if (arg.equals("-help") || arg.equals("-?")) {
showUsage();
return;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
process(dir, db);
}
// in src/main/org/h2/tools/Recover.java
public static void execute(String dir, String db) throws SQLException {
try {
new Recover().process(dir, db);
} catch (DbException e) {
throw DbException.toSQLException(e);
}
}
// in src/main/org/h2/tools/Server.java
public static void main(String... args) throws SQLException {
new Server().runTool(args);
}
// in src/main/org/h2/tools/Server.java
private void verifyArgs(String... args) throws SQLException {
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg == null) {
continue;
} else if ("-?".equals(arg) || "-help".equals(arg)) {
// ok
} else if (arg.startsWith("-web")) {
if ("-web".equals(arg)) {
// ok
} else if ("-webAllowOthers".equals(arg)) {
// no parameters
} else if ("-webDaemon".equals(arg)) {
// no parameters
} else if ("-webSSL".equals(arg)) {
// no parameters
} else if ("-webPort".equals(arg)) {
i++;
} else {
throwUnsupportedOption(arg);
}
} else if ("-browser".equals(arg)) {
// ok
} else if (arg.startsWith("-tcp")) {
if ("-tcp".equals(arg)) {
// ok
} else if ("-tcpAllowOthers".equals(arg)) {
// no parameters
} else if ("-tcpDaemon".equals(arg)) {
// no parameters
} else if ("-tcpSSL".equals(arg)) {
// no parameters
} else if ("-tcpPort".equals(arg)) {
i++;
} else if ("-tcpPassword".equals(arg)) {
i++;
} else if ("-tcpShutdown".equals(arg)) {
i++;
} else if ("-tcpShutdownForce".equals(arg)) {
// ok
} else {
throwUnsupportedOption(arg);
}
} else if (arg.startsWith("-pg")) {
if ("-pg".equals(arg)) {
// ok
} else if ("-pgAllowOthers".equals(arg)) {
// no parameters
} else if ("-pgDaemon".equals(arg)) {
// no parameters
} else if ("-pgPort".equals(arg)) {
i++;
} else {
throwUnsupportedOption(arg);
}
} else if (arg.startsWith("-ftp")) {
if ("-ftpPort".equals(arg)) {
i++;
} else if ("-ftpDir".equals(arg)) {
i++;
} else if ("-ftpRead".equals(arg)) {
i++;
} else if ("-ftpWrite".equals(arg)) {
i++;
} else if ("-ftpWritePassword".equals(arg)) {
i++;
} else if ("-ftpTask".equals(arg)) {
// no parameters
} else {
throwUnsupportedOption(arg);
}
} else if ("-properties".equals(arg)) {
i++;
} else if ("-trace".equals(arg)) {
// no parameters
} else if ("-ifExists".equals(arg)) {
// no parameters
} else if ("-baseDir".equals(arg)) {
i++;
} else if ("-key".equals(arg)) {
i += 2;
} else if ("-tool".equals(arg)) {
// no parameters
} else {
throwUnsupportedOption(arg);
}
}
}
// in src/main/org/h2/tools/Server.java
public void runTool(String... args) throws SQLException {
boolean tcpStart = false, pgStart = false, webStart = false;
boolean browserStart = false;
boolean tcpShutdown = false, tcpShutdownForce = false;
String tcpPassword = "";
String tcpShutdownServer = "";
boolean startDefaultServers = true;
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg == null) {
continue;
} else if ("-?".equals(arg) || "-help".equals(arg)) {
showUsage();
return;
} else if (arg.startsWith("-web")) {
if ("-web".equals(arg)) {
startDefaultServers = false;
webStart = true;
} else if ("-webAllowOthers".equals(arg)) {
// no parameters
} else if ("-webDaemon".equals(arg)) {
// no parameters
} else if ("-webSSL".equals(arg)) {
// no parameters
} else if ("-webPort".equals(arg)) {
i++;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
} else if ("-browser".equals(arg)) {
startDefaultServers = false;
browserStart = true;
} else if (arg.startsWith("-tcp")) {
if ("-tcp".equals(arg)) {
startDefaultServers = false;
tcpStart = true;
} else if ("-tcpAllowOthers".equals(arg)) {
// no parameters
} else if ("-tcpDaemon".equals(arg)) {
// no parameters
} else if ("-tcpSSL".equals(arg)) {
// no parameters
} else if ("-tcpPort".equals(arg)) {
i++;
} else if ("-tcpPassword".equals(arg)) {
tcpPassword = args[++i];
} else if ("-tcpShutdown".equals(arg)) {
startDefaultServers = false;
tcpShutdown = true;
tcpShutdownServer = args[++i];
} else if ("-tcpShutdownForce".equals(arg)) {
tcpShutdownForce = true;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
} else if (arg.startsWith("-pg")) {
if ("-pg".equals(arg)) {
startDefaultServers = false;
pgStart = true;
} else if ("-pgAllowOthers".equals(arg)) {
// no parameters
} else if ("-pgDaemon".equals(arg)) {
// no parameters
} else if ("-pgPort".equals(arg)) {
i++;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
} else if ("-properties".equals(arg)) {
i++;
} else if ("-trace".equals(arg)) {
// no parameters
} else if ("-ifExists".equals(arg)) {
// no parameters
} else if ("-baseDir".equals(arg)) {
i++;
} else if ("-key".equals(arg)) {
i += 2;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
verifyArgs(args);
if (startDefaultServers) {
tcpStart = true;
pgStart = true;
webStart = true;
browserStart = true;
}
// TODO server: maybe use one single properties file?
if (tcpShutdown) {
out.println("Shutting down TCP Server at " + tcpShutdownServer);
shutdownTcpServer(tcpShutdownServer, tcpPassword, tcpShutdownForce, false);
}
try {
if (webStart) {
web = createWebServer(args);
web.setShutdownHandler(this);
SQLException result = null;
try {
web.start();
} catch (Exception e) {
result = DbException.toSQLException(e);
}
out.println(web.getStatus());
// start browser in any case (even if the server is already running)
// because some people don't look at the output,
// but are wondering why nothing happens
if (browserStart) {
try {
openBrowser(web.getURL());
} catch (Exception e) {
out.println(e.getMessage());
}
}
if (result != null) {
throw result;
}
}
if (tcpStart) {
tcp = createTcpServer(args);
tcp.start();
out.println(tcp.getStatus());
tcp.setShutdownHandler(this);
}
if (pgStart) {
pg = createPgServer(args);
pg.start();
out.println(pg.getStatus());
}
} catch (SQLException e) {
stopAll();
throw e;
}
}
// in src/main/org/h2/tools/Server.java
public static void shutdownTcpServer(String url, String password, boolean force, boolean all) throws SQLException {
TcpServer.shutdown(url, password, force, all);
}
// in src/main/org/h2/tools/Server.java
public static Server createWebServer(String... args) throws SQLException {
WebServer service = new WebServer();
Server server = new Server(service, args);
service.setShutdownHandler(server);
return server;
}
// in src/main/org/h2/tools/Server.java
public static Server createTcpServer(String... args) throws SQLException {
TcpServer service = new TcpServer();
Server server = new Server(service, args);
service.setShutdownHandler(server);
return server;
}
// in src/main/org/h2/tools/Server.java
public static Server createPgServer(String... args) throws SQLException {
return new Server(new PgServer(), args);
}
// in src/main/org/h2/tools/Server.java
public Server start() throws SQLException {
try {
started = true;
service.start();
String name = service.getName() + " (" + service.getURL() + ")";
Thread t = new Thread(this, name);
t.setDaemon(service.isDaemon());
t.start();
for (int i = 1; i < 64; i += i) {
wait(i);
if (isRunning(false)) {
return this;
}
}
if (isRunning(true)) {
return this;
}
throw DbException.get(ErrorCode.EXCEPTION_OPENING_PORT_2, name, "timeout; " +
"please check your network configuration, specially the file /etc/hosts");
} catch (DbException e) {
throw DbException.toSQLException(e);
}
}
// in src/main/org/h2/tools/Server.java
public static void startWebServer(Connection conn) throws SQLException {
WebServer webServer = new WebServer();
Server web = new Server(webServer, new String[] { "-webPort", "0" });
web.start();
Server server = new Server();
server.web = web;
webServer.setShutdownHandler(server);
String url = webServer.addSession(conn);
try {
Server.openBrowser(url);
while (!webServer.isStopped()) {
Thread.sleep(1000);
}
} catch (Exception e) {
// ignore
}
}
// in src/main/org/h2/tools/RunScript.java
public static void main(String... args) throws SQLException {
new RunScript().runTool(args);
}
// in src/main/org/h2/tools/RunScript.java
public void runTool(String... args) throws SQLException {
String url = null;
String user = "sa";
String password = "";
String script = "backup.sql";
String options = null;
boolean continueOnError = false;
boolean showTime = false;
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg.equals("-url")) {
url = args[++i];
} else if (arg.equals("-user")) {
user = args[++i];
} else if (arg.equals("-password")) {
password = args[++i];
} else if (arg.equals("-continueOnError")) {
continueOnError = true;
} else if (arg.equals("-checkResults")) {
checkResults = true;
} else if (arg.equals("-showResults")) {
showResults = true;
} else if (arg.equals("-script")) {
script = args[++i];
} else if (arg.equals("-time")) {
showTime = true;
} else if (arg.equals("-driver")) {
String driver = args[++i];
Utils.loadUserClass(driver);
} else if (arg.equals("-options")) {
StringBuilder buff = new StringBuilder();
i++;
for (; i < args.length; i++) {
buff.append(' ').append(args[i]);
}
options = buff.toString();
} else if (arg.equals("-help") || arg.equals("-?")) {
showUsage();
return;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
if (url == null) {
showUsage();
throw new SQLException("URL not set");
}
long time = System.currentTimeMillis();
if (options != null) {
processRunscript(url, user, password, script, options);
} else {
process(url, user, password, script, null, continueOnError);
}
if (showTime) {
time = System.currentTimeMillis() - time;
out.println("Done in " + time + " ms");
}
}
// in src/main/org/h2/tools/RunScript.java
public static ResultSet execute(Connection conn, Reader reader) throws SQLException {
Statement stat = conn.createStatement();
ResultSet rs = null;
ScriptReader r = new ScriptReader(reader);
while (true) {
String sql = r.readStatement();
if (sql == null) {
break;
}
if (sql.trim().length() == 0) {
continue;
}
boolean resultSet = stat.execute(sql);
if (resultSet) {
if (rs != null) {
rs.close();
rs = null;
}
rs = stat.getResultSet();
}
}
return rs;
}
// in src/main/org/h2/tools/RunScript.java
private void process(Connection conn, String fileName,
boolean continueOnError, String charsetName) throws SQLException, IOException {
InputStream in = FileUtils.newInputStream(fileName);
String path = FileUtils.getParent(fileName);
try {
in = new BufferedInputStream(in, Constants.IO_BUFFER_SIZE);
Reader reader = new InputStreamReader(in, charsetName);
process(conn, continueOnError, path, reader, charsetName);
} finally {
IOUtils.closeSilently(in);
}
}
// in src/main/org/h2/tools/RunScript.java
private void process(Connection conn, boolean continueOnError,
String path, Reader reader, String charsetName) throws SQLException, IOException {
Statement stat = conn.createStatement();
ScriptReader r = new ScriptReader(reader);
while (true) {
String sql = r.readStatement();
if (sql == null) {
break;
}
String trim = sql.trim();
if (trim.length() == 0) {
continue;
}
if (trim.startsWith("@") && StringUtils.toUpperEnglish(trim).startsWith("@INCLUDE")) {
sql = trim;
sql = sql.substring("@INCLUDE".length()).trim();
if (!FileUtils.isAbsolute(sql)) {
sql = path + SysProperties.FILE_SEPARATOR + sql;
}
process(conn, sql, continueOnError, charsetName);
} else {
try {
if (showResults && !trim.startsWith("-->")) {
out.print(sql + ";");
}
if (showResults || checkResults) {
boolean query = stat.execute(sql);
if (query) {
ResultSet rs = stat.getResultSet();
int columns = rs.getMetaData().getColumnCount();
StringBuilder buff = new StringBuilder();
while (rs.next()) {
buff.append("\n-->");
for (int i = 0; i < columns; i++) {
String s = rs.getString(i + 1);
if (s != null) {
s = StringUtils.replaceAll(s, "\r\n", "\n");
s = StringUtils.replaceAll(s, "\n", "\n--> ");
s = StringUtils.replaceAll(s, "\r", "\r--> ");
}
buff.append(' ').append(s);
}
}
buff.append("\n;");
String result = buff.toString();
if (showResults) {
out.print(result);
}
if (checkResults) {
String expected = r.readStatement() + ";";
expected = StringUtils.replaceAll(expected, "\r\n", "\n");
expected = StringUtils.replaceAll(expected, "\r", "\n");
if (!expected.equals(result)) {
expected = StringUtils.replaceAll(expected, " ", "+");
result = StringUtils.replaceAll(result, " ", "+");
throw new SQLException("Unexpected output for:\n" + sql.trim() + "\nGot:\n" + result + "\nExpected:\n" + expected);
}
}
}
} else {
stat.execute(sql);
}
} catch (Exception e) {
if (continueOnError) {
e.printStackTrace(out);
} else {
throw DbException.toSQLException(e);
}
}
}
}
}
// in src/main/org/h2/tools/RunScript.java
private static void processRunscript(String url, String user, String password,
String fileName, String options) throws SQLException {
Connection conn = null;
Statement stat = null;
try {
org.h2.Driver.load();
conn = DriverManager.getConnection(url, user, password);
stat = conn.createStatement();
String sql = "RUNSCRIPT FROM '" + fileName + "' " + options;
stat.execute(sql);
} finally {
JdbcUtils.closeSilently(stat);
JdbcUtils.closeSilently(conn);
}
}
// in src/main/org/h2/tools/RunScript.java
public static void execute(String url, String user, String password,
String fileName, String charsetName, boolean continueOnError) throws SQLException {
new RunScript().process(url, user, password, fileName, charsetName, continueOnError);
}
// in src/main/org/h2/tools/RunScript.java
void process(String url, String user, String password,
String fileName, String charsetName,
boolean continueOnError) throws SQLException {
try {
org.h2.Driver.load();
Connection conn = DriverManager.getConnection(url, user, password);
if (charsetName == null) {
charsetName = Constants.UTF8;
}
try {
process(conn, fileName, continueOnError, charsetName);
} finally {
conn.close();
}
} catch (IOException e) {
throw DbException.convertIOException(e, fileName);
}
}
// in src/main/org/h2/tools/Console.java
public static void main(String... args) throws SQLException {
new Console().runTool(args);
}
// in src/main/org/h2/tools/Console.java
public void runTool(String... args) throws SQLException {
isWindows = Utils.getProperty("os.name", "").startsWith("Windows");
boolean tcpStart = false, pgStart = false, webStart = false, toolStart = false;
boolean browserStart = false;
boolean startDefaultServers = true;
boolean printStatus = args != null && args.length > 0;
String driver = null, url = null, user = null, password = null;
boolean tcpShutdown = false, tcpShutdownForce = false;
String tcpPassword = "";
String tcpShutdownServer = "";
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg == null) {
continue;
} else if ("-?".equals(arg) || "-help".equals(arg)) {
showUsage();
return;
} else if ("-url".equals(arg)) {
startDefaultServers = false;
url = args[++i];
} else if ("-driver".equals(arg)) {
driver = args[++i];
} else if ("-user".equals(arg)) {
user = args[++i];
} else if ("-password".equals(arg)) {
password = args[++i];
} else if (arg.startsWith("-web")) {
if ("-web".equals(arg)) {
startDefaultServers = false;
webStart = true;
} else if ("-webAllowOthers".equals(arg)) {
// no parameters
} else if ("-webDaemon".equals(arg)) {
// no parameters
} else if ("-webSSL".equals(arg)) {
// no parameters
} else if ("-webPort".equals(arg)) {
i++;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
} else if ("-tool".equals(arg)) {
startDefaultServers = false;
webStart = true;
toolStart = true;
} else if ("-browser".equals(arg)) {
startDefaultServers = false;
webStart = true;
browserStart = true;
} else if (arg.startsWith("-tcp")) {
if ("-tcp".equals(arg)) {
startDefaultServers = false;
tcpStart = true;
} else if ("-tcpAllowOthers".equals(arg)) {
// no parameters
} else if ("-tcpDaemon".equals(arg)) {
// no parameters
} else if ("-tcpSSL".equals(arg)) {
// no parameters
} else if ("-tcpPort".equals(arg)) {
i++;
} else if ("-tcpPassword".equals(arg)) {
tcpPassword = args[++i];
} else if ("-tcpShutdown".equals(arg)) {
startDefaultServers = false;
tcpShutdown = true;
tcpShutdownServer = args[++i];
} else if ("-tcpShutdownForce".equals(arg)) {
tcpShutdownForce = true;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
} else if (arg.startsWith("-pg")) {
if ("-pg".equals(arg)) {
startDefaultServers = false;
pgStart = true;
} else if ("-pgAllowOthers".equals(arg)) {
// no parameters
} else if ("-pgDaemon".equals(arg)) {
// no parameters
} else if ("-pgPort".equals(arg)) {
i++;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
} else if ("-properties".equals(arg)) {
i++;
} else if ("-trace".equals(arg)) {
// no parameters
} else if ("-ifExists".equals(arg)) {
// no parameters
} else if ("-baseDir".equals(arg)) {
i++;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
if (startDefaultServers) {
webStart = true;
toolStart = true;
browserStart = true;
tcpStart = true;
pgStart = true;
}
if (tcpShutdown) {
out.println("Shutting down TCP Server at " + tcpShutdownServer);
Server.shutdownTcpServer(tcpShutdownServer, tcpPassword, tcpShutdownForce, false);
}
SQLException startException = null;
boolean webRunning = false;
if (url != null) {
Connection conn = JdbcUtils.getConnection(driver, url, user, password);
Server.startWebServer(conn);
}
if (webStart) {
try {
web = Server.createWebServer(args);
web.setShutdownHandler(this);
web.start();
if (printStatus) {
out.println(web.getStatus());
}
webRunning = true;
} catch (SQLException e) {
printProblem(e, web);
startException = e;
}
}
//## AWT ##
if (toolStart && webRunning && !GraphicsEnvironment.isHeadless()) {
loadFont();
try {
if (!createTrayIcon()) {
showWindow();
}
} catch (Exception e) {
e.printStackTrace();
}
}
//*/
// start browser in any case (even if the server is already running)
// because some people don't look at the output,
// but are wondering why nothing happens
if (browserStart && web != null) {
openBrowser(web.getURL());
}
if (tcpStart) {
try {
tcp = Server.createTcpServer(args);
tcp.start();
if (printStatus) {
out.println(tcp.getStatus());
}
tcp.setShutdownHandler(this);
} catch (SQLException e) {
printProblem(e, tcp);
if (startException == null) {
startException = e;
}
}
}
if (pgStart) {
try {
pg = Server.createPgServer(args);
pg.start();
if (printStatus) {
out.println(pg.getStatus());
}
} catch (SQLException e) {
printProblem(e, pg);
if (startException == null) {
startException = e;
}
}
}
if (startException != null) {
shutdown();
throw startException;
}
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Object getArray(Map<String, Class<?>> map) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Object getArray(long index, int count) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Object getArray(long index, int count, Map<String, Class<?>> map) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public ResultSet getResultSet() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public ResultSet getResultSet(long index, int count) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean next() throws SQLException {
if (source != null) {
rowId++;
currentRow = source.readRow();
if (currentRow != null) {
return true;
}
} else if (rows != null && rowId < rows.size()) {
rowId++;
if (rowId < rows.size()) {
currentRow = rows.get(rowId);
return true;
}
}
if (autoClose) {
close();
}
return false;
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void beforeFirst() throws SQLException {
rowId = -1;
if (source != null) {
source.reset();
}
}
// in src/main/org/h2/tools/SimpleResultSet.java
public int findColumn(String columnLabel) throws SQLException {
if (columnLabel != null && columns != null) {
for (int i = 0, size = columns.size(); i < size; i++) {
if (columnLabel.equalsIgnoreCase(getColumn(i).name)) {
return i + 1;
}
}
}
throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1, columnLabel).getSQLException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Array getArray(int columnIndex) throws SQLException {
Object[] o = (Object[]) get(columnIndex);
return o == null ? null : new SimpleArray(o);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Array getArray(String columnLabel) throws SQLException {
return getArray(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public InputStream getAsciiStream(int columnIndex) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public InputStream getAsciiStream(String columnLabel) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
Object o = get(columnIndex);
if (o != null && !(o instanceof BigDecimal)) {
o = new BigDecimal(o.toString());
}
return (BigDecimal) o;
}
// in src/main/org/h2/tools/SimpleResultSet.java
public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
return getBigDecimal(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public InputStream getBinaryStream(int columnIndex) throws SQLException {
Blob b = (Blob) get(columnIndex);
return b == null ? null : b.getBinaryStream();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public InputStream getBinaryStream(String columnLabel) throws SQLException {
return getBinaryStream(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Blob getBlob(int columnIndex) throws SQLException {
Blob b = (Blob) get(columnIndex);
return b == null ? null : b;
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Blob getBlob(String columnLabel) throws SQLException {
return getBlob(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean getBoolean(int columnIndex) throws SQLException {
Object o = get(columnIndex);
if (o != null && !(o instanceof Boolean)) {
o = Boolean.valueOf(o.toString());
}
return o == null ? false : ((Boolean) o).booleanValue();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean getBoolean(String columnLabel) throws SQLException {
return getBoolean(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public byte getByte(int columnIndex) throws SQLException {
Object o = get(columnIndex);
if (o != null && !(o instanceof Number)) {
o = Byte.decode(o.toString());
}
return o == null ? 0 : ((Number) o).byteValue();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public byte getByte(String columnLabel) throws SQLException {
return getByte(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public byte[] getBytes(int columnIndex) throws SQLException {
return (byte[]) get(columnIndex);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public byte[] getBytes(String columnLabel) throws SQLException {
return getBytes(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Reader getCharacterStream(int columnIndex) throws SQLException {
Clob c = (Clob) get(columnIndex);
return c == null ? null : c.getCharacterStream();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Reader getCharacterStream(String columnLabel) throws SQLException {
return getCharacterStream(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Clob getClob(int columnIndex) throws SQLException {
Clob c = (Clob) get(columnIndex);
return c == null ? null : c;
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Clob getClob(String columnLabel) throws SQLException {
return getClob(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Date getDate(int columnIndex) throws SQLException {
return (Date) get(columnIndex);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Date getDate(String columnLabel) throws SQLException {
return getDate(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Date getDate(int columnIndex, Calendar cal) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Date getDate(String columnLabel, Calendar cal) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public double getDouble(int columnIndex) throws SQLException {
Object o = get(columnIndex);
if (o != null && !(o instanceof Number)) {
return Double.parseDouble(o.toString());
}
return o == null ? 0 : ((Number) o).doubleValue();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public double getDouble(String columnLabel) throws SQLException {
return getDouble(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public float getFloat(int columnIndex) throws SQLException {
Object o = get(columnIndex);
if (o != null && !(o instanceof Number)) {
return Float.parseFloat(o.toString());
}
return o == null ? 0 : ((Number) o).floatValue();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public float getFloat(String columnLabel) throws SQLException {
return getFloat(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public int getInt(int columnIndex) throws SQLException {
Object o = get(columnIndex);
if (o != null && !(o instanceof Number)) {
o = Integer.decode(o.toString());
}
return o == null ? 0 : ((Number) o).intValue();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public int getInt(String columnLabel) throws SQLException {
return getInt(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public long getLong(int columnIndex) throws SQLException {
Object o = get(columnIndex);
if (o != null && !(o instanceof Number)) {
o = Long.decode(o.toString());
}
return o == null ? 0 : ((Number) o).longValue();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public long getLong(String columnLabel) throws SQLException {
return getLong(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Reader getNCharacterStream(int columnIndex) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Reader getNCharacterStream(String columnLabel) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public NClob getNClob(int columnIndex) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public NClob getNClob(String columnLabel) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public String getNString(int columnIndex) throws SQLException {
return getString(columnIndex);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public String getNString(String columnLabel) throws SQLException {
return getString(columnLabel);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Object getObject(int columnIndex) throws SQLException {
return get(columnIndex);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Object getObject(String columnLabel) throws SQLException {
return getObject(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Ref getRef(int columnIndex) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Ref getRef(String columnLabel) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public RowId getRowId(int columnIndex) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public RowId getRowId(String columnLabel) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public short getShort(int columnIndex) throws SQLException {
Object o = get(columnIndex);
if (o != null && !(o instanceof Number)) {
o = Short.decode(o.toString());
}
return o == null ? 0 : ((Number) o).shortValue();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public short getShort(String columnLabel) throws SQLException {
return getShort(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public SQLXML getSQLXML(int columnIndex) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public SQLXML getSQLXML(String columnLabel) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public String getString(int columnIndex) throws SQLException {
Object o = get(columnIndex);
if (o == null) {
return null;
}
switch (columns.get(columnIndex - 1).sqlType) {
case Types.CLOB:
Clob c = (Clob) o;
return c.getSubString(1, MathUtils.convertLongToInt(c.length()));
}
return o.toString();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public String getString(String columnLabel) throws SQLException {
return getString(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Time getTime(int columnIndex) throws SQLException {
return (Time) get(columnIndex);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Time getTime(String columnLabel) throws SQLException {
return getTime(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Time getTime(int columnIndex, Calendar cal) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Time getTime(String columnLabel, Calendar cal) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Timestamp getTimestamp(int columnIndex) throws SQLException {
return (Timestamp) get(columnIndex);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Timestamp getTimestamp(String columnLabel) throws SQLException {
return getTimestamp(findColumn(columnLabel));
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public InputStream getUnicodeStream(int columnIndex) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public InputStream getUnicodeStream(String columnLabel) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public URL getURL(int columnIndex) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public URL getURL(String columnLabel) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateArray(int columnIndex, Array x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateArray(String columnLabel, Array x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateAsciiStream(int columnIndex, InputStream x)
throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateAsciiStream(String columnLabel, InputStream x)
throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateAsciiStream(int columnIndex, InputStream x, long length)
throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateAsciiStream(String columnLabel, InputStream x, long length)
throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBinaryStream(int columnIndex, InputStream x)
throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBinaryStream(String columnLabel, InputStream x)
throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBinaryStream(int columnIndex, InputStream x, long length)
throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBinaryStream(String columnLabel, InputStream x, long length)
throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBlob(int columnIndex, Blob x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBlob(String columnLabel, Blob x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBlob(int columnIndex, InputStream x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBlob(String columnLabel, InputStream x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBlob(int columnIndex, InputStream x, long length)
throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBlob(String columnLabel, InputStream x, long length)
throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBoolean(int columnIndex, boolean x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBoolean(String columnLabel, boolean x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateByte(int columnIndex, byte x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateByte(String columnLabel, byte x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBytes(int columnIndex, byte[] x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateBytes(String columnLabel, byte[] x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateCharacterStream(int columnIndex, Reader x)
throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateCharacterStream(String columnLabel, Reader x)
throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateCharacterStream(String columnLabel, Reader x, int length) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateCharacterStream(int columnIndex, Reader x, long length)
throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateCharacterStream(String columnLabel, Reader x, long length)
throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateClob(int columnIndex, Clob x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateClob(String columnLabel, Clob x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateClob(int columnIndex, Reader x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateClob(String columnLabel, Reader x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateClob(int columnIndex, Reader x, long length)
throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateClob(String columnLabel, Reader x, long length)
throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateDate(int columnIndex, Date x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateDate(String columnLabel, Date x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateDouble(int columnIndex, double x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateDouble(String columnLabel, double x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateFloat(int columnIndex, float x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateFloat(String columnLabel, float x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateInt(int columnIndex, int x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateInt(String columnLabel, int x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateLong(int columnIndex, long x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateLong(String columnLabel, long x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateNCharacterStream(int columnIndex, Reader x)
throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateNCharacterStream(String columnLabel, Reader x)
throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateNCharacterStream(int columnIndex, Reader x, long length)
throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateNCharacterStream(String columnLabel, Reader x, long length)
throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateNClob(int columnIndex, NClob x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateNClob(String columnLabel, NClob x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateNClob(int columnIndex, Reader x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateNClob(String columnLabel, Reader x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateNClob(int columnIndex, Reader x, long length)
throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateNClob(String columnLabel, Reader x, long length)
throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateNString(int columnIndex, String x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateNString(String columnLabel, String x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateNull(int columnIndex) throws SQLException {
update(columnIndex, null);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateNull(String columnLabel) throws SQLException {
update(columnLabel, null);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateObject(int columnIndex, Object x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateObject(String columnLabel, Object x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateObject(int columnIndex, Object x, int scale) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateObject(String columnLabel, Object x, int scale) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateRef(int columnIndex, Ref x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateRef(String columnLabel, Ref x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateRowId(int columnIndex, RowId x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateRowId(String columnLabel, RowId x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateShort(int columnIndex, short x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateShort(String columnLabel, short x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateSQLXML(int columnIndex, SQLXML x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateSQLXML(String columnLabel, SQLXML x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateString(int columnIndex, String x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateString(String columnLabel, String x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateTime(int columnIndex, Time x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateTime(String columnLabel, Time x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
update(columnIndex, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException {
update(columnLabel, x);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public int getColumnType(int columnIndex) throws SQLException {
return getColumn(columnIndex - 1).sqlType;
}
// in src/main/org/h2/tools/SimpleResultSet.java
public int getPrecision(int columnIndex) throws SQLException {
return getColumn(columnIndex - 1).precision;
}
// in src/main/org/h2/tools/SimpleResultSet.java
public int getScale(int columnIndex) throws SQLException {
return getColumn(columnIndex - 1).scale;
}
// in src/main/org/h2/tools/SimpleResultSet.java
public String getColumnClassName(int columnIndex) throws SQLException {
int sqlType = getColumn(columnIndex - 1).sqlType;
int type = DataType.convertSQLTypeToValueType(sqlType);
return DataType.getTypeClassName(type);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public String getColumnLabel(int columnIndex) throws SQLException {
return getColumn(columnIndex - 1).name;
}
// in src/main/org/h2/tools/SimpleResultSet.java
public String getColumnName(int columnIndex) throws SQLException {
return getColumnLabel(columnIndex);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public String getColumnTypeName(int columnIndex) throws SQLException {
int sqlType = getColumn(columnIndex - 1).sqlType;
int type = DataType.convertSQLTypeToValueType(sqlType);
return DataType.getDataType(type).name;
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void afterLast() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void cancelRowUpdates() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void deleteRow() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void insertRow() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void moveToCurrentRow() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void moveToInsertRow() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void refreshRow() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void updateRow() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean first() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean isAfterLast() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean isBeforeFirst() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean isFirst() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean isLast() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean last() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean previous() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean rowDeleted() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean rowInserted() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean rowUpdated() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void setFetchDirection(int direction) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public void setFetchSize(int rows) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean absolute(int row) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean relative(int offset) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public String getCursorName() throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
private void update(int columnIndex, Object obj) throws SQLException {
checkColumnIndex(columnIndex);
this.currentRow[columnIndex - 1] = obj;
}
// in src/main/org/h2/tools/SimpleResultSet.java
private void update(String columnLabel, Object obj) throws SQLException {
this.currentRow[findColumn(columnLabel) - 1] = obj;
}
// in src/main/org/h2/tools/SimpleResultSet.java
private void checkColumnIndex(int columnIndex) throws SQLException {
if (columnIndex < 1 || columnIndex > columns.size()) {
throw DbException.getInvalidValueException("columnIndex", columnIndex).getSQLException();
}
}
// in src/main/org/h2/tools/SimpleResultSet.java
private Object get(int columnIndex) throws SQLException {
if (currentRow == null) {
throw DbException.get(ErrorCode.NO_DATA_AVAILABLE).getSQLException();
}
checkColumnIndex(columnIndex);
columnIndex--;
Object o = columnIndex < currentRow.length ? currentRow[columnIndex] : null;
wasNull = o == null;
return o;
}
// in src/main/org/h2/tools/SimpleResultSet.java
private Column getColumn(int i) throws SQLException {
checkColumnIndex(i + 1);
return columns.get(i);
}
// in src/main/org/h2/tools/SimpleResultSet.java
public <T> T unwrap(Class<T> iface) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/SimpleResultSet.java
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw getUnsupportedException();
}
// in src/main/org/h2/tools/MultiDimension.java
public ResultSet getResult(PreparedStatement prep, int[] min, int[] max) throws SQLException {
long[][] ranges = getMortonRanges(min, max);
int len = ranges.length;
Long[] from = new Long[len];
Long[] to = new Long[len];
for (int i = 0; i < len; i++) {
from[i] = Long.valueOf(ranges[i][0]);
to[i] = Long.valueOf(ranges[i][1]);
}
prep.setObject(1, from);
prep.setObject(2, to);
len = min.length;
for (int i = 0, idx = 3; i < len; i++) {
prep.setInt(idx++, min[i]);
prep.setInt(idx++, max[i]);
}
return prep.executeQuery();
}
// in src/main/org/h2/tools/Shell.java
public static void main(String... args) throws SQLException {
new Shell().runTool(args);
}
// in src/main/org/h2/tools/Shell.java
public void runTool(String... args) throws SQLException {
String url = null;
String user = "";
String password = "";
String sql = null;
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg.equals("-url")) {
url = args[++i];
} else if (arg.equals("-user")) {
user = args[++i];
} else if (arg.equals("-password")) {
password = args[++i];
} else if (arg.equals("-driver")) {
String driver = args[++i];
Utils.loadUserClass(driver);
} else if (arg.equals("-sql")) {
sql = args[++i];
} else if (arg.equals("-properties")) {
serverPropertiesDir = args[++i];
} else if (arg.equals("-help") || arg.equals("-?")) {
showUsage();
return;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
if (url != null) {
org.h2.Driver.load();
conn = DriverManager.getConnection(url, user, password);
stat = conn.createStatement();
}
if (sql == null) {
promptLoop();
} else {
ScriptReader r = new ScriptReader(new StringReader(sql));
while (true) {
String s = r.readStatement();
if (s == null) {
break;
}
execute(s);
}
}
}
// in src/main/org/h2/tools/Shell.java
private void connect() throws IOException, SQLException {
String url = "jdbc:h2:~/test";
String user = "sa";
String driver = null;
try {
Properties prop;
if ("null".equals(serverPropertiesDir)) {
prop = new Properties();
} else {
prop = SortedProperties.loadProperties(serverPropertiesDir + "/" + Constants.SERVER_PROPERTIES_NAME);
}
String data = null;
boolean found = false;
for (int i = 0;; i++) {
String d = prop.getProperty(String.valueOf(i));
if (d == null) {
break;
}
found = true;
data = d;
}
if (found) {
ConnectionInfo info = new ConnectionInfo(data);
url = info.url;
user = info.user;
driver = info.driver;
}
} catch (IOException e) {
// ignore
}
println("[Enter] " + url);
print("URL ");
url = readLine(url).trim();
if (driver == null) {
driver = JdbcUtils.getDriver(url);
}
if (driver != null) {
println("[Enter] " + driver);
}
print("Driver ");
driver = readLine(driver).trim();
println("[Enter] " + user);
print("User ");
user = readLine(user);
println("[Enter] Hide");
print("Password ");
String password = readLine();
if (password.length() == 0) {
password = readPassword();
}
conn = JdbcUtils.getConnection(driver, url, user, password);
stat = conn.createStatement();
println("Connected");
}
// in src/main/org/h2/tools/Shell.java
private int printResult(ResultSet rs, boolean asList) throws SQLException {
if (asList) {
return printResultAsList(rs);
}
return printResultAsTable(rs);
}
// in src/main/org/h2/tools/Shell.java
private int printResultAsTable(ResultSet rs) throws SQLException {
ResultSetMetaData meta = rs.getMetaData();
int len = meta.getColumnCount();
boolean truncated = false;
ArrayList<String[]> rows = New.arrayList();
// buffer the header
String[] columns = new String[len];
for (int i = 0; i < len; i++) {
String s = meta.getColumnLabel(i + 1);
columns[i] = s == null ? "" : s;
}
rows.add(columns);
int rowCount = 0;
while (rs.next()) {
rowCount++;
truncated |= loadRow(rs, len, rows);
if (rowCount > MAX_ROW_BUFFER) {
printRows(rows, len);
rows.clear();
}
}
printRows(rows, len);
rows.clear();
if (truncated) {
println("(data is partially truncated)");
}
return rowCount;
}
// in src/main/org/h2/tools/Shell.java
private boolean loadRow(ResultSet rs, int len, ArrayList<String[]> rows) throws SQLException {
boolean truncated = false;
String[] row = new String[len];
for (int i = 0; i < len; i++) {
String s = rs.getString(i + 1);
if (s == null) {
s = "null";
}
// only truncate if more than one column
if (len > 1 && s.length() > maxColumnSize) {
s = s.substring(0, maxColumnSize);
truncated = true;
}
row[i] = s;
}
rows.add(row);
return truncated;
}
// in src/main/org/h2/tools/Shell.java
private int printResultAsList(ResultSet rs) throws SQLException {
ResultSetMetaData meta = rs.getMetaData();
int longestLabel = 0;
int len = meta.getColumnCount();
String[] columns = new String[len];
for (int i = 0; i < len; i++) {
String s = meta.getColumnLabel(i + 1);
columns[i] = s;
longestLabel = Math.max(longestLabel, s.length());
}
StringBuilder buff = new StringBuilder();
int rowCount = 0;
while (rs.next()) {
rowCount++;
buff.setLength(0);
if (rowCount > 1) {
println("");
}
for (int i = 0; i < len; i++) {
if (i > 0) {
buff.append('\n');
}
String label = columns[i];
buff.append(label);
for (int j = label.length(); j < longestLabel; j++) {
buff.append(' ');
}
buff.append(": ").append(rs.getString(i + 1));
}
println(buff.toString());
}
if (rowCount == 0) {
for (int i = 0; i < len; i++) {
if (i > 0) {
buff.append('\n');
}
String label = columns[i];
buff.append(label);
}
println(buff.toString());
}
return rowCount;
}
// in src/main/org/h2/tools/DeleteDbFiles.java
public static void main(String... args) throws SQLException {
new DeleteDbFiles().runTool(args);
}
// in src/main/org/h2/tools/DeleteDbFiles.java
public void runTool(String... args) throws SQLException {
String dir = ".";
String db = null;
boolean quiet = false;
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg.equals("-dir")) {
dir = args[++i];
} else if (arg.equals("-db")) {
db = args[++i];
} else if (arg.equals("-quiet")) {
quiet = true;
} else if (arg.equals("-help") || arg.equals("-?")) {
showUsage();
return;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
process(dir, db, quiet);
}
// in src/main/org/h2/value/ValueNull.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setNull(parameterIndex, DataType.convertTypeToSQLType(Value.NULL));
}
// in src/main/org/h2/value/ValueTime.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setTime(parameterIndex, getTime());
}
// in src/main/org/h2/value/ValueLob.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
long p = getPrecision();
if (p > Integer.MAX_VALUE || p <= 0) {
p = -1;
}
if (type == Value.BLOB) {
prep.setBinaryStream(parameterIndex, getInputStream(), (int) p);
} else {
prep.setCharacterStream(parameterIndex, getReader(), (int) p);
}
}
// in src/main/org/h2/value/ValueDate.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setDate(parameterIndex, getDate());
}
// in src/main/org/h2/value/ValueInt.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setInt(parameterIndex, value);
}
// in src/main/org/h2/value/ValueByte.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setByte(parameterIndex, value);
}
// in src/main/org/h2/value/ValueLong.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setLong(parameterIndex, value);
}
// in src/main/org/h2/value/ValueFloat.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setFloat(parameterIndex, value);
}
// in src/main/org/h2/value/ValueLobDb.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
long p = getPrecision();
if (p > Integer.MAX_VALUE || p <= 0) {
p = -1;
}
if (type == Value.BLOB) {
prep.setBinaryStream(parameterIndex, getInputStream(), (int) p);
} else {
prep.setCharacterStream(parameterIndex, getReader(), (int) p);
}
}
// in src/main/org/h2/value/ValueBytes.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setBytes(parameterIndex, value);
}
// in src/main/org/h2/value/ValueTimestamp.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setTimestamp(parameterIndex, getTimestamp());
}
// in src/main/org/h2/value/ValueDouble.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setDouble(parameterIndex, value);
}
// in src/main/org/h2/value/ValueShort.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setShort(parameterIndex, value);
}
// in src/main/org/h2/value/ValueJavaObject.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
Object obj = Utils.deserialize(getBytesNoCopy());
prep.setObject(parameterIndex, obj, Types.JAVA_OBJECT);
}
// in src/main/org/h2/value/ValueString.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setString(parameterIndex, value);
}
// in src/main/org/h2/value/ValueUuid.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setBytes(parameterIndex, getBytes());
}
// in src/main/org/h2/value/ValueBoolean.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setBoolean(parameterIndex, value.booleanValue());
}
// in src/main/org/h2/value/ValueDecimal.java
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setBigDecimal(parameterIndex, value);
}
// in src/main/org/h2/upgrade/DbUpgrade.java
public static Connection connectOrUpgrade(String url, Properties info) throws SQLException {
if (!upgradeClassesPresent) {
return null;
}
Properties i2 = new Properties();
i2.putAll(info);
// clone so that the password (if set as a char array) is not cleared
Object o = info.get("password");
if (o != null && o instanceof char[]) {
i2.put("password", StringUtils.cloneCharArray((char[]) o));
}
info = i2;
ConnectionInfo ci = new ConnectionInfo(url, info);
if (ci.isRemote() || !ci.isPersistent()) {
return null;
}
String name = ci.getName();
if (FileUtils.exists(name + ".h2.db")) {
return null;
}
if (!FileUtils.exists(name + ".data.db")) {
return null;
}
if (ci.removeProperty("NO_UPGRADE", false)) {
return connectWithOldVersion(url, info);
}
synchronized (DbUpgrade.class) {
upgrade(ci, info);
return null;
}
// in src/main/org/h2/upgrade/DbUpgrade.java
private static Connection connectWithOldVersion(String url, Properties info) throws SQLException {
url = "jdbc:h2v1_1:" + url.substring("jdbc:h2:".length()) + ";IGNORE_UNKNOWN_SETTINGS=TRUE";
return DriverManager.getConnection(url, info);
}
// in src/main/org/h2/upgrade/DbUpgrade.java
private static void upgrade(ConnectionInfo ci, Properties info) throws SQLException {
String name = ci.getName();
String data = name + ".data.db";
String index = name + ".index.db";
String lobs = name + ".lobs.db";
String backupData = data + ".backup";
String backupIndex = index + ".backup";
String backupLobs = lobs + ".backup";
String script = null;
try {
if (scriptInTempDir) {
new File(Utils.getProperty("java.io.tmpdir", ".")).mkdirs();
script = File.createTempFile("h2dbmigration", "backup.sql").getAbsolutePath();
} else {
script = name + ".script.sql";
}
String oldUrl = "jdbc:h2v1_1:" + name + ";UNDO_LOG=0;LOG=0;LOCK_MODE=0";
String cipher = ci.getProperty("CIPHER", null);
if (cipher != null) {
oldUrl += ";CIPHER=" + cipher;
}
Connection conn = DriverManager.getConnection(oldUrl, info);
Statement stat = conn.createStatement();
String uuid = UUID.randomUUID().toString();
if (cipher != null) {
stat.execute("script to '" + script + "' cipher aes password '" + uuid + "' --hide--");
} else {
stat.execute("script to '" + script + "'");
}
conn.close();
FileUtils.moveTo(data, backupData);
FileUtils.moveTo(index, backupIndex);
if (FileUtils.exists(lobs)) {
FileUtils.moveTo(lobs, backupLobs);
}
ci.removeProperty("IFEXISTS", false);
conn = new JdbcConnection(ci, true);
stat = conn.createStatement();
if (cipher != null) {
stat.execute("runscript from '" + script + "' cipher aes password '" + uuid + "' --hide--");
} else {
stat.execute("runscript from '" + script + "'");
}
stat.execute("analyze");
stat.execute("shutdown compact");
stat.close();
conn.close();
if (deleteOldDb) {
FileUtils.delete(backupData);
FileUtils.delete(backupIndex);
FileUtils.deleteRecursive(backupLobs, false);
}
} catch (Exception e) {
if (FileUtils.exists(backupData)) {
FileUtils.moveTo(backupData, data);
}
if (FileUtils.exists(backupIndex)) {
FileUtils.moveTo(backupIndex, index);
}
if (FileUtils.exists(backupLobs)) {
FileUtils.moveTo(backupLobs, lobs);
}
FileUtils.delete(name + ".h2.db");
throw DbException.toSQLException(e);
} finally {
if (script != null) {
FileUtils.delete(script);
}
}
}
// in src/main/org/h2/result/UpdatableRow.java
private void setKey(PreparedStatement prep, int start, Value[] current) throws SQLException {
for (int i = 0, size = key.size(); i < size; i++) {
String col = key.get(i);
int idx = getColumnIndex(col);
Value v = current[idx];
if (v == null || v == ValueNull.INSTANCE) {
// rows with a unique key containing NULL are not supported,
// as multiple such rows could exist
throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
}
v.set(prep, start + i);
}
}
// in src/main/org/h2/result/UpdatableRow.java
public Value[] readRow(Value[] row) throws SQLException {
StatementBuilder buff = new StatementBuilder("SELECT ");
appendColumnList(buff, false);
buff.append(" FROM ");
appendTableName(buff);
appendKeyCondition(buff);
PreparedStatement prep = conn.prepareStatement(buff.toString());
setKey(prep, 1, row);
ResultSet rs = prep.executeQuery();
if (!rs.next()) {
throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
}
Value[] newRow = new Value[columnCount];
for (int i = 0; i < columnCount; i++) {
int type = result.getColumnType(i);
newRow[i] = DataType.readValue(conn.getSession(), rs, i + 1, type);
}
return newRow;
}
// in src/main/org/h2/result/UpdatableRow.java
public void deleteRow(Value[] current) throws SQLException {
StatementBuilder buff = new StatementBuilder("DELETE FROM ");
appendTableName(buff);
appendKeyCondition(buff);
PreparedStatement prep = conn.prepareStatement(buff.toString());
setKey(prep, 1, current);
int count = prep.executeUpdate();
if (count != 1) {
// the row has already been deleted
throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
}
}
// in src/main/org/h2/result/UpdatableRow.java
public void updateRow(Value[] current, Value[] updateRow) throws SQLException {
StatementBuilder buff = new StatementBuilder("UPDATE ");
appendTableName(buff);
buff.append(" SET ");
appendColumnList(buff, true);
// TODO updatable result set: we could add all current values to the
// where clause
// - like this optimistic ('no') locking is possible
appendKeyCondition(buff);
PreparedStatement prep = conn.prepareStatement(buff.toString());
int j = 1;
for (int i = 0; i < columnCount; i++) {
Value v = updateRow[i];
if (v == null) {
v = current[i];
}
v.set(prep, j++);
}
setKey(prep, j, current);
int count = prep.executeUpdate();
if (count != 1) {
// the row has been deleted
throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
}
}
// in src/main/org/h2/result/UpdatableRow.java
public void insertRow(Value[] row) throws SQLException {
StatementBuilder buff = new StatementBuilder("INSERT INTO ");
appendTableName(buff);
buff.append('(');
appendColumnList(buff, false);
buff.append(")VALUES(");
buff.resetCount();
for (int i = 0; i < columnCount; i++) {
buff.appendExceptFirst(",");
Value v = row[i];
if (v == null) {
buff.append("DEFAULT");
} else {
buff.append('?');
}
}
buff.append(')');
PreparedStatement prep = conn.prepareStatement(buff.toString());
for (int i = 0, j = 0; i < columnCount; i++) {
Value v = row[i];
if (v != null) {
v.set(prep, j++ + 1);
}
}
int count = prep.executeUpdate();
if (count != 1) {
throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
}
}
// in src/main/org/h2/schema/TriggerObject.java
public void close() throws SQLException {
if (triggerCallback != null) {
triggerCallback.close();
}
}
// in src/main/org/h2/expression/JavaAggregate.java
private AggregateFunction getInstance() throws SQLException {
AggregateFunction agg = userAggregate.getInstance();
agg.init(userConnection);
return agg;
}
// in src/main/org/h2/store/FileLister.java
public static void tryUnlockDatabase(List<String> files, String message) throws SQLException {
for (String fileName : files) {
if (fileName.endsWith(Constants.SUFFIX_LOCK_FILE)) {
FileLock lock = new FileLock(new TraceSystem(null), fileName, Constants.LOCK_SLEEP);
try {
lock.lock(FileLock.LOCK_FILE);
lock.unlock();
} catch (DbException e) {
throw DbException.get(
ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1, message).getSQLException();
}
}
}
}
// in src/main/org/h2/store/LobStorage.java
private long getNextLobId() throws SQLException {
String sql = "SELECT MAX(LOB) FROM " + LOB_MAP;
PreparedStatement prep = prepare(sql);
ResultSet rs = prep.executeQuery();
rs.next();
long x = rs.getLong(1) + 1;
reuse(sql, prep);
sql = "SELECT MAX(ID) FROM " + LOBS;
prep = prepare(sql);
rs = prep.executeQuery();
rs.next();
x = Math.max(x, rs.getLong(1) + 1);
reuse(sql, prep);
return x;
}
// in src/main/org/h2/store/LobStorage.java
byte[] readBlock(long lob, int seq) throws SQLException {
synchronized (handler) {
String sql = "SELECT COMPRESSED, DATA FROM " + LOB_MAP + " M " +
"INNER JOIN " + LOB_DATA + " D ON M.BLOCK = D.BLOCK " +
"WHERE M.LOB = ? AND M.SEQ = ?";
PreparedStatement prep = prepare(sql);
prep.setLong(1, lob);
prep.setInt(2, seq);
ResultSet rs = prep.executeQuery();
if (!rs.next()) {
throw DbException.get(ErrorCode.IO_EXCEPTION_1, "Missing lob entry: "+ lob + "/" + seq).getSQLException();
}
int compressed = rs.getInt(1);
byte[] buffer = rs.getBytes(2);
if (compressed != 0) {
buffer = compress.expand(buffer);
}
reuse(sql, prep);
return buffer;
}
}
// in src/main/org/h2/store/LobStorage.java
long[] skipBuffer(long lob, long pos) throws SQLException {
synchronized (handler) {
String sql = "SELECT MAX(SEQ), MAX(POS) FROM " + LOB_MAP +
" WHERE LOB = ? AND POS < ?";
PreparedStatement prep = prepare(sql);
prep.setLong(1, lob);
prep.setLong(2, pos);
ResultSet rs = prep.executeQuery();
rs.next();
int seq = rs.getInt(1);
pos = rs.getLong(2);
boolean wasNull = rs.wasNull();
rs.close();
reuse(sql, prep);
// upgraded: offset not set
return wasNull ? null : new long[]{seq, pos};
}
}
// in src/main/org/h2/store/LobStorage.java
private PreparedStatement prepare(String sql) throws SQLException {
if (SysProperties.CHECK2) {
if (!Thread.holdsLock(handler)) {
throw DbException.throwInternalError();
}
}
PreparedStatement prep = prepared.remove(sql);
if (prep == null) {
prep = conn.prepareStatement(sql);
}
return prep;
}
// in src/main/org/h2/store/LobStorage.java
void storeBlock(long lobId, int seq, long pos, byte[] b, String compressAlgorithm) throws SQLException {
long block;
boolean blockExists = false;
if (compressAlgorithm != null) {
b = compress.compress(b, compressAlgorithm);
}
int hash = Arrays.hashCode(b);
synchronized (handler) {
block = getHashCacheBlock(hash);
if (block != -1) {
String sql = "SELECT COMPRESSED, DATA FROM " + LOB_DATA +
" WHERE BLOCK = ?";
PreparedStatement prep = prepare(sql);
prep.setLong(1, block);
ResultSet rs = prep.executeQuery();
if (rs.next()) {
boolean compressed = rs.getInt(1) != 0;
byte[] compare = rs.getBytes(2);
if (compressed == (compressAlgorithm != null) && Arrays.equals(b, compare)) {
blockExists = true;
}
}
reuse(sql, prep);
}
if (!blockExists) {
block = nextBlock++;
setHashCacheBlock(hash, block);
String sql = "INSERT INTO " + LOB_DATA + "(BLOCK, COMPRESSED, DATA) VALUES(?, ?, ?)";
PreparedStatement prep = prepare(sql);
prep.setLong(1, block);
prep.setInt(2, compressAlgorithm == null ? 0 : 1);
prep.setBytes(3, b);
prep.execute();
reuse(sql, prep);
}
String sql = "INSERT INTO " + LOB_MAP + "(LOB, SEQ, POS, HASH, BLOCK) VALUES(?, ?, ?, ?, ?)";
PreparedStatement prep = prepare(sql);
prep.setLong(1, lobId);
prep.setInt(2, seq);
prep.setLong(3, pos);
prep.setLong(4, hash);
prep.setLong(5, block);
prep.execute();
reuse(sql, prep);
}
}
// in src/main/org/h2/Driver.java
public Connection connect(String url, Properties info) throws SQLException {
try {
if (info == null) {
info = new Properties();
}
if (!acceptsURL(url)) {
return null;
}
if (url.equals(DEFAULT_URL)) {
return DEFAULT_CONNECTION.get();
}
Connection c = DbUpgrade.connectOrUpgrade(url, info);
if (c != null) {
return c;
}
return new JdbcConnection(url, info);
} catch (Exception e) {
throw DbException.toSQLException(e);
}
}
// in src/main/org/h2/command/dml/ScriptCommand.java
public static InputStream combineBlob(Connection conn, int id) throws SQLException {
if (id < 0) {
return null;
}
final ResultSet rs = getLobStream(conn, "BDATA", id);
return new InputStream() {
private InputStream current;
private boolean closed;
public int read() throws IOException {
while (true) {
try {
if (current == null) {
if (closed) {
return -1;
}
if (!rs.next()) {
close();
return -1;
}
current = rs.getBinaryStream(1);
current = new BufferedInputStream(current);
}
int x = current.read();
if (x >= 0) {
return x;
}
current = null;
} catch (SQLException e) {
throw DbException.convertToIOException(e);
}
}
}
public void close() throws IOException {
if (closed) {
return;
}
closed = true;
try {
rs.close();
} catch (SQLException e) {
throw DbException.convertToIOException(e);
}
}
};
}
// in src/main/org/h2/command/dml/ScriptCommand.java
public static Reader combineClob(Connection conn, int id) throws SQLException {
if (id < 0) {
return null;
}
final ResultSet rs = getLobStream(conn, "CDATA", id);
return new Reader() {
private Reader current;
private boolean closed;
public int read() throws IOException {
while (true) {
try {
if (current == null) {
if (closed) {
return -1;
}
if (!rs.next()) {
close();
return -1;
}
current = rs.getCharacterStream(1);
current = new BufferedReader(current);
}
int x = current.read();
if (x >= 0) {
return x;
}
current = null;
} catch (SQLException e) {
throw DbException.convertToIOException(e);
}
}
}
public void close() throws IOException {
if (closed) {
return;
}
closed = true;
try {
rs.close();
} catch (SQLException e) {
throw DbException.convertToIOException(e);
}
}
public int read(char[] buffer, int off, int len) throws IOException {
if (len == 0) {
return 0;
}
int c = read();
if (c == -1) {
return -1;
}
buffer[off] = (char) c;
int i = 1;
for (; i < len; i++) {
c = read();
if (c == -1) {
break;
}
buffer[off + i] = (char) c;
}
return i;
}
};
}
// in src/main/org/h2/command/dml/ScriptCommand.java
private static ResultSet getLobStream(Connection conn, String column, int id) throws SQLException {
PreparedStatement prep = conn.prepareStatement(
"SELECT " + column + " FROM SYSTEM_LOB_STREAM WHERE ID=? ORDER BY PART");
prep.setInt(1, id);
return prep.executeQuery();
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public Statement createStatement() throws SQLException {
try {
int id = getNextId(TraceObject.STATEMENT);
if (isDebugEnabled()) {
debugCodeAssign("Statement", TraceObject.STATEMENT, id, "createStatement()");
}
checkClosed();
return new JdbcStatement(this, id, ResultSet.TYPE_FORWARD_ONLY, Constants.DEFAULT_RESULT_SET_CONCURRENCY, false);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
try {
int id = getNextId(TraceObject.STATEMENT);
if (isDebugEnabled()) {
debugCodeAssign("Statement", TraceObject.STATEMENT, id,
"createStatement(" + resultSetType + ", " + resultSetConcurrency + ")");
}
checkTypeConcurrency(resultSetType, resultSetConcurrency);
checkClosed();
return new JdbcStatement(this, id, resultSetType, resultSetConcurrency, false);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
throws SQLException {
try {
int id = getNextId(TraceObject.STATEMENT);
if (isDebugEnabled()) {
debugCodeAssign("Statement", TraceObject.STATEMENT, id,
"createStatement(" + resultSetType + ", " + resultSetConcurrency + ", " + resultSetHoldability + ")");
}
checkTypeConcurrency(resultSetType, resultSetConcurrency);
checkHoldability(resultSetHoldability);
checkClosed();
return new JdbcStatement(this, id, resultSetType, resultSetConcurrency, false);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public PreparedStatement prepareStatement(String sql) throws SQLException {
try {
int id = getNextId(TraceObject.PREPARED_STATEMENT);
if (isDebugEnabled()) {
debugCodeAssign("PreparedStatement", TraceObject.PREPARED_STATEMENT, id, "prepareStatement(" + quote(sql) + ")");
}
checkClosed();
sql = translateSQL(sql);
return new JdbcPreparedStatement(this, sql, id,
ResultSet.TYPE_FORWARD_ONLY, Constants.DEFAULT_RESULT_SET_CONCURRENCY, false);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
PreparedStatement prepareAutoCloseStatement(String sql) throws SQLException {
try {
int id = getNextId(TraceObject.PREPARED_STATEMENT);
if (isDebugEnabled()) {
debugCodeAssign("PreparedStatement", TraceObject.PREPARED_STATEMENT, id, "prepareStatement(" + quote(sql) + ")");
}
checkClosed();
sql = translateSQL(sql);
return new JdbcPreparedStatement(this, sql, id,
ResultSet.TYPE_FORWARD_ONLY, Constants.DEFAULT_RESULT_SET_CONCURRENCY, true);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public DatabaseMetaData getMetaData() throws SQLException {
try {
int id = getNextId(TraceObject.DATABASE_META_DATA);
if (isDebugEnabled()) {
debugCodeAssign("DatabaseMetaData", TraceObject.DATABASE_META_DATA, id, "getMetaData()");
}
checkClosed();
return new JdbcDatabaseMetaData(this, trace, id);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public synchronized void close() throws SQLException {
try {
debugCodeCall("close");
if (session == null) {
return;
}
CloseWatcher.unregister(watcher);
session.cancel();
if (executingStatement != null) {
try {
executingStatement.cancel();
} catch (NullPointerException e) {
// ignore
}
}
synchronized (session) {
try {
if (!session.isClosed()) {
try {
if (session.getUndoLogPos() != 0) {
// roll back unless that would require to re-connect
// (the transaction can't be rolled back after re-connecting)
if (!session.isReconnectNeeded(true)) {
try {
rollbackInternal();
} catch (DbException e) {
// ignore if the connection is broken right now
if (e.getErrorCode() != ErrorCode.CONNECTION_BROKEN_1) {
throw e;
}
}
}
session.afterWriting();
}
closePreparedCommands();
} finally {
session.close();
}
}
} finally {
session = null;
}
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public synchronized void setAutoCommit(boolean autoCommit) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setAutoCommit(" + autoCommit + ");");
}
checkClosed();
if (autoCommit && !session.getAutoCommit()) {
commit();
}
session.setAutoCommit(autoCommit);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public synchronized boolean getAutoCommit() throws SQLException {
try {
checkClosed();
debugCodeCall("getAutoCommit");
return session.getAutoCommit();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public synchronized void commit() throws SQLException {
try {
debugCodeCall("commit");
checkClosedForWrite();
try {
commit = prepareCommand("COMMIT", commit);
commit.executeUpdate();
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public synchronized void rollback() throws SQLException {
try {
debugCodeCall("rollback");
checkClosedForWrite();
try {
rollbackInternal();
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public boolean isClosed() throws SQLException {
try {
debugCodeCall("isClosed");
return session == null || session.isClosed();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public String nativeSQL(String sql) throws SQLException {
try {
debugCodeCall("nativeSQL", sql);
checkClosed();
return translateSQL(sql);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public void setReadOnly(boolean readOnly) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setReadOnly(" + readOnly + ");");
}
checkClosed();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public boolean isReadOnly() throws SQLException {
try {
debugCodeCall("isReadOnly");
checkClosed();
getReadOnly = prepareCommand("CALL READONLY()", getReadOnly);
ResultInterface result = getReadOnly.executeQuery(0, false);
result.next();
boolean readOnly = result.currentRow()[0].getBoolean().booleanValue();
return readOnly;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public void setCatalog(String catalog) throws SQLException {
try {
debugCodeCall("setCatalog", catalog);
checkClosed();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
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);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public SQLWarning getWarnings() throws SQLException {
try {
debugCodeCall("getWarnings");
checkClosed();
return null;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public void clearWarnings() throws SQLException {
try {
debugCodeCall("clearWarnings");
checkClosed();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
try {
int id = getNextId(TraceObject.PREPARED_STATEMENT);
if (isDebugEnabled()) {
debugCodeAssign("PreparedStatement", TraceObject.PREPARED_STATEMENT, id,
"prepareStatement(" + quote(sql) + ", " + resultSetType + ", " + resultSetConcurrency + ")");
}
checkTypeConcurrency(resultSetType, resultSetConcurrency);
checkClosed();
sql = translateSQL(sql);
return new JdbcPreparedStatement(this, sql, id, resultSetType, resultSetConcurrency, false);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public void setTransactionIsolation(int level) throws SQLException {
try {
debugCodeCall("setTransactionIsolation", level);
checkClosed();
int lockMode;
switch(level) {
case Connection.TRANSACTION_READ_UNCOMMITTED:
lockMode = Constants.LOCK_MODE_OFF;
break;
case Connection.TRANSACTION_READ_COMMITTED:
lockMode = Constants.LOCK_MODE_READ_COMMITTED;
break;
case Connection.TRANSACTION_REPEATABLE_READ:
case Connection.TRANSACTION_SERIALIZABLE:
lockMode = Constants.LOCK_MODE_TABLE;
break;
default:
throw DbException.getInvalidValueException("level", level);
}
commit();
setLockMode = prepareCommand("SET LOCK_MODE ?", setLockMode);
setLockMode.getParameters().get(0).setValue(ValueInt.get(lockMode), false);
setLockMode.executeUpdate();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public void setQueryTimeout(int seconds) throws SQLException {
try {
debugCodeCall("setQueryTimeout", seconds);
checkClosed();
setQueryTimeout = prepareCommand("SET QUERY_TIMEOUT ?", setQueryTimeout);
setQueryTimeout.getParameters().get(0).setValue(ValueInt.get(seconds * 1000), false);
setQueryTimeout.executeUpdate();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public int getQueryTimeout() throws SQLException {
try {
debugCodeCall("getQueryTimeout");
checkClosed();
getQueryTimeout = prepareCommand("SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME=?", getQueryTimeout);
getQueryTimeout.getParameters().get(0).setValue(ValueString.get("QUERY_TIMEOUT"), false);
ResultInterface result = getQueryTimeout.executeQuery(0, false);
result.next();
int queryTimeout = result.currentRow()[0].getInt();
result.close();
if (queryTimeout == 0) {
return 0;
}
// round to the next second, otherwise 999 millis would return 0 seconds
return (queryTimeout + 999) / 1000;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public int getTransactionIsolation() throws SQLException {
try {
debugCodeCall("getTransactionIsolation");
checkClosed();
getLockMode = prepareCommand("CALL LOCK_MODE()", getLockMode);
ResultInterface result = getLockMode.executeQuery(0, false);
result.next();
int lockMode = result.currentRow()[0].getInt();
result.close();
int transactionIsolationLevel;
switch(lockMode) {
case Constants.LOCK_MODE_OFF:
transactionIsolationLevel = Connection.TRANSACTION_READ_UNCOMMITTED;
break;
case Constants.LOCK_MODE_READ_COMMITTED:
transactionIsolationLevel = Connection.TRANSACTION_READ_COMMITTED;
break;
case Constants.LOCK_MODE_TABLE:
case Constants.LOCK_MODE_TABLE_GC:
transactionIsolationLevel = Connection.TRANSACTION_SERIALIZABLE;
break;
default:
throw DbException.throwInternalError("lockMode:" + lockMode);
}
return transactionIsolationLevel;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public void setHoldability(int holdability) throws SQLException {
try {
debugCodeCall("setHoldability", holdability);
checkClosed();
checkHoldability(holdability);
this.holdability = holdability;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public int getHoldability() throws SQLException {
try {
debugCodeCall("getHoldability");
checkClosed();
return holdability;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public Map<String, Class<?>> getTypeMap() throws SQLException {
try {
debugCodeCall("getTypeMap");
checkClosed();
return null;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
try {
debugCode("setTypeMap(" + quoteMap(map) + ");");
checkMap(map);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public CallableStatement prepareCall(String sql) throws SQLException {
try {
int id = getNextId(TraceObject.CALLABLE_STATEMENT);
if (isDebugEnabled()) {
debugCodeAssign("CallableStatement", TraceObject.CALLABLE_STATEMENT, id, "prepareCall(" + quote(sql) + ")");
}
checkClosed();
sql = translateSQL(sql);
return new JdbcCallableStatement(this, sql, id, ResultSet.TYPE_FORWARD_ONLY, Constants.DEFAULT_RESULT_SET_CONCURRENCY);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
try {
int id = getNextId(TraceObject.CALLABLE_STATEMENT);
if (isDebugEnabled()) {
debugCodeAssign("CallableStatement", TraceObject.CALLABLE_STATEMENT, id,
"prepareCall(" + quote(sql) + ", " + resultSetType + ", " + resultSetConcurrency + ")");
}
checkTypeConcurrency(resultSetType, resultSetConcurrency);
checkClosed();
sql = translateSQL(sql);
return new JdbcCallableStatement(this, sql, id, resultSetType, resultSetConcurrency);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public CallableStatement prepareCall(String sql, int resultSetType,
int resultSetConcurrency, int resultSetHoldability) throws SQLException {
try {
int id = getNextId(TraceObject.CALLABLE_STATEMENT);
if (isDebugEnabled()) {
debugCodeAssign("CallableStatement", TraceObject.CALLABLE_STATEMENT, id,
"prepareCall(" + quote(sql) + ", " + resultSetType + ", " + resultSetConcurrency + ", "
+ resultSetHoldability + ")");
}
checkTypeConcurrency(resultSetType, resultSetConcurrency);
checkHoldability(resultSetHoldability);
checkClosed();
sql = translateSQL(sql);
return new JdbcCallableStatement(this, sql, id, resultSetType, resultSetConcurrency);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
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();
JdbcSavepoint savepoint = new JdbcSavepoint(this, savepointId, null, trace, id);
savepointId++;
return savepoint;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public Savepoint setSavepoint(String name) throws SQLException {
try {
int id = getNextId(TraceObject.SAVEPOINT);
if (isDebugEnabled()) {
debugCodeAssign("Savepoint", TraceObject.SAVEPOINT, id, "setSavepoint(" + quote(name) + ")");
}
checkClosed();
CommandInterface set = prepareCommand("SAVEPOINT " + JdbcSavepoint.getName(name, 0), Integer.MAX_VALUE);
set.executeUpdate();
JdbcSavepoint savepoint = new JdbcSavepoint(this, 0, name, trace, id);
return savepoint;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public void rollback(Savepoint savepoint) throws SQLException {
try {
JdbcSavepoint sp = convertSavepoint(savepoint);
debugCode("rollback(" + sp.getTraceObjectName() + ");");
checkClosedForWrite();
try {
sp.rollback();
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
try {
debugCode("releaseSavepoint(savepoint);");
checkClosed();
convertSavepoint(savepoint).release();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public PreparedStatement prepareStatement(String sql, int resultSetType,
int resultSetConcurrency, int resultSetHoldability) throws SQLException {
try {
int id = getNextId(TraceObject.PREPARED_STATEMENT);
if (isDebugEnabled()) {
debugCodeAssign("PreparedStatement", TraceObject.PREPARED_STATEMENT, id,
"prepareStatement(" + quote(sql) + ", " + resultSetType + ", " + resultSetConcurrency + ", "
+ resultSetHoldability + ")");
}
checkTypeConcurrency(resultSetType, resultSetConcurrency);
checkHoldability(resultSetHoldability);
checkClosed();
sql = translateSQL(sql);
return new JdbcPreparedStatement(this, sql, id, resultSetType, resultSetConcurrency, false);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("prepareStatement(" + quote(sql) + ", " + autoGeneratedKeys + ");");
}
return prepareStatement(sql);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("prepareStatement(" + quote(sql) + ", " + quoteIntArray(columnIndexes) + ");");
}
return prepareStatement(sql);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("prepareStatement(" + quote(sql) + ", " + quoteArray(columnNames) + ");");
}
return prepareStatement(sql);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public Clob createClob() throws SQLException {
try {
int id = getNextId(TraceObject.CLOB);
debugCodeAssign("Clob", TraceObject.CLOB, id, "createClob()");
checkClosedForWrite();
try {
Value v = session.getDataHandler().getLobStorage().createClob(
new InputStreamReader(
new ByteArrayInputStream(Utils.EMPTY_BYTES)), 0);
return new JdbcClob(this, v, id);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public Blob createBlob() throws SQLException {
try {
int id = getNextId(TraceObject.BLOB);
debugCodeAssign("Blob", TraceObject.BLOB, id, "createClob()");
checkClosedForWrite();
try {
Value v = session.getDataHandler().getLobStorage().createBlob(
new ByteArrayInputStream(Utils.EMPTY_BYTES), 0);
return new JdbcBlob(this, v, id);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public NClob createNClob() throws SQLException {
try {
int id = getNextId(TraceObject.CLOB);
debugCodeAssign("NClob", TraceObject.CLOB, id, "createNClob()");
checkClosedForWrite();
try {
Value v = session.getDataHandler().getLobStorage().createClob(
new InputStreamReader(
new ByteArrayInputStream(Utils.EMPTY_BYTES)), 0);
return new JdbcClob(this, v, id);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public SQLXML createSQLXML() throws SQLException {
throw unsupported("SQLXML");
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public Array createArrayOf(String typeName, Object[] elements)
throws SQLException {
throw unsupported("createArray");
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public Struct createStruct(String typeName, Object[] attributes)
throws SQLException {
throw unsupported("Struct");
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public String getClientInfo(String name) throws SQLException {
throw unsupported("clientInfo");
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public <T> T unwrap(Class<T> iface) throws SQLException {
throw unsupported("unwrap");
}
// in src/main/org/h2/jdbc/JdbcConnection.java
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw unsupported("isWrapperFor");
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public ResultSet executeQuery() throws SQLException {
try {
int id = getNextId(TraceObject.RESULT_SET);
if (isDebugEnabled()) {
debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id, "executeQuery()");
}
synchronized (session) {
checkClosed();
closeOldResultSet();
ResultInterface result;
boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
try {
setExecutingStatement(command);
result = command.executeQuery(maxRows, scrollable);
} finally {
setExecutingStatement(null);
}
resultSet = new JdbcResultSet(conn, this, result, id, closedByResultSet, scrollable, updatable, cachedColumnLabelMap);
}
return resultSet;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public int executeUpdate() throws SQLException {
try {
debugCodeCall("executeUpdate");
checkClosedForWrite();
try {
return executeUpdateInternal();
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
private int executeUpdateInternal() throws SQLException {
closeOldResultSet();
synchronized (session) {
try {
setExecutingStatement(command);
updateCount = command.executeUpdate();
} finally {
setExecutingStatement(null);
}
}
return updateCount;
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public boolean execute() throws SQLException {
try {
int id = getNextId(TraceObject.RESULT_SET);
if (isDebugEnabled()) {
debugCodeCall("execute");
}
checkClosedForWrite();
try {
boolean returnsResultSet;
synchronized (conn.getSession()) {
closeOldResultSet();
try {
setExecutingStatement(command);
if (command.isQuery()) {
returnsResultSet = true;
boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
ResultInterface result = command.executeQuery(maxRows, scrollable);
resultSet = new JdbcResultSet(conn, this, result, id, closedByResultSet, scrollable, updatable);
} else {
returnsResultSet = false;
updateCount = command.executeUpdate();
}
} finally {
setExecutingStatement(null);
}
}
return returnsResultSet;
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void clearParameters() throws SQLException {
try {
debugCodeCall("clearParameters");
checkClosed();
ArrayList<? extends ParameterInterface> parameters = command.getParameters();
for (int i = 0, size = parameters.size(); i < size; i++) {
ParameterInterface param = parameters.get(i);
// can only delete old temp files if they are not in the batch
param.setValue(null, batchParameters == null);
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public ResultSet executeQuery(String sql) throws SQLException {
try {
debugCodeCall("executeQuery", sql);
throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void addBatch(String sql) throws SQLException {
try {
debugCodeCall("addBatch", sql);
throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public int executeUpdate(String sql) throws SQLException {
try {
debugCodeCall("executeUpdate", sql);
throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public boolean execute(String sql) throws SQLException {
try {
debugCodeCall("execute", sql);
throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setNull(int parameterIndex, int sqlType) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setNull("+parameterIndex+", "+sqlType+");");
}
setParameter(parameterIndex, ValueNull.INSTANCE);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setInt(int parameterIndex, int x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setInt("+parameterIndex+", "+x+");");
}
setParameter(parameterIndex, ValueInt.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setString(int parameterIndex, String x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setString("+parameterIndex+", "+quote(x)+");");
}
Value v = x == null ? (Value) ValueNull.INSTANCE : ValueString.get(x);
setParameter(parameterIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setBigDecimal("+parameterIndex+", " + quoteBigDecimal(x) + ");");
}
Value v = x == null ? (Value) ValueNull.INSTANCE : ValueDecimal.get(x);
setParameter(parameterIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setDate(int parameterIndex, java.sql.Date x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setDate("+parameterIndex+", " + quoteDate(x) + ");");
}
Value v = x == null ? (Value) ValueNull.INSTANCE : ValueDate.get(x);
setParameter(parameterIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setTime(int parameterIndex, java.sql.Time x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setTime("+parameterIndex+", " + quoteTime(x) + ");");
}
Value v = x == null ? (Value) ValueNull.INSTANCE : ValueTime.get(x);
setParameter(parameterIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setTimestamp(int parameterIndex, java.sql.Timestamp x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setTimestamp("+parameterIndex+", " + quoteTimestamp(x) + ");");
}
Value v = x == null ? (Value) ValueNull.INSTANCE : ValueTimestamp.get(x);
setParameter(parameterIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setObject(int parameterIndex, Object x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setObject("+parameterIndex+", x);");
}
if (x == null) {
// throw Errors.getInvalidValueException("null", "x");
setParameter(parameterIndex, ValueNull.INSTANCE);
} else {
setParameter(parameterIndex, DataType.convertToValue(session, x, Value.UNKNOWN));
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setObject("+parameterIndex+", x, "+targetSqlType+");");
}
int type = DataType.convertSQLTypeToValueType(targetSqlType);
if (x == null) {
setParameter(parameterIndex, ValueNull.INSTANCE);
} else {
Value v = DataType.convertToValue(conn.getSession(), x, type);
setParameter(parameterIndex, v.convertTo(type));
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setObject("+parameterIndex+", x, "+targetSqlType+", "+scale+");");
}
setObject(parameterIndex, x, targetSqlType);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setBoolean(int parameterIndex, boolean x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setBoolean("+parameterIndex+", "+x+");");
}
setParameter(parameterIndex, ValueBoolean.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setByte(int parameterIndex, byte x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setByte("+parameterIndex+", "+x+");");
}
setParameter(parameterIndex, ValueByte.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setShort(int parameterIndex, short x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setShort("+parameterIndex+", (short) "+x+");");
}
setParameter(parameterIndex, ValueShort.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setLong(int parameterIndex, long x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setLong("+parameterIndex+", "+x+"L);");
}
setParameter(parameterIndex, ValueLong.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setFloat(int parameterIndex, float x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setFloat("+parameterIndex+", "+x+"f);");
}
setParameter(parameterIndex, ValueFloat.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setDouble(int parameterIndex, double x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setDouble("+parameterIndex+", "+x+"d);");
}
setParameter(parameterIndex, ValueDouble.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setRef(int parameterIndex, Ref x) throws SQLException {
throw unsupported("ref");
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setDate(int parameterIndex, java.sql.Date x, Calendar calendar) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setDate("+parameterIndex+", " + quoteDate(x) + ", calendar);");
}
if (x == null) {
setParameter(parameterIndex, ValueNull.INSTANCE);
} else {
setParameter(parameterIndex, DateTimeUtils.convertDate(x, calendar));
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setTime(int parameterIndex, java.sql.Time x, Calendar calendar) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setTime("+parameterIndex+", " + quoteTime(x) + ", calendar);");
}
if (x == null) {
setParameter(parameterIndex, ValueNull.INSTANCE);
} else {
setParameter(parameterIndex, DateTimeUtils.convertTime(x, calendar));
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setTimestamp(int parameterIndex, java.sql.Timestamp x, Calendar calendar) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setTimestamp("+parameterIndex+", " + quoteTimestamp(x) + ", calendar);");
}
if (x == null) {
setParameter(parameterIndex, ValueNull.INSTANCE);
} else {
setParameter(parameterIndex, DateTimeUtils.convertTimestamp(x, calendar));
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
throw unsupported("unicodeStream");
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setNull("+parameterIndex+", "+sqlType+", "+quote(typeName)+");");
}
setNull(parameterIndex, sqlType);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setBlob(int parameterIndex, Blob x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setBlob("+parameterIndex+", x);");
}
checkClosedForWrite();
try {
Value v;
if (x == null) {
v = ValueNull.INSTANCE;
} else {
v = conn.createBlob(x.getBinaryStream(), -1);
}
setParameter(parameterIndex, v);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setBlob(int parameterIndex, InputStream x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setBlob("+parameterIndex+", x);");
}
checkClosedForWrite();
try {
Value v = conn.createBlob(x, -1);
setParameter(parameterIndex, v);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setClob(int parameterIndex, Clob x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setClob("+parameterIndex+", x);");
}
checkClosedForWrite();
try {
Value v;
if (x == null) {
v = ValueNull.INSTANCE;
} else {
v = conn.createClob(x.getCharacterStream(), -1);
}
setParameter(parameterIndex, v);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setClob(int parameterIndex, Reader x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setClob("+parameterIndex+", x);");
}
checkClosedForWrite();
try {
Value v;
if (x == null) {
v = ValueNull.INSTANCE;
} else {
v = conn.createClob(x, -1);
}
setParameter(parameterIndex, v);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setArray(int parameterIndex, Array x) throws SQLException {
throw unsupported("setArray");
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setBytes(int parameterIndex, byte[] x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setBytes("+parameterIndex+", "+quoteBytes(x)+");");
}
Value v = x == null ? (Value) ValueNull.INSTANCE : ValueBytes.get(x);
setParameter(parameterIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setBinaryStream("+parameterIndex+", x, "+length+"L);");
}
checkClosedForWrite();
try {
Value v = conn.createBlob(x, length);
setParameter(parameterIndex, v);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
setBinaryStream(parameterIndex, x, (long) length);
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
setBinaryStream(parameterIndex, x, -1);
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
setAsciiStream(parameterIndex, x, (long) length);
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setAsciiStream("+parameterIndex+", x, "+length+"L);");
}
checkClosedForWrite();
try {
Value v = conn.createClob(IOUtils.getAsciiReader(x), length);
setParameter(parameterIndex, v);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
setAsciiStream(parameterIndex, x, -1);
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setCharacterStream(int parameterIndex, Reader x, int length) throws SQLException {
setCharacterStream(parameterIndex, x, (long) length);
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setCharacterStream(int parameterIndex, Reader x) throws SQLException {
setCharacterStream(parameterIndex, x, -1);
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setCharacterStream(int parameterIndex, Reader x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setCharacterStream("+parameterIndex+", x, "+length+"L);");
}
checkClosedForWrite();
try {
Value v = conn.createClob(x, length);
setParameter(parameterIndex, v);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setURL(int parameterIndex, URL x) throws SQLException {
throw unsupported("url");
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public ResultSetMetaData getMetaData() throws SQLException {
try {
debugCodeCall("getMetaData");
checkClosed();
ResultInterface result = command.getMetaData();
if (result == null) {
return null;
}
int id = getNextId(TraceObject.RESULT_SET_META_DATA);
if (isDebugEnabled()) {
debugCodeAssign("ResultSetMetaData", TraceObject.RESULT_SET_META_DATA, id, "getMetaData()");
}
String catalog = conn.getCatalog();
JdbcResultSetMetaData meta = new JdbcResultSetMetaData(null, this, result, catalog, session.getTrace(), id);
return meta;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void clearBatch() throws SQLException {
try {
debugCodeCall("clearBatch");
checkClosed();
batchParameters = null;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void close() throws SQLException {
try {
super.close();
batchParameters = null;
if (command != null) {
command.close();
command = null;
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public int[] executeBatch() throws SQLException {
try {
debugCodeCall("executeBatch");
if (batchParameters == null) {
// TODO batch: check what other database do if no parameters are set
batchParameters = New.arrayList();
}
int size = batchParameters.size();
int[] result = new int[size];
boolean error = false;
SQLException next = null;
checkClosedForWrite();
try {
for (int i = 0; i < size; i++) {
Value[] set = batchParameters.get(i);
ArrayList<? extends ParameterInterface> parameters = command.getParameters();
for (int j = 0; j < set.length; j++) {
Value value = set[j];
ParameterInterface param = parameters.get(j);
param.setValue(value, false);
}
try {
result[i] = executeUpdateInternal();
} catch (Exception re) {
SQLException e = logAndConvert(re);
if (next == null) {
next = e;
} else {
e.setNextException(next);
next = e;
}
result[i] = Statement.EXECUTE_FAILED;
error = true;
}
}
batchParameters = null;
if (error) {
JdbcBatchUpdateException e = new JdbcBatchUpdateException(next, result);
throw e;
}
return result;
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void addBatch() throws SQLException {
try {
debugCodeCall("addBatch");
checkClosedForWrite();
try {
ArrayList<? extends ParameterInterface> parameters = command.getParameters();
int size = parameters.size();
Value[] set = new Value[size];
for (int i = 0; i < size; i++) {
ParameterInterface param = parameters.get(i);
Value value = param.getParamValue();
set[i] = value;
}
if (batchParameters == null) {
batchParameters = New.arrayList();
}
batchParameters.add(set);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
try {
debugCode("executeUpdate("+quote(sql)+", "+autoGeneratedKeys+");");
throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
try {
debugCode("executeUpdate(" + quote(sql) + ", " + quoteIntArray(columnIndexes) + ");");
throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
try {
debugCode("executeUpdate(" + quote(sql) + ", " + quoteArray(columnNames) + ");");
throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
try {
debugCode("execute(" + quote(sql) + ", " + autoGeneratedKeys + ");");
throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
try {
debugCode("execute(" + quote(sql) + ", " + quoteIntArray(columnIndexes) + ");");
throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public boolean execute(String sql, String[] columnNames) throws SQLException {
try {
debugCode("execute(" + quote(sql) + ", " + quoteArray(columnNames) + ");");
throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public ParameterMetaData getParameterMetaData() throws SQLException {
try {
int id = getNextId(TraceObject.PARAMETER_META_DATA);
if (isDebugEnabled()) {
debugCodeAssign("ParameterMetaData", TraceObject.PARAMETER_META_DATA, id, "getParameterMetaData()");
}
checkClosed();
JdbcParameterMetaData meta = new JdbcParameterMetaData(session.getTrace(), this, command, id);
return meta;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setRowId(int parameterIndex, RowId x) throws SQLException {
throw unsupported("rowId");
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setNString(int parameterIndex, String x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setNString("+parameterIndex+", "+quote(x)+");");
}
Value v = x == null ? (Value) ValueNull.INSTANCE : ValueString.get(x);
setParameter(parameterIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setNCharacterStream(int parameterIndex, Reader x, long length)
throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setNCharacterStream("+
parameterIndex+", x, "+length+"L);");
}
checkClosedForWrite();
try {
Value v = conn.createClob(x, length);
setParameter(parameterIndex, v);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setNCharacterStream(int parameterIndex, Reader x)
throws SQLException {
setNCharacterStream(parameterIndex, x, -1);
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setNClob(int parameterIndex, NClob x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setNClob("+parameterIndex+", x);");
}
checkClosedForWrite();
Value v;
if (x == null) {
v = ValueNull.INSTANCE;
} else {
v = conn.createClob(x.getCharacterStream(), -1);
}
setParameter(parameterIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setNClob(int parameterIndex, Reader x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setNClob("+parameterIndex+", x);");
}
checkClosedForWrite();
try {
Value v = conn.createClob(x, -1);
setParameter(parameterIndex, v);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setClob(int parameterIndex, Reader x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setClob("+parameterIndex+", x, "+length+"L);");
}
checkClosedForWrite();
try {
Value v = conn.createClob(x, length);
setParameter(parameterIndex, v);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setBlob(int parameterIndex, InputStream x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setBlob("+parameterIndex+", x, "+length+"L);");
}
checkClosedForWrite();
try {
Value v = conn.createBlob(x, length);
setParameter(parameterIndex, v);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setNClob(int parameterIndex, Reader x, long length)
throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setNClob("+parameterIndex+", x, "+length+"L);");
}
checkClosedForWrite();
try {
Value v = conn.createClob(x, length);
setParameter(parameterIndex, v);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcPreparedStatement.java
public void setSQLXML(int parameterIndex, SQLXML x) throws SQLException {
throw unsupported("SQLXML");
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public int getColumnCount() throws SQLException {
try {
debugCodeCall("getColumnCount");
checkClosed();
return columnCount;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public String getColumnLabel(int column) throws SQLException {
try {
debugCodeCall("getColumnLabel", column);
checkColumnIndex(column);
return result.getAlias(--column);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public String getColumnName(int column) throws SQLException {
try {
debugCodeCall("getColumnName", column);
checkColumnIndex(column);
return result.getColumnName(--column);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public int getColumnType(int column) throws SQLException {
try {
debugCodeCall("getColumnType", column);
checkColumnIndex(column);
int type = result.getColumnType(--column);
return DataType.convertTypeToSQLType(type);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public String getColumnTypeName(int column) throws SQLException {
try {
debugCodeCall("getColumnTypeName", column);
checkColumnIndex(column);
int type = result.getColumnType(--column);
return DataType.getDataType(type).name;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public String getSchemaName(int column) throws SQLException {
try {
debugCodeCall("getSchemaName", column);
checkColumnIndex(column);
return result.getSchemaName(--column);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public String getTableName(int column) throws SQLException {
try {
debugCodeCall("getTableName", column);
checkColumnIndex(column);
return result.getTableName(--column);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public String getCatalogName(int column) throws SQLException {
try {
debugCodeCall("getCatalogName", column);
checkColumnIndex(column);
return catalog;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public boolean isAutoIncrement(int column) throws SQLException {
try {
debugCodeCall("isAutoIncrement", column);
checkColumnIndex(column);
return result.isAutoIncrement(--column);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public boolean isCaseSensitive(int column) throws SQLException {
try {
debugCodeCall("isCaseSensitive", column);
checkColumnIndex(column);
return true;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public boolean isSearchable(int column) throws SQLException {
try {
debugCodeCall("isSearchable", column);
checkColumnIndex(column);
return true;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public boolean isCurrency(int column) throws SQLException {
try {
debugCodeCall("isCurrency", column);
checkColumnIndex(column);
return false;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public int isNullable(int column) throws SQLException {
try {
debugCodeCall("isNullable", column);
checkColumnIndex(column);
return result.getNullable(--column);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public boolean isSigned(int column) throws SQLException {
try {
debugCodeCall("isSigned", column);
checkColumnIndex(column);
return true;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public boolean isReadOnly(int column) throws SQLException {
try {
debugCodeCall("isReadOnly", column);
checkColumnIndex(column);
return false;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public boolean isWritable(int column) throws SQLException {
try {
debugCodeCall("isWritable", column);
checkColumnIndex(column);
return true;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public boolean isDefinitelyWritable(int column) throws SQLException {
try {
debugCodeCall("isDefinitelyWritable", column);
checkColumnIndex(column);
return false;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public String getColumnClassName(int column) throws SQLException {
try {
debugCodeCall("getColumnClassName", column);
checkColumnIndex(column);
int type = result.getColumnType(--column);
return DataType.getTypeClassName(type);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public int getPrecision(int column) throws SQLException {
try {
debugCodeCall("getPrecision", column);
checkColumnIndex(column);
long prec = result.getColumnPrecision(--column);
return MathUtils.convertLongToInt(prec);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public int getScale(int column) throws SQLException {
try {
debugCodeCall("getScale", column);
checkColumnIndex(column);
return result.getColumnScale(--column);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public int getColumnDisplaySize(int column) throws SQLException {
try {
debugCodeCall("getColumnDisplaySize", column);
checkColumnIndex(column);
return result.getDisplaySize(--column);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public <T> T unwrap(Class<T> iface) throws SQLException {
throw unsupported("unwrap");
}
// in src/main/org/h2/jdbc/JdbcResultSetMetaData.java
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw unsupported("isWrapperFor");
}
// in src/main/org/h2/jdbc/JdbcSavepoint.java
public int getSavepointId() throws SQLException {
try {
debugCodeCall("getSavepointId");
checkValid();
if (name != null) {
throw DbException.get(ErrorCode.SAVEPOINT_IS_NAMED);
}
return savepointId;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcSavepoint.java
public String getSavepointName() throws SQLException {
try {
debugCodeCall("getSavepointName");
checkValid();
if (name == null) {
throw DbException.get(ErrorCode.SAVEPOINT_IS_UNNAMED);
}
return name;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcClob.java
public long length() throws SQLException {
try {
debugCodeCall("length");
checkClosed();
if (value.getType() == Value.CLOB) {
long precision = value.getPrecision();
if (precision > 0) {
return precision;
}
}
return IOUtils.copyAndCloseInput(value.getReader(), null, Long.MAX_VALUE);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcClob.java
public void truncate(long len) throws SQLException {
throw unsupported("LOB update");
}
// in src/main/org/h2/jdbc/JdbcClob.java
public InputStream getAsciiStream() throws SQLException {
try {
debugCodeCall("getAsciiStream");
checkClosed();
String s = value.getString();
return IOUtils.getInputStreamFromString(s);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcClob.java
public OutputStream setAsciiStream(long pos) throws SQLException {
throw unsupported("LOB update");
}
// in src/main/org/h2/jdbc/JdbcClob.java
public Reader getCharacterStream() throws SQLException {
try {
debugCodeCall("getCharacterStream");
checkClosed();
return value.getReader();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcClob.java
public Writer setCharacterStream(long pos) throws SQLException {
try {
if (isDebugEnabled()) {
debugCodeCall("setCharacterStream(" + pos + ");");
}
checkClosed();
if (pos != 1) {
throw DbException.getInvalidValueException("pos", pos);
}
if (value.getPrecision() != 0) {
throw DbException.getInvalidValueException("length", value.getPrecision());
}
final JdbcConnection c = conn;
// PipedReader / PipedWriter are a lot slower
// than PipedInputStream / PipedOutputStream
// (Sun/Oracle Java 1.6.0_20)
final PipedInputStream in = new PipedInputStream();
final Task task = new Task() {
public void call() {
value = c.createClob(IOUtils.getReader(in), -1);
}
};
PipedOutputStream out = new PipedOutputStream(in) {
public void close() throws IOException {
super.close();
try {
task.get();
} catch (Exception e) {
throw DbException.convertToIOException(e);
}
}
};
task.execute();
return IOUtils.getBufferedWriter(out);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcClob.java
public String getSubString(long pos, int length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getSubString(" + pos + ", " + length + ");");
}
checkClosed();
if (pos < 1) {
throw DbException.getInvalidValueException("pos", pos);
}
if (length < 0) {
throw DbException.getInvalidValueException("length", length);
}
StringWriter writer = new StringWriter(Math.min(Constants.IO_BUFFER_SIZE, length));
Reader reader = value.getReader();
try {
IOUtils.skipFully(reader, pos - 1);
IOUtils.copyAndCloseInput(reader, writer, length);
} finally {
reader.close();
}
return writer.toString();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcClob.java
public int setString(long pos, String str) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setString(" + pos + ", " + quote(str) + ");");
}
checkClosed();
if (pos != 1) {
throw DbException.getInvalidValueException("pos", pos);
} else if (str == null) {
throw DbException.getInvalidValueException("str", str);
}
value = conn.createClob(new StringReader(str), -1);
return str.length();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcClob.java
public int setString(long pos, String str, int offset, int len) throws SQLException {
throw unsupported("LOB update");
}
// in src/main/org/h2/jdbc/JdbcClob.java
public long position(String pattern, long start) throws SQLException {
throw unsupported("LOB search");
}
// in src/main/org/h2/jdbc/JdbcClob.java
public long position(Clob clobPattern, long start) throws SQLException {
throw unsupported("LOB search");
}
// in src/main/org/h2/jdbc/JdbcClob.java
public Reader getCharacterStream(long pos, long length) throws SQLException {
throw unsupported("LOB subset");
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getTables(String catalogPattern, String schemaPattern,
String tableNamePattern, String[] types) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getTables(" + quote(catalogPattern) + ", " + quote(schemaPattern) + ", " + quote(tableNamePattern)
+ ", " + quoteArray(types) + ");");
}
checkClosed();
String tableType;
if (types != null && types.length > 0) {
StatementBuilder buff = new StatementBuilder("TABLE_TYPE IN(");
for (int i = 0; i < types.length; i++) {
buff.appendExceptFirst(", ");
buff.append('?');
}
tableType = buff.append(')').toString();
} else {
tableType = "TRUE";
}
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TABLE_CATALOG TABLE_CAT, "
+ "TABLE_SCHEMA TABLE_SCHEM, "
+ "TABLE_NAME, "
+ "TABLE_TYPE, "
+ "REMARKS, "
+ "TYPE_NAME TYPE_CAT, "
+ "TYPE_NAME TYPE_SCHEM, "
+ "TYPE_NAME, "
+ "TYPE_NAME SELF_REFERENCING_COL_NAME, "
+ "TYPE_NAME REF_GENERATION, "
+ "SQL "
+ "FROM INFORMATION_SCHEMA.TABLES "
+ "WHERE TABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND TABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND TABLE_NAME LIKE ? ESCAPE ? "
+ "AND (" + tableType + ") "
+ "ORDER BY TABLE_TYPE, TABLE_SCHEMA, TABLE_NAME");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, getPattern(tableNamePattern));
prep.setString(6, "\\");
for (int i = 0; types != null && i < types.length; i++) {
prep.setString(7 + i, types[i]);
}
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getColumns(String catalogPattern, String schemaPattern,
String tableNamePattern, String columnNamePattern)
throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getColumns(" + quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(tableNamePattern)+", "
+quote(columnNamePattern)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TABLE_CATALOG TABLE_CAT, "
+ "TABLE_SCHEMA TABLE_SCHEM, "
+ "TABLE_NAME, "
+ "COLUMN_NAME, "
+ "DATA_TYPE, "
+ "TYPE_NAME, "
+ "CHARACTER_MAXIMUM_LENGTH COLUMN_SIZE, "
+ "CHARACTER_MAXIMUM_LENGTH BUFFER_LENGTH, "
+ "NUMERIC_SCALE DECIMAL_DIGITS, "
+ "NUMERIC_PRECISION_RADIX NUM_PREC_RADIX, "
+ "NULLABLE, "
+ "REMARKS, "
+ "COLUMN_DEFAULT COLUMN_DEF, "
+ "DATA_TYPE SQL_DATA_TYPE, "
+ "ZERO() SQL_DATETIME_SUB, "
+ "CHARACTER_OCTET_LENGTH CHAR_OCTET_LENGTH, "
+ "ORDINAL_POSITION, "
+ "IS_NULLABLE IS_NULLABLE, "
+ "CAST(SOURCE_DATA_TYPE AS VARCHAR) SCOPE_CATALOG, "
+ "CAST(SOURCE_DATA_TYPE AS VARCHAR) SCOPE_SCHEMA, "
+ "CAST(SOURCE_DATA_TYPE AS VARCHAR) SCOPE_TABLE, "
+ "SOURCE_DATA_TYPE, "
+ "CASE WHEN SEQUENCE_NAME IS NULL THEN CAST(? AS VARCHAR) ELSE CAST(? AS VARCHAR) END IS_AUTOINCREMENT, "
+ "CAST(SOURCE_DATA_TYPE AS VARCHAR) SCOPE_CATLOG "
+ "FROM INFORMATION_SCHEMA.COLUMNS "
+ "WHERE TABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND TABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND TABLE_NAME LIKE ? ESCAPE ? "
+ "AND COLUMN_NAME LIKE ? ESCAPE ? "
+ "ORDER BY TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION");
prep.setString(1, "NO");
prep.setString(2, "YES");
prep.setString(3, getCatalogPattern(catalogPattern));
prep.setString(4, "\\");
prep.setString(5, getSchemaPattern(schemaPattern));
prep.setString(6, "\\");
prep.setString(7, getPattern(tableNamePattern));
prep.setString(8, "\\");
prep.setString(9, getPattern(columnNamePattern));
prep.setString(10, "\\");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getIndexInfo(String catalogPattern, String schemaPattern,
String tableName, boolean unique, boolean approximate)
throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getIndexInfo(" + quote(catalogPattern) + ", " + quote(schemaPattern) + ", " + quote(tableName) + ", "
+ unique + ", " + approximate + ");");
}
String uniqueCondition;
if (unique) {
uniqueCondition = "NON_UNIQUE=FALSE";
} else {
uniqueCondition = "TRUE";
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TABLE_CATALOG TABLE_CAT, "
+ "TABLE_SCHEMA TABLE_SCHEM, "
+ "TABLE_NAME, "
+ "NON_UNIQUE, "
+ "TABLE_CATALOG INDEX_QUALIFIER, "
+ "INDEX_NAME, "
+ "INDEX_TYPE TYPE, "
+ "ORDINAL_POSITION, "
+ "COLUMN_NAME, "
+ "ASC_OR_DESC, "
// TODO meta data for number of unique values in an index
+ "CARDINALITY, "
+ "PAGES, "
+ "FILTER_CONDITION, "
+ "SORT_TYPE "
+ "FROM INFORMATION_SCHEMA.INDEXES "
+ "WHERE TABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND TABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND (" + uniqueCondition + ") "
+ "AND TABLE_NAME = ? "
+ "ORDER BY NON_UNIQUE, TYPE, TABLE_SCHEM, INDEX_NAME, ORDINAL_POSITION");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, tableName);
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getPrimaryKeys(String catalogPattern, String schemaPattern, String tableName) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getPrimaryKeys("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(tableName)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TABLE_CATALOG TABLE_CAT, "
+ "TABLE_SCHEMA TABLE_SCHEM, "
+ "TABLE_NAME, "
+ "COLUMN_NAME, "
+ "ORDINAL_POSITION KEY_SEQ, "
+ "IFNULL(CONSTRAINT_NAME, INDEX_NAME) PK_NAME "
+ "FROM INFORMATION_SCHEMA.INDEXES "
+ "WHERE TABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND TABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND TABLE_NAME = ? "
+ "AND PRIMARY_KEY = TRUE "
+ "ORDER BY COLUMN_NAME");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, tableName);
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public String getURL() throws SQLException {
try {
debugCodeCall("getURL");
return conn.getURL();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public String getUserName() throws SQLException {
try {
debugCodeCall("getUserName");
return conn.getUser();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public boolean isReadOnly() throws SQLException {
try {
debugCodeCall("isReadOnly");
return conn.isReadOnly();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getProcedures(String catalogPattern, String schemaPattern,
String procedureNamePattern) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getProcedures("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(procedureNamePattern)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "ALIAS_CATALOG PROCEDURE_CAT, "
+ "ALIAS_SCHEMA PROCEDURE_SCHEM, "
+ "ALIAS_NAME PROCEDURE_NAME, "
+ "COLUMN_COUNT NUM_INPUT_PARAMS, "
+ "ZERO() NUM_OUTPUT_PARAMS, "
+ "ZERO() NUM_RESULT_SETS, "
+ "REMARKS, "
+ "RETURNS_RESULT PROCEDURE_TYPE, "
+ "ALIAS_NAME SPECIFIC_NAME "
+ "FROM INFORMATION_SCHEMA.FUNCTION_ALIASES "
+ "WHERE ALIAS_CATALOG LIKE ? ESCAPE ? "
+ "AND ALIAS_SCHEMA LIKE ? ESCAPE ? "
+ "AND ALIAS_NAME LIKE ? ESCAPE ? "
+ "ORDER BY PROCEDURE_SCHEM, PROCEDURE_NAME, NUM_INPUT_PARAMS");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, getPattern(procedureNamePattern));
prep.setString(6, "\\");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getProcedureColumns(String catalogPattern, String schemaPattern,
String procedureNamePattern, String columnNamePattern)
throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getProcedureColumns("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(procedureNamePattern)+", "
+quote(columnNamePattern)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "ALIAS_CATALOG PROCEDURE_CAT, "
+ "ALIAS_SCHEMA PROCEDURE_SCHEM, "
+ "ALIAS_NAME PROCEDURE_NAME, "
+ "COLUMN_NAME, "
+ "COLUMN_TYPE, "
+ "DATA_TYPE, "
+ "TYPE_NAME, "
+ "PRECISION, "
+ "PRECISION LENGTH, "
+ "SCALE, "
+ "RADIX, "
+ "NULLABLE, "
+ "REMARKS, "
+ "COLUMN_DEFAULT COLUMN_DEF, "
+ "ZERO() SQL_DATA_TYPE, "
+ "ZERO() SQL_DATETIME_SUB, "
+ "ZERO() CHAR_OCTET_LENGTH, "
+ "POS ORDINAL_POSITION, "
+ "? IS_NULLABLE, "
+ "ALIAS_NAME SPECIFIC_NAME "
+ "FROM INFORMATION_SCHEMA.FUNCTION_COLUMNS "
+ "WHERE ALIAS_CATALOG LIKE ? ESCAPE ? "
+ "AND ALIAS_SCHEMA LIKE ? ESCAPE ? "
+ "AND ALIAS_NAME LIKE ? ESCAPE ? "
+ "AND COLUMN_NAME LIKE ? ESCAPE ? "
+ "ORDER BY PROCEDURE_SCHEM, PROCEDURE_NAME, ORDINAL_POSITION");
prep.setString(1, "YES");
prep.setString(2, getCatalogPattern(catalogPattern));
prep.setString(3, "\\");
prep.setString(4, getSchemaPattern(schemaPattern));
prep.setString(5, "\\");
prep.setString(6, getPattern(procedureNamePattern));
prep.setString(7, "\\");
prep.setString(8, getPattern(columnNamePattern));
prep.setString(9, "\\");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getSchemas() throws SQLException {
try {
debugCodeCall("getSchemas");
checkClosed();
PreparedStatement prep = conn
.prepareAutoCloseStatement("SELECT "
+ "SCHEMA_NAME TABLE_SCHEM, "
+ "CATALOG_NAME TABLE_CATALOG, "
+" IS_DEFAULT "
+ "FROM INFORMATION_SCHEMA.SCHEMATA "
+ "ORDER BY SCHEMA_NAME");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getCatalogs() throws SQLException {
try {
debugCodeCall("getCatalogs");
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement(
"SELECT CATALOG_NAME TABLE_CAT "
+ "FROM INFORMATION_SCHEMA.CATALOGS");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getTableTypes() throws SQLException {
try {
debugCodeCall("getTableTypes");
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TYPE TABLE_TYPE "
+ "FROM INFORMATION_SCHEMA.TABLE_TYPES "
+ "ORDER BY TABLE_TYPE");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getColumnPrivileges(String catalogPattern, String schemaPattern,
String table, String columnNamePattern) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getColumnPrivileges("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(table)+", "
+quote(columnNamePattern)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TABLE_CATALOG TABLE_CAT, "
+ "TABLE_SCHEMA TABLE_SCHEM, "
+ "TABLE_NAME, "
+ "COLUMN_NAME, "
+ "GRANTOR, "
+ "GRANTEE, "
+ "PRIVILEGE_TYPE PRIVILEGE, "
+ "IS_GRANTABLE "
+ "FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES "
+ "WHERE TABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND TABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND TABLE_NAME = ? "
+ "AND COLUMN_NAME LIKE ? ESCAPE ? "
+ "ORDER BY COLUMN_NAME, PRIVILEGE");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, table);
prep.setString(6, getPattern(columnNamePattern));
prep.setString(7, "\\");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getTablePrivileges(String catalogPattern, String schemaPattern,
String tableNamePattern) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getTablePrivileges("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(tableNamePattern)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TABLE_CATALOG TABLE_CAT, "
+ "TABLE_SCHEMA TABLE_SCHEM, "
+ "TABLE_NAME, "
+ "GRANTOR, "
+ "GRANTEE, "
+ "PRIVILEGE_TYPE PRIVILEGE, "
+ "IS_GRANTABLE "
+ "FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES "
+ "WHERE TABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND TABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND TABLE_NAME LIKE ? ESCAPE ? "
+ "ORDER BY TABLE_SCHEM, TABLE_NAME, PRIVILEGE");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, getPattern(tableNamePattern));
prep.setString(6, "\\");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getBestRowIdentifier(String catalogPattern, String schemaPattern,
String tableName, int scope, boolean nullable) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getBestRowIdentifier("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(tableName)+", "
+scope+", "+nullable+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "CAST(? AS SMALLINT) SCOPE, "
+ "C.COLUMN_NAME, "
+ "C.DATA_TYPE, "
+ "C.TYPE_NAME, "
+ "C.CHARACTER_MAXIMUM_LENGTH COLUMN_SIZE, "
+ "C.CHARACTER_MAXIMUM_LENGTH BUFFER_LENGTH, "
+ "CAST(C.NUMERIC_SCALE AS SMALLINT) DECIMAL_DIGITS, "
+ "CAST(? AS SMALLINT) PSEUDO_COLUMN "
+ "FROM INFORMATION_SCHEMA.INDEXES I, "
+" INFORMATION_SCHEMA.COLUMNS C "
+ "WHERE C.TABLE_NAME = I.TABLE_NAME "
+ "AND C.COLUMN_NAME = I.COLUMN_NAME "
+ "AND C.TABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND C.TABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND C.TABLE_NAME = ? "
+ "AND I.PRIMARY_KEY = TRUE "
+ "ORDER BY SCOPE");
// SCOPE
prep.setInt(1, DatabaseMetaData.bestRowSession);
// PSEUDO_COLUMN
prep.setInt(2, DatabaseMetaData.bestRowNotPseudo);
prep.setString(3, getCatalogPattern(catalogPattern));
prep.setString(4, "\\");
prep.setString(5, getSchemaPattern(schemaPattern));
prep.setString(6, "\\");
prep.setString(7, tableName);
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getVersionColumns(String catalog, String schema,
String tableName) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getVersionColumns("
+quote(catalog)+", "
+quote(schema)+", "
+quote(tableName)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "ZERO() SCOPE, "
+ "COLUMN_NAME, "
+ "CAST(DATA_TYPE AS INT) DATA_TYPE, "
+ "TYPE_NAME, "
+ "NUMERIC_PRECISION COLUMN_SIZE, "
+ "NUMERIC_PRECISION BUFFER_LENGTH, "
+ "NUMERIC_PRECISION DECIMAL_DIGITS, "
+ "ZERO() PSEUDO_COLUMN "
+ "FROM INFORMATION_SCHEMA.COLUMNS "
+ "WHERE FALSE");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getImportedKeys(String catalogPattern, String schemaPattern, String tableName) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getImportedKeys("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(tableName)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "PKTABLE_CATALOG PKTABLE_CAT, "
+ "PKTABLE_SCHEMA PKTABLE_SCHEM, "
+ "PKTABLE_NAME PKTABLE_NAME, "
+ "PKCOLUMN_NAME, "
+ "FKTABLE_CATALOG FKTABLE_CAT, "
+ "FKTABLE_SCHEMA FKTABLE_SCHEM, "
+ "FKTABLE_NAME, "
+ "FKCOLUMN_NAME, "
+ "ORDINAL_POSITION KEY_SEQ, "
+ "UPDATE_RULE, "
+ "DELETE_RULE, "
+ "FK_NAME, "
+ "PK_NAME, "
+ "DEFERRABILITY "
+ "FROM INFORMATION_SCHEMA.CROSS_REFERENCES "
+ "WHERE FKTABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND FKTABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND FKTABLE_NAME = ? "
+ "ORDER BY PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME, FK_NAME, KEY_SEQ");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, tableName);
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getExportedKeys(String catalogPattern, String schemaPattern, String tableName)
throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getExportedKeys("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(tableName)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "PKTABLE_CATALOG PKTABLE_CAT, "
+ "PKTABLE_SCHEMA PKTABLE_SCHEM, "
+ "PKTABLE_NAME PKTABLE_NAME, "
+ "PKCOLUMN_NAME, "
+ "FKTABLE_CATALOG FKTABLE_CAT, "
+ "FKTABLE_SCHEMA FKTABLE_SCHEM, "
+ "FKTABLE_NAME, "
+ "FKCOLUMN_NAME, "
+ "ORDINAL_POSITION KEY_SEQ, "
+ "UPDATE_RULE, "
+ "DELETE_RULE, "
+ "FK_NAME, "
+ "PK_NAME, "
+ "DEFERRABILITY "
+ "FROM INFORMATION_SCHEMA.CROSS_REFERENCES "
+ "WHERE PKTABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND PKTABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND PKTABLE_NAME = ? "
+ "ORDER BY FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, FK_NAME, KEY_SEQ");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, tableName);
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getCrossReference(String primaryCatalogPattern,
String primarySchemaPattern, String primaryTable, String foreignCatalogPattern,
String foreignSchemaPattern, String foreignTable) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getCrossReference("
+quote(primaryCatalogPattern)+", "
+quote(primarySchemaPattern)+", "
+quote(primaryTable)+", "
+quote(foreignCatalogPattern)+", "
+quote(foreignSchemaPattern)+", "
+quote(foreignTable)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "PKTABLE_CATALOG PKTABLE_CAT, "
+ "PKTABLE_SCHEMA PKTABLE_SCHEM, "
+ "PKTABLE_NAME PKTABLE_NAME, "
+ "PKCOLUMN_NAME, "
+ "FKTABLE_CATALOG FKTABLE_CAT, "
+ "FKTABLE_SCHEMA FKTABLE_SCHEM, "
+ "FKTABLE_NAME, "
+ "FKCOLUMN_NAME, "
+ "ORDINAL_POSITION KEY_SEQ, "
+ "UPDATE_RULE, "
+ "DELETE_RULE, "
+ "FK_NAME, "
+ "PK_NAME, "
+ "DEFERRABILITY "
+ "FROM INFORMATION_SCHEMA.CROSS_REFERENCES "
+ "WHERE PKTABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND PKTABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND PKTABLE_NAME = ? "
+ "AND FKTABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND FKTABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND FKTABLE_NAME = ? "
+ "ORDER BY FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, FK_NAME, KEY_SEQ");
prep.setString(1, getCatalogPattern(primaryCatalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(primarySchemaPattern));
prep.setString(4, "\\");
prep.setString(5, primaryTable);
prep.setString(6, getCatalogPattern(foreignCatalogPattern));
prep.setString(7, "\\");
prep.setString(8, getSchemaPattern(foreignSchemaPattern));
prep.setString(9, "\\");
prep.setString(10, foreignTable);
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getUDTs(String catalog, String schemaPattern,
String typeNamePattern, int[] types) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getUDTs("
+quote(catalog)+", "
+quote(schemaPattern)+", "
+quote(typeNamePattern)+", "
+quoteIntArray(types)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "CAST(NULL AS VARCHAR) TYPE_CAT, "
+ "CAST(NULL AS VARCHAR) TYPE_SCHEM, "
+ "CAST(NULL AS VARCHAR) TYPE_NAME, "
+ "CAST(NULL AS VARCHAR) CLASS_NAME, "
+ "CAST(NULL AS SMALLINT) DATA_TYPE, "
+ "CAST(NULL AS VARCHAR) REMARKS, "
+ "CAST(NULL AS SMALLINT) BASE_TYPE "
+ "FROM DUAL WHERE FALSE");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getTypeInfo() throws SQLException {
try {
debugCodeCall("getTypeInfo");
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TYPE_NAME, "
+ "DATA_TYPE, "
+ "PRECISION, "
+ "PREFIX LITERAL_PREFIX, "
+ "SUFFIX LITERAL_SUFFIX, "
+ "PARAMS CREATE_PARAMS, "
+ "NULLABLE, "
+ "CASE_SENSITIVE, "
+ "SEARCHABLE, "
+ "FALSE UNSIGNED_ATTRIBUTE, "
+ "FALSE FIXED_PREC_SCALE, "
+ "AUTO_INCREMENT, "
+ "TYPE_NAME LOCAL_TYPE_NAME, "
+ "MINIMUM_SCALE, "
+ "MAXIMUM_SCALE, "
+ "DATA_TYPE SQL_DATA_TYPE, "
+ "ZERO() SQL_DATETIME_SUB, "
+ "RADIX NUM_PREC_RADIX "
+ "FROM INFORMATION_SCHEMA.TYPE_INFO "
+ "ORDER BY DATA_TYPE, POS");
ResultSet rs = prep.executeQuery();
return rs;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public String getNumericFunctions() throws SQLException {
debugCodeCall("getNumericFunctions");
return getFunctions("Functions (Numeric)");
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public String getStringFunctions() throws SQLException {
debugCodeCall("getStringFunctions");
return getFunctions("Functions (String)");
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public String getSystemFunctions() throws SQLException {
debugCodeCall("getSystemFunctions");
return getFunctions("Functions (System)");
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public String getTimeDateFunctions() throws SQLException {
debugCodeCall("getTimeDateFunctions");
return getFunctions("Functions (Time and Date)");
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
private String getFunctions(String section) throws SQLException {
try {
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT TOPIC "
+ "FROM INFORMATION_SCHEMA.HELP WHERE SECTION = ?");
prep.setString(1, section);
ResultSet rs = prep.executeQuery();
StatementBuilder buff = new StatementBuilder();
while (rs.next()) {
String s = rs.getString(1).trim();
String[] array = StringUtils.arraySplit(s, ',', true);
for (String a : array) {
buff.appendExceptFirst(",");
String f = a.trim();
if (f.indexOf(' ') >= 0) {
// remove 'Function' from 'INSERT Function'
f = f.substring(0, f.indexOf(' ')).trim();
}
buff.append(f);
}
}
rs.close();
prep.close();
return buff.toString();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getSuperTypes(String catalog, String schemaPattern,
String typeNamePattern) throws SQLException {
throw unsupported("superTypes");
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getSuperTables(String catalog, String schemaPattern,
String tableNamePattern) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getSuperTables("
+quote(catalog)+", "
+quote(schemaPattern)+", "
+quote(tableNamePattern)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "CATALOG_NAME TABLE_CAT, "
+ "CATALOG_NAME TABLE_SCHEM, "
+ "CATALOG_NAME TABLE_NAME, "
+ "CATALOG_NAME SUPERTABLE_NAME "
+ "FROM INFORMATION_SCHEMA.CATALOGS "
+ "WHERE FALSE");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getAttributes(String catalog, String schemaPattern,
String typeNamePattern, String attributeNamePattern)
throws SQLException {
throw unsupported("attributes");
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getSchemas(String catalog, String schemaPattern)
throws SQLException {
throw unsupported("getSchemas(., .)");
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getClientInfoProperties() throws SQLException {
throw unsupported("clientInfoProperties");
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public <T> T unwrap(Class<T> iface) throws SQLException {
throw unsupported("unwrap");
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw unsupported("isWrapperFor");
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getFunctionColumns(String catalog, String schemaPattern,
String functionNamePattern, String columnNamePattern)
throws SQLException {
throw unsupported("getFunctionColumns");
}
// in src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
public ResultSet getFunctions(String catalog, String schemaPattern,
String functionNamePattern) throws SQLException {
throw unsupported("getFunctions");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean next() throws SQLException {
try {
debugCodeCall("next");
checkClosed();
return nextRow();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public ResultSetMetaData getMetaData() throws SQLException {
try {
int id = getNextId(TraceObject.RESULT_SET_META_DATA);
if (isDebugEnabled()) {
debugCodeAssign("ResultSetMetaData", TraceObject.RESULT_SET_META_DATA, id, "getMetaData()");
}
checkClosed();
String catalog = conn.getCatalog();
JdbcResultSetMetaData meta = new JdbcResultSetMetaData(this, null, result, catalog, conn.getSession().getTrace(), id);
return meta;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean wasNull() throws SQLException {
try {
debugCodeCall("wasNull");
checkClosed();
return wasNull;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public int findColumn(String columnLabel) throws SQLException {
try {
debugCodeCall("findColumn", columnLabel);
return getColumnIndex(columnLabel);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void close() throws SQLException {
try {
debugCodeCall("close");
closeInternal();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
void closeInternal() throws SQLException {
if (result != null) {
try {
result.close();
if (closeStatement && stat != null) {
stat.close();
}
} finally {
columnCount = 0;
result = null;
stat = null;
conn = null;
insertRow = null;
updateRow = null;
}
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Statement getStatement() throws SQLException {
try {
debugCodeCall("getStatement");
checkClosed();
if (closeStatement) {
// if the result set was opened by a DatabaseMetaData call
return null;
}
return stat;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public SQLWarning getWarnings() throws SQLException {
try {
debugCodeCall("getWarnings");
checkClosed();
return null;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void clearWarnings() throws SQLException {
try {
debugCodeCall("clearWarnings");
checkClosed();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public String getString(int columnIndex) throws SQLException {
try {
debugCodeCall("getString", columnIndex);
return get(columnIndex).getString();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public String getString(String columnLabel) throws SQLException {
try {
debugCodeCall("getString", columnLabel);
return get(columnLabel).getString();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public int getInt(int columnIndex) throws SQLException {
try {
debugCodeCall("getInt", columnIndex);
return get(columnIndex).getInt();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public int getInt(String columnLabel) throws SQLException {
try {
debugCodeCall("getInt", columnLabel);
return get(columnLabel).getInt();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
try {
debugCodeCall("getBigDecimal", columnIndex);
return get(columnIndex).getBigDecimal();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Date getDate(int columnIndex) throws SQLException {
try {
debugCodeCall("getDate", columnIndex);
return get(columnIndex).getDate();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Time getTime(int columnIndex) throws SQLException {
try {
debugCodeCall("getTime", columnIndex);
return get(columnIndex).getTime();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Timestamp getTimestamp(int columnIndex) throws SQLException {
try {
debugCodeCall("getTimestamp", columnIndex);
return get(columnIndex).getTimestamp();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
try {
debugCodeCall("getBigDecimal", columnLabel);
return get(columnLabel).getBigDecimal();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Date getDate(String columnLabel) throws SQLException {
try {
debugCodeCall("getDate", columnLabel);
return get(columnLabel).getDate();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Time getTime(String columnLabel) throws SQLException {
try {
debugCodeCall("getTime", columnLabel);
return get(columnLabel).getTime();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Timestamp getTimestamp(String columnLabel) throws SQLException {
try {
debugCodeCall("getTimestamp", columnLabel);
return get(columnLabel).getTimestamp();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Object getObject(int columnIndex) throws SQLException {
try {
debugCodeCall("getObject", columnIndex);
Value v = get(columnIndex);
return conn.convertToDefaultObject(v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Object getObject(String columnLabel) throws SQLException {
try {
debugCodeCall("getObject", columnLabel);
Value v = get(columnLabel);
return conn.convertToDefaultObject(v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean getBoolean(int columnIndex) throws SQLException {
try {
debugCodeCall("getBoolean", columnIndex);
Boolean v = get(columnIndex).getBoolean();
return v == null ? false : v.booleanValue();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean getBoolean(String columnLabel) throws SQLException {
try {
debugCodeCall("getBoolean", columnLabel);
Boolean v = get(columnLabel).getBoolean();
return v == null ? false : v.booleanValue();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public byte getByte(int columnIndex) throws SQLException {
try {
debugCodeCall("getByte", columnIndex);
return get(columnIndex).getByte();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public byte getByte(String columnLabel) throws SQLException {
try {
debugCodeCall("getByte", columnLabel);
return get(columnLabel).getByte();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public short getShort(int columnIndex) throws SQLException {
try {
debugCodeCall("getShort", columnIndex);
return get(columnIndex).getShort();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public short getShort(String columnLabel) throws SQLException {
try {
debugCodeCall("getShort", columnLabel);
return get(columnLabel).getShort();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public long getLong(int columnIndex) throws SQLException {
try {
debugCodeCall("getLong", columnIndex);
return get(columnIndex).getLong();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public long getLong(String columnLabel) throws SQLException {
try {
debugCodeCall("getLong", columnLabel);
return get(columnLabel).getLong();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public float getFloat(int columnIndex) throws SQLException {
try {
debugCodeCall("getFloat", columnIndex);
return get(columnIndex).getFloat();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public float getFloat(String columnLabel) throws SQLException {
try {
debugCodeCall("getFloat", columnLabel);
return get(columnLabel).getFloat();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public double getDouble(int columnIndex) throws SQLException {
try {
debugCodeCall("getDouble", columnIndex);
return get(columnIndex).getDouble();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public double getDouble(String columnLabel) throws SQLException {
try {
debugCodeCall("getDouble", columnLabel);
return get(columnLabel).getDouble();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getBigDecimal(" + StringUtils.quoteJavaString(columnLabel)+", "+scale+");");
}
if (scale < 0) {
throw DbException.getInvalidValueException("scale", scale);
}
BigDecimal bd = get(columnLabel).getBigDecimal();
return bd == null ? null : MathUtils.setScale(bd, scale);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getBigDecimal(" + columnIndex + ", " + scale + ");");
}
if (scale < 0) {
throw DbException.getInvalidValueException("scale", scale);
}
BigDecimal bd = get(columnIndex).getBigDecimal();
return bd == null ? null : MathUtils.setScale(bd, scale);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public InputStream getUnicodeStream(int columnIndex) throws SQLException {
throw unsupported("unicodeStream");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public InputStream getUnicodeStream(String columnLabel) throws SQLException {
throw unsupported("unicodeStream");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException {
throw unsupported("map");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException {
throw unsupported("map");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Ref getRef(int columnIndex) throws SQLException {
throw unsupported("ref");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Ref getRef(String columnLabel) throws SQLException {
throw unsupported("ref");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Date getDate(int columnIndex, Calendar calendar) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getDate(" + columnIndex + ", calendar)");
}
return DateTimeUtils.convertDate(get(columnIndex), calendar);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Date getDate(String columnLabel, Calendar calendar) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getDate(" + StringUtils.quoteJavaString(columnLabel) + ", calendar)");
}
return DateTimeUtils.convertDate(get(columnLabel), calendar);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Time getTime(int columnIndex, Calendar calendar) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getTime(" + columnIndex + ", calendar)");
}
return DateTimeUtils.convertTime(get(columnIndex), calendar);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Time getTime(String columnLabel, Calendar calendar) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getTime(" + StringUtils.quoteJavaString(columnLabel) + ", calendar)");
}
return DateTimeUtils.convertTime(get(columnLabel), calendar);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Timestamp getTimestamp(int columnIndex, Calendar calendar) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getTimestamp(" + columnIndex + ", calendar)");
}
Value value = get(columnIndex);
return DateTimeUtils.convertTimestamp(value, calendar);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Timestamp getTimestamp(String columnLabel, Calendar calendar) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getTimestamp(" + StringUtils.quoteJavaString(columnLabel) + ", calendar)");
}
Value value = get(columnLabel);
return DateTimeUtils.convertTimestamp(value, calendar);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Blob getBlob(int columnIndex) throws SQLException {
try {
int id = getNextId(TraceObject.BLOB);
debugCodeAssign("Blob", TraceObject.BLOB, id, "getBlob(" + columnIndex + ")");
Value v = get(columnIndex);
return v == ValueNull.INSTANCE ? null : new JdbcBlob(conn, v, id);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Blob getBlob(String columnLabel) throws SQLException {
try {
int id = getNextId(TraceObject.BLOB);
debugCodeAssign("Blob", TraceObject.BLOB, id, "getBlob(" + quote(columnLabel) + ")");
Value v = get(columnLabel);
return v == ValueNull.INSTANCE ? null : new JdbcBlob(conn, v, id);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public byte[] getBytes(int columnIndex) throws SQLException {
try {
debugCodeCall("getBytes", columnIndex);
return get(columnIndex).getBytes();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public byte[] getBytes(String columnLabel) throws SQLException {
try {
debugCodeCall("getBytes", columnLabel);
return get(columnLabel).getBytes();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public InputStream getBinaryStream(int columnIndex) throws SQLException {
try {
debugCodeCall("getBinaryStream", columnIndex);
return get(columnIndex).getInputStream();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public InputStream getBinaryStream(String columnLabel) throws SQLException {
try {
debugCodeCall("getBinaryStream", columnLabel);
return get(columnLabel).getInputStream();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Clob getClob(int columnIndex) throws SQLException {
try {
int id = getNextId(TraceObject.CLOB);
debugCodeAssign("Clob", TraceObject.CLOB, id, "getClob(" + columnIndex + ")");
Value v = get(columnIndex);
return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Clob getClob(String columnLabel) throws SQLException {
try {
int id = getNextId(TraceObject.CLOB);
debugCodeAssign("Clob", TraceObject.CLOB, id, "getClob(" + quote(columnLabel) + ")");
Value v = get(columnLabel);
return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Array getArray(int columnIndex) throws SQLException {
try {
int id = getNextId(TraceObject.ARRAY);
debugCodeAssign("Clob", TraceObject.ARRAY, id, "getArray(" + columnIndex + ")");
Value v = get(columnIndex);
return v == ValueNull.INSTANCE ? null : new JdbcArray(conn, v, id);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Array getArray(String columnLabel) throws SQLException {
try {
int id = getNextId(TraceObject.ARRAY);
debugCodeAssign("Clob", TraceObject.ARRAY, id, "getArray(" + quote(columnLabel) + ")");
Value v = get(columnLabel);
return v == ValueNull.INSTANCE ? null : new JdbcArray(conn, v, id);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public InputStream getAsciiStream(int columnIndex) throws SQLException {
try {
debugCodeCall("getAsciiStream", columnIndex);
String s = get(columnIndex).getString();
return s == null ? null : IOUtils.getInputStreamFromString(s);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public InputStream getAsciiStream(String columnLabel) throws SQLException {
try {
debugCodeCall("getAsciiStream", columnLabel);
String s = get(columnLabel).getString();
return IOUtils.getInputStreamFromString(s);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Reader getCharacterStream(int columnIndex) throws SQLException {
try {
debugCodeCall("getCharacterStream", columnIndex);
return get(columnIndex).getReader();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Reader getCharacterStream(String columnLabel) throws SQLException {
try {
debugCodeCall("getCharacterStream", columnLabel);
return get(columnLabel).getReader();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public URL getURL(int columnIndex) throws SQLException {
throw unsupported("url");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public URL getURL(String columnLabel) throws SQLException {
throw unsupported("url");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateNull(int columnIndex) throws SQLException {
try {
debugCodeCall("updateNull", columnIndex);
update(columnIndex, ValueNull.INSTANCE);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateNull(String columnLabel) throws SQLException {
try {
debugCodeCall("updateNull", columnLabel);
update(columnLabel, ValueNull.INSTANCE);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBoolean(int columnIndex, boolean x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBoolean("+columnIndex+", "+x+");");
}
update(columnIndex, ValueBoolean.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBoolean(String columnLabel, boolean x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBoolean("+quote(columnLabel)+", "+x+");");
}
update(columnLabel, ValueBoolean.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateByte(int columnIndex, byte x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateByte("+columnIndex+", "+x+");");
}
update(columnIndex, ValueByte.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateByte(String columnLabel, byte x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateByte("+columnLabel+", "+x+");");
}
update(columnLabel, ValueByte.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBytes(int columnIndex, byte[] x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBytes("+columnIndex+", x);");
}
update(columnIndex, x == null ? (Value) ValueNull.INSTANCE : ValueBytes.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBytes(String columnLabel, byte[] x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBytes("+quote(columnLabel)+", x);");
}
update(columnLabel, x == null ? (Value) ValueNull.INSTANCE : ValueBytes.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateShort(int columnIndex, short x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateShort("+columnIndex+", (short) "+x+");");
}
update(columnIndex, ValueShort.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateShort(String columnLabel, short x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateShort("+quote(columnLabel)+", (short) "+x+");");
}
update(columnLabel, ValueShort.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateInt(int columnIndex, int x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateInt("+columnIndex+", "+x+");");
}
update(columnIndex, ValueInt.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateInt(String columnLabel, int x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateInt("+quote(columnLabel)+", "+x+");");
}
update(columnLabel, ValueInt.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateLong(int columnIndex, long x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateLong("+columnIndex+", "+x+"L);");
}
update(columnIndex, ValueLong.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateLong(String columnLabel, long x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateLong("+quote(columnLabel)+", "+x+"L);");
}
update(columnLabel, ValueLong.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateFloat(int columnIndex, float x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateFloat("+columnIndex+", "+x+"f);");
}
update(columnIndex, ValueFloat.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateFloat(String columnLabel, float x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateFloat("+quote(columnLabel)+", "+x+"f);");
}
update(columnLabel, ValueFloat.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateDouble(int columnIndex, double x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateDouble("+columnIndex+", "+x+"d);");
}
update(columnIndex, ValueDouble.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateDouble(String columnLabel, double x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateDouble("+quote(columnLabel)+", "+x+"d);");
}
update(columnLabel, ValueDouble.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBigDecimal("+columnIndex+", " + quoteBigDecimal(x) + ");");
}
update(columnIndex, x == null ? (Value) ValueNull.INSTANCE : ValueDecimal.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBigDecimal("+quote(columnLabel)+", " + quoteBigDecimal(x) + ");");
}
update(columnLabel, x == null ? (Value) ValueNull.INSTANCE : ValueDecimal.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateString(int columnIndex, String x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateString("+columnIndex+", "+quote(x)+");");
}
update(columnIndex, x == null ? (Value) ValueNull.INSTANCE : ValueString.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateString(String columnLabel, String x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateString("+quote(columnLabel)+", "+quote(x)+");");
}
update(columnLabel, x == null ? (Value) ValueNull.INSTANCE : ValueString.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateDate(int columnIndex, Date x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateDate("+columnIndex+", x);");
}
update(columnIndex, x == null ? (Value) ValueNull.INSTANCE : ValueDate.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateDate(String columnLabel, Date x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateDate("+quote(columnLabel)+", x);");
}
update(columnLabel, x == null ? (Value) ValueNull.INSTANCE : ValueDate.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateTime(int columnIndex, Time x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateTime("+columnIndex+", x);");
}
update(columnIndex, x == null ? (Value) ValueNull.INSTANCE : ValueTime.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateTime(String columnLabel, Time x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateTime("+quote(columnLabel)+", x);");
}
update(columnLabel, x == null ? (Value) ValueNull.INSTANCE : ValueTime.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateTimestamp("+columnIndex+", x);");
}
update(columnIndex, x == null ? (Value) ValueNull.INSTANCE : ValueTimestamp.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateTimestamp("+quote(columnLabel)+", x);");
}
update(columnLabel, x == null ? (Value) ValueNull.INSTANCE : ValueTimestamp.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
updateAsciiStream(columnIndex, x, (long) length);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
updateAsciiStream(columnIndex, x, -1);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateAsciiStream("+columnIndex+", x, "+length+"L);");
}
checkClosed();
Value v = conn.createClob(IOUtils.getAsciiReader(x), length);
update(columnIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException {
updateAsciiStream(columnLabel, x, (long) length);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException {
updateAsciiStream(columnLabel, x, -1);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateAsciiStream("+quote(columnLabel)+", x, "+length+"L);");
}
checkClosed();
Value v = conn.createClob(IOUtils.getAsciiReader(x), length);
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
updateBinaryStream(columnIndex, x, (long) length);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException {
updateBinaryStream(columnIndex, x, -1);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBinaryStream("+columnIndex+", x, "+length+"L);");
}
checkClosed();
Value v = conn.createBlob(x, length);
update(columnIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException {
updateBinaryStream(columnLabel, x, -1);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException {
updateBinaryStream(columnLabel, x, (long) length);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBinaryStream("+quote(columnLabel)+", x, "+length+"L);");
}
checkClosed();
Value v = conn.createBlob(x, length);
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateCharacterStream("+columnIndex+", x, "+length+"L);");
}
checkClosed();
Value v = conn.createClob(x, length);
update(columnIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
updateCharacterStream(columnIndex, x, (long) length);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateCharacterStream(int columnIndex, Reader x) throws SQLException {
updateCharacterStream(columnIndex, x, -1);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateCharacterStream(String columnLabel, Reader x, int length) throws SQLException {
updateCharacterStream(columnLabel, x, (long) length);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateCharacterStream(String columnLabel, Reader x) throws SQLException {
updateCharacterStream(columnLabel, x, -1);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateCharacterStream(String columnLabel, Reader x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateCharacterStream("+quote(columnLabel)+", x, "+length+"L);");
}
checkClosed();
Value v = conn.createClob(x, length);
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateObject(int columnIndex, Object x, int scale) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateObject("+columnIndex+", x, "+scale+");");
}
update(columnIndex, convertToUnknownValue(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateObject(String columnLabel, Object x, int scale) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateObject("+quote(columnLabel)+", x, "+scale+");");
}
update(columnLabel, convertToUnknownValue(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateObject(int columnIndex, Object x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateObject("+columnIndex+", x);");
}
update(columnIndex, convertToUnknownValue(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateObject(String columnLabel, Object x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateObject("+quote(columnLabel)+", x);");
}
update(columnLabel, convertToUnknownValue(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateRef(int columnIndex, Ref x) throws SQLException {
throw unsupported("ref");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateRef(String columnLabel, Ref x) throws SQLException {
throw unsupported("ref");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBlob(int columnIndex, InputStream x) throws SQLException {
updateBlob(columnIndex, x, -1);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBlob(int columnIndex, InputStream x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBlob("+columnIndex+", x, " + length + "L);");
}
checkClosed();
Value v = conn.createBlob(x, length);
update(columnIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBlob(int columnIndex, Blob x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBlob("+columnIndex+", x);");
}
checkClosed();
Value v;
if (x == null) {
v = ValueNull.INSTANCE;
} else {
v = conn.createBlob(x.getBinaryStream(), -1);
}
update(columnIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBlob(String columnLabel, Blob x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBlob("+quote(columnLabel)+", x);");
}
checkClosed();
Value v;
if (x == null) {
v = ValueNull.INSTANCE;
} else {
v = conn.createBlob(x.getBinaryStream(), -1);
}
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBlob(String columnLabel, InputStream x) throws SQLException {
updateBlob(columnLabel, x, -1);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateBlob(String columnLabel, InputStream x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBlob("+quote(columnLabel)+", x, " + length + "L);");
}
checkClosed();
Value v = conn.createBlob(x, -1);
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateClob(int columnIndex, Clob x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateClob("+columnIndex+", x);");
}
checkClosed();
Value v;
if (x == null) {
v = ValueNull.INSTANCE;
} else {
v = conn.createClob(x.getCharacterStream(), -1);
}
update(columnIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateClob(int columnIndex, Reader x) throws SQLException {
updateClob(columnIndex, x, -1);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateClob(int columnIndex, Reader x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateClob("+columnIndex+", x, " + length + "L);");
}
checkClosed();
Value v = conn.createClob(x, length);
update(columnIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateClob(String columnLabel, Clob x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateClob("+quote(columnLabel)+", x);");
}
checkClosed();
Value v;
if (x == null) {
v = ValueNull.INSTANCE;
} else {
v = conn.createClob(x.getCharacterStream(), -1);
}
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateClob(String columnLabel, Reader x) throws SQLException {
updateClob(columnLabel, x, -1);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateClob(String columnLabel, Reader x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateClob("+quote(columnLabel)+", x, " + length + "L);");
}
checkClosed();
Value v = conn.createClob(x, length);
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateArray(int columnIndex, Array x) throws SQLException {
throw unsupported("setArray");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateArray(String columnLabel, Array x) throws SQLException {
throw unsupported("setArray");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public String getCursorName() throws SQLException {
throw unsupported("cursorName");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public int getRow() throws SQLException {
try {
debugCodeCall("getRow");
checkClosed();
int rowId = result.getRowId();
if (rowId >= result.getRowCount()) {
return 0;
}
return rowId + 1;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public int getConcurrency() throws SQLException {
try {
debugCodeCall("getConcurrency");
checkClosed();
if (!updatable) {
return ResultSet.CONCUR_READ_ONLY;
}
UpdatableRow row = new UpdatableRow(conn, result);
return row.isUpdatable() ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public int getFetchDirection() throws SQLException {
try {
debugCodeCall("getFetchDirection");
checkClosed();
return ResultSet.FETCH_FORWARD;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public int getFetchSize() throws SQLException {
try {
debugCodeCall("getFetchSize");
checkClosed();
return result.getFetchSize();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void setFetchSize(int rows) throws SQLException {
try {
debugCodeCall("setFetchSize", rows);
checkClosed();
if (rows < 0) {
throw DbException.getInvalidValueException("rows", rows);
} else if (rows > 0) {
if (stat != null) {
int maxRows = stat.getMaxRows();
if (maxRows > 0 && rows > maxRows) {
throw DbException.getInvalidValueException("rows", rows);
}
}
} else {
rows = SysProperties.SERVER_RESULT_SET_FETCH_SIZE;
}
result.setFetchSize(rows);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void setFetchDirection(int direction) throws SQLException {
throw unsupported("setFetchDirection");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public int getType() throws SQLException {
try {
debugCodeCall("getType");
checkClosed();
return stat == null ? ResultSet.TYPE_FORWARD_ONLY : stat.resultSetType;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean isBeforeFirst() throws SQLException {
try {
debugCodeCall("isBeforeFirst");
checkClosed();
int row = result.getRowId();
int count = result.getRowCount();
return count > 0 && row < 0;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean isAfterLast() throws SQLException {
try {
debugCodeCall("isAfterLast");
checkClosed();
int row = result.getRowId();
int count = result.getRowCount();
return count > 0 && row >= count;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean isFirst() throws SQLException {
try {
debugCodeCall("isFirst");
checkClosed();
int row = result.getRowId();
return row == 0 && row < result.getRowCount();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean isLast() throws SQLException {
try {
debugCodeCall("isLast");
checkClosed();
int row = result.getRowId();
return row >= 0 && row == result.getRowCount() - 1;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void beforeFirst() throws SQLException {
try {
debugCodeCall("beforeFirst");
checkClosed();
if (result.getRowId() >= 0) {
resetResult();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void afterLast() throws SQLException {
try {
debugCodeCall("afterLast");
checkClosed();
while (nextRow()) {
// nothing
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean first() throws SQLException {
try {
debugCodeCall("first");
checkClosed();
if (result.getRowId() < 0) {
return nextRow();
}
resetResult();
return nextRow();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean last() throws SQLException {
try {
debugCodeCall("last");
checkClosed();
return absolute(-1);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean absolute(int rowNumber) throws SQLException {
try {
debugCodeCall("absolute", rowNumber);
checkClosed();
if (rowNumber < 0) {
rowNumber = result.getRowCount() + rowNumber + 1;
} else if (rowNumber > result.getRowCount() + 1) {
rowNumber = result.getRowCount() + 1;
}
if (rowNumber <= result.getRowId()) {
resetResult();
}
while (result.getRowId() + 1 < rowNumber) {
nextRow();
}
int row = result.getRowId();
return row >= 0 && row < result.getRowCount();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean relative(int rowCount) throws SQLException {
try {
debugCodeCall("relative", rowCount);
checkClosed();
int row = result.getRowId() + 1 + rowCount;
if (row < 0) {
row = 0;
} else if (row > result.getRowCount()) {
row = result.getRowCount() + 1;
}
return absolute(row);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean previous() throws SQLException {
try {
debugCodeCall("previous");
checkClosed();
return relative(-1);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void moveToInsertRow() throws SQLException {
try {
debugCodeCall("moveToInsertRow");
checkUpdatable();
insertRow = new Value[columnCount];
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void moveToCurrentRow() throws SQLException {
try {
debugCodeCall("moveToCurrentRow");
checkUpdatable();
insertRow = null;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean rowUpdated() throws SQLException {
try {
debugCodeCall("rowUpdated");
return false;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean rowInserted() throws SQLException {
try {
debugCodeCall("rowInserted");
return false;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean rowDeleted() throws SQLException {
try {
debugCodeCall("rowDeleted");
return false;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void insertRow() throws SQLException {
try {
debugCodeCall("insertRow");
checkUpdatable();
if (insertRow == null) {
throw DbException.get(ErrorCode.NOT_ON_UPDATABLE_ROW);
}
getUpdatableRow().insertRow(insertRow);
insertRow = null;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateRow() throws SQLException {
try {
debugCodeCall("updateRow");
checkUpdatable();
if (insertRow != null) {
throw DbException.get(ErrorCode.NOT_ON_UPDATABLE_ROW);
}
checkOnValidRow();
if (updateRow != null) {
UpdatableRow row = getUpdatableRow();
Value[] current = new Value[columnCount];
for (int i = 0; i < updateRow.length; i++) {
current[i] = get(i + 1);
}
row.updateRow(current, updateRow);
for (int i = 0; i < updateRow.length; i++) {
if (updateRow[i] == null) {
updateRow[i] = current[i];
}
}
Value[] patch = row.readRow(updateRow);
patchCurrentRow(patch);
updateRow = null;
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void deleteRow() throws SQLException {
try {
debugCodeCall("deleteRow");
checkUpdatable();
if (insertRow != null) {
throw DbException.get(ErrorCode.NOT_ON_UPDATABLE_ROW);
}
checkOnValidRow();
getUpdatableRow().deleteRow(result.currentRow());
updateRow = null;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void refreshRow() throws SQLException {
try {
debugCodeCall("refreshRow");
checkClosed();
if (insertRow != null) {
throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
}
checkOnValidRow();
patchCurrentRow(getUpdatableRow().readRow(result.currentRow()));
updateRow = null;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void cancelRowUpdates() throws SQLException {
try {
debugCodeCall("cancelRowUpdates");
checkClosed();
if (insertRow != null) {
throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
}
updateRow = null;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
private UpdatableRow getUpdatableRow() throws SQLException {
UpdatableRow row = new UpdatableRow(conn, result);
if (!row.isUpdatable()) {
throw DbException.get(ErrorCode.RESULT_SET_NOT_UPDATABLE);
}
return row;
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public RowId getRowId(int columnIndex) throws SQLException {
throw unsupported("rowId");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public RowId getRowId(String columnLabel) throws SQLException {
throw unsupported("rowId");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateRowId(int columnIndex, RowId x) throws SQLException {
throw unsupported("rowId");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateRowId(String columnLabel, RowId x) throws SQLException {
throw unsupported("rowId");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public int getHoldability() throws SQLException {
try {
debugCodeCall("getHoldability");
checkClosed();
return conn.getHoldability();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean isClosed() throws SQLException {
try {
debugCodeCall("isClosed");
return result == null;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateNString(int columnIndex, String x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateNString("+columnIndex+", "+quote(x)+");");
}
update(columnIndex, x == null ? (Value)
ValueNull.INSTANCE : ValueString.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateNString(String columnLabel, String x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateNString("+quote(columnLabel)+", "+quote(x)+");");
}
update(columnLabel, x == null ? (Value) ValueNull.INSTANCE :
ValueString.get(x));
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateNClob(int columnIndex, NClob x) throws SQLException {
throw unsupported("NClob");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateNClob(int columnIndex, Reader x) throws SQLException {
throw unsupported("NClob");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateNClob(int columnIndex, Reader x, long length)
throws SQLException {
throw unsupported("NClob");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateNClob(String columnLabel, Reader x)
throws SQLException {
throw unsupported("NClob");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateNClob(String columnLabel, Reader x, long length)
throws SQLException {
throw unsupported("NClob");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateNClob(String columnLabel, NClob x) throws SQLException {
throw unsupported("NClob");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public NClob getNClob(int columnIndex) throws SQLException {
try {
int id = getNextId(TraceObject.CLOB);
debugCodeAssign("NClob", TraceObject.CLOB, id, "getNClob(" + columnIndex + ")");
Value v = get(columnIndex);
return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public NClob getNClob(String columnLabel) throws SQLException {
try {
int id = getNextId(TraceObject.CLOB);
debugCodeAssign("NClob", TraceObject.CLOB, id, "getNClob(" + columnLabel + ")");
Value v = get(columnLabel);
return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public SQLXML getSQLXML(int columnIndex) throws SQLException {
throw unsupported("SQLXML");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public SQLXML getSQLXML(String columnLabel) throws SQLException {
throw unsupported("SQLXML");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateSQLXML(int columnIndex, SQLXML xmlObject)
throws SQLException {
throw unsupported("SQLXML");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateSQLXML(String columnLabel, SQLXML xmlObject)
throws SQLException {
throw unsupported("SQLXML");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public String getNString(int columnIndex) throws SQLException {
try {
debugCodeCall("getNString", columnIndex);
return get(columnIndex).getString();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public String getNString(String columnLabel) throws SQLException {
try {
debugCodeCall("getNString", columnLabel);
return get(columnLabel).getString();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Reader getNCharacterStream(int columnIndex) throws SQLException {
try {
debugCodeCall("getNCharacterStream", columnIndex);
return get(columnIndex).getReader();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public Reader getNCharacterStream(String columnLabel) throws SQLException {
try {
debugCodeCall("getNCharacterStream", columnLabel);
return get(columnLabel).getReader();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateNCharacterStream(int columnIndex, Reader x)
throws SQLException {
updateNCharacterStream(columnIndex, x, -1);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateNCharacterStream(int columnIndex, Reader x, long length)
throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateNCharacterStream("+columnIndex+", x, "+length+"L);");
}
checkClosed();
Value v = conn.createClob(x, length);
update(columnIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateNCharacterStream(String columnLabel, Reader x)
throws SQLException {
updateNCharacterStream(columnLabel, x, -1);
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public void updateNCharacterStream(String columnLabel, Reader x, long length)
throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateNCharacterStream("+quote(columnLabel)+", x, "+length+"L);");
}
checkClosed();
Value v = conn.createClob(x, length);
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public <T> T unwrap(Class<T> iface) throws SQLException {
throw unsupported("unwrap");
}
// in src/main/org/h2/jdbc/JdbcResultSet.java
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw unsupported("isWrapperFor");
}
// in src/main/org/h2/jdbc/JdbcArray.java
public Object getArray() throws SQLException {
try {
debugCodeCall("getArray");
checkClosed();
return get();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcArray.java
public Object getArray(Map<String, Class<?>> map) throws SQLException {
try {
debugCode("getArray("+quoteMap(map)+");");
checkMap(map);
checkClosed();
return get();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcArray.java
public Object getArray(long index, int count) throws SQLException {
try {
debugCode("getArray(" + index + ", " + count + ");");
checkClosed();
return get(index, count);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcArray.java
public Object getArray(long index, int count, Map<String, Class<?>> map) throws SQLException {
try {
debugCode("getArray(" + index + ", " + count + ", " + quoteMap(map)+");");
checkClosed();
checkMap(map);
return get(index, count);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcArray.java
public int getBaseType() throws SQLException {
try {
debugCodeCall("getBaseType");
checkClosed();
return Types.NULL;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcArray.java
public String getBaseTypeName() throws SQLException {
try {
debugCodeCall("getBaseTypeName");
checkClosed();
return "NULL";
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcArray.java
public ResultSet getResultSet() throws SQLException {
try {
debugCodeCall("getResultSet");
checkClosed();
return getResultSet(get(), 0);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcArray.java
public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
try {
debugCode("getResultSet("+quoteMap(map)+");");
checkClosed();
checkMap(map);
return getResultSet(get(), 0);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcArray.java
public ResultSet getResultSet(long index, int count) throws SQLException {
try {
debugCode("getResultSet("+index+", " + count+");");
checkClosed();
return getResultSet(get(index, count), index);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcArray.java
public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map) throws SQLException {
try {
debugCode("getResultSet("+index+", " + count+", " + quoteMap(map)+");");
checkClosed();
checkMap(map);
return getResultSet(get(index, count), index);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcParameterMetaData.java
public int getParameterCount() throws SQLException {
try {
debugCodeCall("getParameterCount");
checkClosed();
return paramCount;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcParameterMetaData.java
public int getParameterMode(int param) throws SQLException {
try {
debugCodeCall("getParameterMode", param);
getParameter(param);
return parameterModeIn;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcParameterMetaData.java
public int getParameterType(int param) throws SQLException {
try {
debugCodeCall("getParameterType", param);
ParameterInterface p = getParameter(param);
int type = p.getType();
if (type == Value.UNKNOWN) {
type = Value.STRING;
}
return DataType.getDataType(type).sqlType;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcParameterMetaData.java
public int getPrecision(int param) throws SQLException {
try {
debugCodeCall("getPrecision", param);
ParameterInterface p = getParameter(param);
return MathUtils.convertLongToInt(p.getPrecision());
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcParameterMetaData.java
public int getScale(int param) throws SQLException {
try {
debugCodeCall("getScale", param);
ParameterInterface p = getParameter(param);
return p.getScale();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcParameterMetaData.java
public int isNullable(int param) throws SQLException {
try {
debugCodeCall("isNullable", param);
return getParameter(param).getNullable();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcParameterMetaData.java
public boolean isSigned(int param) throws SQLException {
try {
debugCodeCall("isSigned", param);
getParameter(param);
return true;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcParameterMetaData.java
public String getParameterClassName(int param) throws SQLException {
try {
debugCodeCall("getParameterClassName", param);
ParameterInterface p = getParameter(param);
int type = p.getType();
if (type == Value.UNKNOWN) {
type = Value.STRING;
}
return DataType.getTypeClassName(type);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcParameterMetaData.java
public String getParameterTypeName(int param) throws SQLException {
try {
debugCodeCall("getParameterTypeName", param);
ParameterInterface p = getParameter(param);
int type = p.getType();
if (type == Value.UNKNOWN) {
type = Value.STRING;
}
return DataType.getDataType(type).name;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcParameterMetaData.java
public <T> T unwrap(Class<T> iface) throws SQLException {
throw unsupported("unwrap");
}
// in src/main/org/h2/jdbc/JdbcParameterMetaData.java
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw unsupported("isWrapperFor");
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public int executeUpdate() throws SQLException {
try {
checkClosed();
if (command.isQuery()) {
super.executeQuery();
return 0;
}
return super.executeUpdate();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
registerOutParameter(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException {
registerOutParameter(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
registerOutParameter(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
registerOutParameter(getIndexForName(parameterName), sqlType, typeName);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
registerOutParameter(getIndexForName(parameterName), sqlType, scale);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void registerOutParameter(String parameterName, int sqlType) throws SQLException {
registerOutParameter(getIndexForName(parameterName), sqlType);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public boolean wasNull() throws SQLException {
return getOpenResultSet().wasNull();
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public URL getURL(int parameterIndex) throws SQLException {
throw unsupported("url");
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public String getString(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getString(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public boolean getBoolean(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getBoolean(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public byte getByte(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getByte(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public short getShort(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getShort(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public int getInt(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getInt(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public long getLong(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getLong(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public float getFloat(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getFloat(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public double getDouble(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getDouble(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getBigDecimal(parameterIndex, scale);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public byte[] getBytes(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getBytes(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Date getDate(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getDate(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Time getTime(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getTime(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Timestamp getTimestamp(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getTimestamp(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Object getObject(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getObject(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getBigDecimal(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Object getObject(int parameterIndex, Map<String, Class<?>> map) throws SQLException {
throw unsupported("map");
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Ref getRef(int parameterIndex) throws SQLException {
throw unsupported("ref");
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Blob getBlob(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getBlob(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Clob getClob(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getClob(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Array getArray(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getArray(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Date getDate(int parameterIndex, Calendar cal) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getDate(parameterIndex, cal);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Time getTime(int parameterIndex, Calendar cal) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getTime(parameterIndex, cal);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getTimestamp(parameterIndex, cal);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public URL getURL(String parameterName) throws SQLException {
throw unsupported("url");
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
return getTimestamp(getIndexForName(parameterName), cal);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Time getTime(String parameterName, Calendar cal) throws SQLException {
return getTime(getIndexForName(parameterName), cal);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Date getDate(String parameterName, Calendar cal) throws SQLException {
return getDate(getIndexForName(parameterName), cal);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Array getArray(String parameterName) throws SQLException {
return getArray(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Clob getClob(String parameterName) throws SQLException {
return getClob(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Blob getBlob(String parameterName) throws SQLException {
return getBlob(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Ref getRef(String parameterName) throws SQLException {
throw unsupported("ref");
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Object getObject(String parameterName, Map<String, Class<?>> map) throws SQLException {
throw unsupported("map");
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public BigDecimal getBigDecimal(String parameterName) throws SQLException {
return getBigDecimal(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Object getObject(String parameterName) throws SQLException {
return getObject(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Timestamp getTimestamp(String parameterName) throws SQLException {
return getTimestamp(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Time getTime(String parameterName) throws SQLException {
return getTime(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Date getDate(String parameterName) throws SQLException {
return getDate(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public byte[] getBytes(String parameterName) throws SQLException {
return getBytes(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public double getDouble(String parameterName) throws SQLException {
return getDouble(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public float getFloat(String parameterName) throws SQLException {
return getFloat(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public long getLong(String parameterName) throws SQLException {
return getLong(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public int getInt(String parameterName) throws SQLException {
return getInt(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public short getShort(String parameterName) throws SQLException {
return getShort(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public byte getByte(String parameterName) throws SQLException {
return getByte(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public boolean getBoolean(String parameterName) throws SQLException {
return getBoolean(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public String getString(String parameterName) throws SQLException {
return getString(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public RowId getRowId(int parameterIndex) throws SQLException {
throw unsupported("rowId");
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public RowId getRowId(String parameterName) throws SQLException {
throw unsupported("rowId");
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public NClob getNClob(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getNClob(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public NClob getNClob(String parameterName) throws SQLException {
return getNClob(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public SQLXML getSQLXML(int parameterIndex) throws SQLException {
throw unsupported("SQLXML");
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public SQLXML getSQLXML(String parameterName) throws SQLException {
throw unsupported("SQLXML");
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public String getNString(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getNString(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public String getNString(String parameterName) throws SQLException {
return getNString(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Reader getNCharacterStream(int parameterIndex)
throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getNCharacterStream(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Reader getNCharacterStream(String parameterName)
throws SQLException {
return getNCharacterStream(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Reader getCharacterStream(int parameterIndex)
throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getCharacterStream(parameterIndex);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public Reader getCharacterStream(String parameterName)
throws SQLException {
return getCharacterStream(getIndexForName(parameterName));
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
setNull(getIndexForName(parameterName), sqlType, typeName);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setNull(String parameterName, int sqlType) throws SQLException {
setNull(getIndexForName(parameterName), sqlType);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
setTimestamp(getIndexForName(parameterName), x, cal);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
setTime(getIndexForName(parameterName), x, cal);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
setDate(getIndexForName(parameterName), x, cal);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setCharacterStream(String parameterName, Reader x, int length) throws SQLException {
setCharacterStream(getIndexForName(parameterName), x, length);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setObject(String parameterName, Object x) throws SQLException {
setObject(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
setObject(getIndexForName(parameterName), x, targetSqlType);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException {
setObject(getIndexForName(parameterName), x, targetSqlType, scale);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
setBinaryStream(getIndexForName(parameterName), x, length);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setAsciiStream(String parameterName,
InputStream x, long length) throws SQLException {
setAsciiStream(getIndexForName(parameterName), x, length);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
setTimestamp(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setTime(String parameterName, Time x) throws SQLException {
setTime(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setDate(String parameterName, Date x) throws SQLException {
setDate(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setBytes(String parameterName, byte[] x) throws SQLException {
setBytes(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setString(String parameterName, String x) throws SQLException {
setString(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
setBigDecimal(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setDouble(String parameterName, double x) throws SQLException {
setDouble(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setFloat(String parameterName, float x) throws SQLException {
setFloat(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setLong(String parameterName, long x) throws SQLException {
setLong(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setInt(String parameterName, int x) throws SQLException {
setInt(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setShort(String parameterName, short x) throws SQLException {
setShort(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setByte(String parameterName, byte x) throws SQLException {
setByte(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setBoolean(String parameterName, boolean x) throws SQLException {
setBoolean(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setURL(String parameterName, URL val) throws SQLException {
throw unsupported("url");
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setRowId(String parameterName, RowId x)
throws SQLException {
throw unsupported("rowId");
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setNString(String parameterName, String x)
throws SQLException {
setNString(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setNCharacterStream(String parameterName,
Reader x, long length) throws SQLException {
setNCharacterStream(getIndexForName(parameterName), x, length);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setNClob(String parameterName, NClob x)
throws SQLException {
setNClob(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setClob(String parameterName, Reader x,
long length) throws SQLException {
setClob(getIndexForName(parameterName), x, length);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setBlob(String parameterName, InputStream x,
long length) throws SQLException {
setBlob(getIndexForName(parameterName), x, length);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setNClob(String parameterName, Reader x,
long length) throws SQLException {
setNClob(getIndexForName(parameterName), x, length);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setBlob(String parameterName, Blob x)
throws SQLException {
setBlob(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setClob(String parameterName, Clob x) throws SQLException {
setClob(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setAsciiStream(String parameterName, InputStream x)
throws SQLException {
setAsciiStream(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setAsciiStream(String parameterName,
InputStream x, int length) throws SQLException {
setAsciiStream(getIndexForName(parameterName), x, length);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setBinaryStream(String parameterName,
InputStream x) throws SQLException {
setBinaryStream(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setBinaryStream(String parameterName,
InputStream x, long length) throws SQLException {
setBinaryStream(getIndexForName(parameterName), x, length);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setBlob(String parameterName, InputStream x)
throws SQLException {
setBlob(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setCharacterStream(String parameterName, Reader x)
throws SQLException {
setCharacterStream(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setCharacterStream(String parameterName,
Reader x, long length) throws SQLException {
setCharacterStream(getIndexForName(parameterName), x, length);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setClob(String parameterName, Reader x) throws SQLException {
setClob(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setNCharacterStream(String parameterName, Reader x)
throws SQLException {
setNCharacterStream(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setNClob(String parameterName, Reader x)
throws SQLException {
setNClob(getIndexForName(parameterName), x);
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
public void setSQLXML(String parameterName, SQLXML x)
throws SQLException {
throw unsupported("SQLXML");
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
private ResultSetMetaData getCheckedMetaData() throws SQLException {
ResultSetMetaData meta = getMetaData();
if (meta == null) {
throw DbException.getUnsupportedException("Supported only for calling stored procedures");
}
return meta;
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
private void registerOutParameter(int parameterIndex) throws SQLException {
try {
checkClosed();
if (outParameters == null) {
maxOutParameters = Math.min(
getParameterMetaData().getParameterCount(),
getCheckedMetaData().getColumnCount());
outParameters = new BitField();
}
checkIndexBounds(parameterIndex);
ParameterInterface param = command.getParameters().get(--parameterIndex);
if (param.getParamValue() == null) {
param.setValue(ValueNull.INSTANCE, false);
}
outParameters.set(parameterIndex);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
private void checkRegistered(int parameterIndex) throws SQLException {
try {
checkIndexBounds(parameterIndex);
if (!outParameters.get(parameterIndex - 1)) {
throw DbException.getInvalidValueException("parameterIndex", parameterIndex);
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
private int getIndexForName(String parameterName) throws SQLException {
try {
checkClosed();
if (namedParameters == null) {
ResultSetMetaData meta = getCheckedMetaData();
int columnCount = meta.getColumnCount();
HashMap<String, Integer> map = New.hashMap(columnCount);
for (int i = 1; i <= columnCount; i++) {
map.put(meta.getColumnLabel(i), i);
}
namedParameters = map;
}
Integer index = namedParameters.get(parameterName);
if (index == null) {
throw DbException.getInvalidValueException("parameterName", parameterName);
}
return index;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcCallableStatement.java
private JdbcResultSet getOpenResultSet() throws SQLException {
try {
checkClosed();
if (resultSet == null) {
throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
}
if (resultSet.isBeforeFirst()) {
resultSet.next();
}
return resultSet;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcBlob.java
public long length() throws SQLException {
try {
debugCodeCall("length");
checkClosed();
if (value.getType() == Value.BLOB) {
long precision = value.getPrecision();
if (precision > 0) {
return precision;
}
}
return IOUtils.copyAndCloseInput(value.getInputStream(), null);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcBlob.java
public void truncate(long len) throws SQLException {
throw unsupported("LOB update");
}
// in src/main/org/h2/jdbc/JdbcBlob.java
public byte[] getBytes(long pos, int length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getBytes("+pos+", "+length+");");
}
checkClosed();
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = value.getInputStream();
try {
IOUtils.skipFully(in, pos - 1);
IOUtils.copy(in, out, length);
} finally {
in.close();
}
return out.toByteArray();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcBlob.java
public int setBytes(long pos, byte[] bytes) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setBytes("+pos+", "+quoteBytes(bytes)+");");
}
checkClosed();
if (pos != 1) {
throw DbException.getInvalidValueException("pos", pos);
}
value = conn.createBlob(new ByteArrayInputStream(bytes), -1);
return bytes.length;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcBlob.java
public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException {
throw unsupported("LOB update");
}
// in src/main/org/h2/jdbc/JdbcBlob.java
public InputStream getBinaryStream() throws SQLException {
try {
debugCodeCall("getBinaryStream");
checkClosed();
return value.getInputStream();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcBlob.java
public OutputStream setBinaryStream(long pos) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setBinaryStream("+pos+");");
}
checkClosed();
if (pos != 1) {
throw DbException.getInvalidValueException("pos", pos);
}
if (value.getPrecision() != 0) {
throw DbException.getInvalidValueException("length", value.getPrecision());
}
final JdbcConnection c = conn;
final PipedInputStream in = new PipedInputStream();
final Task task = new Task() {
public void call() {
value = c.createBlob(in, -1);
}
};
PipedOutputStream out = new PipedOutputStream(in) {
public void close() throws IOException {
super.close();
try {
task.get();
} catch (Exception e) {
throw DbException.convertToIOException(e);
}
}
};
task.execute();
return new BufferedOutputStream(out);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcBlob.java
public long position(byte[] pattern, long start) throws SQLException {
if (isDebugEnabled()) {
debugCode("position("+quoteBytes(pattern)+", "+start+");");
}
if (Constants.BLOB_SEARCH) {
try {
checkClosed();
if (pattern == null) {
return -1;
}
if (pattern.length == 0) {
return 1;
}
// TODO performance: blob pattern search is slow
BufferedInputStream in = new BufferedInputStream(value.getInputStream());
IOUtils.skipFully(in, start - 1);
int pos = 0;
int patternPos = 0;
while (true) {
int x = in.read();
if (x < 0) {
break;
}
if (x == (pattern[patternPos] & 0xff)) {
if (patternPos == 0) {
in.mark(pattern.length);
}
if (patternPos == pattern.length) {
return pos - patternPos;
}
patternPos++;
} else {
if (patternPos > 0) {
in.reset();
pos -= patternPos;
}
}
pos++;
}
return -1;
} catch (Exception e) {
throw logAndConvert(e);
}
}
throw unsupported("LOB search");
}
// in src/main/org/h2/jdbc/JdbcBlob.java
public long position(Blob blobPattern, long start) throws SQLException {
if (isDebugEnabled()) {
debugCode("position(blobPattern, "+start+");");
}
if (Constants.BLOB_SEARCH) {
try {
checkClosed();
if (blobPattern == null) {
return -1;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = blobPattern.getBinaryStream();
while (true) {
int x = in.read();
if (x < 0) {
break;
}
out.write(x);
}
return position(out.toByteArray(), start);
} catch (Exception e) {
throw logAndConvert(e);
}
}
throw unsupported("LOB subset");
}
// in src/main/org/h2/jdbc/JdbcBlob.java
public InputStream getBinaryStream(long pos, long length) throws SQLException {
throw unsupported("LOB update");
}
// in src/main/org/h2/jdbc/JdbcStatement.java
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 scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
setExecutingStatement(command);
try {
result = command.executeQuery(maxRows, scrollable);
} finally {
setExecutingStatement(null);
}
command.close();
resultSet = new JdbcResultSet(conn, this, result, id, closedByResultSet, scrollable, updatable);
}
return resultSet;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public int executeUpdate(String sql) throws SQLException {
try {
debugCodeCall("executeUpdate", sql);
return executeUpdateInternal(sql);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
private int executeUpdateInternal(String sql) throws SQLException {
checkClosedForWrite();
try {
closeOldResultSet();
sql = JdbcConnection.translateSQL(sql, escapeProcessing);
CommandInterface command = conn.prepareCommand(sql, fetchSize);
synchronized (session) {
setExecutingStatement(command);
try {
updateCount = command.executeUpdate();
} finally {
setExecutingStatement(null);
}
}
command.close();
return updateCount;
} finally {
afterWriting();
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public boolean execute(String sql) throws SQLException {
try {
debugCodeCall("execute", sql);
return executeInternal(sql);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
private boolean executeInternal(String sql) throws SQLException {
int id = getNextId(TraceObject.RESULT_SET);
checkClosedForWrite();
try {
closeOldResultSet();
sql = JdbcConnection.translateSQL(sql, escapeProcessing);
CommandInterface command = conn.prepareCommand(sql, fetchSize);
boolean returnsResultSet;
synchronized (session) {
setExecutingStatement(command);
try {
if (command.isQuery()) {
returnsResultSet = true;
boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
ResultInterface result = command.executeQuery(maxRows, scrollable);
resultSet = new JdbcResultSet(conn, this, result, id, closedByResultSet, scrollable, updatable);
} else {
returnsResultSet = false;
updateCount = command.executeUpdate();
}
} finally {
setExecutingStatement(null);
}
}
command.close();
return returnsResultSet;
} finally {
afterWriting();
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public ResultSet getResultSet() throws SQLException {
try {
checkClosed();
if (resultSet != null) {
int id = resultSet.getTraceId();
debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id, "getResultSet()");
} else {
debugCodeCall("getResultSet");
}
return resultSet;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public int getUpdateCount() throws SQLException {
try {
debugCodeCall("getUpdateCount");
checkClosed();
return updateCount;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public void close() throws SQLException {
try {
debugCodeCall("close");
synchronized (session) {
closeOldResultSet();
if (conn != null) {
conn = null;
}
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public SQLWarning getWarnings() throws SQLException {
try {
debugCodeCall("getWarnings");
checkClosed();
return null;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public void clearWarnings() throws SQLException {
try {
debugCodeCall("clearWarnings");
checkClosed();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public void setCursorName(String name) throws SQLException {
try {
debugCodeCall("setCursorName", name);
checkClosed();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public void setFetchDirection(int direction) throws SQLException {
try {
debugCodeCall("setFetchDirection", direction);
checkClosed();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public int getFetchDirection() throws SQLException {
try {
debugCodeCall("getFetchDirection");
checkClosed();
return ResultSet.FETCH_FORWARD;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public int getMaxRows() throws SQLException {
try {
debugCodeCall("getMaxRows");
checkClosed();
return maxRows;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public void setMaxRows(int maxRows) throws SQLException {
try {
debugCodeCall("setMaxRows", maxRows);
checkClosed();
if (maxRows < 0) {
throw DbException.getInvalidValueException("maxRows", maxRows);
}
this.maxRows = maxRows;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public void setFetchSize(int rows) throws SQLException {
try {
debugCodeCall("setFetchSize", rows);
checkClosed();
if (rows < 0 || (rows > 0 && maxRows > 0 && rows > maxRows)) {
throw DbException.getInvalidValueException("rows", rows);
}
if (rows == 0) {
rows = SysProperties.SERVER_RESULT_SET_FETCH_SIZE;
}
fetchSize = rows;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public int getFetchSize() throws SQLException {
try {
debugCodeCall("getFetchSize");
checkClosed();
return fetchSize;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public int getResultSetConcurrency() throws SQLException {
try {
debugCodeCall("getResultSetConcurrency");
checkClosed();
return resultSetConcurrency;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public int getResultSetType() throws SQLException {
try {
debugCodeCall("getResultSetType");
checkClosed();
return resultSetType;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public int getMaxFieldSize() throws SQLException {
try {
debugCodeCall("getMaxFieldSize");
checkClosed();
return 0;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public void setMaxFieldSize(int max) throws SQLException {
try {
debugCodeCall("setMaxFieldSize", max);
checkClosed();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public void setEscapeProcessing(boolean enable) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setEscapeProcessing("+enable+");");
}
checkClosed();
escapeProcessing = enable;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public void cancel() throws SQLException {
try {
debugCodeCall("cancel");
checkClosed();
// executingCommand can be reset by another thread
CommandInterface c = executingCommand;
try {
if (c != null) {
c.cancel();
}
} finally {
setExecutingStatement(null);
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public int getQueryTimeout() throws SQLException {
try {
debugCodeCall("getQueryTimeout");
checkClosed();
return conn.getQueryTimeout();
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public void setQueryTimeout(int seconds) throws SQLException {
try {
debugCodeCall("setQueryTimeout", seconds);
checkClosed();
if (seconds < 0) {
throw DbException.getInvalidValueException("seconds", seconds);
}
conn.setQueryTimeout(seconds);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public void addBatch(String sql) throws SQLException {
try {
debugCodeCall("addBatch", sql);
checkClosed();
sql = JdbcConnection.translateSQL(sql, escapeProcessing);
if (batchCommands == null) {
batchCommands = New.arrayList();
}
batchCommands.add(sql);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public void clearBatch() throws SQLException {
try {
debugCodeCall("clearBatch");
checkClosed();
batchCommands = null;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public int[] executeBatch() throws SQLException {
try {
debugCodeCall("executeBatch");
checkClosedForWrite();
try {
if (batchCommands == null) {
// TODO batch: check what other database do if no commands are set
batchCommands = New.arrayList();
}
int size = batchCommands.size();
int[] result = new int[size];
boolean error = false;
SQLException next = null;
for (int i = 0; i < size; i++) {
String sql = batchCommands.get(i);
try {
result[i] = executeUpdateInternal(sql);
} catch (Exception re) {
SQLException e = logAndConvert(re);
if (next == null) {
next = e;
} else {
e.setNextException(next);
next = e;
}
result[i] = Statement.EXECUTE_FAILED;
error = true;
}
}
batchCommands = null;
if (error) {
throw new JdbcBatchUpdateException(next, result);
}
return result;
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public ResultSet getGeneratedKeys() throws SQLException {
try {
int id = getNextId(TraceObject.RESULT_SET);
if (isDebugEnabled()) {
debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id, "getGeneratedKeys()");
}
checkClosed();
return conn.getGeneratedKeys(this, id);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public boolean getMoreResults() throws SQLException {
try {
debugCodeCall("getMoreResults");
checkClosed();
closeOldResultSet();
return false;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public boolean getMoreResults(int current) throws SQLException {
try {
debugCodeCall("getMoreResults", current);
switch (current) {
case Statement.CLOSE_CURRENT_RESULT:
case Statement.CLOSE_ALL_RESULTS:
checkClosed();
closeOldResultSet();
break;
case Statement.KEEP_CURRENT_RESULT:
// nothing to do
break;
default:
throw DbException.getInvalidValueException("current", current);
}
return false;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("executeUpdate("+quote(sql)+", "+autoGeneratedKeys+");");
}
return executeUpdateInternal(sql);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("executeUpdate("+quote(sql)+", "+quoteIntArray(columnIndexes)+");");
}
return executeUpdateInternal(sql);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("executeUpdate("+quote(sql)+", "+quoteArray(columnNames)+");");
}
return executeUpdateInternal(sql);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("execute("+quote(sql)+", "+autoGeneratedKeys+");");
}
return executeInternal(sql);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("execute("+quote(sql)+", "+quoteIntArray(columnIndexes)+");");
}
return executeInternal(sql);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public boolean execute(String sql, String[] columnNames) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("execute("+quote(sql)+", "+quoteArray(columnNames)+");");
}
return executeInternal(sql);
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public int getResultSetHoldability() throws SQLException {
try {
debugCodeCall("getResultSetHoldability");
checkClosed();
return ResultSet.HOLD_CURSORS_OVER_COMMIT;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
protected void closeOldResultSet() throws SQLException {
try {
if (!closedByResultSet) {
if (resultSet != null) {
resultSet.closeInternal();
}
}
} finally {
resultSet = null;
updateCount = -1;
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public boolean isClosed() throws SQLException {
try {
debugCodeCall("isClosed");
return conn == null;
} catch (Exception e) {
throw logAndConvert(e);
}
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public <T> T unwrap(Class<T> iface) throws SQLException {
throw unsupported("unwrap");
}
// in src/main/org/h2/jdbc/JdbcStatement.java
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw unsupported("isWrapperFor");
}
// in src/main/org/h2/bnf/Bnf.java
public static Bnf getInstance(Reader csv) throws SQLException, IOException {
Bnf bnf = new Bnf();
if (csv == null) {
byte[] data = Utils.getResource("/org/h2/res/help.csv");
csv = new InputStreamReader(new ByteArrayInputStream(data));
}
bnf.parse(csv);
return bnf;
}
// in src/main/org/h2/bnf/Bnf.java
private void parse(Reader reader) throws SQLException, IOException {
Rule functions = null;
statements = New.arrayList();
Csv csv = new Csv();
csv.setLineCommentCharacter('#');
ResultSet rs = csv.read(reader, null);
while (rs.next()) {
String section = rs.getString("SECTION").trim();
if (section.startsWith("System")) {
continue;
}
String topic = rs.getString("TOPIC");
syntax = rs.getString("SYNTAX").trim();
currentTopic = section;
tokens = tokenize();
index = 0;
Rule rule = parseRule();
if (section.startsWith("Command")) {
rule = new RuleList(rule, new RuleElement(";\n\n", currentTopic), false);
}
RuleHead head = addRule(topic, section, rule);
if (section.startsWith("Function")) {
if (functions == null) {
functions = rule;
} else {
functions = new RuleList(rule, functions, true);
}
} else if (section.startsWith("Commands")) {
statements.add(head);
}
}
addRule("@func@", "Function", functions);
addFixedRule("@ymd@", RuleFixed.YMD);
addFixedRule("@hms@", RuleFixed.HMS);
addFixedRule("@nanos@", RuleFixed.NANOS);
addFixedRule("anything_except_single_quote", RuleFixed.ANY_EXCEPT_SINGLE_QUOTE);
addFixedRule("anything_except_double_quote", RuleFixed.ANY_EXCEPT_DOUBLE_QUOTE);
addFixedRule("anything_until_end_of_line", RuleFixed.ANY_UNTIL_EOL);
addFixedRule("anything_until_end_comment", RuleFixed.ANY_UNTIL_END);
addFixedRule("anything_except_two_dollar_signs", RuleFixed.ANY_EXCEPT_2_DOLLAR);
addFixedRule("anything", RuleFixed.ANY_WORD);
addFixedRule("@hex_start@", RuleFixed.HEX_START);
addFixedRule("@concat@", RuleFixed.CONCAT);
addFixedRule("@az_@", RuleFixed.AZ_UNDERSCORE);
addFixedRule("@af@", RuleFixed.AF);
addFixedRule("@digit@", RuleFixed.DIGIT);
addFixedRule("@open_bracket@", RuleFixed.OPEN_BRACKET);
addFixedRule("@close_bracket@", RuleFixed.CLOSE_BRACKET);
}
// in src/main/org/h2/util/JdbcUtils.java
public static Connection getConnection(String driver, String url, String user, String password) throws SQLException {
Properties prop = new Properties();
if (user != null) {
prop.setProperty("user", user);
}
if (password != null) {
prop.setProperty("password", password);
}
return getConnection(driver, url, prop);
}
// in src/main/org/h2/util/JdbcUtils.java
public static Connection getConnection(String driver, String url, Properties prop) throws SQLException {
if (StringUtils.isNullOrEmpty(driver)) {
JdbcUtils.load(url);
} else {
Class<?> d = Utils.loadUserClass(driver);
if (java.sql.Driver.class.isAssignableFrom(d)) {
return DriverManager.getConnection(url, prop);
} else if (javax.naming.Context.class.isAssignableFrom(d)) {
// JNDI context
try {
Context context = (Context) d.newInstance();
DataSource ds = (DataSource) context.lookup(url);
String user = prop.getProperty("user");
String password = prop.getProperty("password");
if (StringUtils.isNullOrEmpty(user) && StringUtils.isNullOrEmpty(password)) {
return ds.getConnection();
}
return ds.getConnection(user, password);
} catch (Exception e) {
throw DbException.toSQLException(e);
}
} else {
// don't know, but maybe it loaded a JDBC Driver
return DriverManager.getConnection(url, prop);
}
}
return DriverManager.getConnection(url, prop);
}
// in src/main/org/h2/util/Tool.java
protected SQLException showUsageAndThrowUnsupportedOption(String option) throws SQLException {
showUsage();
throw throwUnsupportedOption(option);
}
// in src/main/org/h2/util/Tool.java
protected SQLException throwUnsupportedOption(String option) throws SQLException {
throw DbException.get(ErrorCode.FEATURE_NOT_SUPPORTED_1, option).getSQLException();
}
// in src/main/org/h2/server/TcpServer.java
private void initManagementDb() throws SQLException {
Properties prop = new Properties();
prop.setProperty("user", "");
prop.setProperty("password", managementPassword);
// avoid using the driver manager
Connection conn = Driver.load().connect("jdbc:h2:" + getManagementDbName(port), prop);
managementDb = conn;
Statement stat = null;
try {
stat = conn.createStatement();
stat.execute("CREATE ALIAS IF NOT EXISTS STOP_SERVER FOR \"" + TcpServer.class.getName() + ".stopServer\"");
stat.execute("CREATE TABLE IF NOT EXISTS SESSIONS(ID INT PRIMARY KEY, URL VARCHAR, USER VARCHAR, CONNECTED TIMESTAMP)");
managementDbAdd = conn.prepareStatement("INSERT INTO SESSIONS VALUES(?, ?, ?, NOW())");
managementDbRemove = conn.prepareStatement("DELETE FROM SESSIONS WHERE ID=?");
} finally {
JdbcUtils.closeSilently(stat);
}
SERVERS.put(port, this);
}
// in src/main/org/h2/server/TcpServer.java
public synchronized void start() throws SQLException {
stop = false;
try {
serverSocket = NetUtils.createServerSocket(port, ssl);
} catch (DbException e) {
if (!portIsSet) {
serverSocket = NetUtils.createServerSocket(0, ssl);
} else {
throw e;
}
}
port = serverSocket.getLocalPort();
initManagementDb();
}
// in src/main/org/h2/server/TcpServer.java
public static synchronized void shutdown(String url, String password, boolean force, boolean all) throws SQLException {
try {
int port = Constants.DEFAULT_TCP_PORT;
int idx = url.lastIndexOf(':');
if (idx >= 0) {
String p = url.substring(idx + 1);
if (StringUtils.isNumber(p)) {
port = Integer.decode(p);
}
}
String db = getManagementDbName(port);
try {
org.h2.Driver.load();
} catch (Throwable e) {
throw DbException.convert(e);
}
for (int i = 0; i < 2; i++) {
Connection conn = null;
PreparedStatement prep = null;
try {
conn = DriverManager.getConnection("jdbc:h2:" + url + "/" + db, "", password);
prep = conn.prepareStatement("CALL STOP_SERVER(?, ?, ?)");
prep.setInt(1, all ? 0 : port);
prep.setString(2, password);
prep.setInt(3, force ? SHUTDOWN_FORCE : SHUTDOWN_NORMAL);
try {
prep.execute();
} catch (SQLException e) {
if (force) {
// ignore
} else {
if (e.getErrorCode() != ErrorCode.CONNECTION_BROKEN_1) {
throw e;
}
}
}
break;
} catch (SQLException e) {
if (i == 1) {
throw e;
}
} finally {
JdbcUtils.closeSilently(prep);
JdbcUtils.closeSilently(conn);
}
}
} catch (Exception e) {
throw DbException.toSQLException(e);
}
}
// in src/main/org/h2/server/pg/PgServer.java
public static String getIndexColumn(Connection conn, int indexId, Integer ordinalPosition, Boolean pretty)
throws SQLException {
if (ordinalPosition == null || ordinalPosition.intValue() == 0) {
PreparedStatement prep = conn.prepareStatement("select sql from information_schema.indexes where id=?");
prep.setInt(1, indexId);
ResultSet rs = prep.executeQuery();
if (rs.next()) {
return rs.getString(1);
}
return "";
}
PreparedStatement prep = conn.prepareStatement(
"select column_name from information_schema.indexes where id=? and ordinal_position=?");
prep.setInt(1, indexId);
prep.setInt(2, ordinalPosition.intValue());
ResultSet rs = prep.executeQuery();
if (rs.next()) {
return rs.getString(1);
}
return "";
}
// in src/main/org/h2/server/pg/PgServer.java
public static String getCurrentSchema(Connection conn) throws SQLException {
ResultSet rs = conn.createStatement().executeQuery("call schema()");
rs.next();
return rs.getString(1);
}
// in src/main/org/h2/server/pg/PgServer.java
public static int getOid(Connection conn, String tableName) throws SQLException {
if (tableName.startsWith("\"") && tableName.endsWith("\"")) {
tableName = tableName.substring(1, tableName.length() - 1);
}
PreparedStatement prep = conn.prepareStatement("select oid from pg_class where relName = ?");
prep.setString(1, tableName);
ResultSet rs = prep.executeQuery();
if (!rs.next()) {
return 0;
}
return rs.getInt(1);
}
// in src/main/org/h2/server/pg/PgServer.java
public static String getUserById(Connection conn, int id) throws SQLException {
PreparedStatement prep = conn.prepareStatement("SELECT NAME FROM INFORMATION_SCHEMA.USERS WHERE ID=?");
prep.setInt(1, id);
ResultSet rs = prep.executeQuery();
if (rs.next()) {
return rs.getString(1);
}
return null;
}
// in src/main/org/h2/server/pg/PgServerThread.java
private void setParameter(PreparedStatement prep, int i, byte[] d2, int[] formatCodes) throws SQLException {
boolean text = (i >= formatCodes.length) || (formatCodes[i] == 0);
String s;
try {
if (text) {
s = new String(d2, getEncoding());
} else {
server.trace("Binary format not supported");
s = new String(d2, getEncoding());
}
} catch (Exception e) {
server.traceError(e);
s = null;
}
// if(server.getLog()) {
// server.log(" " + i + ": " + s);
// }
prep.setString(i + 1, s);
}
// in src/main/org/h2/server/pg/PgServerThread.java
private void initDb() throws SQLException {
Statement stat = null;
ResultSet rs = null;
try {
synchronized (server) {
// better would be: set the database to exclusive mode
rs = conn.getMetaData().getTables(null, "PG_CATALOG", "PG_VERSION", null);
boolean tableFound = rs.next();
stat = conn.createStatement();
if (!tableFound) {
installPgCatalog(stat);
}
rs = stat.executeQuery("SELECT * FROM PG_CATALOG.PG_VERSION");
if (!rs.next() || rs.getInt(1) < 2) {
// installation incomplete, or old version
installPgCatalog(stat);
} else {
// version 2 or newer: check the read version
int versionRead = rs.getInt(2);
if (versionRead > 2) {
throw DbException.throwInternalError("Incompatible PG_VERSION");
}
}
}
stat.execute("set search_path = PUBLIC, pg_catalog");
HashSet<Integer> typeSet = server.getTypeSet();
if (typeSet.size() == 0) {
rs = stat.executeQuery("SELECT OID FROM PG_CATALOG.PG_TYPE");
while (rs.next()) {
typeSet.add(rs.getInt(1));
}
}
} finally {
JdbcUtils.closeSilently(stat);
JdbcUtils.closeSilently(rs);
}
}
// in src/main/org/h2/server/pg/PgServerThread.java
private static void installPgCatalog(Statement stat) throws SQLException {
Reader r = null;
try {
r = new InputStreamReader(new ByteArrayInputStream(Utils
.getResource("/org/h2/server/pg/pg_catalog.sql")));
ScriptReader reader = new ScriptReader(r);
while (true) {
String sql = reader.readStatement();
if (sql == null) {
break;
}
stat.execute(sql);
}
reader.close();
} catch (IOException e) {
throw DbException.convertIOException(e, "Can not read pg_catalog resource");
} finally {
IOUtils.closeSilently(r);
}
}
// in src/main/org/h2/server/web/DbSchema.java
void readTables(DatabaseMetaData meta, String[] tableTypes) throws SQLException {
ResultSet rs = meta.getTables(null, name, null, tableTypes);
ArrayList<DbTableOrView> list = New.arrayList();
while (rs.next()) {
DbTableOrView table = new DbTableOrView(this, rs);
if (contents.isOracle && table.name.indexOf('$') > 0) {
continue;
}
list.add(table);
}
rs.close();
tables = new DbTableOrView[list.size()];
list.toArray(tables);
if (tables.length < MAX_TABLES_LIST_COLUMNS) {
for (DbTableOrView tab : tables) {
tab.readColumns(meta);
}
}
}
// in src/main/org/h2/server/web/DbContents.java
synchronized void readContents(DatabaseMetaData meta) throws SQLException {
String prod = StringUtils.toLowerEnglish(meta.getDatabaseProductName());
isSQLite = prod.indexOf("sqlite") >= 0;
String url = meta.getURL();
if (url != null) {
isH2 = url.startsWith("jdbc:h2:");
if (isH2) {
Statement stat = meta.getConnection().createStatement();
ResultSet rs = stat.executeQuery(
"SELECT UPPER(VALUE) FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME='MODE'");
rs.next();
if ("MYSQL".equals(rs.getString(1))) {
isH2ModeMySQL = true;
}
rs.close();
stat.close();
}
isOracle = url.startsWith("jdbc:oracle:");
isPostgreSQL = url.startsWith("jdbc:postgresql:");
// isHSQLDB = url.startsWith("jdbc:hsqldb:");
isMySQL = url.startsWith("jdbc:mysql:");
isDerby = url.startsWith("jdbc:derby:");
isFirebird = url.startsWith("jdbc:firebirdsql:");
isMSSQLServer = url.startsWith("jdbc:sqlserver:");
}
storedUpperCaseIdentifiers = meta.storesUpperCaseIdentifiers();
String defaultSchemaName = getDefaultSchemaName(meta);
String[] schemaNames = getSchemaNames(meta);
schemas = new DbSchema[schemaNames.length];
for (int i = 0; i < schemaNames.length; i++) {
String schemaName = schemaNames[i];
boolean isDefault = defaultSchemaName == null || defaultSchemaName.equals(schemaName);
DbSchema schema = new DbSchema(this, schemaName, isDefault);
if (schema.isDefault) {
defaultSchema = schema;
}
schemas[i] = schema;
String[] tableTypes = { "TABLE", "SYSTEM TABLE", "VIEW", "SYSTEM VIEW",
"TABLE LINK", "SYNONYM" };
schema.readTables(meta, tableTypes);
}
if (defaultSchema == null) {
String best = null;
for (DbSchema schema : schemas) {
if ("dbo".equals(schema.name)) {
// MS SQL Server
defaultSchema = schema;
break;
}
if (defaultSchema == null || best == null || schema.name.length() < best.length()) {
best = schema.name;
defaultSchema = schema;
}
}
}
}
// in src/main/org/h2/server/web/DbContents.java
private String[] getSchemaNames(DatabaseMetaData meta) throws SQLException {
if (isMySQL || isSQLite) {
return new String[] { "" };
} else if (isFirebird) {
return new String[] { null };
}
ResultSet rs = meta.getSchemas();
ArrayList<String> schemaList = New.arrayList();
while (rs.next()) {
String schema = rs.getString(findColumn(rs, "TABLE_SCHEM", 1));
if (isOracle) {
for (String ignore : new String[] {
"CTXSYS", "DIP", "DBSNMP", "DMSYS", "EXFSYS", "FLOWS_020100", "FLOWS_FILES", "MDDATA", "MDSYS",
"MGMT_VIEW", "OLAPSYS", "ORDSYS", "ORDPLUGINS", "OUTLN", "SI_INFORMTN_SCHEMA", "SYS", "SYSMAN",
"SYSTEM", "TSMSYS", "WMSYS", "XDB"
}) {
if (ignore.equals(schema)) {
schema = null;
break;
}
}
} else if (isMSSQLServer) {
for (String ignore : new String[] {
"sys", "db_accessadmin", "db_backupoperator", "db_datareader", "db_datawriter", "db_ddladmin",
"db_denydatareader", "db_denydatawriter", "db_owner", "db_securityadmin"
}) {
if (ignore.equals(schema)) {
schema = null;
break;
}
}
}
if (schema == null) {
continue;
}
schemaList.add(schema);
}
rs.close();
String[] list = new String[schemaList.size()];
schemaList.toArray(list);
return list;
}
// in src/main/org/h2/server/web/WebApp.java
private static int addIndexes(boolean mainSchema, DatabaseMetaData meta,
String table, String schema, StringBuilder buff, int treeIndex)
throws SQLException {
ResultSet rs;
try {
rs = meta.getIndexInfo(null, schema, table, false, true);
} catch (SQLException e) {
// SQLite
return treeIndex;
}
HashMap<String, IndexInfo> indexMap = New.hashMap();
while (rs.next()) {
String name = rs.getString("INDEX_NAME");
IndexInfo info = indexMap.get(name);
if (info == null) {
int t = rs.getInt("TYPE");
String type;
if (t == DatabaseMetaData.tableIndexClustered) {
type = "";
} else if (t == DatabaseMetaData.tableIndexHashed) {
type = " (${text.tree.hashed})";
} else if (t == DatabaseMetaData.tableIndexOther) {
type = "";
} else {
type = null;
}
if (name != null && type != null) {
info = new IndexInfo();
info.name = name;
type = (rs.getBoolean("NON_UNIQUE") ? "${text.tree.nonUnique}" : "${text.tree.unique}") + type;
info.type = type;
info.columns = rs.getString("COLUMN_NAME");
indexMap.put(name, info);
}
} else {
info.columns += ", " + rs.getString("COLUMN_NAME");
}
}
rs.close();
if (indexMap.size() > 0) {
String level = mainSchema ? ", 1, 1" : ", 2, 1";
String levelIndex = mainSchema ? ", 2, 1" : ", 3, 1";
String levelColumnType = mainSchema ? ", 3, 2" : ", 4, 2";
buff.append("setNode(" + treeIndex + level + ", 'index_az', '${text.tree.indexes}', null);\n");
treeIndex++;
for (IndexInfo info : indexMap.values()) {
buff.append("setNode(" + treeIndex + levelIndex + ", 'index', '" + PageParser.escapeJavaScript(info.name)
+ "', null);\n");
treeIndex++;
buff.append("setNode(" + treeIndex + levelColumnType + ", 'type', '" + info.type + "', null);\n");
treeIndex++;
buff.append("setNode(" + treeIndex + levelColumnType + ", 'type', '" + PageParser.escapeJavaScript(info.columns)
+ "', null);\n");
treeIndex++;
}
}
return treeIndex;
}
// in src/main/org/h2/server/web/WebApp.java
private int addTablesAndViews(DbSchema schema, boolean mainSchema, StringBuilder buff, int treeIndex)
throws SQLException {
if (schema == null) {
return treeIndex;
}
Connection conn = session.getConnection();
DatabaseMetaData meta = session.getMetaData();
int level = mainSchema ? 0 : 1;
boolean showColumns = mainSchema || !schema.isSystem;
String indentation = ", " + level + ", " + (showColumns ? "1" : "2") + ", ";
String indentNode = ", " + (level + 1) + ", 2, ";
DbTableOrView[] tables = schema.tables;
if (tables == null) {
return treeIndex;
}
boolean isOracle = schema.contents.isOracle;
boolean notManyTables = tables.length < DbSchema.MAX_TABLES_LIST_INDEXES;
for (DbTableOrView table : tables) {
if (table.isView) {
continue;
}
int tableId = treeIndex;
String tab = table.quotedName;
if (!mainSchema) {
tab = schema.quotedName + "." + tab;
}
tab = escapeIdentifier(tab);
buff.append("setNode(" + treeIndex + indentation + " 'table', '" + PageParser.escapeJavaScript(table.name)
+ "', 'javascript:ins(\\'" + tab + "\\',true)');\n");
treeIndex++;
if (mainSchema || showColumns) {
StringBuilder columnsBuffer = new StringBuilder();
treeIndex = addColumns(mainSchema, table, buff, treeIndex, notManyTables, columnsBuffer);
if (!isOracle && notManyTables) {
treeIndex = addIndexes(mainSchema, meta, table.name, schema.name, buff, treeIndex);
}
buff.append("addTable('" + PageParser.escapeJavaScript(table.name) + "', '"
+ PageParser.escapeJavaScript(columnsBuffer.toString()) + "', " + tableId + ");\n");
}
}
tables = schema.tables;
for (DbTableOrView view : tables) {
if (!view.isView) {
continue;
}
int tableId = treeIndex;
String tab = view.quotedName;
if (!mainSchema) {
tab = view.schema.quotedName + "." + tab;
}
tab = escapeIdentifier(tab);
buff.append("setNode(" + treeIndex + indentation + " 'view', '" + PageParser.escapeJavaScript(view.name)
+ "', 'javascript:ins(\\'" + tab + "\\',true)');\n");
treeIndex++;
if (mainSchema) {
StringBuilder columnsBuffer = new StringBuilder();
treeIndex = addColumns(mainSchema, view, buff, treeIndex, notManyTables, columnsBuffer);
if (schema.contents.isH2) {
PreparedStatement prep = null;
try {
prep = conn.prepareStatement("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=?");
prep.setString(1, view.name);
ResultSet rs = prep.executeQuery();
if (rs.next()) {
String sql = rs.getString("SQL");
buff.append("setNode(" + treeIndex + indentNode + " 'type', '"
+ PageParser.escapeJavaScript(sql) + "', null);\n");
treeIndex++;
}
rs.close();
} finally {
JdbcUtils.closeSilently(prep);
}
}
buff.append("addTable('" + PageParser.escapeJavaScript(view.name) + "', '"
+ PageParser.escapeJavaScript(columnsBuffer.toString()) + "', " + tableId + ");\n");
}
}
return treeIndex;
}
// in src/main/org/h2/server/web/WebApp.java
private ResultSet getMetaResultSet(Connection conn, String sql) throws SQLException {
DatabaseMetaData meta = conn.getMetaData();
if (isBuiltIn(sql, "@best_row_identifier")) {
String[] p = split(sql);
int scale = p[4] == null ? 0 : Integer.parseInt(p[4]);
boolean nullable = p[5] == null ? false : Boolean.valueOf(p[5]).booleanValue();
return meta.getBestRowIdentifier(p[1], p[2], p[3], scale, nullable);
} else if (isBuiltIn(sql, "@catalogs")) {
return meta.getCatalogs();
} else if (isBuiltIn(sql, "@columns")) {
String[] p = split(sql);
return meta.getColumns(p[1], p[2], p[3], p[4]);
} else if (isBuiltIn(sql, "@column_privileges")) {
String[] p = split(sql);
return meta.getColumnPrivileges(p[1], p[2], p[3], p[4]);
} else if (isBuiltIn(sql, "@cross_references")) {
String[] p = split(sql);
return meta.getCrossReference(p[1], p[2], p[3], p[4], p[5], p[6]);
} else if (isBuiltIn(sql, "@exported_keys")) {
String[] p = split(sql);
return meta.getExportedKeys(p[1], p[2], p[3]);
} else if (isBuiltIn(sql, "@imported_keys")) {
String[] p = split(sql);
return meta.getImportedKeys(p[1], p[2], p[3]);
} else if (isBuiltIn(sql, "@index_info")) {
String[] p = split(sql);
boolean unique = p[4] == null ? false : Boolean.valueOf(p[4]).booleanValue();
boolean approx = p[5] == null ? false : Boolean.valueOf(p[5]).booleanValue();
return meta.getIndexInfo(p[1], p[2], p[3], unique, approx);
} else if (isBuiltIn(sql, "@primary_keys")) {
String[] p = split(sql);
return meta.getPrimaryKeys(p[1], p[2], p[3]);
} else if (isBuiltIn(sql, "@procedures")) {
String[] p = split(sql);
return meta.getProcedures(p[1], p[2], p[3]);
} else if (isBuiltIn(sql, "@procedure_columns")) {
String[] p = split(sql);
return meta.getProcedureColumns(p[1], p[2], p[3], p[4]);
} else if (isBuiltIn(sql, "@schemas")) {
return meta.getSchemas();
} else if (isBuiltIn(sql, "@tables")) {
String[] p = split(sql);
String[] types = p[4] == null ? null : StringUtils.arraySplit(p[4], ',', false);
return meta.getTables(p[1], p[2], p[3], types);
} else if (isBuiltIn(sql, "@table_privileges")) {
String[] p = split(sql);
return meta.getTablePrivileges(p[1], p[2], p[3]);
} else if (isBuiltIn(sql, "@table_types")) {
return meta.getTableTypes();
} else if (isBuiltIn(sql, "@type_info")) {
return meta.getTypeInfo();
} else if (isBuiltIn(sql, "@udts")) {
String[] p = split(sql);
int[] types;
if (p[4] == null) {
types = null;
} else {
String[] t = StringUtils.arraySplit(p[4], ',', false);
types = new int[t.length];
for (int i = 0; i < t.length; i++) {
types[i] = Integer.parseInt(t[i]);
}
}
return meta.getUDTs(p[1], p[2], p[3], types);
} else if (isBuiltIn(sql, "@version_columns")) {
String[] p = split(sql);
return meta.getVersionColumns(p[1], p[2], p[3]);
} else if (isBuiltIn(sql, "@memory")) {
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("Type", Types.VARCHAR, 0, 0);
rs.addColumn("KB", Types.VARCHAR, 0, 0);
rs.addRow("Used Memory", "" + Utils.getMemoryUsed());
rs.addRow("Free Memory", "" + Utils.getMemoryFree());
return rs;
} else if (isBuiltIn(sql, "@info")) {
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("KEY", Types.VARCHAR, 0, 0);
rs.addColumn("VALUE", Types.VARCHAR, 0, 0);
rs.addRow("conn.getCatalog", conn.getCatalog());
rs.addRow("conn.getAutoCommit", "" + conn.getAutoCommit());
rs.addRow("conn.getTransactionIsolation", "" + conn.getTransactionIsolation());
rs.addRow("conn.getWarnings", "" + conn.getWarnings());
String map;
try {
map = "" + conn.getTypeMap();
} catch (SQLException e) {
map = e.toString();
}
rs.addRow("conn.getTypeMap", "" + map);
rs.addRow("conn.isReadOnly", "" + conn.isReadOnly());
rs.addRow("conn.getHoldability", "" + conn.getHoldability());
addDatabaseMetaData(rs, meta);
return rs;
} else if (isBuiltIn(sql, "@attributes")) {
String[] p = split(sql);
return meta.getAttributes(p[1], p[2], p[3], p[4]);
} else if (isBuiltIn(sql, "@super_tables")) {
String[] p = split(sql);
return meta.getSuperTables(p[1], p[2], p[3]);
} else if (isBuiltIn(sql, "@super_types")) {
String[] p = split(sql);
return meta.getSuperTypes(p[1], p[2], p[3]);
} else if (isBuiltIn(sql, "@prof_stop")) {
if (profiler != null) {
profiler.stopCollecting();
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("Top Stack Trace(s)", Types.VARCHAR, 0, 0);
rs.addRow(profiler.getTop(3));
profiler = null;
return rs;
}
}
return null;
}
// in src/main/org/h2/server/web/WebApp.java
private String executeLoop(Connection conn, int count, String sql) throws SQLException {
ArrayList<Integer> params = New.arrayList();
int idx = 0;
while (!stop) {
idx = sql.indexOf('?', idx);
if (idx < 0) {
break;
}
if (isBuiltIn(sql.substring(idx), "?/*rnd*/")) {
params.add(1);
sql = sql.substring(0, idx) + "?" + sql.substring(idx + "/*rnd*/".length() + 1);
} else {
params.add(0);
}
idx++;
}
boolean prepared;
Random random = new Random(1);
long time = System.currentTimeMillis();
if (isBuiltIn(sql, "@statement")) {
sql = sql.substring("@statement".length()).trim();
prepared = false;
Statement stat = conn.createStatement();
for (int i = 0; !stop && i < count; i++) {
String s = sql;
for (Integer type : params) {
idx = s.indexOf('?');
if (type.intValue() == 1) {
s = s.substring(0, idx) + random.nextInt(count) + s.substring(idx + 1);
} else {
s = s.substring(0, idx) + i + s.substring(idx + 1);
}
}
if (stat.execute(s)) {
ResultSet rs = stat.getResultSet();
while (!stop && rs.next()) {
// maybe get the data as well
}
rs.close();
}
}
} else {
prepared = true;
PreparedStatement prep = conn.prepareStatement(sql);
for (int i = 0; !stop && i < count; i++) {
for (int j = 0; j < params.size(); j++) {
Integer type = params.get(j);
if (type.intValue() == 1) {
prep.setInt(j + 1, random.nextInt(count));
} else {
prep.setInt(j + 1, i);
}
}
if (session.getContents().isSQLite) {
// SQLite currently throws an exception on prep.execute()
prep.executeUpdate();
} else {
if (prep.execute()) {
ResultSet rs = prep.getResultSet();
while (!stop && rs.next()) {
// maybe get the data as well
}
rs.close();
}
}
}
}
time = System.currentTimeMillis() - time;
StatementBuilder buff = new StatementBuilder();
buff.append(time).append(" ms: ").append(count).append(" * ");
if (prepared) {
buff.append("(Prepared) ");
} else {
buff.append("(Statement) ");
}
buff.append('(');
for (int p : params) {
buff.appendExceptFirst(", ");
buff.append(p == 0 ? "i" : "rnd");
}
return buff.append(") ").append(sql).toString();
}
// in src/main/org/h2/server/web/WebApp.java
private static String getParameterResultSet(ParameterMetaData meta) throws SQLException {
StringBuilder buff = new StringBuilder();
if (meta == null) {
return "No parameter meta data";
}
buff.append("<table cellspacing=0 cellpadding=0>").
append("<tr><th>className</th><th>mode</th><th>type</th>").
append("<th>typeName</th><th>precision</th><th>scale</th></tr>");
for (int i = 0; i < meta.getParameterCount(); i++) {
buff.append("</tr><td>").
append(meta.getParameterClassName(i + 1)).
append("</td><td>").
append(meta.getParameterMode(i + 1)).
append("</td><td>").
append(meta.getParameterType(i + 1)).
append("</td><td>").
append(meta.getParameterTypeName(i + 1)).
append("</td><td>").
append(meta.getPrecision(i + 1)).
append("</td><td>").
append(meta.getScale(i + 1)).
append("</td></tr>");
}
buff.append("</table>");
return buff.toString();
}
// in src/main/org/h2/server/web/WebApp.java
private String getResultSet(String sql, ResultSet rs, boolean metadata, boolean list, boolean edit, long time,
boolean allowEdit) throws SQLException {
int maxrows = getMaxrows();
time = System.currentTimeMillis() - time;
StringBuilder buff = new StringBuilder();
if (edit) {
buff.append("<form id=\"editing\" name=\"editing\" method=\"post\" " +
"action=\"editResult.do?jsessionid=${sessionId}\" id=\"mainForm\" target=\"h2result\">" +
"<input type=\"hidden\" name=\"op\" value=\"1\" />" +
"<input type=\"hidden\" name=\"row\" value=\"\" />" +
"<table cellspacing=0 cellpadding=0 id=\"editTable\">");
} else {
buff.append("<table cellspacing=0 cellpadding=0>");
}
if (metadata) {
SimpleResultSet r = new SimpleResultSet();
r.addColumn("#", Types.INTEGER, 0, 0);
r.addColumn("label", Types.VARCHAR, 0, 0);
r.addColumn("catalog", Types.VARCHAR, 0, 0);
r.addColumn("schema", Types.VARCHAR, 0, 0);
r.addColumn("table", Types.VARCHAR, 0, 0);
r.addColumn("column", Types.VARCHAR, 0, 0);
r.addColumn("type", Types.INTEGER, 0, 0);
r.addColumn("typeName", Types.VARCHAR, 0, 0);
r.addColumn("class", Types.VARCHAR, 0, 0);
r.addColumn("precision", Types.INTEGER, 0, 0);
r.addColumn("scale", Types.INTEGER, 0, 0);
r.addColumn("displaySize", Types.INTEGER, 0, 0);
r.addColumn("autoIncrement", Types.BOOLEAN, 0, 0);
r.addColumn("caseSensitive", Types.BOOLEAN, 0, 0);
r.addColumn("currency", Types.BOOLEAN, 0, 0);
r.addColumn("nullable", Types.INTEGER, 0, 0);
r.addColumn("readOnly", Types.BOOLEAN, 0, 0);
r.addColumn("searchable", Types.BOOLEAN, 0, 0);
r.addColumn("signed", Types.BOOLEAN, 0, 0);
r.addColumn("writable", Types.BOOLEAN, 0, 0);
r.addColumn("definitelyWritable", Types.BOOLEAN, 0, 0);
ResultSetMetaData m = rs.getMetaData();
for (int i = 1; i <= m.getColumnCount(); i++) {
r.addRow(i,
m.getColumnLabel(i),
m.getCatalogName(i),
m.getSchemaName(i),
m.getTableName(i),
m.getColumnName(i),
m.getColumnType(i),
m.getColumnTypeName(i),
m.getColumnClassName(i),
m.getPrecision(i),
m.getScale(i),
m.getColumnDisplaySize(i),
m.isAutoIncrement(i),
m.isCaseSensitive(i),
m.isCurrency(i),
m.isNullable(i),
m.isReadOnly(i),
m.isSearchable(i),
m.isSigned(i),
m.isWritable(i),
m.isDefinitelyWritable(i));
}
rs = r;
}
ResultSetMetaData meta = rs.getMetaData();
int columns = meta.getColumnCount();
int rows = 0;
if (list) {
buff.append("<tr><th>Column</th><th>Data</th></tr><tr>");
while (rs.next()) {
if (maxrows > 0 && rows >= maxrows) {
break;
}
rows++;
buff.append("<tr><td>Row #</td><td>").
append(rows).append("</tr>");
for (int i = 0; i < columns; i++) {
buff.append("<tr><td>").
append(PageParser.escapeHtml(meta.getColumnLabel(i + 1))).
append("</td><td>").
append(escapeData(rs, i + 1)).
append("</td></tr>");
}
}
} else {
buff.append("<tr>");
if (edit) {
buff.append("<th>${text.resultEdit.action}</th>");
}
for (int i = 0; i < columns; i++) {
buff.append("<th>").
append(PageParser.escapeHtml(meta.getColumnLabel(i + 1))).
append("</th>");
}
buff.append("</tr>");
while (rs.next()) {
if (maxrows > 0 && rows >= maxrows) {
break;
}
rows++;
buff.append("<tr>");
if (edit) {
buff.append("<td>").
append("<img onclick=\"javascript:editRow(").
append(rs.getRow()).
append(",'${sessionId}', '${text.resultEdit.save}', '${text.resultEdit.cancel}'").
append(")\" width=16 height=16 src=\"ico_write.gif\" " +
"onmouseover = \"this.className ='icon_hover'\" " +
"onmouseout = \"this.className ='icon'\" " +
"class=\"icon\" alt=\"${text.resultEdit.edit}\" " +
"title=\"${text.resultEdit.edit}\" border=\"1\"/>").
append("<a href=\"editResult.do?op=2&row=").
append(rs.getRow()).
append("&jsessionid=${sessionId}\" target=\"h2result\" >" +
"<img width=16 height=16 src=\"ico_remove.gif\" " +
"onmouseover = \"this.className ='icon_hover'\" " +
"onmouseout = \"this.className ='icon'\" " +
"class=\"icon\" alt=\"${text.resultEdit.delete}\" " +
"title=\"${text.resultEdit.delete}\" border=\"1\" /></a>").
append("</td>");
}
for (int i = 0; i < columns; i++) {
buff.append("<td>").
append(escapeData(rs, i + 1)).
append("</td>");
}
buff.append("</tr>");
}
}
boolean isUpdatable = false;
try {
isUpdatable = rs.getConcurrency() == ResultSet.CONCUR_UPDATABLE
&& rs.getType() != ResultSet.TYPE_FORWARD_ONLY;
} catch (NullPointerException e) {
// ignore
// workaround for a JDBC-ODBC bridge problem
}
if (edit) {
ResultSet old = session.result;
if (old != null) {
old.close();
}
session.result = rs;
} else {
rs.close();
}
if (edit) {
buff.append("<tr><td>").
append("<img onclick=\"javascript:editRow(-1, '${sessionId}', '${text.resultEdit.save}', '${text.resultEdit.cancel}'").
append(")\" width=16 height=16 src=\"ico_add.gif\" " +
"onmouseover = \"this.className ='icon_hover'\" " +
"onmouseout = \"this.className ='icon'\" " +
"class=\"icon\" alt=\"${text.resultEdit.add}\" " +
"title=\"${text.resultEdit.add}\" border=\"1\"/>").
append("</td>");
for (int i = 0; i < columns; i++) {
buff.append("<td></td>");
}
buff.append("</tr>");
}
buff.append("</table>");
if (edit) {
buff.append("</form>");
}
if (rows == 0) {
buff.append("(${text.result.noRows}");
} else if (rows == 1) {
buff.append("(${text.result.1row}");
} else {
buff.append('(').append(rows).append(" ${text.result.rows}");
}
buff.append(", ");
time = System.currentTimeMillis() - time;
buff.append(time).append(" ms)");
if (!edit && isUpdatable && allowEdit) {
buff.append("<br /><br />" +
"<form name=\"editResult\" method=\"post\" " +
"action=\"query.do?jsessionid=${sessionId}\" target=\"h2result\">" +
"<input type=\"submit\" class=\"button\" value=\"${text.resultEdit.editResult}\" />" +
"<input type=\"hidden\" name=\"sql\" value=\"@edit ").
append(PageParser.escapeHtmlData(sql)).
append("\" /></form>");
}
return buff.toString();
}
// in src/main/org/h2/server/web/WebApp.java
private static String escapeData(ResultSet rs, int columnIndex) throws SQLException {
String d = rs.getString(columnIndex);
if (d == null) {
return "<i>null</i>";
} else if (d.length() > 100000) {
String s;
if (isBinary(rs.getMetaData().getColumnType(columnIndex))) {
s = PageParser.escapeHtml(d.substring(0, 6)) + "... (" + (d.length() / 2) + " ${text.result.bytes})";
} else {
s = PageParser.escapeHtml(d.substring(0, 100)) + "... (" + d.length() + " ${text.result.characters})";
}
return "<div style='display: none'>=+</div>" + s;
} else if (d.equals("null") || d.startsWith("= ") || d.startsWith("=+")) {
return "<div style='display: none'>= </div>" + PageParser.escapeHtml(d);
} else if (d.equals("")) {
// PageParser.escapeHtml replaces "" with a non-breaking space
return "";
}
return PageParser.escapeHtml(d);
}
// in src/main/org/h2/server/web/WebApp.java
private void unescapeData(String x, ResultSet rs, int columnIndex) throws SQLException {
if (x.equals("null")) {
rs.updateNull(columnIndex);
return;
} else if (x.startsWith("=+")) {
// don't update
return;
} else if (x.equals("=*")) {
// set an appropriate default value
int type = rs.getMetaData().getColumnType(columnIndex);
switch (type) {
case Types.TIME:
rs.updateString(columnIndex, "12:00:00");
break;
case Types.TIMESTAMP:
case Types.DATE:
rs.updateString(columnIndex, "2001-01-01");
break;
default:
rs.updateString(columnIndex, "1");
break;
}
return;
} else if (x.startsWith("= ")) {
x = x.substring(2);
}
ResultSetMetaData meta = rs.getMetaData();
int type = meta.getColumnType(columnIndex);
if (session.getContents().isH2) {
rs.updateString(columnIndex, x);
return;
}
switch (type) {
case Types.BIGINT:
rs.updateLong(columnIndex, Long.decode(x));
break;
case Types.DECIMAL:
rs.updateBigDecimal(columnIndex, new BigDecimal(x));
break;
case Types.DOUBLE:
case Types.FLOAT:
rs.updateDouble(columnIndex, Double.parseDouble(x));
break;
case Types.REAL:
rs.updateFloat(columnIndex, Float.parseFloat(x));
break;
case Types.INTEGER:
rs.updateInt(columnIndex, Integer.decode(x));
break;
case Types.TINYINT:
rs.updateShort(columnIndex, Short.decode(x));
break;
default:
rs.updateString(columnIndex, x);
}
}
// in src/main/org/h2/server/web/DbTableOrView.java
void readColumns(DatabaseMetaData meta) throws SQLException {
ResultSet rs = meta.getColumns(null, schema.name, name, null);
ArrayList<DbColumn> list = New.arrayList();
while (rs.next()) {
DbColumn column = new DbColumn(schema.contents, rs);
list.add(column);
}
rs.close();
columns = new DbColumn[list.size()];
list.toArray(columns);
}
// in src/main/org/h2/server/web/WebServer.java
Connection getConnection(String driver, String databaseUrl, String user, String password) throws SQLException {
driver = driver.trim();
databaseUrl = databaseUrl.trim();
org.h2.Driver.load();
Properties p = new Properties();
p.setProperty("user", user.trim());
// do not trim the password, otherwise an
// encrypted H2 database with empty user password doesn't work
p.setProperty("password", password);
if (databaseUrl.startsWith("jdbc:h2:")) {
if (ifExists) {
databaseUrl += ";IFEXISTS=TRUE";
}
// PostgreSQL would throw a NullPointerException
// if it is loaded before the H2 driver
// because it can't deal with non-String objects in the connection Properties
return org.h2.Driver.load().connect(databaseUrl, p);
}
// try {
// Driver dr = (Driver) urlClassLoader.
// loadClass(driver).newInstance();
// return dr.connect(url, p);
// } catch(ClassNotFoundException e2) {
// throw e2;
// }
return JdbcUtils.getConnection(driver, databaseUrl, p);
}
// in src/main/org/h2/server/web/WebServer.java
public String addSession(Connection conn) throws SQLException {
WebSession session = createNewSession("local");
session.setShutdownServerOnDisconnect();
session.setConnection(conn);
session.put("url", conn.getMetaData().getURL());
String s = (String) session.get("sessionId");
return url + "/frame.jsp?jsessionid=" + s;
}
// in src/main/org/h2/server/web/WebSession.java
void setConnection(Connection conn) throws SQLException {
this.conn = conn;
if (conn == null) {
meta = null;
} else {
meta = conn.getMetaData();
}
contents = new DbContents();
}
// in src/main/org/h2/table/TableLink.java
private void readMetaData() throws SQLException {
DatabaseMetaData meta = conn.getConnection().getMetaData();
storesLowerCase = meta.storesLowerCaseIdentifiers();
storesMixedCase = meta.storesMixedCaseIdentifiers();
storesMixedCaseQuoted = meta.storesMixedCaseQuotedIdentifiers();
supportsMixedCaseIdentifiers = meta.supportsMixedCaseIdentifiers();
ResultSet rs = meta.getTables(null, originalSchema, originalTable, null);
if (rs.next() && rs.next()) {
throw DbException.get(ErrorCode.SCHEMA_NAME_MUST_MATCH, originalTable);
}
rs.close();
rs = meta.getColumns(null, originalSchema, originalTable, null);
int i = 0;
ArrayList<Column> columnList = New.arrayList();
HashMap<String, Column> columnMap = New.hashMap();
String catalog = null, schema = null;
while (rs.next()) {
String thisCatalog = rs.getString("TABLE_CAT");
if (catalog == null) {
catalog = thisCatalog;
}
String thisSchema = rs.getString("TABLE_SCHEM");
if (schema == null) {
schema = thisSchema;
}
if (!StringUtils.equals(catalog, thisCatalog) || !StringUtils.equals(schema, thisSchema)) {
// if the table exists in multiple schemas or tables,
// use the alternative solution
columnMap.clear();
columnList.clear();
break;
}
String n = rs.getString("COLUMN_NAME");
n = convertColumnName(n);
int sqlType = rs.getInt("DATA_TYPE");
long precision = rs.getInt("COLUMN_SIZE");
precision = convertPrecision(sqlType, precision);
int scale = rs.getInt("DECIMAL_DIGITS");
scale = convertScale(sqlType, scale);
int displaySize = MathUtils.convertLongToInt(precision);
int type = DataType.convertSQLTypeToValueType(sqlType);
Column col = new Column(n, type, precision, scale, displaySize);
col.setTable(this, i++);
columnList.add(col);
columnMap.put(n, col);
}
rs.close();
if (originalTable.indexOf('.') < 0 && !StringUtils.isNullOrEmpty(schema)) {
qualifiedTableName = schema + "." + originalTable;
} else {
qualifiedTableName = originalTable;
}
// check if the table is accessible
Statement stat = null;
try {
stat = conn.getConnection().createStatement();
rs = stat.executeQuery("SELECT * FROM " + qualifiedTableName + " T WHERE 1=0");
if (columnList.size() == 0) {
// alternative solution
ResultSetMetaData rsMeta = rs.getMetaData();
for (i = 0; i < rsMeta.getColumnCount();) {
String n = rsMeta.getColumnName(i + 1);
n = convertColumnName(n);
int sqlType = rsMeta.getColumnType(i + 1);
long precision = rsMeta.getPrecision(i + 1);
precision = convertPrecision(sqlType, precision);
int scale = rsMeta.getScale(i + 1);
scale = convertScale(sqlType, scale);
int displaySize = rsMeta.getColumnDisplaySize(i + 1);
int type = DataType.convertSQLTypeToValueType(sqlType);
Column col = new Column(n, type, precision, scale, displaySize);
col.setTable(this, i++);
columnList.add(col);
columnMap.put(n, col);
}
}
rs.close();
} catch (Exception e) {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, e,
originalTable + "(" + e.toString() + ")");
} finally {
JdbcUtils.closeSilently(stat);
}
Column[] cols = new Column[columnList.size()];
columnList.toArray(cols);
setColumns(cols);
int id = getId();
linkedIndex = new LinkedIndex(this, id, IndexColumn.wrap(cols), IndexType.createNonUnique(false));
indexes.add(linkedIndex);
try {
rs = meta.getPrimaryKeys(null, originalSchema, originalTable);
} catch (Exception e) {
// Some ODBC bridge drivers don't support it:
// some combinations of "DataDirect SequeLink(R) for JDBC"
// http://www.datadirect.com/index.ssp
rs = null;
}
String pkName = "";
ArrayList<Column> list;
if (rs != null && rs.next()) {
// the problem is, the rows are not sorted by KEY_SEQ
list = New.arrayList();
do {
int idx = rs.getInt("KEY_SEQ");
if (pkName == null) {
pkName = rs.getString("PK_NAME");
}
while (list.size() < idx) {
list.add(null);
}
String col = rs.getString("COLUMN_NAME");
col = convertColumnName(col);
Column column = columnMap.get(col);
if (idx == 0) {
// workaround for a bug in the SQLite JDBC driver
list.add(column);
} else {
list.set(idx - 1, column);
}
} while (rs.next());
addIndex(list, IndexType.createPrimaryKey(false, false));
rs.close();
}
try {
rs = meta.getIndexInfo(null, originalSchema, originalTable, false, true);
} catch (Exception e) {
// Oracle throws an exception if the table is not found or is a
// SYNONYM
rs = null;
}
String indexName = null;
list = New.arrayList();
IndexType indexType = null;
if (rs != null) {
while (rs.next()) {
if (rs.getShort("TYPE") == DatabaseMetaData.tableIndexStatistic) {
// ignore index statistics
continue;
}
String newIndex = rs.getString("INDEX_NAME");
if (pkName.equals(newIndex)) {
continue;
}
if (indexName != null && !indexName.equals(newIndex)) {
addIndex(list, indexType);
indexName = null;
}
if (indexName == null) {
indexName = newIndex;
list.clear();
}
boolean unique = !rs.getBoolean("NON_UNIQUE");
indexType = unique ? IndexType.createUnique(false, false) : IndexType.createNonUnique(false);
String col = rs.getString("COLUMN_NAME");
col = convertColumnName(col);
Column column = columnMap.get(col);
list.add(column);
}
rs.close();
}
if (indexName != null) {
addIndex(list, indexType);
}
}
// in src/main/org/h2/fulltext/FullTextLucene.java
public static void init(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
stat.execute("CREATE SCHEMA IF NOT EXISTS " + SCHEMA);
stat.execute("CREATE TABLE IF NOT EXISTS " + SCHEMA
+ ".INDEXES(SCHEMA VARCHAR, TABLE VARCHAR, COLUMNS VARCHAR, PRIMARY KEY(SCHEMA, TABLE))");
stat.execute("CREATE ALIAS IF NOT EXISTS FTL_CREATE_INDEX FOR \"" + FullTextLucene.class.getName() + ".createIndex\"");
stat.execute("CREATE ALIAS IF NOT EXISTS FTL_SEARCH FOR \"" + FullTextLucene.class.getName() + ".search\"");
stat.execute("CREATE ALIAS IF NOT EXISTS FTL_SEARCH_DATA FOR \"" + FullTextLucene.class.getName() + ".searchData\"");
stat.execute("CREATE ALIAS IF NOT EXISTS FTL_REINDEX FOR \"" + FullTextLucene.class.getName() + ".reindex\"");
stat.execute("CREATE ALIAS IF NOT EXISTS FTL_DROP_ALL FOR \"" + FullTextLucene.class.getName() + ".dropAll\"");
try {
getIndexAccess(conn);
} catch (SQLException e) {
throw convertException(e);
}
}
// in src/main/org/h2/fulltext/FullTextLucene.java
public static void createIndex(Connection conn, String schema, String table, String columnList) throws SQLException {
init(conn);
PreparedStatement prep = conn.prepareStatement("INSERT INTO " + SCHEMA
+ ".INDEXES(SCHEMA, TABLE, COLUMNS) VALUES(?, ?, ?)");
prep.setString(1, schema);
prep.setString(2, table);
prep.setString(3, columnList);
prep.execute();
createTrigger(conn, schema, table);
indexExistingRows(conn, schema, table);
}
// in src/main/org/h2/fulltext/FullTextLucene.java
public static void reindex(Connection conn) throws SQLException {
init(conn);
removeAllTriggers(conn, TRIGGER_PREFIX);
removeIndexFiles(conn);
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT * FROM " + SCHEMA + ".INDEXES");
while (rs.next()) {
String schema = rs.getString("SCHEMA");
String table = rs.getString("TABLE");
createTrigger(conn, schema, table);
indexExistingRows(conn, schema, table);
}
}
// in src/main/org/h2/fulltext/FullTextLucene.java
public static void dropAll(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
stat.execute("DROP SCHEMA IF EXISTS " + SCHEMA);
removeAllTriggers(conn, TRIGGER_PREFIX);
removeIndexFiles(conn);
}
// in src/main/org/h2/fulltext/FullTextLucene.java
public static ResultSet search(Connection conn, String text, int limit, int offset) throws SQLException {
return search(conn, text, limit, offset, false);
}
// in src/main/org/h2/fulltext/FullTextLucene.java
public static ResultSet searchData(Connection conn, String text, int limit, int offset) throws SQLException {
return search(conn, text, limit, offset, true);
}
// in src/main/org/h2/fulltext/FullTextLucene.java
protected static void createTrigger(Connection conn, String schema, String table) throws SQLException {
Statement stat = conn.createStatement();
String trigger = StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(TRIGGER_PREFIX + table);
stat.execute("DROP TRIGGER IF EXISTS " + trigger);
StringBuilder buff = new StringBuilder("CREATE TRIGGER IF NOT EXISTS ");
// the trigger is also called on rollback because transaction rollback
// will not undo the changes in the Lucene index
buff.append(trigger).
append(" AFTER INSERT, UPDATE, DELETE, ROLLBACK ON ").
append(StringUtils.quoteIdentifier(schema)).
append('.').
append(StringUtils.quoteIdentifier(table)).
append(" FOR EACH ROW CALL \"").
append(FullTextLucene.FullTextTrigger.class.getName()).
append('\"');
stat.execute(buff.toString());
}
// in src/main/org/h2/fulltext/FullTextLucene.java
protected static IndexAccess getIndexAccess(Connection conn) throws SQLException {
String path = getIndexPath(conn);
synchronized (INDEX_ACCESS) {
IndexAccess access = INDEX_ACCESS.get(path);
if (access == null) {
try {
/*## LUCENE2 ##
boolean recreate = !IndexReader.indexExists(path);
Analyzer analyzer = new StandardAnalyzer();
access = new IndexAccess();
access.modifier = new IndexModifier(path, analyzer, recreate);
//*/
//## LUCENE3 ##
File f = new File(path);
Directory indexDir = FSDirectory.open(f);
boolean recreate = !IndexReader.indexExists(indexDir);
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);
IndexWriter writer = new IndexWriter(indexDir, analyzer,
recreate, IndexWriter.MaxFieldLength.UNLIMITED);
//see http://wiki.apache.org/lucene-java/NearRealtimeSearch
IndexReader reader = writer.getReader();
access = new IndexAccess();
access.writer = writer;
access.reader = reader;
access.searcher = new IndexSearcher(reader);
//*/
} catch (IOException e) {
throw convertException(e);
}
INDEX_ACCESS.put(path, access);
}
return access;
}
}
// in src/main/org/h2/fulltext/FullTextLucene.java
protected static String getIndexPath(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("CALL DATABASE_PATH()");
rs.next();
String path = rs.getString(1);
if (path == null) {
throw throwException("Fulltext search for in-memory databases is not supported.");
}
int index = path.lastIndexOf(':');
// position 1 means a windows drive letter is used, ignore that
if (index > 1) {
path = path.substring(index + 1);
}
rs.close();
return path;
}
// in src/main/org/h2/fulltext/FullTextLucene.java
protected static void indexExistingRows(Connection conn, String schema, String table) throws SQLException {
FullTextLucene.FullTextTrigger existing = new FullTextLucene.FullTextTrigger();
existing.init(conn, schema, null, table, false, Trigger.INSERT);
String sql = "SELECT * FROM " + StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(table);
ResultSet rs = conn.createStatement().executeQuery(sql);
int columnCount = rs.getMetaData().getColumnCount();
while (rs.next()) {
Object[] row = new Object[columnCount];
for (int i = 0; i < columnCount; i++) {
row[i] = rs.getObject(i + 1);
}
existing.insert(row, false);
}
existing.commitIndex();
}
// in src/main/org/h2/fulltext/FullTextLucene.java
private static void removeIndexFiles(Connection conn) throws SQLException {
String path = getIndexPath(conn);
IndexAccess access = INDEX_ACCESS.get(path);
if (access != null) {
removeIndexAccess(access, path);
}
FileUtils.deleteRecursive(path, false);
}
// in src/main/org/h2/fulltext/FullTextLucene.java
protected static void removeIndexAccess(IndexAccess access, String indexPath) throws SQLException {
synchronized (INDEX_ACCESS) {
try {
INDEX_ACCESS.remove(indexPath);
/*## LUCENE2 ##
access.modifier.flush();
access.modifier.close();
//*/
//## LUCENE3 ##
access.searcher.close();
access.reader.close();
access.writer.close();
//*/
} catch (Exception e) {
throw convertException(e);
}
}
}
// in src/main/org/h2/fulltext/FullTextLucene.java
protected static ResultSet search(Connection conn, String text,
int limit, int offset, boolean data) throws SQLException {
SimpleResultSet result = createResultSet(data);
if (conn.getMetaData().getURL().startsWith("jdbc:columnlist:")) {
// this is just to query the result set columns
return result;
}
if (text == null || text.trim().length() == 0) {
return result;
}
try {
IndexAccess access = getIndexAccess(conn);
/*## LUCENE2 ##
access.modifier.flush();
String path = getIndexPath(conn);
IndexReader reader = IndexReader.open(path);
Analyzer analyzer = new StandardAnalyzer();
Searcher searcher = new IndexSearcher(reader);
QueryParser parser = new QueryParser(LUCENE_FIELD_DATA, analyzer);
Query query = parser.parse(text);
Hits hits = searcher.search(query);
int max = hits.length();
if (limit == 0) {
limit = max;
}
for (int i = 0; i < limit && i + offset < max; i++) {
Document doc = hits.doc(i + offset);
float score = hits.score(i + offset);
//*/
//## LUCENE3 ##
// take a reference as the searcher may change
Searcher searcher = access.searcher;
// reuse the same analyzer; it's thread-safe;
// also allows subclasses to control the analyzer used.
Analyzer analyzer = access.writer.getAnalyzer();
QueryParser parser = new QueryParser(Version.LUCENE_30,
LUCENE_FIELD_DATA, analyzer);
Query query = parser.parse(text);
// Lucene 3 insists on a hard limit and will not provide
// a total hits value. Take at least 100 which is
// an optimal limit for Lucene as any more
// will trigger writing results to disk.
int maxResults = (limit == 0 ? 100 : limit) + offset;
TopDocs docs = searcher.search(query, maxResults);
if (limit == 0) {
limit = docs.totalHits;
}
for (int i = 0, len = docs.scoreDocs.length;
i < limit && i + offset < docs.totalHits
&& i + offset < len; i++) {
ScoreDoc sd = docs.scoreDocs[i + offset];
Document doc = searcher.doc(sd.doc);
float score = sd.score;
//*/
String q = doc.get(LUCENE_FIELD_QUERY);
if (data) {
int idx = q.indexOf(" WHERE ");
JdbcConnection c = (JdbcConnection) conn;
Session session = (Session) c.getSession();
Parser p = new Parser(session);
String tab = q.substring(0, idx);
ExpressionColumn expr = (ExpressionColumn) p.parseExpression(tab);
String schemaName = expr.getOriginalTableAliasName();
String tableName = expr.getColumnName();
q = q.substring(idx + " WHERE ".length());
Object[][] columnData = parseKey(conn, q);
result.addRow(
schemaName,
tableName,
columnData[0],
columnData[1],
score);
} else {
result.addRow(q, score);
}
}
/*## LUCENE2 ##
// TODO keep it open if possible
reader.close();
//*/
} catch (Exception e) {
throw convertException(e);
}
return result;
}
// in src/main/org/h2/fulltext/FullTextLucene.java
public void init(Connection conn, String schemaName, String triggerName,
String tableName, boolean before, int type) throws SQLException {
this.schema = schemaName;
this.table = tableName;
this.indexPath = getIndexPath(conn);
this.indexAccess = getIndexAccess(conn);
ArrayList<String> keyList = New.arrayList();
DatabaseMetaData meta = conn.getMetaData();
ResultSet rs = meta.getColumns(null,
JdbcUtils.escapeMetaDataPattern(schemaName),
JdbcUtils.escapeMetaDataPattern(tableName),
null);
ArrayList<String> columnList = New.arrayList();
while (rs.next()) {
columnList.add(rs.getString("COLUMN_NAME"));
}
columnTypes = new int[columnList.size()];
columns = new String[columnList.size()];
columnList.toArray(columns);
rs = meta.getColumns(null,
JdbcUtils.escapeMetaDataPattern(schemaName),
JdbcUtils.escapeMetaDataPattern(tableName),
null);
for (int i = 0; rs.next(); i++) {
columnTypes[i] = rs.getInt("DATA_TYPE");
}
if (keyList.size() == 0) {
rs = meta.getPrimaryKeys(null,
JdbcUtils.escapeMetaDataPattern(schemaName),
tableName);
while (rs.next()) {
keyList.add(rs.getString("COLUMN_NAME"));
}
}
if (keyList.size() == 0) {
throw throwException("No primary key for table " + tableName);
}
ArrayList<String> indexList = New.arrayList();
PreparedStatement prep = conn.prepareStatement(
"SELECT COLUMNS FROM " + SCHEMA
+ ".INDEXES WHERE SCHEMA=? AND TABLE=?");
prep.setString(1, schemaName);
prep.setString(2, tableName);
rs = prep.executeQuery();
if (rs.next()) {
String cols = rs.getString(1);
if (cols != null) {
for (String s : StringUtils.arraySplit(cols, ',', true)) {
indexList.add(s);
}
}
}
if (indexList.size() == 0) {
indexList.addAll(columnList);
}
keys = new int[keyList.size()];
setColumns(keys, keyList, columnList);
indexColumns = new int[indexList.size()];
setColumns(indexColumns, indexList, columnList);
}
// in src/main/org/h2/fulltext/FullTextLucene.java
public void fire(Connection conn, Object[] oldRow, Object[] newRow)
throws SQLException {
if (oldRow != null) {
if (newRow != null) {
// update
if (hasChanged(oldRow, newRow, indexColumns)) {
delete(oldRow);
insert(newRow, true);
}
} else {
// delete
delete(oldRow);
}
} else if (newRow != null) {
// insert
insert(newRow, true);
}
}
// in src/main/org/h2/fulltext/FullTextLucene.java
public void close() throws SQLException {
if (indexAccess != null) {
removeIndexAccess(indexAccess, indexPath);
indexAccess = null;
}
}
// in src/main/org/h2/fulltext/FullTextLucene.java
void commitIndex() throws SQLException {
try {
indexAccess.writer.commit();
// recreate Searcher with the IndexWriter's reader.
indexAccess.searcher.close();
indexAccess.reader.close();
IndexReader reader = indexAccess.writer.getReader();
indexAccess.reader = reader;
indexAccess.searcher = new IndexSearcher(reader);
} catch (IOException e) {
throw convertException(e);
}
}
// in src/main/org/h2/fulltext/FullTextLucene.java
protected void insert(Object[] row, boolean commitIndex) throws SQLException {
/*## LUCENE2 ##
String query = getQuery(row);
Document doc = new Document();
doc.add(new Field(LUCENE_FIELD_QUERY, query,
Field.Store.YES, Field.Index.UN_TOKENIZED));
long time = System.currentTimeMillis();
doc.add(new Field(LUCENE_FIELD_MODIFIED,
DateTools.timeToString(time, DateTools.Resolution.SECOND),
Field.Store.YES, Field.Index.UN_TOKENIZED));
StatementBuilder buff = new StatementBuilder();
for (int index : indexColumns) {
String columnName = columns[index];
String data = asString(row[index], columnTypes[index]);
// column names that start with _ must be escaped to avoid conflicts
// with internal field names (_DATA, _QUERY, _modified)
if (columnName.startsWith(LUCENE_FIELD_COLUMN_PREFIX)) {
columnName = LUCENE_FIELD_COLUMN_PREFIX + columnName;
}
doc.add(new Field(columnName, data,
Field.Store.NO, Field.Index.TOKENIZED));
buff.appendExceptFirst(" ");
buff.append(data);
}
Field.Store storeText = STORE_DOCUMENT_TEXT_IN_INDEX ?
Field.Store.YES : Field.Store.NO;
doc.add(new Field(LUCENE_FIELD_DATA, buff.toString(), storeText,
Field.Index.TOKENIZED));
try {
indexAccess.modifier.addDocument(doc);
} catch (IOException e) {
throw convertException(e);
}
//*/
//## LUCENE3 ##
String query = getQuery(row);
Document doc = new Document();
doc.add(new Field(LUCENE_FIELD_QUERY, query,
Field.Store.YES, Field.Index.NOT_ANALYZED));
long time = System.currentTimeMillis();
doc.add(new Field(LUCENE_FIELD_MODIFIED,
DateTools.timeToString(time, DateTools.Resolution.SECOND),
Field.Store.YES, Field.Index.NOT_ANALYZED));
StatementBuilder buff = new StatementBuilder();
for (int index : indexColumns) {
String columnName = columns[index];
String data = asString(row[index], columnTypes[index]);
// column names that start with _
// must be escaped to avoid conflicts
// with internal field names (_DATA, _QUERY, _modified)
if (columnName.startsWith(LUCENE_FIELD_COLUMN_PREFIX)) {
columnName = LUCENE_FIELD_COLUMN_PREFIX + columnName;
}
doc.add(new Field(columnName, data,
Field.Store.NO, Field.Index.ANALYZED));
buff.appendExceptFirst(" ");
buff.append(data);
}
Field.Store storeText = STORE_DOCUMENT_TEXT_IN_INDEX ?
Field.Store.YES : Field.Store.NO;
doc.add(new Field(LUCENE_FIELD_DATA, buff.toString(), storeText,
Field.Index.ANALYZED));
try {
indexAccess.writer.addDocument(doc);
if (commitIndex) {
indexAccess.writer.commit();
// recreate Searcher with the IndexWriter's reader.
indexAccess.searcher.close();
indexAccess.reader.close();
IndexReader reader = indexAccess.writer.getReader();
indexAccess.reader = reader;
indexAccess.searcher = new IndexSearcher(reader);
}
} catch (IOException e) {
throw convertException(e);
}
//*/
}
// in src/main/org/h2/fulltext/FullTextLucene.java
protected void delete(Object[] row) throws SQLException {
String query = getQuery(row);
try {
Term term = new Term(LUCENE_FIELD_QUERY, query);
/*## LUCENE2 ##
indexAccess.modifier.deleteDocuments(term);
//*/
//## LUCENE3 ##
indexAccess.writer.deleteDocuments(term);
//*/
} catch (IOException e) {
throw convertException(e);
}
}
// in src/main/org/h2/fulltext/FullTextLucene.java
private String getQuery(Object[] row) throws SQLException {
StatementBuilder buff = new StatementBuilder();
if (schema != null) {
buff.append(StringUtils.quoteIdentifier(schema)).append('.');
}
buff.append(StringUtils.quoteIdentifier(table)).append(" WHERE ");
for (int columnIndex : keys) {
buff.appendExceptFirst(" AND ");
buff.append(StringUtils.quoteIdentifier(columns[columnIndex]));
Object o = row[columnIndex];
if (o == null) {
buff.append(" IS NULL");
} else {
buff.append('=').append(FullText.quoteSQL(o, columnTypes[columnIndex]));
}
}
return buff.toString();
}
// in src/main/org/h2/fulltext/FullText.java
public static void init(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
stat.execute("CREATE SCHEMA IF NOT EXISTS " + SCHEMA);
stat.execute("CREATE TABLE IF NOT EXISTS " + SCHEMA
+ ".INDEXES(ID INT AUTO_INCREMENT PRIMARY KEY, SCHEMA VARCHAR, TABLE VARCHAR, COLUMNS VARCHAR, UNIQUE(SCHEMA, TABLE))");
stat.execute("CREATE TABLE IF NOT EXISTS " + SCHEMA
+ ".WORDS(ID INT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR, UNIQUE(NAME))");
stat.execute("CREATE TABLE IF NOT EXISTS " + SCHEMA
+ ".ROWS(ID IDENTITY, HASH INT, INDEXID INT, KEY VARCHAR, UNIQUE(HASH, INDEXID, KEY))");
stat.execute("CREATE TABLE IF NOT EXISTS " + SCHEMA
+ ".MAP(ROWID INT, WORDID INT, PRIMARY KEY(WORDID, ROWID))");
stat.execute("CREATE TABLE IF NOT EXISTS " + SCHEMA + ".IGNORELIST(LIST VARCHAR)");
stat.execute("CREATE TABLE IF NOT EXISTS " + SCHEMA + ".SETTINGS(KEY VARCHAR PRIMARY KEY, VALUE VARCHAR)");
stat.execute("CREATE ALIAS IF NOT EXISTS FT_CREATE_INDEX FOR \"" + FullText.class.getName() + ".createIndex\"");
stat.execute("CREATE ALIAS IF NOT EXISTS FT_DROP_INDEX FOR \"" + FullText.class.getName() + ".dropIndex\"");
stat.execute("CREATE ALIAS IF NOT EXISTS FT_SEARCH FOR \"" + FullText.class.getName() + ".search\"");
stat.execute("CREATE ALIAS IF NOT EXISTS FT_SEARCH_DATA FOR \"" + FullText.class.getName() + ".searchData\"");
stat.execute("CREATE ALIAS IF NOT EXISTS FT_REINDEX FOR \"" + FullText.class.getName() + ".reindex\"");
stat.execute("CREATE ALIAS IF NOT EXISTS FT_DROP_ALL FOR \"" + FullText.class.getName() + ".dropAll\"");
FullTextSettings setting = FullTextSettings.getInstance(conn);
ResultSet rs = stat.executeQuery("SELECT * FROM " + SCHEMA + ".IGNORELIST");
while (rs.next()) {
String commaSeparatedList = rs.getString(1);
setIgnoreList(setting, commaSeparatedList);
}
rs = stat.executeQuery("SELECT * FROM " + SCHEMA + ".SETTINGS");
while (rs.next()) {
String key = rs.getString(1);
if ("whitespaceChars".equals(key)) {
String value = rs.getString(2);
setting.setWhitespaceChars(value);
}
}
rs = stat.executeQuery("SELECT * FROM " + SCHEMA + ".WORDS");
HashMap<String, Integer> map = setting.getWordList();
while (rs.next()) {
String word = rs.getString("NAME");
int id = rs.getInt("ID");
word = setting.convertWord(word);
if (word != null) {
map.put(word, id);
}
}
setting.setInitialized(true);
}
// in src/main/org/h2/fulltext/FullText.java
public static void createIndex(Connection conn, String schema, String table, String columnList) throws SQLException {
init(conn);
PreparedStatement prep = conn.prepareStatement("INSERT INTO " + SCHEMA
+ ".INDEXES(SCHEMA, TABLE, COLUMNS) VALUES(?, ?, ?)");
prep.setString(1, schema);
prep.setString(2, table);
prep.setString(3, columnList);
prep.execute();
createTrigger(conn, schema, table);
indexExistingRows(conn, schema, table);
}
// in src/main/org/h2/fulltext/FullText.java
public static void reindex(Connection conn) throws SQLException {
init(conn);
removeAllTriggers(conn, TRIGGER_PREFIX);
FullTextSettings setting = FullTextSettings.getInstance(conn);
setting.getWordList().clear();
Statement stat = conn.createStatement();
stat.execute("TRUNCATE TABLE " + SCHEMA + ".WORDS");
stat.execute("TRUNCATE TABLE " + SCHEMA + ".ROWS");
stat.execute("TRUNCATE TABLE " + SCHEMA + ".MAP");
ResultSet rs = stat.executeQuery("SELECT * FROM " + SCHEMA + ".INDEXES");
while (rs.next()) {
String schema = rs.getString("SCHEMA");
String table = rs.getString("TABLE");
createTrigger(conn, schema, table);
indexExistingRows(conn, schema, table);
}
}
// in src/main/org/h2/fulltext/FullText.java
public static void dropIndex(Connection conn, String schema, String table) throws SQLException {
init(conn);
PreparedStatement prep = conn.prepareStatement("SELECT ID FROM " + SCHEMA
+ ".INDEXES WHERE SCHEMA=? AND TABLE=?");
prep.setString(1, schema);
prep.setString(2, table);
ResultSet rs = prep.executeQuery();
if (!rs.next()) {
return;
}
int indexId = rs.getInt(1);
prep = conn.prepareStatement("DELETE FROM " + SCHEMA
+ ".INDEXES WHERE ID=?");
prep.setInt(1, indexId);
prep.execute();
createOrDropTrigger(conn, schema, table, false);
prep = conn.prepareStatement("DELETE FROM " + SCHEMA +
".ROWS WHERE INDEXID=? AND ROWNUM<10000");
while (true) {
prep.setInt(1, indexId);
int deleted = prep.executeUpdate();
if (deleted == 0) {
break;
}
}
prep = conn.prepareStatement("DELETE FROM " + SCHEMA + ".MAP M " +
"WHERE NOT EXISTS (SELECT * FROM " + SCHEMA + ".ROWS R WHERE R.ID=M.ROWID) AND ROWID<10000");
while (true) {
int deleted = prep.executeUpdate();
if (deleted == 0) {
break;
}
}
}
// in src/main/org/h2/fulltext/FullText.java
public static void dropAll(Connection conn) throws SQLException {
init(conn);
Statement stat = conn.createStatement();
stat.execute("DROP SCHEMA IF EXISTS " + SCHEMA);
removeAllTriggers(conn, TRIGGER_PREFIX);
FullTextSettings setting = FullTextSettings.getInstance(conn);
setting.removeAllIndexes();
setting.getIgnoreList().clear();
setting.getWordList().clear();
}
// in src/main/org/h2/fulltext/FullText.java
public static ResultSet search(Connection conn, String text, int limit, int offset) throws SQLException {
try {
return search(conn, text, limit, offset, false);
} catch (DbException e) {
throw DbException.toSQLException(e);
}
}
// in src/main/org/h2/fulltext/FullText.java
public static ResultSet searchData(Connection conn, String text, int limit, int offset) throws SQLException {
try {
return search(conn, text, limit, offset, true);
} catch (DbException e) {
throw DbException.toSQLException(e);
}
}
// in src/main/org/h2/fulltext/FullText.java
public static void setIgnoreList(Connection conn, String commaSeparatedList) throws SQLException {
try {
init(conn);
FullTextSettings setting = FullTextSettings.getInstance(conn);
setIgnoreList(setting, commaSeparatedList);
Statement stat = conn.createStatement();
stat.execute("TRUNCATE TABLE " + SCHEMA + ".IGNORELIST");
PreparedStatement prep = conn.prepareStatement("INSERT INTO " + SCHEMA + ".IGNORELIST VALUES(?)");
prep.setString(1, commaSeparatedList);
prep.execute();
} catch (DbException e) {
throw DbException.toSQLException(e);
}
}
// in src/main/org/h2/fulltext/FullText.java
public static void setWhitespaceChars(Connection conn, String whitespaceChars) throws SQLException {
try {
init(conn);
FullTextSettings setting = FullTextSettings.getInstance(conn);
setting.setWhitespaceChars(whitespaceChars);
PreparedStatement prep = conn.prepareStatement("MERGE INTO " + SCHEMA + ".SETTINGS VALUES(?, ?)");
prep.setString(1, "whitespaceChars");
prep.setString(2, whitespaceChars);
prep.execute();
} catch (DbException e) {
throw DbException.toSQLException(e);
}
}
// in src/main/org/h2/fulltext/FullText.java
protected static String asString(Object data, int type) throws SQLException {
if (data == null) {
return "NULL";
}
switch (type) {
case Types.BIT:
case Types.BOOLEAN:
case Types.INTEGER:
case Types.BIGINT:
case Types.DECIMAL:
case Types.DOUBLE:
case Types.FLOAT:
case Types.NUMERIC:
case Types.REAL:
case Types.SMALLINT:
case Types.TINYINT:
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
case Types.LONGVARCHAR:
case Types.CHAR:
case Types.VARCHAR:
return data.toString();
case Types.CLOB:
try {
if (data instanceof Clob) {
data = ((Clob) data).getCharacterStream();
}
return IOUtils.readStringAndClose((Reader) data, -1);
} catch (IOException e) {
throw DbException.toSQLException(e);
}
case Types.VARBINARY:
case Types.LONGVARBINARY:
case Types.BINARY:
case Types.JAVA_OBJECT:
case Types.OTHER:
case Types.BLOB:
case Types.STRUCT:
case Types.REF:
case Types.NULL:
case Types.ARRAY:
case Types.DATALINK:
case Types.DISTINCT:
throw throwException("Unsupported column data type: " + type);
default:
return "";
}
}
// in src/main/org/h2/fulltext/FullText.java
protected static String quoteSQL(Object data, int type) throws SQLException {
if (data == null) {
return "NULL";
}
switch (type) {
case Types.BIT:
case Types.BOOLEAN:
case Types.INTEGER:
case Types.BIGINT:
case Types.DECIMAL:
case Types.DOUBLE:
case Types.FLOAT:
case Types.NUMERIC:
case Types.REAL:
case Types.SMALLINT:
case Types.TINYINT:
return data.toString();
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
case Types.LONGVARCHAR:
case Types.CHAR:
case Types.VARCHAR:
return quoteString(data.toString());
case Types.VARBINARY:
case Types.LONGVARBINARY:
case Types.BINARY:
return "'" + StringUtils.convertBytesToHex((byte[]) data) + "'";
case Types.CLOB:
case Types.JAVA_OBJECT:
case Types.OTHER:
case Types.BLOB:
case Types.STRUCT:
case Types.REF:
case Types.NULL:
case Types.ARRAY:
case Types.DATALINK:
case Types.DISTINCT:
throw throwException("Unsupported key data type: " + type);
default:
return "";
}
}
// in src/main/org/h2/fulltext/FullText.java
protected static void removeAllTriggers(Connection conn, String prefix) throws SQLException {
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT * FROM INFORMATION_SCHEMA.TRIGGERS");
Statement stat2 = conn.createStatement();
while (rs.next()) {
String schema = rs.getString("TRIGGER_SCHEMA");
String name = rs.getString("TRIGGER_NAME");
if (name.startsWith(prefix)) {
name = StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(name);
stat2.execute("DROP TRIGGER " + name);
}
}
}
// in src/main/org/h2/fulltext/FullText.java
protected static void setColumns(int[] index, ArrayList<String> keys, ArrayList<String> columns) throws SQLException {
for (int i = 0, keySize = keys.size(); i < keySize; i++) {
String key = keys.get(i);
int found = -1;
int columnsSize = columns.size();
for (int j = 0; found == -1 && j < columnsSize; j++) {
String column = columns.get(j);
if (column.equals(key)) {
found = j;
}
}
if (found < 0) {
throw throwException("Column not found: " + key);
}
index[i] = found;
}
}
// in src/main/org/h2/fulltext/FullText.java
protected static ResultSet search(Connection conn, String text, int limit,
int offset, boolean data) throws SQLException {
SimpleResultSet result = createResultSet(data);
if (conn.getMetaData().getURL().startsWith("jdbc:columnlist:")) {
// this is just to query the result set columns
return result;
}
if (text == null || text.trim().length() == 0) {
return result;
}
FullTextSettings setting = FullTextSettings.getInstance(conn);
if (!setting.isInitialized()) {
init(conn);
}
HashSet<String> words = New.hashSet();
addWords(setting, words, text);
HashSet<Integer> rIds = null, lastRowIds = null;
HashMap<String, Integer> allWords = setting.getWordList();
PreparedStatement prepSelectMapByWordId = setting.prepare(conn, SELECT_MAP_BY_WORD_ID);
for (String word : words) {
lastRowIds = rIds;
rIds = New.hashSet();
Integer wId = allWords.get(word);
if (wId == null) {
continue;
}
prepSelectMapByWordId.setInt(1, wId.intValue());
ResultSet rs = prepSelectMapByWordId.executeQuery();
while (rs.next()) {
Integer rId = rs.getInt(1);
if (lastRowIds == null || lastRowIds.contains(rId)) {
rIds.add(rId);
}
}
}
if (rIds == null || rIds.size() == 0) {
return result;
}
PreparedStatement prepSelectRowById = setting.prepare(conn, SELECT_ROW_BY_ID);
int rowCount = 0;
for (int rowId : rIds) {
prepSelectRowById.setInt(1, rowId);
ResultSet rs = prepSelectRowById.executeQuery();
if (!rs.next()) {
continue;
}
if (offset > 0) {
offset--;
} else {
String key = rs.getString(1);
int indexId = rs.getInt(2);
IndexInfo index = setting.getIndexInfo(indexId);
if (data) {
Object[][] columnData = parseKey(conn, key);
result.addRow(
index.schema,
index.table,
columnData[0],
columnData[1],
1.0);
} else {
String query = StringUtils.quoteIdentifier(index.schema) +
"." + StringUtils.quoteIdentifier(index.table) +
" WHERE " + key;
result.addRow(query, 1.0);
}
rowCount++;
if (limit > 0 && rowCount >= limit) {
break;
}
}
}
return result;
}
// in src/main/org/h2/fulltext/FullText.java
protected static void createTrigger(Connection conn, String schema, String table) throws SQLException {
createOrDropTrigger(conn, schema, table, true);
}
// in src/main/org/h2/fulltext/FullText.java
private static void createOrDropTrigger(Connection conn,
String schema, String table, boolean create) throws SQLException {
Statement stat = conn.createStatement();
String trigger = StringUtils.quoteIdentifier(schema) + "."
+ StringUtils.quoteIdentifier(TRIGGER_PREFIX + table);
stat.execute("DROP TRIGGER IF EXISTS " + trigger);
if (create) {
StringBuilder buff = new StringBuilder("CREATE TRIGGER IF NOT EXISTS ");
// needs to be called on rollback as well, because we use the init connection
// do to changes in the index (not the user connection)
buff.append(trigger).
append(" AFTER INSERT, UPDATE, DELETE, ROLLBACK ON ").
append(StringUtils.quoteIdentifier(schema)).
append('.').
append(StringUtils.quoteIdentifier(table)).
append(" FOR EACH ROW CALL \"").
append(FullText.FullTextTrigger.class.getName()).
append('\"');
stat.execute(buff.toString());
}
}
// in src/main/org/h2/fulltext/FullText.java
protected static void indexExistingRows(Connection conn, String schema, String table) throws SQLException {
FullText.FullTextTrigger existing = new FullText.FullTextTrigger();
existing.init(conn, schema, null, table, false, Trigger.INSERT);
String sql = "SELECT * FROM " + StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(table);
ResultSet rs = conn.createStatement().executeQuery(sql);
int columnCount = rs.getMetaData().getColumnCount();
while (rs.next()) {
Object[] row = new Object[columnCount];
for (int i = 0; i < columnCount; i++) {
row[i] = rs.getObject(i + 1);
}
existing.fire(conn, null, row);
}
}
// in src/main/org/h2/fulltext/FullText.java
public void init(Connection conn, String schemaName, String triggerName,
String tableName, boolean before, int type) throws SQLException {
setting = FullTextSettings.getInstance(conn);
if (!setting.isInitialized()) {
FullText.init(conn);
}
ArrayList<String> keyList = New.arrayList();
DatabaseMetaData meta = conn.getMetaData();
ResultSet rs = meta.getColumns(null,
JdbcUtils.escapeMetaDataPattern(schemaName),
JdbcUtils.escapeMetaDataPattern(tableName),
null);
ArrayList<String> columnList = New.arrayList();
while (rs.next()) {
columnList.add(rs.getString("COLUMN_NAME"));
}
columnTypes = new int[columnList.size()];
index = new IndexInfo();
index.schema = schemaName;
index.table = tableName;
index.columns = new String[columnList.size()];
columnList.toArray(index.columns);
rs = meta.getColumns(null,
JdbcUtils.escapeMetaDataPattern(schemaName),
JdbcUtils.escapeMetaDataPattern(tableName),
null);
for (int i = 0; rs.next(); i++) {
columnTypes[i] = rs.getInt("DATA_TYPE");
}
if (keyList.size() == 0) {
rs = meta.getPrimaryKeys(null,
JdbcUtils.escapeMetaDataPattern(schemaName),
tableName);
while (rs.next()) {
keyList.add(rs.getString("COLUMN_NAME"));
}
}
if (keyList.size() == 0) {
throw throwException("No primary key for table " + tableName);
}
ArrayList<String> indexList = New.arrayList();
PreparedStatement prep = conn.prepareStatement(
"SELECT ID, COLUMNS FROM " + SCHEMA + ".INDEXES WHERE SCHEMA=? AND TABLE=?");
prep.setString(1, schemaName);
prep.setString(2, tableName);
rs = prep.executeQuery();
if (rs.next()) {
index.id = rs.getInt(1);
String columns = rs.getString(2);
if (columns != null) {
for (String s : StringUtils.arraySplit(columns, ',', true)) {
indexList.add(s);
}
}
}
if (indexList.size() == 0) {
indexList.addAll(columnList);
}
index.keys = new int[keyList.size()];
setColumns(index.keys, keyList, columnList);
index.indexColumns = new int[indexList.size()];
setColumns(index.indexColumns, indexList, columnList);
setting.addIndexInfo(index);
prepInsertWord = conn.prepareStatement(
"INSERT INTO " + SCHEMA + ".WORDS(NAME) VALUES(?)");
prepInsertRow = conn.prepareStatement(
"INSERT INTO " + SCHEMA + ".ROWS(HASH, INDEXID, KEY) VALUES(?, ?, ?)");
prepInsertMap = conn.prepareStatement(
"INSERT INTO " + SCHEMA + ".MAP(ROWID, WORDID) VALUES(?, ?)");
prepDeleteRow = conn.prepareStatement(
"DELETE FROM " + SCHEMA + ".ROWS WHERE HASH=? AND INDEXID=? AND KEY=?");
prepDeleteMap = conn.prepareStatement(
"DELETE FROM " + SCHEMA + ".MAP WHERE ROWID=? AND WORDID=?");
prepSelectRow = conn.prepareStatement(
"SELECT ID FROM " + SCHEMA + ".ROWS WHERE HASH=? AND INDEXID=? AND KEY=?");
}
// in src/main/org/h2/fulltext/FullText.java
public void fire(Connection conn, Object[] oldRow, Object[] newRow)
throws SQLException {
if (oldRow != null) {
if (newRow != null) {
// update
if (hasChanged(oldRow, newRow, index.indexColumns)) {
delete(oldRow);
insert(newRow);
}
} else {
// delete
delete(oldRow);
}
} else if (newRow != null) {
// insert
insert(newRow);
}
}
// in src/main/org/h2/fulltext/FullText.java
protected void insert(Object[] row) throws SQLException {
String key = getKey(row);
int hash = key.hashCode();
prepInsertRow.setInt(1, hash);
prepInsertRow.setInt(2, index.id);
prepInsertRow.setString(3, key);
prepInsertRow.execute();
ResultSet rs = prepInsertRow.getGeneratedKeys();
rs.next();
int rowId = rs.getInt(1);
prepInsertMap.setInt(1, rowId);
int[] wordIds = getWordIds(row);
for (int id : wordIds) {
prepInsertMap.setInt(2, id);
prepInsertMap.execute();
}
}
// in src/main/org/h2/fulltext/FullText.java
protected void delete(Object[] row) throws SQLException {
String key = getKey(row);
int hash = key.hashCode();
prepSelectRow.setInt(1, hash);
prepSelectRow.setInt(2, index.id);
prepSelectRow.setString(3, key);
ResultSet rs = prepSelectRow.executeQuery();
if (rs.next()) {
int rowId = rs.getInt(1);
prepDeleteMap.setInt(1, rowId);
int[] wordIds = getWordIds(row);
for (int id : wordIds) {
prepDeleteMap.setInt(2, id);
prepDeleteMap.executeUpdate();
}
prepDeleteRow.setInt(1, hash);
prepDeleteRow.setInt(2, index.id);
prepDeleteRow.setString(3, key);
prepDeleteRow.executeUpdate();
}
}
// in src/main/org/h2/fulltext/FullText.java
private int[] getWordIds(Object[] row) throws SQLException {
HashSet<String> words = New.hashSet();
for (int idx : index.indexColumns) {
int type = columnTypes[idx];
Object data = row[idx];
if (type == Types.CLOB && data != null) {
Reader reader;
if (data instanceof Reader) {
reader = (Reader) data;
} else {
reader = ((Clob) data).getCharacterStream();
}
addWords(setting, words, reader);
} else {
String string = asString(data, type);
addWords(setting, words, string);
}
}
HashMap<String, Integer> allWords = setting.getWordList();
int[] wordIds = new int[words.size()];
Iterator<String> it = words.iterator();
for (int i = 0; it.hasNext(); i++) {
String word = it.next();
Integer wId = allWords.get(word);
int wordId;
if (wId == null) {
prepInsertWord.setString(1, word);
prepInsertWord.execute();
ResultSet rs = prepInsertWord.getGeneratedKeys();
rs.next();
wordId = rs.getInt(1);
allWords.put(word, wordId);
} else {
wordId = wId.intValue();
}
wordIds[i] = wordId;
}
Arrays.sort(wordIds);
return wordIds;
}
// in src/main/org/h2/fulltext/FullText.java
private String getKey(Object[] row) throws SQLException {
StatementBuilder buff = new StatementBuilder();
for (int columnIndex : index.keys) {
buff.appendExceptFirst(" AND ");
buff.append(StringUtils.quoteIdentifier(index.columns[columnIndex]));
Object o = row[columnIndex];
if (o == null) {
buff.append(" IS NULL");
} else {
buff.append('=').append(quoteSQL(o, columnTypes[columnIndex]));
}
}
return buff.toString();
}
// in src/main/org/h2/fulltext/FullText.java
protected static SQLException throwException(String message) throws SQLException {
throw new SQLException(message, "FULLTEXT");
}
// in src/main/org/h2/fulltext/FullTextSettings.java
protected static FullTextSettings getInstance(Connection conn) throws SQLException {
String path = getIndexPath(conn);
FullTextSettings setting = SETTINGS.get(path);
if (setting == null) {
setting = new FullTextSettings();
SETTINGS.put(path, setting);
}
return setting;
}
// in src/main/org/h2/fulltext/FullTextSettings.java
protected static String getIndexPath(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("CALL IFNULL(DATABASE_PATH(), 'MEM:' || DATABASE())");
rs.next();
String path = rs.getString(1);
if ("MEM:UNNAMED".equals(path)) {
throw FullText.throwException("Fulltext search for private (unnamed) in-memory databases is not supported.");
}
rs.close();
return path;
}
// in src/main/org/h2/fulltext/FullTextSettings.java
protected synchronized PreparedStatement prepare(Connection conn, String sql) throws SQLException {
SoftHashMap<String, PreparedStatement> c = cache.get(conn);
if (c == null) {
c = new SoftHashMap<String, PreparedStatement>();
cache.put(conn, c);
}
PreparedStatement prep = c.get(sql);
if (prep != null && prep.getConnection().isClosed()) {
prep = null;
}
if (prep == null) {
prep = conn.prepareStatement(sql);
c.put(sql, prep);
}
return prep;
}
// in src/tools/org/h2/dev/ftp/server/FtpServer.java
public static void main(String... args) throws SQLException {
new FtpServer().runTool(args);
}
// in src/tools/org/h2/dev/ftp/server/FtpServer.java
public void runTool(String... args) throws SQLException {
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg == null) {
continue;
} else if ("-?".equals(arg) || "-help".equals(arg)) {
showUsage();
return;
} else if (arg.startsWith("-ftp")) {
if ("-ftpPort".equals(arg)) {
i++;
} else if ("-ftpDir".equals(arg)) {
i++;
} else if ("-ftpRead".equals(arg)) {
i++;
} else if ("-ftpWrite".equals(arg)) {
i++;
} else if ("-ftpWritePassword".equals(arg)) {
i++;
} else if ("-ftpTask".equals(arg)) {
// no parameters
} else {
showUsageAndThrowUnsupportedOption(arg);
}
} else if ("-trace".equals(arg)) {
// no parameters
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
Server server = new Server(this, args);
server.start();
out.println(server.getStatus());
}
// in src/tools/org/h2/dev/ftp/server/FtpServer.java
public static Server createFtpServer(String... args) throws SQLException {
return new Server(new FtpServer(), args);
}
// in src/tools/org/h2/dev/fs/FileShell.java
public static void main(String... args) throws SQLException {
new FileShell().runTool(args);
}
// in src/tools/org/h2/dev/fs/FileShell.java
public void runTool(String... args) throws SQLException {
try {
currentWorkingDirectory = new File(".").getCanonicalPath();
} catch (IOException e) {
throw DbException.convertIOException(e, "cwd");
}
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg.equals("-run")) {
try {
execute(args[++i]);
} catch (Exception e) {
throw DbException.convert(e);
}
} else if (arg.equals("-verbose")) {
verbose = true;
} else if (arg.equals("-help") || arg.equals("-?")) {
showUsage();
return;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
promptLoop();
}
// in src/tools/org/h2/dev/util/FileViewer.java
public static void main(String... args) throws SQLException {
new FileViewer().runTool(args);
}
// in src/tools/org/h2/dev/util/FileViewer.java
public void runTool(String... args) throws SQLException {
String file = null;
String find = null;
boolean head = false, tail = false;
int lines = 30;
boolean quiet = false;
long start = 0;
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg.equals("-file")) {
file = args[++i];
} else if (arg.equals("-find")) {
find = args[++i];
} else if (arg.equals("-start")) {
start = Long.decode(args[++i]).longValue();
} else if (arg.equals("-head")) {
head = true;
} else if (arg.equals("-tail")) {
tail = true;
} else if (arg.equals("-lines")) {
lines = Integer.decode(args[++i]).intValue();
} else if (arg.equals("-quiet")) {
quiet = true;
} else if (arg.equals("-help") || arg.equals("-?")) {
showUsage();
return;
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
if (file == null) {
showUsage();
return;
}
if (!head && !tail && find == null) {
head = true;
}
try {
process(file, find, head, tail, start, lines, quiet);
} catch (IOException e) {
throw DbException.toSQLException(e);
}
}
// in src/tools/org/h2/mode/FunctionsMySQL.java
public static void register(Connection conn) throws SQLException {
String[] init = {
"UNIX_TIMESTAMP", "unixTimestamp",
"FROM_UNIXTIME", "fromUnixTime",
"DATE", "date",
};
Statement stat = conn.createStatement();
for (int i = 0; i < init.length; i += 2) {
String alias = init[i], method = init[i + 1];
stat.execute(
"CREATE ALIAS IF NOT EXISTS " + alias +
" FOR \"" + FunctionsMySQL.class.getName() + "." + method + "\"");
}
}
// in src/tools/org/h2/jaqu/TableInspector.java
void read(DatabaseMetaData metaData) throws SQLException {
ResultSet rs = null;
// primary keys
try {
rs = metaData.getPrimaryKeys(null, schema, table);
while (rs.next()) {
String c = rs.getString("COLUMN_NAME");
primaryKeys.add(c);
}
JdbcUtils.closeSilently(rs);
// indexes
rs = metaData.getIndexInfo(null, schema, table, false, true);
indexes = New.hashMap();
while (rs.next()) {
IndexInspector info = new IndexInspector(rs);
if (info.type.equals(IndexType.UNIQUE)
&& info.name.toLowerCase().startsWith("primary")) {
// skip primary key indexes
continue;
}
if (indexes.containsKey(info.name)) {
indexes.get(info.name).addColumn(rs);
} else {
indexes.put(info.name, info);
}
}
JdbcUtils.closeSilently(rs);
// columns
rs = metaData.getColumns(null, schema, table, null);
columns = New.hashMap();
while (rs.next()) {
ColumnInspector col = new ColumnInspector();
col.name = rs.getString("COLUMN_NAME");
col.type = rs.getString("TYPE_NAME");
col.clazz = ModelUtils.getClassForSqlType(col.type, dateTimeClass);
col.size = rs.getInt("COLUMN_SIZE");
col.allowNull = rs.getInt("NULLABLE") == DatabaseMetaData.columnNullable;
col.isAutoIncrement = rs.getBoolean("IS_AUTOINCREMENT");
if (primaryKeys.size() == 1) {
if (col.name.equalsIgnoreCase(primaryKeys.get(0))) {
col.isPrimaryKey = true;
}
}
if (!col.isAutoIncrement) {
col.defaultValue = rs.getString("COLUMN_DEF");
}
columns.put(col.name, col);
}
} finally {
JdbcUtils.closeSilently(rs);
}
}
// in src/tools/org/h2/jaqu/TableInspector.java
public void addColumn(ResultSet rs) throws SQLException {
columns.add(rs.getString("COLUMN_NAME"));
}
// in src/tools/org/h2/jaqu/DbInspector.java
private DatabaseMetaData getMetaData() throws SQLException {
if (metaData == null) {
metaData = db.getConnection().getMetaData();
}
return metaData;
}
// in src/tools/org/h2/jaqu/DbInspector.java
private <T> TableInspector getTable(T model) throws SQLException {
@SuppressWarnings("unchecked")
Class<T> clazz = (Class<T>) model.getClass();
TableDefinition<T> def = db.define(clazz);
boolean forceUpperCase = getMetaData().storesUpperCaseIdentifiers();
String schema = (forceUpperCase && def.schemaName != null) ?
def.schemaName.toUpperCase() : def.schemaName;
String table = forceUpperCase ? def.tableName.toUpperCase() : def.tableName;
List<TableInspector> tables = getTables(schema, table);
return tables.get(0);
}
// in src/tools/org/h2/jaqu/DbInspector.java
private List<TableInspector> getTables(String schema, String table) throws SQLException {
ResultSet rs = null;
try {
rs = getMetaData().getSchemas();
ArrayList<String> schemaList = New.arrayList();
while (rs.next()) {
schemaList.add(rs.getString("TABLE_SCHEM"));
}
JdbcUtils.closeSilently(rs);
String jaquTables = DbVersion.class.getAnnotation(JQTable.class).name();
List<TableInspector> tables = New.arrayList();
if (schemaList.size() == 0) {
schemaList.add(null);
}
for (String s : schemaList) {
rs = getMetaData().getTables(null, s, null, new String[] { "TABLE" });
while (rs.next()) {
String t = rs.getString("TABLE_NAME");
if (!t.equalsIgnoreCase(jaquTables)) {
tables.add(new TableInspector(s, t,
getMetaData().storesUpperCaseIdentifiers(), dateTimeClass));
}
}
}
if (StringUtils.isNullOrEmpty(schema) && StringUtils.isNullOrEmpty(table)) {
// all schemas and tables
return tables;
}
// schema subset OR table subset OR exact match
List<TableInspector> matches = New.arrayList();
for (TableInspector t : tables) {
if (t.matches(schema, table)) {
matches.add(t);
}
}
if (matches.size() == 0) {
throw new RuntimeException(
MessageFormat.format("Failed to find schema={0} table={1}",
schema == null ? "" : schema, table == null ? "" : table));
}
return matches;
} finally {
JdbcUtils.closeSilently(rs);
}
}
// in src/tools/org/h2/jaqu/util/GenerateModels.java
public static void main(String... args) throws SQLException {
new GenerateModels().runTool(args);
}
// in src/tools/org/h2/jaqu/util/GenerateModels.java
public void runTool(String... args) throws SQLException {
String url = null;
String user = "sa";
String password = "";
String schema = null;
String table = null;
String packageName = "";
String folder = null;
boolean annotateSchema = true;
boolean trimStrings = false;
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg.equals("-url")) {
url = args[++i];
} else if (arg.equals("-user")) {
user = args[++i];
} else if (arg.equals("-password")) {
password = args[++i];
} else if (arg.equals("-schema")) {
schema = args[++i];
} else if (arg.equals("-table")) {
table = args[++i];
} else if (arg.equals("-package")) {
packageName = args[++i];
} else if (arg.equals("-folder")) {
folder = args[++i];
} else if (arg.equals("-annotateSchema")) {
try {
annotateSchema = Boolean.parseBoolean(args[++i]);
} catch (Throwable t) {
throw new SQLException("Can not parse -annotateSchema value");
}
} else if (arg.equals("-trimStrings")) {
try {
trimStrings = Boolean.parseBoolean(args[++i]);
} catch (Throwable t) {
throw new SQLException("Can not parse -trimStrings value");
}
} else {
throwUnsupportedOption(arg);
}
}
if (url == null) {
throw new SQLException("URL not set");
}
execute(url, user, password, schema, table, packageName, folder,
annotateSchema, trimStrings);
}
// in src/tools/org/h2/jaqu/util/GenerateModels.java
public static void execute(String url, String user, String password,
String schema, String table, String packageName, String folder,
boolean annotateSchema, boolean trimStrings)
throws SQLException {
Connection conn = null;
try {
org.h2.Driver.load();
conn = DriverManager.getConnection(url, user, password);
Db db = Db.open(url, user, password.toCharArray());
DbInspector inspector = new DbInspector(db);
List<String> models = inspector.generateModel(schema, table,
packageName, annotateSchema, trimStrings);
File parentFile;
if (StringUtils.isNullOrEmpty(folder)) {
parentFile = new File(System.getProperty("user.dir"));
} else {
parentFile = new File(folder);
}
parentFile.mkdirs();
Pattern p = Pattern.compile("class ([a-zA-Z0-9]+)");
for (String model : models) {
Matcher m = p.matcher(model);
if (m.find()) {
String className = m.group().substring("class".length()).trim();
File classFile = new File(parentFile, className + ".java");
Writer o = new FileWriter(classFile, false);
PrintWriter writer = new PrintWriter(new BufferedWriter(o));
writer.write(model);
writer.close();
System.out.println("Generated " + classFile.getAbsolutePath());
}
}
} catch (IOException io) {
throw DbException.convertIOException(io, "could not generate model").getSQLException();
} finally {
JdbcUtils.closeSilently(conn);
}
}
// in src/tools/org/h2/jaqu/util/GenerateModels.java
protected SQLException throwUnsupportedOption(String option) throws SQLException {
showUsage();
throw new SQLException("Unsupported option: " + option);
}