提交 7ac143fd authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 2748b4f5
......@@ -17,6 +17,7 @@ import java.util.Properties;
import org.h2.engine.Constants;
import org.h2.message.TraceSystem;
import org.h2.util.FileUtils;
import org.h2.util.JdbcUtils;
import org.h2.util.MathUtils;
public class AppServer {
......@@ -208,6 +209,7 @@ public class AppServer {
user = user.trim();
password = password.trim();
org.h2.Driver.load();
JdbcUtils.getConnection(driver, url, user, password);
Class.forName(driver);
// try {
// Driver dr = (Driver) urlClassLoader.loadClass(driver).newInstance();
......
......@@ -508,11 +508,7 @@ public class AppThread extends WebServerThread {
session.put("user", user);
try {
Connection conn = server.getAppServer().getConnection(driver, url, user, password);
try {
conn.close();
} catch(SQLException e2) {
// TODO log error
}
JdbcUtils.closeSilently(conn);
session.put("error", "${text.login.testSuccessful}");
return "index.jsp";
} catch(Exception e) {
......
......@@ -19,7 +19,6 @@ public interface DataHandler {
void handleInvalidChecksum() throws SQLException;
int compareTypeSave(Value a, Value b) throws SQLException;
int getMaxLengthInplaceLob();
String getLobCompressionAlgorithm(int type);
// only temporarily, until LOB_FILES_IN_DIRECTORIES is enabled
......
......@@ -16,6 +16,13 @@ import org.h2.util.FileUtils;
public class FileLister {
public static String getDatabaseNameFromFileName(String fileName) {
if(fileName.endsWith(Constants.SUFFIX_DATA_FILE)) {
return fileName.substring(0, fileName.length() - Constants.SUFFIX_DATA_FILE.length());
}
return null;
}
/**
* Get the list of database files.
*
......
......@@ -24,10 +24,10 @@ public class FileStore {
protected String name;
protected DataHandler handler;
private byte[] magic;
private RandomAccessFile file;
private long filePos;
private Reference autoDeleteReference;
private boolean checkedWriting = true;
public static FileStore open(DataHandler handler, String name, byte[] magic) throws SQLException {
return open(handler, name, magic, null, null, 0);
......@@ -80,8 +80,12 @@ public class FileStore {
// do nothing
}
public void setCheckedWriting(boolean value) {
this.checkedWriting = value;
}
protected void checkWritingAllowed() throws SQLException {
if(handler != null) {
if(handler != null && checkedWriting) {
handler.checkWritingAllowed();
}
}
......@@ -97,12 +101,14 @@ public class FileStore {
byte[] salt;
if(length() < HEADER_LENGTH) {
// write unencrypted
checkedWriting = false;
writeDirect(magic, 0, len);
salt = generateSalt();
writeDirect(salt, 0, len);
initKey(salt);
// write (maybe) encrypted
write(magic, 0, len);
checkedWriting = true;
} else {
// write unencrypted
seek(0);
......
......@@ -79,6 +79,9 @@ public class Column {
newColumn.convertNullToDefault = convertNullToDefault;
newColumn.sequence = sequence;
newColumn.comment = comment;
newColumn.isComputed = isComputed;
newColumn.selectivity = selectivity;
newColumn.primaryKey = primaryKey;
return newColumn;
}
......
......@@ -120,6 +120,10 @@ public class FunctionTable extends Table {
return null;
}
public String getDropSQL() {
return null;
}
public void checkRename() throws SQLException {
throw Message.getUnsupportedException();
}
......
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.table;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import org.h2.tools.SimpleResultSet;
import org.h2.util.JdbcUtils;
import org.h2.util.StringUtils;
public class LinkSchema {
public static ResultSet linkSchema(Connection conn, String targetSchema, String driver, String url, String user, String password, String sourceSchema) throws SQLException {
Connection c2 = null;
Statement stat = null;
ResultSet rs = null;
SimpleResultSet result = new SimpleResultSet();
result.addColumn("TABLE_NAME", Types.VARCHAR, 255, 0);
try {
c2 = JdbcUtils.getConnection(driver, url, user, password);
stat = conn.createStatement();
stat.execute("CREATE SCHEMA IF NOT EXISTS " + StringUtils.quoteIdentifier(targetSchema));
rs = c2.getMetaData().getTables(null, sourceSchema, null, null);
while(rs.next()) {
String table = rs.getString("TABLE_NAME");
StringBuffer buff = new StringBuffer();
buff.append("DROP TABLE IF EXISTS ");
buff.append(StringUtils.quoteIdentifier(targetSchema));
buff.append('.');
buff.append(StringUtils.quoteIdentifier(table));
String sql = buff.toString();
stat.execute(sql);
buff = new StringBuffer();
buff.append("CREATE LINKED TABLE ");
buff.append(StringUtils.quoteIdentifier(targetSchema));
buff.append('.');
buff.append(StringUtils.quoteIdentifier(table));
buff.append('(');
buff.append(StringUtils.quoteStringSQL(driver));
buff.append(", ");
buff.append(StringUtils.quoteStringSQL(url));
buff.append(", ");
buff.append(StringUtils.quoteStringSQL(user));
buff.append(", ");
buff.append(StringUtils.quoteStringSQL(password));
buff.append(", ");
buff.append(StringUtils.quoteStringSQL(table));
buff.append(')');
sql = buff.toString();
stat.execute(sql);
result.addRow(new String[]{table});
}
} finally {
JdbcUtils.closeSilently(rs);
JdbcUtils.closeSilently(c2);
JdbcUtils.closeSilently(stat);
}
return result;
}
}
......@@ -443,6 +443,10 @@ public class MetaTable extends Table {
return cols;
}
public String getDropSQL() {
return null;
}
public String getCreateSQL() {
return null;
}
......
......@@ -31,6 +31,10 @@ public class RangeTable extends Table {
setColumns(cols);
}
public String getDropSQL() {
return null;
}
public String getCreateSQL() {
return null;
}
......
......@@ -49,6 +49,7 @@ public abstract class Table extends SchemaObject {
private ObjectArray sequences;
private ObjectArray views;
private boolean checkForeignKeyConstraints = true;
private boolean onCommitDrop, onCommitTruncate;
public Table(Schema schema, int id, String name, boolean persistent) {
super(schema, id, name, Trace.TABLE);
......@@ -444,4 +445,20 @@ public abstract class Table extends SchemaObject {
return null;
}
public boolean isOnCommitDrop() {
return onCommitDrop;
}
public void setOnCommitDrop(boolean onCommitDrop) {
this.onCommitDrop = onCommitDrop;
}
public boolean isOnCommitTruncate() {
return onCommitTruncate;
}
public void setOnCommitTruncate(boolean onCommitTruncate) {
this.onCommitTruncate = onCommitTruncate;
}
}
......@@ -43,7 +43,6 @@ public class TableData extends Table implements RecordReader {
private HashSet lockShared = new HashSet();
private Trace traceLock;
private boolean globalTemporary;
private boolean onCommitDrop, onCommitTruncate;
private ObjectArray indexes = new ObjectArray();
private long lastModificationId;
......@@ -338,6 +337,10 @@ public class TableData extends Table implements RecordReader {
}
}
public String getDropSQL() {
return "DROP TABLE IF EXISTS " + getSQL();
}
public String getCreateSQL() {
StringBuffer buff = new StringBuffer();
buff.append("CREATE ");
......@@ -460,22 +463,6 @@ public class TableData extends Table implements RecordReader {
return globalTemporary;
}
public boolean isOnCommitDrop() {
return onCommitDrop;
}
public void setOnCommitDrop(boolean onCommitDrop) {
this.onCommitDrop = onCommitDrop;
}
public boolean isOnCommitTruncate() {
return onCommitTruncate;
}
public void setOnCommitTruncate(boolean onCommitTruncate) {
this.onCommitTruncate = onCommitTruncate;
}
public long getMaxDataModificationId() {
return lastModificationId;
}
......
......@@ -6,7 +6,6 @@ package org.h2.table;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
......@@ -45,12 +44,7 @@ public class TableLink extends Table {
this.user = user;
this.password = password;
this.originalTable = originalTable;
try {
database.loadClass(driver);
} catch(ClassNotFoundException e) {
throw Message.getSQLException(Message.CLASS_NOT_FOUND_1, new String[]{driver}, e);
}
conn = DriverManager.getConnection(url, user, password);
conn = JdbcUtils.getConnection(driver, url, user, password);
DatabaseMetaData meta = conn.getMetaData();
boolean storesLowerCase = meta.storesLowerCaseIdentifiers();
ResultSet rs = meta.getColumns(null, null, originalTable, null);
......@@ -162,6 +156,10 @@ public class TableLink extends Table {
indexes.add(index);
}
public String getDropSQL() {
return "DROP TABLE IF EXISTS " + getSQL();
}
public String getCreateSQL() {
StringBuffer buff = new StringBuffer();
buff.append("CREATE LINKED TABLE ");
......
......@@ -34,6 +34,7 @@ public class TableView extends Table {
super(schema, id, name, false);
this.querySQL = querySQL;
this.columnNames = columnNames;
this.recursive = recursive;
index = new ViewIndex(this, querySQL, params, recursive);
initColumnsAndTables(session);
}
......@@ -80,16 +81,16 @@ public class TableView extends Table {
tables = new ObjectArray();
cols = new Column[0];
int testing;
// if(recursive && columnNames != null) {
// cols = new Column[columnNames.length];
// for(int i=0; i<columnNames.length; i++) {
// cols[i] = new Column(columnNames[i], Value.STRING, 255, 0);
// }
// index.setRecursive(true);
// recursive = true;
// createException = null;
// }
int needToTestRecursiveQueries;
if(recursive && columnNames != null) {
cols = new Column[columnNames.length];
for(int i=0; i<columnNames.length; i++) {
cols[i] = new Column(columnNames[i], Value.STRING, 255, 0);
}
index.setRecursive(true);
recursive = true;
createException = null;
}
}
setColumns(cols);
......@@ -106,6 +107,10 @@ public class TableView extends Table {
return item;
}
public String getDropSQL() {
return "DROP VIEW IF EXISTS " + getSQL();
}
public String getCreateSQL() {
StringBuffer buff = new StringBuffer();
buff.append("CREATE FORCE VIEW ");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论