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

--no commit message

--no commit message
上级 2748b4f5
...@@ -17,6 +17,7 @@ import java.util.Properties; ...@@ -17,6 +17,7 @@ import java.util.Properties;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.message.TraceSystem; import org.h2.message.TraceSystem;
import org.h2.util.FileUtils; import org.h2.util.FileUtils;
import org.h2.util.JdbcUtils;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
public class AppServer { public class AppServer {
...@@ -208,6 +209,7 @@ public class AppServer { ...@@ -208,6 +209,7 @@ public class AppServer {
user = user.trim(); user = user.trim();
password = password.trim(); password = password.trim();
org.h2.Driver.load(); org.h2.Driver.load();
JdbcUtils.getConnection(driver, url, user, password);
Class.forName(driver); Class.forName(driver);
// try { // try {
// Driver dr = (Driver) urlClassLoader.loadClass(driver).newInstance(); // Driver dr = (Driver) urlClassLoader.loadClass(driver).newInstance();
......
...@@ -508,11 +508,7 @@ public class AppThread extends WebServerThread { ...@@ -508,11 +508,7 @@ public class AppThread extends WebServerThread {
session.put("user", user); session.put("user", user);
try { try {
Connection conn = server.getAppServer().getConnection(driver, url, user, password); Connection conn = server.getAppServer().getConnection(driver, url, user, password);
try { JdbcUtils.closeSilently(conn);
conn.close();
} catch(SQLException e2) {
// TODO log error
}
session.put("error", "${text.login.testSuccessful}"); session.put("error", "${text.login.testSuccessful}");
return "index.jsp"; return "index.jsp";
} catch(Exception e) { } catch(Exception e) {
......
...@@ -102,4 +102,4 @@ tree.indexes=Índices ...@@ -102,4 +102,4 @@ tree.indexes=Índices
tree.nonUnique=Não único tree.nonUnique=Não único
tree.sequences=Sequências tree.sequences=Sequências
tree.unique=Único tree.unique=Único
tree.users=Utilizadoreses tree.users=Utilizadoreses
\ No newline at end of file
...@@ -19,7 +19,6 @@ public interface DataHandler { ...@@ -19,7 +19,6 @@ public interface DataHandler {
void handleInvalidChecksum() throws SQLException; void handleInvalidChecksum() throws SQLException;
int compareTypeSave(Value a, Value b) throws SQLException; int compareTypeSave(Value a, Value b) throws SQLException;
int getMaxLengthInplaceLob(); int getMaxLengthInplaceLob();
String getLobCompressionAlgorithm(int type); String getLobCompressionAlgorithm(int type);
// only temporarily, until LOB_FILES_IN_DIRECTORIES is enabled // only temporarily, until LOB_FILES_IN_DIRECTORIES is enabled
......
...@@ -16,6 +16,13 @@ import org.h2.util.FileUtils; ...@@ -16,6 +16,13 @@ import org.h2.util.FileUtils;
public class FileLister { 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. * Get the list of database files.
* *
......
...@@ -24,10 +24,10 @@ public class FileStore { ...@@ -24,10 +24,10 @@ public class FileStore {
protected String name; protected String name;
protected DataHandler handler; protected DataHandler handler;
private byte[] magic; private byte[] magic;
private RandomAccessFile file; private RandomAccessFile file;
private long filePos; private long filePos;
private Reference autoDeleteReference; private Reference autoDeleteReference;
private boolean checkedWriting = true;
public static FileStore open(DataHandler handler, String name, byte[] magic) throws SQLException { public static FileStore open(DataHandler handler, String name, byte[] magic) throws SQLException {
return open(handler, name, magic, null, null, 0); return open(handler, name, magic, null, null, 0);
...@@ -79,9 +79,13 @@ public class FileStore { ...@@ -79,9 +79,13 @@ public class FileStore {
protected void initKey(byte[] salt) { protected void initKey(byte[] salt) {
// do nothing // do nothing
} }
public void setCheckedWriting(boolean value) {
this.checkedWriting = value;
}
protected void checkWritingAllowed() throws SQLException { protected void checkWritingAllowed() throws SQLException {
if(handler != null) { if(handler != null && checkedWriting) {
handler.checkWritingAllowed(); handler.checkWritingAllowed();
} }
} }
...@@ -97,12 +101,14 @@ public class FileStore { ...@@ -97,12 +101,14 @@ public class FileStore {
byte[] salt; byte[] salt;
if(length() < HEADER_LENGTH) { if(length() < HEADER_LENGTH) {
// write unencrypted // write unencrypted
checkedWriting = false;
writeDirect(magic, 0, len); writeDirect(magic, 0, len);
salt = generateSalt(); salt = generateSalt();
writeDirect(salt, 0, len); writeDirect(salt, 0, len);
initKey(salt); initKey(salt);
// write (maybe) encrypted // write (maybe) encrypted
write(magic, 0, len); write(magic, 0, len);
checkedWriting = true;
} else { } else {
// write unencrypted // write unencrypted
seek(0); seek(0);
......
...@@ -79,6 +79,9 @@ public class Column { ...@@ -79,6 +79,9 @@ public class Column {
newColumn.convertNullToDefault = convertNullToDefault; newColumn.convertNullToDefault = convertNullToDefault;
newColumn.sequence = sequence; newColumn.sequence = sequence;
newColumn.comment = comment; newColumn.comment = comment;
newColumn.isComputed = isComputed;
newColumn.selectivity = selectivity;
newColumn.primaryKey = primaryKey;
return newColumn; return newColumn;
} }
......
...@@ -119,6 +119,10 @@ public class FunctionTable extends Table { ...@@ -119,6 +119,10 @@ public class FunctionTable extends Table {
public String getCreateSQL() { public String getCreateSQL() {
return null; return null;
} }
public String getDropSQL() {
return null;
}
public void checkRename() throws SQLException { public void checkRename() throws SQLException {
throw Message.getUnsupportedException(); 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 { ...@@ -443,6 +443,10 @@ public class MetaTable extends Table {
return cols; return cols;
} }
public String getDropSQL() {
return null;
}
public String getCreateSQL() { public String getCreateSQL() {
return null; return null;
} }
......
...@@ -31,6 +31,10 @@ public class RangeTable extends Table { ...@@ -31,6 +31,10 @@ public class RangeTable extends Table {
setColumns(cols); setColumns(cols);
} }
public String getDropSQL() {
return null;
}
public String getCreateSQL() { public String getCreateSQL() {
return null; return null;
} }
......
...@@ -49,6 +49,7 @@ public abstract class Table extends SchemaObject { ...@@ -49,6 +49,7 @@ public abstract class Table extends SchemaObject {
private ObjectArray sequences; private ObjectArray sequences;
private ObjectArray views; private ObjectArray views;
private boolean checkForeignKeyConstraints = true; private boolean checkForeignKeyConstraints = true;
private boolean onCommitDrop, onCommitTruncate;
public Table(Schema schema, int id, String name, boolean persistent) { public Table(Schema schema, int id, String name, boolean persistent) {
super(schema, id, name, Trace.TABLE); super(schema, id, name, Trace.TABLE);
...@@ -443,5 +444,21 @@ public abstract class Table extends SchemaObject { ...@@ -443,5 +444,21 @@ public abstract class Table extends SchemaObject {
} }
return null; 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 { ...@@ -43,7 +43,6 @@ public class TableData extends Table implements RecordReader {
private HashSet lockShared = new HashSet(); private HashSet lockShared = new HashSet();
private Trace traceLock; private Trace traceLock;
private boolean globalTemporary; private boolean globalTemporary;
private boolean onCommitDrop, onCommitTruncate;
private ObjectArray indexes = new ObjectArray(); private ObjectArray indexes = new ObjectArray();
private long lastModificationId; private long lastModificationId;
...@@ -337,6 +336,10 @@ public class TableData extends Table implements RecordReader { ...@@ -337,6 +336,10 @@ public class TableData extends Table implements RecordReader {
traceLock.debug(session.getId()+" "+(exclusive?"xlock":"slock") + " " + s+" "+getName()); traceLock.debug(session.getId()+" "+(exclusive?"xlock":"slock") + " " + s+" "+getName());
} }
} }
public String getDropSQL() {
return "DROP TABLE IF EXISTS " + getSQL();
}
public String getCreateSQL() { public String getCreateSQL() {
StringBuffer buff = new StringBuffer(); StringBuffer buff = new StringBuffer();
...@@ -460,22 +463,6 @@ public class TableData extends Table implements RecordReader { ...@@ -460,22 +463,6 @@ public class TableData extends Table implements RecordReader {
return globalTemporary; 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() { public long getMaxDataModificationId() {
return lastModificationId; return lastModificationId;
} }
......
...@@ -6,7 +6,6 @@ package org.h2.table; ...@@ -6,7 +6,6 @@ package org.h2.table;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
...@@ -45,12 +44,7 @@ public class TableLink extends Table { ...@@ -45,12 +44,7 @@ public class TableLink extends Table {
this.user = user; this.user = user;
this.password = password; this.password = password;
this.originalTable = originalTable; this.originalTable = originalTable;
try { conn = JdbcUtils.getConnection(driver, url, user, password);
database.loadClass(driver);
} catch(ClassNotFoundException e) {
throw Message.getSQLException(Message.CLASS_NOT_FOUND_1, new String[]{driver}, e);
}
conn = DriverManager.getConnection(url, user, password);
DatabaseMetaData meta = conn.getMetaData(); DatabaseMetaData meta = conn.getMetaData();
boolean storesLowerCase = meta.storesLowerCaseIdentifiers(); boolean storesLowerCase = meta.storesLowerCaseIdentifiers();
ResultSet rs = meta.getColumns(null, null, originalTable, null); ResultSet rs = meta.getColumns(null, null, originalTable, null);
...@@ -161,6 +155,10 @@ public class TableLink extends Table { ...@@ -161,6 +155,10 @@ public class TableLink extends Table {
Index index = new LinkedIndex(this, 0, cols, indexType); Index index = new LinkedIndex(this, 0, cols, indexType);
indexes.add(index); indexes.add(index);
} }
public String getDropSQL() {
return "DROP TABLE IF EXISTS " + getSQL();
}
public String getCreateSQL() { public String getCreateSQL() {
StringBuffer buff = new StringBuffer(); StringBuffer buff = new StringBuffer();
......
...@@ -34,6 +34,7 @@ public class TableView extends Table { ...@@ -34,6 +34,7 @@ public class TableView extends Table {
super(schema, id, name, false); super(schema, id, name, false);
this.querySQL = querySQL; this.querySQL = querySQL;
this.columnNames = columnNames; this.columnNames = columnNames;
this.recursive = recursive;
index = new ViewIndex(this, querySQL, params, recursive); index = new ViewIndex(this, querySQL, params, recursive);
initColumnsAndTables(session); initColumnsAndTables(session);
} }
...@@ -80,16 +81,16 @@ public class TableView extends Table { ...@@ -80,16 +81,16 @@ public class TableView extends Table {
tables = new ObjectArray(); tables = new ObjectArray();
cols = new Column[0]; cols = new Column[0];
int testing; int needToTestRecursiveQueries;
// if(recursive && columnNames != null) { if(recursive && columnNames != null) {
// cols = new Column[columnNames.length]; cols = new Column[columnNames.length];
// for(int i=0; i<columnNames.length; i++) { for(int i=0; i<columnNames.length; i++) {
// cols[i] = new Column(columnNames[i], Value.STRING, 255, 0); cols[i] = new Column(columnNames[i], Value.STRING, 255, 0);
// } }
// index.setRecursive(true); index.setRecursive(true);
// recursive = true; recursive = true;
// createException = null; createException = null;
// } }
} }
setColumns(cols); setColumns(cols);
...@@ -105,6 +106,10 @@ public class TableView extends Table { ...@@ -105,6 +106,10 @@ public class TableView extends Table {
item.setIndex(index); item.setIndex(index);
return item; return item;
} }
public String getDropSQL() {
return "DROP VIEW IF EXISTS " + getSQL();
}
public String getCreateSQL() { public String getCreateSQL() {
StringBuffer buff = new StringBuffer(); StringBuffer buff = new StringBuffer();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论