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

--no commit message

--no commit message
上级 958e48d2
......@@ -26,8 +26,8 @@ public class Bnf {
private static final String SEPARATORS = " [](){}|.,\r\n<>:-+*/=<\">!'";
private static final long MAX_PARSE_TIME = 100;
private Random random;
private HashMap ruleMap = new HashMap();
private final Random random = new Random();
private final HashMap ruleMap = new HashMap();
private String syntax;
private String currentToken;
private String[] tokens;
......@@ -54,7 +54,6 @@ public class Bnf {
}
Bnf() {
this.random = new Random();
random.setSeed(1);
}
......@@ -170,8 +169,7 @@ public class Bnf {
private Rule parseRule() {
read();
Rule r= parseOr();
return r;
return parseOr();
}
private Rule parseOr() {
......
......@@ -86,7 +86,7 @@ public class RuleElement implements Rule {
String up = StringUtils.toUpperEnglish(query);
if(up.startsWith(name)) {
query = query.substring(name.length());
while(!name.equals("_") && query.length()>0 && Character.isWhitespace(query.charAt(0))) {
while(!"_".equals(name) && query.length()>0 && Character.isWhitespace(query.charAt(0))) {
query = query.substring(1);
}
return query;
......
......@@ -18,7 +18,7 @@ public class RuleFixed implements Rule {
public static final int ANY_WORD = 7;
public static final int HEX_START = 10, CONCAT = 11, AZ_ = 12, AF = 13, DIGIT = 14;
private int type;
private final int type;
public RuleFixed(int type) {
this.type = type;
......@@ -212,14 +212,14 @@ public class RuleFixed implements Rule {
case HEX_START:
if(query.length() == 0) {
sentence.add("0x", "0x", Sentence.KEYWORD);
} else if(query.equals("0")) {
} else if("0".equals(query)) {
sentence.add("0x", "x", Sentence.KEYWORD);
}
break;
case CONCAT:
if(query.length() == 0) {
sentence.add("||", "||", Sentence.KEYWORD);
} else if(query.equals("|")) {
} else if("|".equals(query)) {
sentence.add("||", "|", Sentence.KEYWORD);
}
break;
......
......@@ -61,13 +61,12 @@ public abstract class Command implements CommandInterface {
public LocalResult executeQueryLocal(int maxrows) throws SQLException {
startTime = System.currentTimeMillis();
Database database = session.getDatabase();
Object sync = Constants.MULTI_THREADED_KERNEL ? (Object)session : (Object)database;
Object sync = Constants.multiThreadedKernel ? (Object)session : (Object)database;
synchronized (sync) {
try {
database.checkPowerOff();
session.setCurrentCommand(this);
LocalResult result = query(maxrows);
return result;
return query(maxrows);
} catch(Throwable e) {
SQLException s = Message.convert(e);
database.exceptionThrown(s, sql);
......@@ -95,7 +94,7 @@ public abstract class Command implements CommandInterface {
session.commit(true);
} else if (session.getAutoCommit()) {
session.commit(false);
} else if (Constants.MULTI_THREADED_KERNEL) {
} else if (Constants.multiThreadedKernel) {
Database db = session.getDatabase();
if (db != null && db.getLockMode() == Constants.LOCK_MODE_READ_COMMITTED) {
session.unlockReadLocks();
......@@ -112,14 +111,13 @@ public abstract class Command implements CommandInterface {
public int executeUpdate() throws SQLException {
startTime = System.currentTimeMillis();
Database database = session.getDatabase();
Object sync = Constants.MULTI_THREADED_KERNEL ? (Object)session : (Object)database;
Object sync = Constants.multiThreadedKernel ? (Object)session : (Object)database;
synchronized (sync) {
int rollback = session.getLogId();
session.setCurrentCommand(this);
try {
database.checkPowerOff();
int result = update();
return result;
return update();
} catch (SQLException e) {
database.exceptionThrown(e, sql);
database.checkPowerOff();
......
......@@ -186,8 +186,7 @@ public class Parser {
public Prepared parseOnly(String sql) throws SQLException {
try {
Prepared p = parse(sql);
return p;
return parse(sql);
} catch(Exception e) {
throw Message.convert(e);
}
......@@ -489,8 +488,7 @@ public class Parser {
readIf("SCRIPT");
}
}
TransactionCommand command = new TransactionCommand(session, type);
return command;
return new TransactionCommand(session, type);
}
private TransactionCommand parseRollback() throws SQLException {
......@@ -623,8 +621,7 @@ public class Parser {
alias = readAliasIdentifier();
}
}
TableFilter filter = new TableFilter(session, table, alias, rightsChecked, currentSelect);
return filter;
return new TableFilter(session, table, alias, rightsChecked, currentSelect);
}
private Delete parseDelete() throws SQLException {
......@@ -694,8 +691,7 @@ public class Parser {
buff.append("UPPER(TOPIC) LIKE ");
buff.append(StringUtils.quoteStringSQL("%"+s+"%"));
}
Prepared command = session.prepare(buff.toString());
return command;
return session.prepare(buff.toString());
}
private Merge parseMerge() throws SQLException {
......@@ -817,7 +813,7 @@ public class Parser {
}
table = new FunctionTable(mainSchema, session, (FunctionCall)func);
}
} else if(tableName.equals("DUAL")) {
} else if("DUAL".equals(tableName)) {
table = new RangeTable(mainSchema, 1, 1);
} else {
table = readTableOrView(tableName);
......@@ -832,8 +828,7 @@ public class Parser {
alias = readAliasIdentifier();
}
}
TableFilter filter = new TableFilter(session, table, alias, rightsChecked, currentSelect);
return filter;
return new TableFilter(session, table, alias, rightsChecked, currentSelect);
}
private Prepared parseTruncate() throws SQLException {
......@@ -2683,31 +2678,31 @@ public class Parser {
} else if(s.length()==2) {
switch (c0) {
case ':':
if(s.equals("::")) {
if("::".equals(s)) {
return KEYWORD;
}
break;
case '>':
if(s.equals(">=")) {
if(">=".equals(s)) {
return BIGGER_EQUAL;
}
break;
case '<':
if (s.equals("<=")) {
if ("<=".equals(s)) {
return SMALLER_EQUAL;
} else if (s.equals("<>")) {
} else if ("<>".equals(s)) {
return NOT_EQUAL;
}
break;
case '!':
if (s.equals("!=")) {
if ("!=".equals(s)) {
return NOT_EQUAL;
} else if(s.equals("!~")) {
} else if("!~".equals(s)) {
return KEYWORD;
}
break;
case '|':
if(s.equals("||")) {
if("||".equals(s)) {
return STRING_CONCAT;
}
break;
......@@ -2746,16 +2741,16 @@ public class Parser {
case 'D':
return getKeywordOrIdentifier(s, "DISTINCT", KEYWORD);
case 'E':
if(s.equals("EXCEPT")) {
if("EXCEPT".equals(s)) {
return KEYWORD;
}
return getKeywordOrIdentifier(s, "EXISTS", KEYWORD);
case 'F':
if(s.equals("FROM")) {
if("FROM".equals(s)) {
return KEYWORD;
} else if(s.equals("FOR")) {
} else if("FOR".equals(s)) {
return KEYWORD;
} else if(s.equals("FULL")) {
} else if("FULL".equals(s)) {
return KEYWORD;
}
return getKeywordOrIdentifier(s, "FALSE", FALSE);
......@@ -2764,33 +2759,33 @@ public class Parser {
case 'H':
return getKeywordOrIdentifier(s, "HAVING", KEYWORD);
case 'I':
if (s.equals("INNER")) {
if ("INNER".equals(s)) {
return KEYWORD;
} else if(s.equals("INTERSECT")) {
} else if("INTERSECT".equals(s)) {
return KEYWORD;
}
return getKeywordOrIdentifier(s, "IS", KEYWORD);
case 'J':
return getKeywordOrIdentifier(s, "JOIN", KEYWORD);
case 'L':
if (s.equals("LIMIT")) {
if ("LIMIT".equals(s)) {
return KEYWORD;
}
return getKeywordOrIdentifier(s, "LIKE", KEYWORD);
case 'M':
if(s.equals("MINUS")) {
if("MINUS".equals(s)) {
return KEYWORD;
}
break;
case 'N':
if(s.equals("NOT")) {
if("NOT".equals(s)) {
return KEYWORD;
} else if(s.equals("NATURAL")) {
} else if("NATURAL".equals(s)) {
return KEYWORD;
}
return getKeywordOrIdentifier(s, "NULL", NULL);
case 'O':
if (s.equals("ON")) {
if ("ON".equals(s)) {
return KEYWORD;
}
return getKeywordOrIdentifier(s, "ORDER", KEYWORD);
......@@ -2808,7 +2803,7 @@ public class Parser {
}
return getKeywordOrIdentifier(s, "SELECT", KEYWORD);
case 'T':
if(s.equals("TODAY")) {
if("TODAY".equals(s)) {
return CURRENT_DATE;
}
return getKeywordOrIdentifier(s, "TRUE", TRUE);
......
......@@ -37,7 +37,6 @@ public class AlterTableAddConstraint extends SchemaCommand {
private int type;
private String constraintName;
private String tableName;
private Table table;
private String[] columnNames;
private int deleteAction;
private int updateAction;
......@@ -62,7 +61,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
public int update() throws SQLException {
session.commit(true);
Database db = session.getDatabase();
table = getSchema().getTableOrView(session, tableName);
Table table = getSchema().getTableOrView(session, tableName);
if(getSchema().findConstraint(constraintName)!=null) {
throw Message.getSQLException(Message.CONSTRAINT_ALREADY_EXISTS_1,
constraintName);
......
......@@ -34,7 +34,6 @@ public class CreateTable extends SchemaCommand {
private boolean ifNotExists;
private boolean persistent = true;
private boolean hashPrimaryKey;
private ObjectArray sequences;
private boolean temporary;
private boolean globalTemporary;
private boolean onCommitDrop;
......@@ -107,7 +106,7 @@ public class CreateTable extends SchemaCommand {
}
}
}
sequences = new ObjectArray();
ObjectArray sequences = new ObjectArray();
for(int i=0; i<columns.size(); i++) {
Column c = (Column) columns.get(i);
if(c.getAutoIncrement()) {
......
......@@ -59,7 +59,7 @@ public abstract class ScriptBase extends Prepared implements DataHandler {
if(fileName == null || fileName.trim().length() == 0) {
fileName = "script.sql";
}
this.fileName = Constants.SCRIPT_DIRECTORY + fileName;
this.fileName = Constants.scriptDirectory + fileName;
}
public boolean isTransactional() {
......
......@@ -169,7 +169,7 @@ public class Set extends Prepared {
}
case SetTypes.MULTI_THREADED: {
session.getUser().checkAdmin();
Constants.MULTI_THREADED_KERNEL = (getIntValue() == 1);
Constants.multiThreadedKernel = (getIntValue() == 1);
break;
}
case SetTypes.DB_CLOSE_DELAY: {
......
......@@ -22,9 +22,9 @@ public class CompressDeflate implements Compressor {
StringTokenizer tokenizer = new StringTokenizer(options);
while(tokenizer.hasMoreElements()) {
String option = tokenizer.nextToken();
if(option.equals("level") || option.equals("l")) {
if("level".equals(option) || "l".equals(option)) {
level = Integer.parseInt(tokenizer.nextToken());
} else if(option.equals("strategy") || option.equals("s")) {
} else if("strategy".equals(option) || "s".equals(option)) {
strategy = Integer.parseInt(tokenizer.nextToken());
}
}
......
......@@ -75,7 +75,7 @@ public class ConnectionInfo {
}
private void parseName() {
if(name.equals(".")) {
if(".".equals(name)) {
name = "mem:";
}
if(name.startsWith("tcp:")) {
......@@ -87,7 +87,7 @@ public class ConnectionInfo {
name = name.substring("ssl:".length());
} else if(name.startsWith("mem:")) {
persistent = false;
if(name.equals("mem:")) {
if("mem:".equals(name)) {
unnamed = true;
}
} else if(name.startsWith("file:")) {
......
......@@ -77,7 +77,6 @@ public class Constants {
public static final String MAGIC_FILE_HEADER_TEXT = "-- H2 0.5/T -- ".substring(0, FILE_BLOCK_SIZE-1) + "\n";
public static final String MAGIC_FILE_HEADER = "-- H2 0.5/B -- ".substring(0, FILE_BLOCK_SIZE-1) + "\n";
public static final int TCP_DRIVER_VERSION = 4;
public static final int VERSION_JDBC_MAJOR = 3;
public static final int VERSION_JDBC_MINOR = 0;
......@@ -88,22 +87,14 @@ public class Constants {
public static final int NULL_SORT_LOW = 1, NULL_SORT_HIGH = 2;
public static final int NULL_SORT_START = 3, NULL_SORT_END = 4;
public static final int NULL_SORT_DEFAULT = NULL_SORT_LOW;
public static final int DEFAULT_SERVER_PORT = 9092; // this is also in the docs
public static final String START_URL = "jdbc:h2:";
public static final String URL_FORMAT = START_URL + "{ {.|mem:}[name] | [file:]fileName | {tcp|ssl}:[//]server[:port][,server2[:port]]/name }[;key=value...]";
public static final String PRODUCT_NAME = "H2";
public static final String DRIVER_NAME = "H2 JDBC Driver";
public static final int IO_BUFFER_SIZE = 4 * 1024;
public static final int IO_BUFFER_SIZE_COMPRESS = 128 * 1024;
public static final int DEFAULT_CACHE_SIZE_LINEAR_INDEX = 64 * 1024;
public static final String SUFFIX_DB_FILE = ".db";
public static final String SUFFIX_DATA_FILE = ".data.db";
public static final String SUFFIX_LOG_FILE = ".log.db";
......@@ -115,59 +106,40 @@ public class Constants {
public static final String SUFFIX_LOB_FILE = ".lob.db";
public static final String SUFFIX_TRACE_START_FILE = ".start";
public static final String SUFFIX_LOBS_DIRECTORY = ".lobs.db";
public static final String UTF8 = "UTF8";
public static final int DEFAULT_TABLE_TYPE = 0;
public static final int DEFAULT_MAX_LENGTH_INPLACE_LOB = 128;
public static final int DEFAULT_MAX_LENGTH_CLIENTSIDE_LOB = 65536;
public static final int SALT_LEN = 8;
public static final int DEFAULT_DATA_PAGE_SIZE = 512;
public static final String PRIMARY_KEY_PREFIX = "PRIMARY_KEY_";
public static final int LOCK_SLEEP = 1000;
// TODO for testing, the lock timeout is smaller than for interactive use cases
// public static final int INITIAL_LOCK_TIMEOUT = 60 * 1000;
public static final int INITIAL_LOCK_TIMEOUT = 1000;
public static final char DEFAULT_ESCAPE_CHAR = '\\';
public static final int DEFAULT_HTTP_PORT = 8082; // also in the docs
public static final boolean DEFAULT_HTTP_SSL = false;
public static final boolean DEFAULT_HTTP_ALLOW_OTHERS = false;
public static final int DEFAULT_FTP_PORT = 8021;
public static final int DEFAULT_MAX_MEMORY_ROWS = 10000;
public static final int DEFAULT_WRITE_DELAY = 500;
public static final String SERVER_PROPERTIES_TITLE = "H2 Server Properties";
public static final String SERVER_PROPERTIES_FILE = ".h2.server.properties";
public static final long LONG_QUERY_LIMIT_MS = 100;
public static final String PUBLIC_ROLE_NAME = "PUBLIC";
public static final String TEMP_TABLE_PREFIX = "TEMP_TABLE_";
public static final int BIG_DECIMAL_SCALE_MAX = 100000;
public static final String SCHEMA_MAIN = "PUBLIC";
public static final String SCHEMA_INFORMATION = "INFORMATION_SCHEMA";
public static final String DBA_NAME = "DBA";
public static final String CHARACTER_SET_NAME = "Unicode";
public static final String CLUSTERING_DISABLED = "''";
public static final int LOCK_MODE_OFF = 0;
public static final int LOCK_MODE_TABLE = 1;
public static final int LOCK_MODE_TABLE_GC = 2;
public static final int LOCK_MODE_READ_COMMITTED = 3;
public static final int SELECTIVITY_DISTINCT_COUNT = 10000;
public static final int SELECTIVITY_DEFAULT = 50;
public static final int SELECTIVITY_ANALYZE_SAMPLE_ROWS = 10000;
......@@ -177,52 +149,44 @@ public class Constants {
public static final int COST_ROW_OFFSET = 1000;
public static final long FLUSH_INDEX_DELAY = 0;
public static final int THROTTLE_DELAY = 50;
public static final String MANAGEMENT_DB_PREFIX = "management_db_";
public static final String MANAGEMENT_DB_USER = "sa";
public static final boolean SERIALIZE_JAVA_OBJECTS = true;
public static final long DEFAULT_MAX_LOG_SIZE = 32 * 1024 * 1024;
public static final long LOG_SIZE_DIVIDER = 10;
public static final int ALLOW_LITERALS_NONE = 0;
public static final int ALLOW_LITERALS_NUMBERS = 1;
public static final int ALLOW_LITERALS_ALL = 2;
public static final int DEFAULT_ALLOW_LITERALS = ALLOW_LITERALS_ALL;
public static final boolean AUTO_CONVERT_LOB_TO_FILES = true;
public static final boolean ALLOW_EMPTY_BTREE_PAGES = true;
public static final String CONN_URL_INTERNAL = "jdbc:default:connection";
public static final String CONN_URL_COLUMNLIST = "jdbc:columnlist:connection";
public static final int VIEW_INDEX_CACHE_SIZE = 64;
public static final int VIEW_COST_CACHE_MAX_AGE = 10000; // 10 seconds
public static final int MAX_PARAMETER_INDEX = 100000;
public static boolean runFinalize = getBooleanSetting("h2.runFinalize", true);
public static String scriptDirectory = getStringSetting("h2.scriptDirectory", "");
private static String baseDir = getStringSetting("h2.baseDir", null);
public static boolean multiThreadedKernel = getBooleanSetting("h2.multiThreadedKernel", false);
public static boolean lobCloseBetweenReads = getBooleanSetting("h2.lobCloseBetweenReads", false);
// TODO: also remove DataHandler.allocateObjectId, createTempFile when setting this to true and removing it
public static final boolean LOB_FILES_IN_DIRECTORIES = getBooleanSetting("h2.lobFilesInDirectories", false);
public static final int LOB_FILES_PER_DIRECTORY = getIntSetting("h2.lobFilesPerDirectory", 256);
// TODO need to refactor & test the code to enable this (add more tests!)
public static final boolean OPTIMIZE_EVALUATABLE_SUBQUERIES = false;
// to slow down dictionary attacks
public static final int ENCRYPTION_KEY_HASH_ITERATIONS = 1024;
public static final String SCRIPT_SQL = "script.sql";
// for testing only
public static final int CACHE_MIN_RECORDS = 16;
public static final int MIN_WRITE_DELAY = getIntSetting("h2.minWriteDelay", 5);
public static final boolean CHECK2 = getBooleanSetting("h2.check2", false);
// TODO: also remove DataHandler.allocateObjectId, createTempFile when setting this to true and removing it
public static final boolean LOB_FILES_IN_DIRECTORIES = getBooleanSetting("h2.lobFilesInDirectories", false);
public static final int LOB_FILES_PER_DIRECTORY = getIntSetting("h2.lobFilesPerDirectory", 256);
public static final boolean CHECK = getBooleanSetting("h2.check", true);
public static boolean MULTI_THREADED_KERNEL = getBooleanSetting("h2.multiThreadedKernel", false);
public static boolean RUN_FINALIZE = getBooleanSetting("h2.runFinalize", true);
public static String SCRIPT_DIRECTORY = getStringSetting("h2.scriptDirectory", "");
public static final boolean OPTIMIZE_MIN_MAX = getBooleanSetting("h2.optimizeMinMax", true);
public static final boolean OPTIMIZE_IN = getBooleanSetting("h2.optimizeIn", true);
public static final int REDO_BUFFER_SIZE = getIntSetting("h2.redoBufferSize", 256 * 1024);
......@@ -239,8 +203,7 @@ public class Constants {
public static final int OBJECT_CACHE_SIZE = getIntSetting("h2.objectCacheSize", 1024);
public static final int OBJECT_CACHE_MAX_PER_ELEMENT_SIZE = getIntSetting("h2.objectCacheMaxPerElementSize", 4096);
public static final String CLIENT_TRACE_DIRECTORY = getStringSetting("h2.clientTraceDirectory", "trace.db/");
public static int MAX_FILE_RETRY = Math.max(1, getIntSetting("h2.maxFileRetry", 16));
public static boolean LOB_CLOSE_BETWEEN_READS = getBooleanSetting("h2.lobCloseBetweenReads", false);
public static final int MAX_FILE_RETRY = Math.max(1, getIntSetting("h2.maxFileRetry", 16));
public static final boolean ALLOW_BIG_DECIMAL_EXTENSIONS = getBooleanSetting("h2.allowBigDecimalExtensions", false);
public static final boolean INDEX_LOOKUP_NEW = getBooleanSetting("h2.indexLookupNew", true);
public static final boolean TRACE_IO = getBooleanSetting("h2.traceIO", false);
......@@ -248,7 +211,6 @@ public class Constants {
public static final int CACHE_SIZE_DEFAULT = getIntSetting("h2.cacheSizeDefault", 16 * 1024);
public static final int CACHE_SIZE_INDEX_SHIFT = getIntSetting("h2.cacheSizeIndexShift", 3);
public static final int CACHE_SIZE_INDEX_DEFAULT = CACHE_SIZE_DEFAULT >> CACHE_SIZE_INDEX_SHIFT;
public static String BASE_DIR = getStringSetting("h2.baseDir", null);
public static final int DEFAULT_MAX_MEMORY_UNDO = getIntSetting("h2.defaultMaxMemoryUndo", 50000);
public static final boolean OPTIMIZE_NOT = getBooleanSetting("h2.optimizeNot", true);
public static final boolean OPTIMIZE_2_EQUALS = getBooleanSetting("h2.optimizeTwoEquals", true);
......@@ -257,7 +219,11 @@ public class Constants {
if(!dir.endsWith("/")) {
dir += "/";
}
BASE_DIR = dir;
baseDir = dir;
}
public static String getBaseDir() {
return baseDir;
}
public static boolean getBooleanSetting(String name, boolean defaultValue) {
......
......@@ -164,7 +164,7 @@ public class Database implements DataHandler {
}
String log = ci.getProperty(SetTypes.LOG, null);
if(log != null) {
this.logIndexChanges = log.equals("2");
this.logIndexChanges = "2".equals(log);
}
String ignoreSummary = ci.getProperty("RECOVER", null);
if(ignoreSummary != null) {
......
......@@ -102,7 +102,7 @@ public class Session implements SessionInterface {
}
protected void finalize() {
if(!Constants.RUN_FINALIZE) {
if(!Constants.runFinalize) {
return;
}
if(database != null) {
......
......@@ -276,12 +276,4 @@ public class BtreeLeaf extends BtreePage {
return (SearchRow)pageData.get(0);
}
public String print(String indent) throws SQLException {
System.out.println(indent + "leaf:");
for(int i=0; i<pageData.size(); i++) {
System.out.println(indent + " " + getData(i).getValue(1).getString().substring(4150));
}
return getData(0).getValue(1).getString().substring(4150);
}
}
......@@ -353,25 +353,4 @@ public class BtreeNode extends BtreePage {
return null;
}
public String print(String indent) throws SQLException {
System.out.println(indent + "node");
String first = null;
String last = null;
for(int i=0; i<pageChildren.size(); i++) {
String firstNow = index.getPage(pageChildren.get(i)).print(indent + " ");
if(first == null) {
first = firstNow;
}
if(last != null && !last.equals(firstNow)) {
System.out.println("STOP!!! " + last + " firstNow:" + firstNow);
}
if(i<pageData.size()) {
String now = getData(i).getValue(1).getString().substring(4150);
System.out.println(indent + " " + now);
last = now;
}
}
return first;
}
}
......@@ -86,5 +86,4 @@ public abstract class BtreePage extends Record {
return root;
}
public abstract String print(String indent) throws SQLException;
}
......@@ -921,7 +921,7 @@ public class JdbcConnection extends TraceObject implements Connection {
session = new SessionRemote().createSession(ci);
} else {
SessionInterface si = (SessionInterface) ClassUtils.loadClass("org.h2.engine.Session").newInstance();
String baseDir = Constants.BASE_DIR;
String baseDir = Constants.getBaseDir();
if(baseDir != null) {
ci.setBaseDir(baseDir);
}
......@@ -1184,7 +1184,7 @@ public class JdbcConnection extends TraceObject implements Connection {
}
protected void finalize() {
if(!Constants.RUN_FINALIZE) {
if(!Constants.runFinalize) {
return;
}
if(isInternal) {
......
......@@ -238,7 +238,7 @@ public class TraceSystem {
}
protected void finalize() {
if(!Constants.RUN_FINALIZE) {
if(!Constants.runFinalize) {
return;
}
close();
......
......@@ -158,7 +158,7 @@ class ResultDiskBuffer {
}
protected void finalize() {
if(!Constants.RUN_FINALIZE) {
if(!Constants.runFinalize) {
return;
}
close();
......
......@@ -29,7 +29,7 @@ public class TcpServer implements Service {
public static final int DEFAULT_PORT = 9092;
public static final int SHUTDOWN_NORMAL = 0;
public static final int SHUTDOWN_FORCE = 1;
public static boolean LOG_INTERNAL_ERRORS;
public static boolean logInternalErrors;
private int port;
private boolean log;
......@@ -80,19 +80,19 @@ public class TcpServer implements Service {
port = DEFAULT_PORT;
for (int i = 0; i < args.length; i++) {
String a = args[i];
if (a.equals("-log")) {
if ("-log".equals(a)) {
log = Boolean.valueOf(args[++i]).booleanValue();
} else if (a.equals("-tcpSSL")) {
} else if ("-tcpSSL".equals(a)) {
ssl = Boolean.valueOf(args[++i]).booleanValue();
} else if (a.equals("-tcpPort")) {
} else if ("-tcpPort".equals(a)) {
port = MathUtils.decodeInt(args[++i]);
} else if (a.equals("-tcpPassword")) {
} else if ("-tcpPassword".equals(a)) {
managementPassword= args[++i];
} else if (a.equals("-baseDir")) {
} else if ("-baseDir".equals(a)) {
baseDir = args[++i];
} else if (a.equals("-tcpAllowOthers")) {
} else if ("-tcpAllowOthers".equals(a)) {
allowOthers = Boolean.valueOf(args[++i]).booleanValue();
} else if (a.equals("-ifExists")) {
} else if ("-ifExists".equals(a)) {
ifExists = Boolean.valueOf(args[++i]).booleanValue();
}
}
......@@ -243,7 +243,7 @@ public class TcpServer implements Service {
}
public void logInternalError(String string) {
if(TcpServer.LOG_INTERNAL_ERRORS) {
if(TcpServer.logInternalErrors) {
System.out.println(string);
new Error(string).printStackTrace();
}
......
......@@ -59,7 +59,7 @@ public class TcpServerThread implements Runnable {
String originalURL = transfer.readString();
String baseDir = server.getBaseDir();
if(baseDir == null) {
baseDir = Constants.BASE_DIR;
baseDir = Constants.getBaseDir();
}
ConnectionInfo ci = new ConnectionInfo(db);
if(baseDir != null) {
......
......@@ -42,15 +42,15 @@ public class PgServer implements Service {
port = DEFAULT_PORT;
for (int i = 0; i < args.length; i++) {
String a = args[i];
if (a.equals("-log")) {
if ("-log".equals(a)) {
log = Boolean.valueOf(args[++i]).booleanValue();
} else if (a.equals("-pgPort")) {
} else if ("-pgPort".equals(a)) {
port = MathUtils.decodeInt(args[++i]);
} else if (a.equals("-baseDir")) {
} else if ("-baseDir".equals(a)) {
baseDir = args[++i];
} else if (a.equals("-pgAllowOthers")) {
} else if ("-pgAllowOthers".equals(a)) {
allowOthers = Boolean.valueOf(args[++i]).booleanValue();
} else if (a.equals("-ifExists")) {
} else if ("-ifExists".equals(a)) {
ifExists = Boolean.valueOf(args[++i]).booleanValue();
}
}
......
......@@ -30,6 +30,7 @@ import java.util.Properties;
import org.h2.Driver;
import org.h2.util.JdbcUtils;
import org.h2.util.ObjectUtils;
import org.h2.util.ScriptReader;
/**
......@@ -362,7 +363,7 @@ public class PgServerThread implements Runnable {
}
private void checkType(int type) {
if(types.contains(new Integer(type))) {
if(types.contains(ObjectUtils.getInteger(type))) {
error("Unsupported type: " + type, null);
}
}
......@@ -431,7 +432,7 @@ public class PgServerThread implements Runnable {
}
private String getEncoding() {
if(clientEncoding.equals("UNICODE")) {
if("UNICODE".equals(clientEncoding)) {
return "UTF-8";
}
return clientEncoding;
......@@ -593,7 +594,7 @@ public class PgServerThread implements Runnable {
rs = stat.executeQuery("SELECT OID FROM PG_CATALOG.PG_TYPE");
while(rs.next()) {
types.add(new Integer(rs.getInt(1)));
types.add(ObjectUtils.getInteger(rs.getInt(1)));
}
}
......
......@@ -23,7 +23,7 @@ public class DbContextRule implements Rule {
static final int COLUMN = 0, TABLE = 1, TABLE_ALIAS = 2;
public static final int NEW_TABLE_ALIAS = 3;
public static final int COLUMN_ALIAS = 4;
private static boolean SUGGEST_TABLE_ALIAS;
private static final boolean SUGGEST_TABLE_ALIAS = false;
DbContextRule(DbContents contents, int type) {
this.contents = contents;
......
......@@ -85,25 +85,25 @@ class WebThread extends Thread {
} else {
suffix = "";
}
if(suffix.equals("ico")) {
if("ico".equals(suffix)) {
mimeType = "image/x-icon";
cache=true;
} else if(suffix.equals("gif")) {
} else if("gif".equals(suffix)) {
mimeType = "image/gif";
cache=true;
} else if(suffix.equals("css")) {
} else if("css".equals(suffix)) {
cache=true;
mimeType = "text/css";
} else if(suffix.equals("html") || suffix.equals("do") || suffix.equals("jsp")) {
} else if("html".equals(suffix) || "do".equals(suffix) || "jsp".equals(suffix)) {
cache=false;
mimeType = "text/html";
if (session == null) {
session = server.createNewSession(hostname);
if (!file.equals("notAllowed.jsp")) {
if (!"notAllowed.jsp".equals(file)) {
file = "index.do";
}
}
} else if(suffix.equals("js")) {
} else if("js".equals(suffix)) {
cache=true;
mimeType = "text/javascript";
} else {
......@@ -329,33 +329,33 @@ class WebThread extends Thread {
String process(String file) {
server.trace("process " + file);
while(file.endsWith(".do")) {
if(file.equals("login.do")) {
if("login.do".equals(file)) {
file = login();
} else if(file.equals("index.do")) {
} else if("index.do".equals(file)) {
file = index();
} else if(file.equals("logout.do")) {
} else if("logout.do".equals(file)) {
file = logout();
} else if(file.equals("settingRemove.do")) {
} else if("settingRemove.do".equals(file)) {
file = settingRemove();
} else if(file.equals("settingSave.do")) {
} else if("settingSave.do".equals(file)) {
file = settingSave();
} else if(file.equals("test.do")) {
} else if("test.do".equals(file)) {
file = test();
} else if(file.equals("query.do")) {
} else if("query.do".equals(file)) {
file = query();
} else if(file.equals("tables.do")) {
} else if("tables.do".equals(file)) {
file = tables();
} else if(file.equals("editResult.do")) {
} else if("editResult.do".equals(file)) {
file = editResult();
} else if(file.equals("getHistory.do")) {
} else if("getHistory.do".equals(file)) {
file = getHistory();
} else if(file.equals("admin.do")) {
} else if("admin.do".equals(file)) {
file = admin();
} else if(file.equals("adminSave.do")) {
} else if("adminSave.do".equals(file)) {
file = adminSave();
} else if(file.equals("adminShutdown.do")) {
} else if("adminShutdown.do".equals(file)) {
file = adminShutdown();
} else if(file.equals("autoCompleteList.do")) {
} else if("autoCompleteList.do".equals(file)) {
file = autoCompleteList();
} else {
file = "error.jsp";
......@@ -425,7 +425,7 @@ class WebThread extends Thread {
key = StringUtils.toLowerEnglish(key);
value = StringUtils.toLowerEnglish(value);
}
if(key.equals(value) && !value.equals(".")) {
if(key.equals(value) && !".".equals(value)) {
value = space + value;
}
key = StringUtils.urlEncode(key);
......@@ -717,7 +717,7 @@ class WebThread extends Thread {
treeIndex++;
buff.append("setNode("+treeIndex+", 2, 2, 'type', '${text.tree.current}: " + PageParser.escapeJavaScript(current)+ "', null);\n");
treeIndex++;
if(!increment.equals("1")) {
if(!"1".equals(increment)) {
buff.append("setNode("+treeIndex+", 2, 2, 'type', '${text.tree.increment}: " + PageParser.escapeJavaScript(increment)+ "', null);\n");
treeIndex++;
}
......@@ -841,10 +841,10 @@ class WebThread extends Thread {
try {
Connection conn = session.getConnection();
String result;
if(sql.equals("@AUTOCOMMIT TRUE")) {
if("@AUTOCOMMIT TRUE".equals(sql)) {
conn.setAutoCommit(true);
result = "${text.result.autoCommitOn}";
} else if(sql.equals("@AUTOCOMMIT FALSE")) {
} else if("@AUTOCOMMIT FALSE".equals(sql)) {
conn.setAutoCommit(false);
result = "${text.result.autoCommitOff}";
} else if(sql.startsWith("@TRANSACTION_ISOLATION")) {
......@@ -1175,7 +1175,7 @@ class WebThread extends Thread {
boolean metadata = false;
boolean generatedKeys = false;
boolean edit = false;
if(sql.equals("@CANCEL")) {
if("@CANCEL".equals(sql)) {
stat = session.executingStatement;
if(stat != null) {
stat.cancel();
......@@ -1201,7 +1201,7 @@ class WebThread extends Thread {
edit = true;
sql = sql.substring("@EDIT".length()).trim();
session.put("resultSetSQL", sql);
} else if(sql.equals("@HISTORY")) {
} else if("@HISTORY".equals(sql)) {
buff.append(getHistoryString());
return buff.toString();
}
......
......@@ -67,7 +67,7 @@ public class FileLock {
}
protected void finalize() {
if (!Constants.RUN_FINALIZE) {
if (!Constants.runFinalize) {
return;
}
if(locked) {
......
......@@ -140,7 +140,7 @@ public class FileStoreInputStream extends InputStream {
}
protected void finalize() {
if (!Constants.RUN_FINALIZE) {
if (!Constants.runFinalize) {
return;
}
try {
......
......@@ -224,7 +224,7 @@ public class Column {
if(!autoIncrement) {
throw Message.getInternalError();
}
if(originalSQL.equals("IDENTITY")) {
if("IDENTITY".equals(originalSQL)) {
originalSQL = "BIGINT";
}
String sequenceName;
......
......@@ -695,8 +695,8 @@ public class MetaTable extends Table {
add(rows, new String[]{"h2.check2", "" + Constants.CHECK2});
add(rows, new String[]{"h2.lobFilesInDirectories", "" + Constants.LOB_FILES_IN_DIRECTORIES});
add(rows, new String[]{"h2.lobFilesPerDirectory", "" + Constants.LOB_FILES_PER_DIRECTORY});
add(rows, new String[]{"h2.multiThreadedKernel", "" + Constants.MULTI_THREADED_KERNEL});
add(rows, new String[]{"h2.runFinalize", "" + Constants.RUN_FINALIZE});
add(rows, new String[]{"h2.multiThreadedKernel", "" + Constants.multiThreadedKernel});
add(rows, new String[]{"h2.runFinalize", "" + Constants.runFinalize});
add(rows, new String[]{"h2.optimizeMinMax", "" + Constants.OPTIMIZE_MIN_MAX});
add(rows, new String[]{"h2.optimizeIn", "" + Constants.OPTIMIZE_IN});
add(rows, new String[]{"h2.redoBufferSize", "" + Constants.REDO_BUFFER_SIZE});
......@@ -713,11 +713,11 @@ public class MetaTable extends Table {
add(rows, new String[]{"h2.objectCacheSize", "" + Constants.OBJECT_CACHE_SIZE});
add(rows, new String[]{"h2.objectCacheMaxPerElementSize", "" + Constants.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE});
add(rows, new String[]{"h2.clientTraceDirectory", Constants.CLIENT_TRACE_DIRECTORY});
add(rows, new String[]{"h2.scriptDirectory", Constants.SCRIPT_DIRECTORY});
add(rows, new String[]{"h2.scriptDirectory", Constants.scriptDirectory});
add(rows, new String[]{"h2.maxFileRetry", "" + Constants.MAX_FILE_RETRY});
add(rows, new String[]{"h2.lobCloseBetweenReads", "" + Constants.LOB_CLOSE_BETWEEN_READS});
add(rows, new String[]{"h2.lobCloseBetweenReads", "" + Constants.lobCloseBetweenReads});
add(rows, new String[]{"h2.allowBigDecimalExtensions", "" + Constants.ALLOW_BIG_DECIMAL_EXTENSIONS});
add(rows, new String[]{"h2.baseDir", "" + Constants.BASE_DIR});
add(rows, new String[]{"h2.baseDir", "" + Constants.getBaseDir()});
add(rows, new String[]{"h2.defaultMaxMemoryUndo", "" + Constants.DEFAULT_MAX_MEMORY_UNDO});
break;
}
......
......@@ -297,7 +297,7 @@ public class TableData extends Table implements RecordReader {
}
} else {
if (lockExclusive == null) {
if(lockMode == Constants.LOCK_MODE_READ_COMMITTED && !Constants.MULTI_THREADED_KERNEL) {
if(lockMode == Constants.LOCK_MODE_READ_COMMITTED && !Constants.multiThreadedKernel) {
// READ_COMMITTED read locks are acquired but they are released immediately
// when allowing only one thread, no read locks are required
return;
......
......@@ -32,7 +32,7 @@ public class CompressTool {
private static CompressTool instance = new CompressTool();
private static byte[] buffer;
private static int MAX_BUFFER_SIZE = 64 * 1024 * 1024;
private static final int MAX_BUFFER_SIZE = 64 * 1024 * 1024;
private static byte[] getBuffer(int min) {
if(min > MAX_BUFFER_SIZE) {
......
......@@ -74,7 +74,7 @@ public class Script {
for(; i<args.length; i++) {
String a = args[i];
String upper = StringUtils.toUpperEnglish(a);
if(upper.startsWith("NO") || upper.equals("DROP")) {
if(upper.startsWith("NO") || "DROP".equals(upper)) {
buff1.append(' ');
buff1.append(args[i]);
} else {
......
......@@ -122,30 +122,30 @@ public class Server implements Runnable {
boolean startDefaultServers = true;
for(int i=0; args != null && i<args.length; i++) {
String a = args[i];
if(a.equals("-?") || a.equals("-help")) {
if("-?".equals(a) || "-help".equals(a)) {
showUsage();
return EXIT_ERROR;
} else if(a.equals("-web")) {
} else if("-web".equals(a)) {
startDefaultServers = false;
webStart = true;
} else if(a.equals("-tcp")) {
} else if("-tcp".equals(a)) {
startDefaultServers = false;
tcpStart = true;
} else if(a.equals("-pg")) {
} else if("-pg".equals(a)) {
startDefaultServers = false;
pgStart = true;
} else if(a.equals("-ftp")) {
} else if("-ftp".equals(a)) {
startDefaultServers = false;
ftpStart = true;
} else if(a.equals("-tcpShutdown")) {
} else if("-tcpShutdown".equals(a)) {
startDefaultServers = false;
tcpShutdown = true;
tcpShutdownServer = args[++i];
} else if(a.equals("-tcpPassword")) {
} else if("-tcpPassword".equals(a)) {
tcpPassword = args[++i];
} else if(a.equals("-tcpShutdownForce")) {
} else if("-tcpShutdownForce".equals(a)) {
tcpShutdownForce = true;
} else if(a.equals("-browser")) {
} else if("-browser".equals(a)) {
startDefaultServers = false;
browserStart = true;
}
......
......@@ -31,7 +31,7 @@ public class FileUtils {
private static final String MEMORY_PREFIX = "inmemory:";
private static final String MEMORY_PREFIX_2 = "mem:";
// TODO detection of 'case in sensitive filesystem' could maybe implemented using some other means
private static final boolean isCaseInsensitiveFileSystem = (File.separatorChar == '\\');
private static final boolean IS_FILE_SYSTEM_CASE_INSENSITIVE = (File.separatorChar == '\\');
public static RandomAccessFile openRandomAccessFile(String fileName, String mode) throws IOException {
fileName = translateFileName(fileName);
......@@ -82,7 +82,7 @@ public class FileUtils {
public static boolean fileStartsWith(String fileName, String prefix) {
fileName = translateFileName(fileName);
if(isCaseInsensitiveFileSystem) {
if(IS_FILE_SYSTEM_CASE_INSENSITIVE) {
fileName = StringUtils.toUpperEnglish(fileName);
prefix = StringUtils.toUpperEnglish(prefix);
}
......
......@@ -7,8 +7,8 @@ package org.h2.util;
public class MemoryUtils {
private static long lastGC;
private static int GC_DELAY = 50;
private static int MAX_GC = 8;
private static final int GC_DELAY = 50;
private static final int MAX_GC = 8;
public static int getMemoryUsed() {
collectGarbage();
......
......@@ -10,7 +10,7 @@ public class ObjectUtils {
*/
//#endif
//#ifdef JDK14
return new Integer(x);
return new Integer(x); // NOPMD
//#endif
}
......@@ -34,7 +34,7 @@ public class ObjectUtils {
*/
//#endif
//#ifdef JDK14
return new Long(x);
return new Long(x); // NOPMD
//#endif
}
......@@ -46,7 +46,7 @@ public class ObjectUtils {
*/
//#endif
//#ifdef JDK14
return new Short(x);
return new Short(x); // NOPMD
//#endif
}
......@@ -58,7 +58,7 @@ public class ObjectUtils {
*/
//#endif
//#ifdef JDK14
return new Byte(x);
return new Byte(x); // NOPMD
//#endif
}
......
......@@ -96,7 +96,7 @@ public class StringCache {
}
}
// create a new object that is not shared (to avoid out of memory if it is a substring of a big String)
s = new String(s);
s = new String(s); // NOPMD
cache[index] = s;
return s;
}
......
......@@ -9,6 +9,7 @@ import java.sql.SQLException;
import org.h2.engine.Constants;
import org.h2.message.Message;
import org.h2.util.ObjectUtils;
public class ValueByte extends Value {
public static final int PRECISION = 3;
......@@ -103,7 +104,7 @@ public class ValueByte extends Value {
}
public Object getObject() {
return new Byte(value);
return ObjectUtils.getByte(value);
}
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
......
......@@ -32,7 +32,7 @@ public class ValueDecimal extends Value {
private ValueDecimal(BigDecimal value) {
if (value == null) {
throw new NullPointerException();
throw new IllegalArgumentException();
} else if(!Constants.ALLOW_BIG_DECIMAL_EXTENSIONS && !value.getClass().equals(BigDecimal.class)) {
SQLException e = Message.getSQLException(Message.INVALID_CLASS_2, new String[]{BigDecimal.class.getName(), value.getClass().getName()}, null);
throw Message.convertToInternal(e);
......
......@@ -477,7 +477,7 @@ public class ValueLob extends Value {
return new ByteArrayInputStream(small);
}
FileStore store = handler.openFile(fileName, "r", true);
boolean alwaysClose = Constants.LOB_CLOSE_BETWEEN_READS;
boolean alwaysClose = Constants.lobCloseBetweenReads;
return new BufferedInputStream(new FileStoreInputStream(store, handler, compression, alwaysClose), Constants.IO_BUFFER_SIZE);
}
......
......@@ -648,7 +648,7 @@ SELECT COUNT(*) AS A FROM TEST GROUP BY ID HAVING A>0;
public void beforeTest() throws SQLException {
if(networked) {
TcpServer.LOG_INTERNAL_ERRORS = true;
TcpServer.logInternalErrors = true;
String[] args = ssl ? new String[]{"-tcpSSL", "true"} : new String[0];
server = Server.createTcpServer(args);
try {
......
......@@ -87,11 +87,11 @@ public class TestLob extends TestBase {
conn.createStatement().execute("INSERT INTO TEST VALUES(1, SPACE(10000))");
ResultSet rs = conn.createStatement().executeQuery("SELECT DATA FROM TEST");
rs.next();
Constants.LOB_CLOSE_BETWEEN_READS = true;
Constants.lobCloseBetweenReads = true;
Reader in = rs.getCharacterStream(1);
in.read();
conn.createStatement().execute("DELETE FROM TEST");
Constants.LOB_CLOSE_BETWEEN_READS = false;
Constants.lobCloseBetweenReads = false;
conn.createStatement().execute("INSERT INTO TEST VALUES(1, SPACE(10000))");
rs = conn.createStatement().executeQuery("SELECT DATA FROM TEST");
rs.next();
......
......@@ -95,7 +95,7 @@ public class TestPowerOff extends TestBase {
}
deleteDb(dir, dbName);
Random random = new Random(1);
Constants.RUN_FINALIZE = false;
Constants.runFinalize = false;
int repeat = getSize(1, 20);
for(int i=0; i<repeat; i++) {
Connection conn = getConnection(url);
......
......@@ -44,7 +44,7 @@ public class TestManyJdbcObjects extends TestBase {
// SERVER_CACHED_OBJECTS = 500: connections = 40
// SERVER_CACHED_OBJECTS = 50: connections = 120
deleteDb("manyObjects");
Constants.RUN_FINALIZE = false;
Constants.runFinalize = false;
int connCount = getSize(4, 40);
Connection[] conn = new Connection[connCount];
for(int i=0; i<connCount; i++) {
......@@ -62,12 +62,12 @@ public class TestManyJdbcObjects extends TestBase {
for(int i=0; i<connCount; i++) {
conn[i].close();
}
Constants.RUN_FINALIZE = true;
Constants.runFinalize = true;
}
private void testOneConnectionPrepare() throws Exception {
deleteDb("manyObjects");
Constants.RUN_FINALIZE = false;
Constants.runFinalize = false;
Connection conn = getConnection("manyObjects");
PreparedStatement prep;
Statement stat;
......@@ -98,7 +98,7 @@ public class TestManyJdbcObjects extends TestBase {
for(int i=0; i<size; i++) {
prep.executeQuery();
}
Constants.RUN_FINALIZE = true;
Constants.runFinalize = true;
conn.close();
}
......
......@@ -139,8 +139,8 @@ public class TestRandomSQL extends TestBase {
}
public void testCase(int i) throws Exception {
String old = Constants.SCRIPT_DIRECTORY;
Constants.SCRIPT_DIRECTORY = "dataScript/";
String old = Constants.scriptDirectory;
Constants.scriptDirectory = "dataScript/";
seed = i;
printTime("TestRandomSQL " + seed);
try {
......@@ -149,7 +149,7 @@ public class TestRandomSQL extends TestBase {
processException("deleteDb", e);
}
testWithSeed(bnf);
Constants.SCRIPT_DIRECTORY = old;
Constants.scriptDirectory = old;
}
public void test() throws Exception {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论