提交 be1fb4db authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 0b187779
......@@ -36,7 +36,7 @@ public class AlterSequence extends DefineCommand {
public void setIncrement(long increment) throws SQLException {
newIncrement = true;
if(increment == 0) {
throw Message.getSQLException(ErrorCode.INVALID_VALUE_2, new String[]{"0", "INCREMENT"}, null);
throw Message.getSQLException(ErrorCode.INVALID_VALUE_2, new String[]{"0", "INCREMENT"});
}
this.increment = increment;
}
......
......@@ -163,7 +163,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
for (int i=0; i<children.size(); i++) {
DbObject child = (DbObject) children.get(i);
if(child.getType() == DbObject.TABLE_OR_VIEW) {
throw Message.getSQLException(ErrorCode.OPERATION_NOT_SUPPORTED_WITH_VIEWS_2, new String[]{table.getName(), child.getName()}, null);
throw Message.getSQLException(ErrorCode.OPERATION_NOT_SUPPORTED_WITH_VIEWS_2, new String[]{table.getName(), child.getName()});
}
}
}
......
......@@ -82,9 +82,9 @@ public class ErrorCode {
public static final int NULL_NOT_ALLOWED = 90006;
public static final int OBJECT_CLOSED = 90007;
public static final int INVALID_VALUE_2 = 90008;
public static final int DATE_CONSTANT_1 = 90009;
public static final int TIME_CONSTANT_1 = 90010;
public static final int TIMESTAMP_CONSTANT_1 = 90011;
public static final int DATE_CONSTANT_2 = 90009;
public static final int TIME_CONSTANT_2 = 90010;
public static final int TIMESTAMP_CONSTANT_2 = 90011;
public static final int PARAMETER_NOT_SET_1 = 90012;
public static final int DATABASE_NOT_FOUND_1 = 90013;
public static final int PARSE_ERROR_1 = 90014;
......@@ -137,15 +137,15 @@ public class ErrorCode {
public static final int COLUMN_MUST_NOT_BE_NULLABLE_1 = 90023;
public static final int FILE_RENAME_FAILED_2 = 90024;
public static final int FILE_DELETE_FAILED_1 = 90025;
public static final int SERIALIZATION_FAILED = 90026;
public static final int DESERIALIZATION_FAILED = 90027;
public static final int SERIALIZATION_FAILED_1 = 90026;
public static final int DESERIALIZATION_FAILED_1 = 90027;
public static final int IO_EXCEPTION_1 = 90028;
public static final int NOT_ON_UPDATABLE_ROW = 90029;
public static final int FILE_CORRUPTED_1 = 90030;
public static final int IO_EXCEPTION_2 = 90031;
public static final int USER_NOT_FOUND_1 = 90032;
public static final int USER_ALREADY_EXISTS_1 = 90033;
public static final int LOG_FILE_ERROR_1 = 90034;
public static final int LOG_FILE_ERROR_2 = 90034;
public static final int SEQUENCE_ALREADY_EXISTS_1 = 90035;
public static final int SEQUENCE_NOT_FOUND_1 = 90036;
public static final int VIEW_NOT_FOUND_1 = 90037;
......@@ -154,8 +154,8 @@ public class ErrorCode {
public static final int ADMIN_RIGHTS_REQUIRED = 90040;
public static final int TRIGGER_ALREADY_EXISTS_1 = 90041;
public static final int TRIGGER_NOT_FOUND_1 = 90042;
public static final int ERROR_CREATING_TRIGGER_OBJECT_2 = 90043;
public static final int ERROR_EXECUTING_TRIGGER_2 = 90044;
public static final int ERROR_CREATING_TRIGGER_OBJECT_3 = 90043;
public static final int ERROR_EXECUTING_TRIGGER_3 = 90044;
public static final int CONSTRAINT_ALREADY_EXISTS_1 = 90045;
public static final int URL_FORMAT_ERROR_2 = 90046;
public static final int DRIVER_VERSION_ERROR_2 = 90047;
......@@ -172,7 +172,7 @@ public class ErrorCode {
public static final int DUPLICATE_TABLE_ALIAS = 90058;
public static final int AMBIGUOUS_COLUMN_NAME_1 = 90059;
public static final int UNSUPPORTED_LOCK_METHOD_1 = 90060;
public static final int EXCEPTION_OPENING_PORT_1 = 90061;
public static final int EXCEPTION_OPENING_PORT_2 = 90061;
public static final int FILE_CREATION_FAILED_1 = 90062;
public static final int SAVEPOINT_IS_INVALID_1 = 90063;
public static final int SAVEPOINT_IS_UNNAMED = 90064;
......@@ -254,7 +254,7 @@ public class ErrorCode {
public static final int NOT_ENOUGH_RIGHTS_FOR_1 = 90096;
public static final int DATABASE_IS_READ_ONLY = 90097;
public static final int SIMULATED_POWER_OFF = 90098;
public static final int ERROR_SETTING_DATABASE_EVENT_LISTENER = 90099;
public static final int ERROR_SETTING_DATABASE_EVENT_LISTENER_2 = 90099;
public static final int NO_DISK_SPACE_AVAILABLE = 90100;
public static final int WRONG_XID_FORMAT_1 = 90101;
public static final int UNSUPPORTED_COMPRESSION_OPTIONS_1 = 90102;
......@@ -266,7 +266,7 @@ public class ErrorCode {
public static final int STACK_OVERFLOW = 90108;
public static final int VIEW_IS_INVALID_2 = 90109;
public static final int OVERFLOW_FOR_TYPE_1 = 90110;
public static final int ERROR_ACCESSING_LINKED_TABLE_1 = 90111;
public static final int ERROR_ACCESSING_LINKED_TABLE_2 = 90111;
/**
* When locking was disabled, a row was deleted twice.
......
......@@ -327,7 +327,7 @@ public class ConnectionInfo {
public SQLException getFormatException() {
String format = Constants.URL_FORMAT;
return Message.getSQLException(ErrorCode.URL_FORMAT_ERROR_2, new String[]{format, url}, null);
return Message.getSQLException(ErrorCode.URL_FORMAT_ERROR_2, new String[]{format, url});
}
}
......@@ -1140,7 +1140,7 @@ public class Database implements DataHandler {
String invalid = getFirstInvalidTable();
if(invalid != null) {
obj.getSchema().add(obj);
throw Message.getSQLException(ErrorCode.CANNOT_DROP_2, new String[]{obj.getSQL(), invalid}, null);
throw Message.getSQLException(ErrorCode.CANNOT_DROP_2, new String[]{obj.getSQL(), invalid});
}
int id = obj.getId();
obj.removeChildrenAndResources(session);
......@@ -1246,7 +1246,7 @@ public class Database implements DataHandler {
eventListener = (DatabaseEventListener)loadClass(className).newInstance();
eventListener.init(databaseURL);
} catch (Throwable e) {
throw Message.getSQLException(ErrorCode.ERROR_SETTING_DATABASE_EVENT_LISTENER, new String[]{className}, e);
throw Message.getSQLException(ErrorCode.ERROR_SETTING_DATABASE_EVENT_LISTENER_2, new String[]{className, e.toString()}, e);
}
}
}
......
......@@ -9,7 +9,6 @@ import java.util.Comparator;
import org.h2.api.DatabaseEventListener;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
import org.h2.message.Message;
import org.h2.message.Trace;
import org.h2.result.SearchRow;
......
......@@ -341,7 +341,7 @@ public class Function extends Expression implements FunctionCall {
varArgs.add(param);
} else {
if(index >= args.length) {
throw Message.getSQLException(ErrorCode.INVALID_PARAMETER_COUNT_2, new String[] {info.name, "" + args.length}, null);
throw Message.getSQLException(ErrorCode.INVALID_PARAMETER_COUNT_2, new String[] {info.name, "" + args.length});
}
args[index] = param;
}
......@@ -957,7 +957,7 @@ public class Function extends Expression implements FunctionCall {
private static int getDatePart(String part) throws SQLException {
Integer p = (Integer) datePart.get(StringUtils.toUpperEnglish(part));
if(p==null) {
throw Message.getSQLException(ErrorCode.INVALID_VALUE_2, new String[] { "date part", part }, null);
throw Message.getSQLException(ErrorCode.INVALID_VALUE_2, new String[] { "date part", part });
}
return p.intValue();
}
......@@ -1300,7 +1300,7 @@ public class Function extends Expression implements FunctionCall {
}
boolean ok = (len >= min) && (len <= max);
if(!ok) {
throw Message.getSQLException(ErrorCode.INVALID_PARAMETER_COUNT_2, new String[]{info.name, min + ".." + max}, null);
throw Message.getSQLException(ErrorCode.INVALID_PARAMETER_COUNT_2, new String[]{info.name, min + ".." + max});
}
args = new Expression[len];
varArgs.toArray(args);
......@@ -1308,7 +1308,7 @@ public class Function extends Expression implements FunctionCall {
} else {
int len = args.length;
if(len>0 && args[len-1] == null) {
throw Message.getSQLException(ErrorCode.INVALID_PARAMETER_COUNT_2, new String[]{info.name, "" + len}, null);
throw Message.getSQLException(ErrorCode.INVALID_PARAMETER_COUNT_2, new String[]{info.name, "" + len});
}
}
}
......
......@@ -75,7 +75,7 @@ public class LinkedIndex extends Index {
prep.executeUpdate();
rowCount++;
} catch(SQLException e) {
throw Message.getSQLException(ErrorCode.ERROR_ACCESSING_LINKED_TABLE_1, new String[]{sql}, e);
throw wrapException(sql, e);
}
}
......@@ -126,7 +126,7 @@ public class LinkedIndex extends Index {
ResultSet rs = prep.executeQuery();
return new LinkedCursor(table, rs, session);
} catch(SQLException e) {
throw Message.getSQLException(ErrorCode.ERROR_ACCESSING_LINKED_TABLE_1, new String[]{sql}, e);
throw wrapException(sql, e);
}
}
......@@ -195,7 +195,7 @@ public class LinkedIndex extends Index {
int count = prep.executeUpdate();
rowCount -= count;
} catch(SQLException e) {
throw Message.getSQLException(ErrorCode.ERROR_ACCESSING_LINKED_TABLE_1, new String[]{sql}, e);
throw wrapException(sql, e);
}
}
......@@ -238,8 +238,12 @@ public class LinkedIndex extends Index {
}
prep.executeUpdate();
} catch(SQLException e) {
throw Message.getSQLException(ErrorCode.ERROR_ACCESSING_LINKED_TABLE_1, new String[]{sql}, e);
throw wrapException(sql, e);
}
}
private SQLException wrapException(String sql, SQLException e) {
return Message.getSQLException(ErrorCode.ERROR_ACCESSING_LINKED_TABLE_2, new String[]{sql, e.toString()}, e);
}
}
......@@ -63,7 +63,7 @@ public class Message {
* @return the SQLException object
*/
public static JdbcSQLException getSQLException(int sqlState, String p1) {
return getSQLException(sqlState, new String[] { p1 }, null);
return getSQLException(sqlState, new String[] { p1 });
}
public static String translate(String key, String[] param) {
......@@ -84,6 +84,10 @@ public class Message {
return new JdbcSQLException(message, null, sqlstate, errorCode, cause, null);
}
public static JdbcSQLException getSQLException(int errorCode, String[] param) {
return getSQLException(errorCode, param);
}
public static SQLException getSyntaxError(String sql, int index) {
sql = StringUtils.addAsterisk(sql, index);
return getSQLException(ErrorCode.SYNTAX_ERROR_1, sql);
......@@ -91,7 +95,7 @@ public class Message {
public static SQLException getSyntaxError(String sql, int index, String expected) {
sql = StringUtils.addAsterisk(sql, index);
return getSQLException(ErrorCode.SYNTAX_ERROR_2, new String[]{sql, expected}, null);
return getSQLException(ErrorCode.SYNTAX_ERROR_2, new String[]{sql, expected});
}
/**
......@@ -102,7 +106,7 @@ public class Message {
* @return the SQLException object
*/
public static JdbcSQLException getSQLException(int sqlstate) {
return getSQLException(sqlstate, null);
return getSQLException(sqlstate, (String)null);
}
public static JdbcSQLException getUnsupportedException() {
......@@ -110,7 +114,7 @@ public class Message {
}
public static JdbcSQLException getInvalidValueException(String value, String param) {
return getSQLException(ErrorCode.INVALID_VALUE_2, new String[]{value, param}, null);
return getSQLException(ErrorCode.INVALID_VALUE_2, new String[]{value, param});
}
public static Error getInternalError(String s) {
......
......@@ -193,7 +193,7 @@ public class TraceSystem {
}
writingErrorLogged = true;
// TODO translate trace messages
SQLException se = Message.getSQLException(ErrorCode.LOG_FILE_ERROR_1, new String[] { fileName }, e);
SQLException se = Message.getSQLException(ErrorCode.LOG_FILE_ERROR_2, new String[] { fileName, e.toString() }, e);
// print this error only once
fileName = null;
System.out.println(se);
......
......@@ -29,9 +29,9 @@
90006=NULL not allowed for column {0}
90007=The object is already closed
90008=Invalid value {0} for parameter {1}
90009=Cannot parse date constant {0}
90010=Cannot parse time constant {0}
90011=Cannot parse timestamp constant {0}
90009=Cannot parse date constant {0}, cause\: {1}
90010=Cannot parse time constant {0}, cause\: {1}
90011=Cannot parse timestamp constant {0}, cause\: {1}
90012=Parameter {0} is not set
90013=Database {0} not found
90014=Error parsing {0}
......@@ -46,15 +46,15 @@
90023=Column {0} must not be nullable
90024=Error while renaming file {0} to {1}
90025=Cannot delete file {0}
90026=Serialization failed
90027=Deserialization failed
90026=Serialization failed, cause\: {0}
90027=Deserialization failed, cause\: {0}
90028=IO Exception\: {0}
90029=Currently not on an updatable row
90030=File corrupted while reading record\: {0}. Possible solution\: use the recovery tool
90031=IO Exception\: {0}; {1}
90032=User {0} not found
90033=User {0} already exists
90034=Log file error\: {0}
90034=Log file error\: {0}, cause\: {1}
90035=Sequence {0} already exists
90036=Sequence {0} not found
90037=View {0} not found
......@@ -63,8 +63,8 @@
90040=Admin rights are required for this operation
90041=Trigger {0} already exists
90042=Trigger {0} not found
90043=Error creating or initializing trigger {0} object, class {1}; see root cause for details
90044=Error executing trigger {0}, class {1}; see root cause for details
90043=Error creating or initializing trigger {0} object, class {1}, cause\: {2}; see root cause for details
90044=Error executing trigger {0}, class {1}, cause \: {2}; see root cause for details
90045=Constraint {0} already exists
90046=URL format error; must be {0} but is {1}
90047=Version mismatch, driver version is {0} but server version is {1}
......@@ -81,7 +81,7 @@
90058=Duplicate table or table alias {0}
90059=Ambiguous column name {0}
90060=Unsupported file lock method {0}
90061=Exception opening port {0} (port may be in use)
90061=Exception opening port {0} (port may be in use), cause\: {1}
90062=Error while creating file {0}
90063=Savepoint is invalid\: {0}
90064=Savepoint is unnamed
......@@ -119,7 +119,7 @@
90096=Not enough rights for object {0}
90097=The database is read only
90098=The database has been closed
90099=Error setting database event listener {0}
90099=Error setting database event listener {0}, cause\: {1}
90100=No disk space available
90101=Wrong XID format\: {0}
90102=Unsupported compression options\: {0}
......@@ -131,7 +131,7 @@
90108=Stack overflow (recursive query or function?)
90109=View {0} is invalid\: {1}
90110={0} out of range
90111=Error accessing linked table with SQL statement {0}
90111=Error accessing linked table with SQL statement {0}, cause\: {1}
90112=Row not found when trying to delete from index {0}
90113=Unsupported connection setting {0}
90114=Constant {0} already exists
......
......@@ -56,7 +56,7 @@ public class TriggerObject extends SchemaObject {
triggerCallback = (Trigger)obj;
triggerCallback.init(c2, getSchema().getName(), getName(), table.getName());
} catch(Throwable e) {
throw Message.getSQLException(ErrorCode.ERROR_CREATING_TRIGGER_OBJECT_2, new String[]{getName(), triggerClassName}, e);
throw Message.getSQLException(ErrorCode.ERROR_CREATING_TRIGGER_OBJECT_3, new String[]{getName(), triggerClassName, e.toString()}, e);
}
}
......@@ -68,7 +68,7 @@ public class TriggerObject extends SchemaObject {
try {
triggerCallback.fire(c2, null, null);
} catch(Throwable e) {
throw Message.getSQLException(ErrorCode.ERROR_EXECUTING_TRIGGER_2, new String[]{getName(), triggerClassName}, e);
throw Message.getSQLException(ErrorCode.ERROR_EXECUTING_TRIGGER_3, new String[]{getName(), triggerClassName, e.toString()}, e);
}
}
......
......@@ -8,13 +8,14 @@ import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Properties;
import org.h2.Driver;
import org.h2.engine.Constants;
import org.h2.message.TraceSystem;
import org.h2.util.JdbcUtils;
......@@ -51,7 +52,11 @@ public class TcpServer implements Service {
}
private void initManagementDb() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:h2:" + getManagementDbName(port), "sa", managementPassword);
Properties prop = new Properties();
prop.setProperty("user", "sa");
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 {
......
......@@ -55,7 +55,7 @@ public class TcpServerThread implements Runnable {
}
if(version != Constants.TCP_DRIVER_VERSION) {
throw Message.getSQLException(ErrorCode.DRIVER_VERSION_ERROR_2,
new String[] { "" + version, "" + Constants.TCP_DRIVER_VERSION }, null);
new String[] { "" + version, "" + Constants.TCP_DRIVER_VERSION });
}
String db = transfer.readString();
String originalURL = transfer.readString();
......
......@@ -21,6 +21,7 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Properties;
import org.h2.Driver;
import org.h2.engine.Constants;
import org.h2.server.Service;
import org.h2.util.FileUtils;
......@@ -177,8 +178,13 @@ public class FtpServer implements Service {
}
}
if(root.startsWith("jdbc:")) {
org.h2.Driver.load();
Connection conn = DriverManager.getConnection(root);
Connection conn;
if(root.startsWith("jdbc:h2:")) {
// avoid using DriverManager if possible
conn = Driver.load().connect(root, new Properties());
} else {
conn = DriverManager.getConnection(root);
}
db = new FileSystemDatabase(conn, log);
root = "/";
}
......
......@@ -6,21 +6,22 @@ package org.h2.server.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class PageParser {
private WebServer server;
private String page;
private int pos;
private HashMap settings;
private Map settings;
private int len;
private StringBuffer result;
public static String parse(WebServer server, String page, HashMap settings) {
public static String parse(WebServer server, String page, Map settings) {
PageParser block = new PageParser(server, page, settings, 0);
return block.parse();
}
private PageParser(WebServer server, String page, HashMap settings, int pos) {
private PageParser(WebServer server, String page, Map settings, int pos) {
this.server = server;
this.page = page;
this.pos = pos;
......
......@@ -56,6 +56,7 @@ public class WebServer implements Service {
};
private static final String[] GENERIC = new String[] {
"Generic JNDI Data Source|javax.naming.InitialContext|java:comp/env/jdbc/Test|sa",
"Generic Firebird Server|org.firebirdsql.jdbc.FBDriver|jdbc:firebirdsql:localhost:c:/temp/firebird/test|sysdba",
"Generic OneDollarDB|in.co.daffodil.db.jdbc.DaffodilDBDriver|jdbc:daffodilDB_embedded:school;path=C:/temp;create=true|sa",
"Generic DB2|COM.ibm.db2.jdbc.net.DB2Driver|jdbc:db2://<host>/<db>|" ,
......@@ -67,6 +68,7 @@ public class WebServer implements Service {
"Generic Derby (Embedded)|org.apache.derby.jdbc.EmbeddedDriver|jdbc:derby:test;create=true|sa",
"Generic Derby (Server)|org.apache.derby.jdbc.ClientDriver|jdbc:derby://localhost:1527/test;create=true|sa",
"Generic HSQLDB|org.hsqldb.jdbcDriver|jdbc:hsqldb:test;hsqldb.default_table_type=cached|sa" ,
// this will be listed on top for new installations
"Generic H2|org.h2.Driver|jdbc:h2:~/test|sa",
};
......
......@@ -108,7 +108,7 @@ public class TableLink extends Table {
columnMap.put(n, col);
}
} catch(SQLException e) {
throw Message.getSQLException(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, new String[]{originalTable}, e);
throw Message.getSQLException(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, new String[]{originalTable + "(" + e.toString() + ")"}, e);
} finally {
JdbcUtils.closeSilently(stat);
}
......
......@@ -9,7 +9,6 @@ import java.sql.SQLException;
import java.util.LinkedList;
import org.h2.constant.ErrorCode;
import org.h2.message.Message;
class RunScriptThread extends Thread {
private int id;
......
......@@ -170,7 +170,7 @@ public class ByteUtils {
os.writeObject(obj);
return out.toByteArray();
} catch(Throwable e) {
throw Message.getSQLException(ErrorCode.SERIALIZATION_FAILED, null, e);
throw Message.getSQLException(ErrorCode.SERIALIZATION_FAILED_1, new String[]{e.toString()}, e);
}
}
......@@ -181,7 +181,7 @@ public class ByteUtils {
Object obj = is.readObject();
return obj;
} catch(Throwable e) {
throw Message.getSQLException(ErrorCode.DESERIALIZATION_FAILED, null, e);
throw Message.getSQLException(ErrorCode.DESERIALIZATION_FAILED_1, new String[]{e.toString()}, e);
}
}
......
......@@ -211,7 +211,7 @@ public class DateTimeUtils {
throw Message.getInternalError("type:"+type);
}
} catch(IllegalArgumentException e) {
throw Message.getSQLException(errorCode, new String[]{original}, e);
throw Message.getSQLException(errorCode, new String[]{original, e.toString()}, e);
}
}
......
......@@ -142,10 +142,10 @@ public class FileUtils {
throw Message.getInternalError("rename file old=new");
}
if(!oldFile.exists()) {
throw Message.getSQLException(ErrorCode.FILE_RENAME_FAILED_2, new String[]{oldName + " (not found)", newName}, null);
throw Message.getSQLException(ErrorCode.FILE_RENAME_FAILED_2, new String[]{oldName + " (not found)", newName});
}
if(newFile.exists()) {
throw Message.getSQLException(ErrorCode.FILE_RENAME_FAILED_2, new String[]{oldName, newName + " (exists)"}, null);
throw Message.getSQLException(ErrorCode.FILE_RENAME_FAILED_2, new String[]{oldName, newName + " (exists)"});
}
for(int i=0; i<SysProperties.MAX_FILE_RETRY; i++) {
trace("rename", oldName + " >" + newName, null);
......@@ -155,7 +155,7 @@ public class FileUtils {
}
wait(i);
}
throw Message.getSQLException(ErrorCode.FILE_RENAME_FAILED_2, new String[]{oldName, newName}, null);
throw Message.getSQLException(ErrorCode.FILE_RENAME_FAILED_2, new String[]{oldName, newName});
}
public static synchronized Properties loadProperties(String fileName) throws IOException {
......
......@@ -196,6 +196,7 @@ public class IntArray {
}
public void sort() {
// insertion sort
for (int i = 1, j; i < size(); i++) {
int t = get(i);
for (j = i - 1; j >= 0 && (get(j) > t); j--) {
......
......@@ -11,6 +11,9 @@ import java.sql.SQLException;
import java.sql.Statement;
//#ifdef JDK14
import javax.naming.Context;
import javax.naming.NamingException;
import javax.sql.DataSource;
import javax.sql.XAConnection;
//#endif
......@@ -72,7 +75,26 @@ public class JdbcUtils {
public static Connection getConnection(String driver, String url, String user, String password) throws SQLException {
if(!StringUtils.isNullOrEmpty(driver)) {
try {
ClassUtils.loadClass(driver);
Class d = ClassUtils.loadClass(driver);
if(java.sql.Driver.class.isAssignableFrom(d)) {
return DriverManager.getConnection(url, user, password);
} else if(javax.naming.Context.class.isAssignableFrom(d)) {
// JNDI context
try {
Context context = (Context) d.newInstance();
DataSource ds = (DataSource) context.lookup(url);
return ds.getConnection(user, password);
} catch (InstantiationException e) {
throw Message.convert(e);
} catch (IllegalAccessException e) {
throw Message.convert(e);
} catch (NamingException e) {
throw Message.convert(e);
}
} else {
// Don't know, but maybe it loaded a JDBC Driver
return DriverManager.getConnection(url, user, password);
}
} catch (ClassNotFoundException e) {
throw Message.getSQLException(ErrorCode.CLASS_NOT_FOUND_1, new String[]{driver}, e);
}
......
......@@ -51,7 +51,7 @@ public class NetUtils {
return new ServerSocket(port);
}
} catch(BindException be) {
throw Message.getSQLException(ErrorCode.EXCEPTION_OPENING_PORT_1, new String[]{""+port}, be);
throw Message.getSQLException(ErrorCode.EXCEPTION_OPENING_PORT_2, new String[]{""+port, be.toString()}, be);
} catch(IOException e) {
throw Message.convertIOException(e, "port: " + port + " ssl: " + ssl);
}
......
......@@ -166,9 +166,11 @@ public class ObjectArray {
}
private void sort(Comparator comp, int l, int r) {
// quicksort
int i, j;
while (r - l > 10) {
i = (r + l) >> 1;
// randomized pivot to avoid worst case
i = RandomUtils.nextInt(r - l - 4) + l + 2;
if (comp.compare(get(l), get(r)) > 0) {
swap(l, r);
}
......
......@@ -9,7 +9,6 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.message.Message;
import org.h2.util.DateTimeUtils;
/**
......@@ -25,7 +24,7 @@ public class ValueDate extends Value {
}
public static Date parseDate(String s) throws SQLException {
return (Date) DateTimeUtils.parseDateTime(s, Value.DATE, ErrorCode.DATE_CONSTANT_1);
return (Date) DateTimeUtils.parseDateTime(s, Value.DATE, ErrorCode.DATE_CONSTANT_2);
}
public Date getDate() {
......
......@@ -35,7 +35,7 @@ public class ValueDecimal extends Value {
if (value == null) {
throw new IllegalArgumentException();
} else if(!SysProperties.ALLOW_BIG_DECIMAL_EXTENSIONS && !value.getClass().equals(BigDecimal.class)) {
SQLException e = Message.getSQLException(ErrorCode.INVALID_CLASS_2, new String[]{BigDecimal.class.getName(), value.getClass().getName()}, null);
SQLException e = Message.getSQLException(ErrorCode.INVALID_CLASS_2, new String[]{BigDecimal.class.getName(), value.getClass().getName()});
throw Message.convertToInternal(e);
}
this.value = value;
......
......@@ -23,7 +23,8 @@ public class ValueString extends ValueStringBase {
}
protected int compareSecure(Value o, CompareMode mode) {
ValueString v = (ValueString) o;
// compatibility: the other object could be ValueStringFixed
ValueStringBase v = (ValueStringBase) o;
return mode.compareString(value, v.value, false);
}
......
......@@ -18,7 +18,8 @@ public class ValueStringFixed extends ValueStringBase {
}
protected int compareSecure(Value o, CompareMode mode) throws SQLException {
ValueStringFixed v = (ValueStringFixed) o;
// compatibility: the other object could be ValueString
ValueStringBase v = (ValueStringBase) o;
return mode.compareString(value, v.value, false);
}
......
......@@ -19,7 +19,7 @@ public class ValueTime extends Value {
}
public static Time parseTime(String s) throws SQLException {
return (Time) DateTimeUtils.parseDateTime(s, Value.TIME, ErrorCode.TIME_CONSTANT_1);
return (Time) DateTimeUtils.parseDateTime(s, Value.TIME, ErrorCode.TIME_CONSTANT_2);
}
public Time getTime() {
......
......@@ -36,7 +36,7 @@ public class ValueTimestamp extends Value {
}
public static Timestamp parseTimestamp(String s) throws SQLException {
return (Timestamp) DateTimeUtils.parseDateTime(s, Value.TIMESTAMP, ErrorCode.TIMESTAMP_CONSTANT_1);
return (Timestamp) DateTimeUtils.parseDateTime(s, Value.TIMESTAMP, ErrorCode.TIMESTAMP_CONSTANT_2);
}
public int getType() {
......
......@@ -6,13 +6,16 @@ package org.h2.test.unit;
import java.util.Arrays;
import java.util.Random;
import org.h2.test.TestBase;
import org.h2.util.IntArray;
public class TestIntArray extends TestBase {
public void test() throws Exception {
testRandom();
}
private void testRandom() throws Exception {
IntArray array = new IntArray();
int[] test = new int[0];
Random random = new Random(1);
......
......@@ -19,7 +19,11 @@ import org.h2.util.StringUtils;
public class PropertiesToUTF8 {
public static void main(String[] args) throws Exception {
File[] list = new File("bin/org/h2/server/web/res").listFiles();
convert("bin/org/h2/server/web/res", ".");
}
private static void convert(String source, String target) throws Exception {
File[] list = new File(source).listFiles();
for(int i=0; list != null && i<list.length; i++) {
File f = list[i];
if(!f.getName().endsWith(".properties")) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论