提交 4419055c authored 作者: Thomas Mueller's avatar Thomas Mueller

Enable warning for 'Local variable declaration hides another field or variable'.

上级 0196101c
......@@ -111,10 +111,10 @@ public class FunctionAlias extends DbObjectBase {
private void loadFromSource() throws SQLException {
SourceCompiler compiler = database.getCompiler();
String className = Constants.USER_PACKAGE + "." + getName();
compiler.setSource(className, source);
String fullClassName = Constants.USER_PACKAGE + "." + getName();
compiler.setSource(fullClassName, source);
try {
Method m = compiler.getMethod(className);
Method m = compiler.getMethod(fullClassName);
JavaMethod method = new JavaMethod(m, 0);
javaMethods = new JavaMethod[] {
method
......
......@@ -31,17 +31,20 @@ public class CompareLike extends Condition {
private static final int MATCH = 0, ONE = 1, ANY = 2;
private final CompareMode compareMode;
private final boolean regexp;
private Expression left;
private Expression right;
private Expression escape;
private boolean isInit;
private char[] pattern;
private char[] patternChars;
private String patternString;
private Pattern patternRegexp;
private int[] types;
private int[] patternTypes;
private int patternLength;
private final boolean regexp;
private Pattern patternRegexp;
private boolean ignoreCase;
private boolean fastCompare;
private boolean invalidPattern;
......@@ -166,7 +169,7 @@ public class CompareLike extends Condition {
if (invalidPattern) {
return;
}
if (patternLength <= 0 || types[0] != MATCH) {
if (patternLength <= 0 || patternTypes[0] != MATCH) {
// can't use an index
return;
}
......@@ -177,8 +180,8 @@ public class CompareLike extends Condition {
}
int maxMatch = 0;
StringBuilder buff = new StringBuilder();
while (maxMatch < patternLength && types[maxMatch] == MATCH) {
buff.append(pattern[maxMatch++]);
while (maxMatch < patternLength && patternTypes[maxMatch] == MATCH) {
buff.append(patternChars[maxMatch++]);
}
String begin = buff.toString();
if (maxMatch == patternLength) {
......@@ -232,7 +235,7 @@ public class CompareLike extends Condition {
// result = patternRegexp.matcher(value).matches();
result = patternRegexp.matcher(value).find();
} else {
result = compareAt(value, 0, 0, value.length(), pattern, types);
result = compareAt(value, 0, 0, value.length(), patternChars, patternTypes);
}
return ValueBoolean.get(result);
}
......@@ -285,10 +288,10 @@ public class CompareLike extends Condition {
if (invalidPattern) {
return false;
}
return compareAt(value, 0, 0, value.length(), pattern, types);
return compareAt(value, 0, 0, value.length(), patternChars, patternTypes);
}
private void initPattern(String p, Character escape) throws SQLException {
private void initPattern(String p, Character escapeChar) throws SQLException {
if (compareMode.getName().equals(CompareMode.OFF) && !ignoreCase) {
fastCompare = true;
}
......@@ -307,18 +310,18 @@ public class CompareLike extends Condition {
}
patternLength = 0;
if (p == null) {
types = null;
pattern = null;
patternTypes = null;
patternChars = null;
return;
}
int len = p.length();
pattern = new char[len];
types = new int[len];
patternChars = new char[len];
patternTypes = new int[len];
boolean lastAny = false;
for (int i = 0; i < len; i++) {
char c = p.charAt(i);
int type;
if (escape != null && escape == c) {
if (escapeChar != null && escapeChar == c) {
if (i >= len - 1) {
invalidPattern = true;
return;
......@@ -338,23 +341,23 @@ public class CompareLike extends Condition {
type = MATCH;
lastAny = false;
}
types[patternLength] = type;
pattern[patternLength++] = c;
patternTypes[patternLength] = type;
patternChars[patternLength++] = c;
}
for (int i = 0; i < patternLength - 1; i++) {
if ((types[i] == ANY) && (types[i + 1] == ONE)) {
types[i] = ONE;
types[i + 1] = ANY;
if ((patternTypes[i] == ANY) && (patternTypes[i + 1] == ONE)) {
patternTypes[i] = ONE;
patternTypes[i + 1] = ANY;
}
}
patternString = new String(pattern, 0, patternLength);
patternString = new String(patternChars, 0, patternLength);
}
private boolean isFullMatch() {
if (types == null) {
if (patternTypes == null) {
return false;
}
for (int type : types) {
for (int type : patternTypes) {
if (type != MATCH) {
return false;
}
......
......@@ -75,12 +75,12 @@ public class ConditionIn extends Condition {
return ValueBoolean.get(result);
}
public void mapColumns(ColumnResolver resolver, int queryLevel) throws SQLException {
left.mapColumns(resolver, queryLevel);
public void mapColumns(ColumnResolver resolver, int level) throws SQLException {
left.mapColumns(resolver, level);
for (Expression e : valueList) {
e.mapColumns(resolver, queryLevel);
e.mapColumns(resolver, level);
}
this.queryLevel = Math.max(queryLevel, this.queryLevel);
this.queryLevel = Math.max(level, this.queryLevel);
}
public Expression optimize(Session session) throws SQLException {
......
......@@ -83,10 +83,10 @@ public class ConditionInSelect extends Condition {
return ValueBoolean.get(result);
}
public void mapColumns(ColumnResolver resolver, int queryLevel) throws SQLException {
left.mapColumns(resolver, queryLevel);
query.mapColumns(resolver, queryLevel + 1);
this.queryLevel = Math.max(queryLevel, this.queryLevel);
public void mapColumns(ColumnResolver resolver, int level) throws SQLException {
left.mapColumns(resolver, level);
query.mapColumns(resolver, level + 1);
this.queryLevel = Math.max(level, this.queryLevel);
}
public Expression optimize(Session session) throws SQLException {
......
......@@ -34,7 +34,7 @@ public class ExpressionColumn extends Expression {
private String schemaName;
private String tableAlias;
private String columnName;
private ColumnResolver resolver;
private ColumnResolver columnResolver;
private int queryLevel;
private Column column;
private boolean evaluatable;
......@@ -68,7 +68,7 @@ public class ExpressionColumn extends Expression {
}
public TableFilter getTableFilter() {
return resolver == null ? null : resolver.getTableFilter();
return columnResolver == null ? null : columnResolver.getTableFilter();
}
public void mapColumns(ColumnResolver resolver, int level) throws SQLException {
......@@ -95,11 +95,11 @@ public class ExpressionColumn extends Expression {
}
private void mapColumn(ColumnResolver resolver, Column col, int level) throws SQLException {
if (this.resolver == null) {
if (this.columnResolver == null) {
queryLevel = level;
column = col;
this.resolver = resolver;
} else if (queryLevel == level && this.resolver != resolver) {
this.columnResolver = resolver;
} else if (queryLevel == level && this.columnResolver != resolver) {
if (resolver instanceof SelectListColumnResolver) {
// ignore - already mapped, that's ok
} else {
......@@ -109,7 +109,7 @@ public class ExpressionColumn extends Expression {
}
public Expression optimize(Session session) throws SQLException {
if (resolver == null) {
if (columnResolver == null) {
Schema schema = session.getDatabase().findSchema(
tableAlias == null ? session.getCurrentSchemaName() : tableAlias);
if (schema != null) {
......@@ -127,12 +127,12 @@ public class ExpressionColumn extends Expression {
}
throw Message.getSQLException(ErrorCode.COLUMN_NOT_FOUND_1, name);
}
return resolver.optimize(this, column);
return columnResolver.optimize(this, column);
}
public void updateAggregate(Session session) throws SQLException {
Value now = resolver.getValue(column);
Select select = resolver.getSelect();
Value now = columnResolver.getValue(column);
Select select = columnResolver.getSelect();
if (select == null) {
throw Message.getSQLException(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL());
}
......@@ -155,7 +155,7 @@ public class ExpressionColumn extends Expression {
// TODO refactor: simplify check if really part of an aggregated value /
// detection of
// usage of non-grouped by columns without aggregate function
Select select = resolver.getSelect();
Select select = columnResolver.getSelect();
if (select != null) {
HashMap<Expression, Object> values = select.getCurrentGroup();
if (values != null) {
......@@ -165,7 +165,7 @@ public class ExpressionColumn extends Expression {
}
}
}
Value value = resolver.getValue(column);
Value value = columnResolver.getValue(column);
if (value == null) {
throw Message.getSQLException(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL());
}
......@@ -177,7 +177,7 @@ public class ExpressionColumn extends Expression {
}
public void setEvaluatable(TableFilter tableFilter, boolean b) {
if (resolver != null && tableFilter == resolver.getTableFilter()) {
if (columnResolver != null && tableFilter == columnResolver.getTableFilter()) {
evaluatable = b;
}
}
......@@ -250,7 +250,7 @@ public class ExpressionColumn extends Expression {
visitor.addDataModificationId(column.getTable().getMaxDataModificationId());
return true;
case ExpressionVisitor.NOT_FROM_RESOLVER:
return resolver != visitor.getResolver();
return columnResolver != visitor.getResolver();
case ExpressionVisitor.GET_DEPENDENCIES:
visitor.addDependency(column.getTable());
return true;
......
......@@ -429,7 +429,7 @@ public class Function extends Expression implements FunctionCall {
return null;
}
private Value getSimpleValue(Session session, Value v0, Expression[] args) throws SQLException {
private Value getSimpleValue(Session session, Value v0, Expression[] argList) throws SQLException {
Value result;
switch (info.type) {
case ABS:
......@@ -538,7 +538,7 @@ public class Function extends Expression implements FunctionCall {
break;
case CONCAT: {
result = ValueNull.INSTANCE;
for (Expression e : args) {
for (Expression e : argList) {
Value v = e.getValue(session);
if (v == ValueNull.INSTANCE) {
continue;
......@@ -730,15 +730,15 @@ public class Function extends Expression implements FunctionCall {
result = ValueInt.get(session.getId());
break;
case IFNULL: {
result = v0 == ValueNull.INSTANCE ? args[1].getValue(session) : v0;
result = v0 == ValueNull.INSTANCE ? argList[1].getValue(session) : v0;
break;
}
case CASEWHEN: {
Expression expr;
if (v0 == ValueNull.INSTANCE || !v0.getBoolean().booleanValue()) {
expr = args[2];
expr = argList[2];
} else {
expr = args[1];
expr = argList[1];
}
Value v = expr.getValue(session);
result = v.convertTo(dataType);
......@@ -746,8 +746,8 @@ public class Function extends Expression implements FunctionCall {
}
case COALESCE: {
result = v0;
for (int i = 0; i < args.length; i++) {
Value v = i == 0 ? v0 : args[i].getValue(session);
for (int i = 0; i < argList.length; i++) {
Value v = i == 0 ? v0 : argList[i].getValue(session);
if (!(v == ValueNull.INSTANCE)) {
result = v.convertTo(dataType);
break;
......@@ -758,8 +758,8 @@ public class Function extends Expression implements FunctionCall {
case GREATEST:
case LEAST: {
result = ValueNull.INSTANCE;
for (int i = 0; i < args.length; i++) {
Value v = i == 0 ? v0 : args[i].getValue(session);
for (int i = 0; i < argList.length; i++) {
Value v = i == 0 ? v0 : argList[i].getValue(session);
if (!(v == ValueNull.INSTANCE)) {
v = v.convertTo(dataType);
if (result == ValueNull.INSTANCE) {
......@@ -779,21 +779,21 @@ public class Function extends Expression implements FunctionCall {
case CASE: {
result = null;
int i = 0;
for (; i < args.length; i++) {
Value when = args[i++].getValue(session);
for (; i < argList.length; i++) {
Value when = argList[i++].getValue(session);
if (Boolean.TRUE.equals(when)) {
result = args[i].getValue(session);
result = argList[i].getValue(session);
break;
}
}
if (result == null) {
result = i < args.length ? args[i].getValue(session) : ValueNull.INSTANCE;
result = i < argList.length ? argList[i].getValue(session) : ValueNull.INSTANCE;
}
break;
}
case ARRAY_GET: {
if (v0.getType() == Value.ARRAY) {
Value v1 = args[1].getValue(session);
Value v1 = argList[1].getValue(session);
int element = v1.getInt();
Value[] list = ((ValueArray) v0).getList();
if (element < 1 || element > list.length) {
......@@ -845,24 +845,24 @@ public class Function extends Expression implements FunctionCall {
return false;
}
private Value getValueWithArgs(Session session, Expression[] args) throws SQLException {
private Value getValueWithArgs(Session session, Expression[] argList) throws SQLException {
if (info.nullIfParameterIsNull) {
for (int i = 0; i < args.length; i++) {
if (getNullOrValue(session, args, i) == ValueNull.INSTANCE) {
for (int i = 0; i < argList.length; i++) {
if (getNullOrValue(session, argList, i) == ValueNull.INSTANCE) {
return ValueNull.INSTANCE;
}
}
}
Value v0 = getNullOrValue(session, args, 0);
Value resultSimple = getSimpleValue(session, v0, args);
Value v0 = getNullOrValue(session, argList, 0);
Value resultSimple = getSimpleValue(session, v0, argList);
if (resultSimple != null) {
return resultSimple;
}
Value v1 = getNullOrValue(session, args, 1);
Value v2 = getNullOrValue(session, args, 2);
Value v3 = getNullOrValue(session, args, 3);
Value v4 = getNullOrValue(session, args, 4);
Value v5 = getNullOrValue(session, args, 5);
Value v1 = getNullOrValue(session, argList, 1);
Value v2 = getNullOrValue(session, argList, 2);
Value v3 = getNullOrValue(session, argList, 3);
Value v4 = getNullOrValue(session, argList, 4);
Value v5 = getNullOrValue(session, argList, 5);
Value result;
switch (info.type) {
case ATAN2:
......@@ -1055,7 +1055,7 @@ public class Function extends Expression implements FunctionCall {
String fieldSeparatorRead = v3 == null ? null : v3.getString();
String fieldDelimiter = v4 == null ? null : v4.getString();
String escapeCharacter = v5 == null ? null : v5.getString();
Value v6 = getNullOrValue(session, args, 6);
Value v6 = getNullOrValue(session, argList, 6);
String nullString = v6 == null ? null : v6.getString();
Csv csv = Csv.getInstance();
setCsvDelimiterEscape(csv, fieldSeparatorRead, fieldDelimiter, escapeCharacter);
......@@ -1081,9 +1081,9 @@ public class Function extends Expression implements FunctionCall {
String fieldSeparatorWrite = v3 == null ? null : v3.getString();
String fieldDelimiter = v4 == null ? null : v4.getString();
String escapeCharacter = v5 == null ? null : v5.getString();
Value v6 = getNullOrValue(session, args, 6);
Value v6 = getNullOrValue(session, argList, 6);
String nullString = v6 == null ? null : v6.getString();
Value v7 = getNullOrValue(session, args, 7);
Value v7 = getNullOrValue(session, argList, 7);
String lineSeparator = v7 == null ? null : v7.getString();
Csv csv = Csv.getInstance();
setCsvDelimiterEscape(csv, fieldSeparatorWrite, fieldDelimiter, escapeCharacter);
......@@ -1096,7 +1096,7 @@ public class Function extends Expression implements FunctionCall {
break;
}
case SET: {
Variable var = (Variable) args[0];
Variable var = (Variable) argList[0];
session.setVariable(var.getName(), v1);
result = v1;
break;
......@@ -1104,7 +1104,7 @@ public class Function extends Expression implements FunctionCall {
case FILE_READ: {
session.getUser().checkAdmin();
String fileName = v0.getString();
boolean blob = args.length == 1;
boolean blob = argList.length == 1;
try {
InputStream in = new AutoCloseInputStream(FileUtils.openFileInputStream(fileName));
if (blob) {
......@@ -1868,18 +1868,18 @@ public class Function extends Expression implements FunctionCall {
return args.length;
}
public ValueResultSet getValueForColumnList(Session session, Expression[] args) throws SQLException {
public ValueResultSet getValueForColumnList(Session session, Expression[] argList) throws SQLException {
switch (info.type) {
case CSVREAD: {
String fileName = args[0].getValue(session).getString();
String fileName = argList[0].getValue(session).getString();
if (fileName == null) {
throw Message.getSQLException(ErrorCode.PARAMETER_NOT_SET_1, "fileName");
}
String columnList = args.length < 2 ? null : args[1].getValue(session).getString();
String charset = args.length < 3 ? null : args[2].getValue(session).getString();
String fieldSeparatorRead = args.length < 4 ? null : args[3].getValue(session).getString();
String fieldDelimiter = args.length < 5 ? null : args[4].getValue(session).getString();
String escapeCharacter = args.length < 6 ? null : args[5].getValue(session).getString();
String columnList = argList.length < 2 ? null : argList[1].getValue(session).getString();
String charset = argList.length < 3 ? null : argList[2].getValue(session).getString();
String fieldSeparatorRead = argList.length < 4 ? null : argList[3].getValue(session).getString();
String fieldDelimiter = argList.length < 5 ? null : argList[4].getValue(session).getString();
String escapeCharacter = argList.length < 6 ? null : argList[5].getValue(session).getString();
Csv csv = Csv.getInstance();
setCsvDelimiterEscape(csv, fieldSeparatorRead, fieldDelimiter, escapeCharacter);
char fieldSeparator = csv.getFieldSeparatorRead();
......@@ -1896,7 +1896,7 @@ public class Function extends Expression implements FunctionCall {
default:
break;
}
return (ValueResultSet) getValueWithArgs(session, args);
return (ValueResultSet) getValueWithArgs(session, argList);
}
private void setCsvDelimiterEscape(Csv csv, String fieldSeparator, String fieldDelimiter, String escapeCharacter) {
......
......@@ -107,8 +107,8 @@ public class JavaFunction extends Expression implements FunctionCall {
return javaMethod.getParameterCount();
}
public ValueResultSet getValueForColumnList(Session session, Expression[] args) throws SQLException {
Value v = javaMethod.getValue(session, args, true);
public ValueResultSet getValueForColumnList(Session session, Expression[] argList) throws SQLException {
Value v = javaMethod.getValue(session, argList, true);
return v == ValueNull.INSTANCE ? null : (ValueResultSet) v;
}
......
......@@ -74,7 +74,7 @@ public class TableFunction extends Function {
columns.toArray(columnList);
}
private ValueResultSet getTable(Session session, Expression[] args, boolean onlyColumnList, boolean distinct) throws SQLException {
private ValueResultSet getTable(Session session, Expression[] argList, boolean onlyColumnList, boolean distinctRows) throws SQLException {
int len = columnList.length;
Expression[] header = new Expression[len];
Database db = session.getDatabase();
......@@ -84,24 +84,24 @@ public class TableFunction extends Function {
header[i] = col;
}
LocalResult result = new LocalResult(session, header, len);
if (distinct) {
if (distinctRows) {
result.setDistinct();
}
if (!onlyColumnList) {
Value[][] list = new Value[len][];
int rowCount = 0;
int rows = 0;
for (int i = 0; i < len; i++) {
Value v = args[i].getValue(session);
Value v = argList[i].getValue(session);
if (v == ValueNull.INSTANCE) {
list[i] = new Value[0];
} else {
ValueArray array = (ValueArray) v.convertTo(Value.ARRAY);
Value[] l = array.getList();
list[i] = l;
rowCount = Math.max(rowCount, l.length);
rows = Math.max(rows, l.length);
}
}
for (int row = 0; row < rowCount; row++) {
for (int row = 0; row < rows; row++) {
Value[] r = new Value[len];
for (int j = 0; j < len; j++) {
Value[] l = list[j];
......
......@@ -871,16 +871,16 @@ public class FullText {
if (newRow != null) {
// update
if (hasChanged(oldRow, newRow, index.indexColumns)) {
delete(setting, oldRow);
insert(setting, newRow);
delete(oldRow);
insert(newRow);
}
} else {
// delete
delete(setting, oldRow);
delete(oldRow);
}
} else if (newRow != null) {
// insert
insert(setting, newRow);
insert(newRow);
}
}
......@@ -901,10 +901,9 @@ public class FullText {
/**
* Add a row to the index.
*
* @param setting the setting
* @param row the row
*/
protected void insert(FullTextSettings setting, Object[] row) throws SQLException {
protected void insert(Object[] row) throws SQLException {
String key = getKey(row);
int hash = key.hashCode();
prepInsertRow.setInt(1, hash);
......@@ -915,7 +914,7 @@ public class FullText {
rs.next();
int rowId = rs.getInt(1);
prepInsertMap.setInt(1, rowId);
int[] wordIds = getWordIds(setting, row);
int[] wordIds = getWordIds(row);
for (int id : wordIds) {
prepInsertMap.setInt(2, id);
prepInsertMap.execute();
......@@ -925,10 +924,9 @@ public class FullText {
/**
* Delete a row from the index.
*
* @param setting the setting
* @param row the row
*/
protected void delete(FullTextSettings setting, Object[] row) throws SQLException {
protected void delete(Object[] row) throws SQLException {
String key = getKey(row);
int hash = key.hashCode();
prepSelectRow.setInt(1, hash);
......@@ -938,7 +936,7 @@ public class FullText {
if (rs.next()) {
int rowId = rs.getInt(1);
prepDeleteMap.setInt(1, rowId);
int[] wordIds = getWordIds(setting, row);
int[] wordIds = getWordIds(row);
for (int id : wordIds) {
prepDeleteMap.setInt(2, id);
prepDeleteMap.executeUpdate();
......@@ -950,7 +948,7 @@ public class FullText {
}
}
private int[] getWordIds(FullTextSettings setting, Object[] row) throws SQLException {
private int[] getWordIds(Object[] row) throws SQLException {
HashSet<String> words = New.hashSet();
for (int i = 0; i < index.indexColumns.length; i++) {
int idx = index.indexColumns[i];
......
......@@ -43,23 +43,23 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
/**
* Initialize the base index.
*
* @param table the table
* @param newTable the table
* @param id the object id
* @param name the index name
* @param indexColumns the columns that are indexed or null if this is not
* yet known
* @param indexType the index type
* @param newIndexColumns the columns that are indexed or null if this is
* not yet known
* @param newIndexType the index type
*/
void initBaseIndex(Table table, int id, String name, IndexColumn[] indexColumns, IndexType indexType) {
initSchemaObjectBase(table.getSchema(), id, name, Trace.INDEX);
this.indexType = indexType;
this.table = table;
if (indexColumns != null) {
this.indexColumns = indexColumns;
columns = new Column[indexColumns.length];
void initBaseIndex(Table newTable, int id, String name, IndexColumn[] newIndexColumns, IndexType newIndexType) {
initSchemaObjectBase(newTable.getSchema(), id, name, Trace.INDEX);
this.indexType = newIndexType;
this.table = newTable;
if (newIndexColumns != null) {
this.indexColumns = newIndexColumns;
columns = new Column[newIndexColumns.length];
columnIds = new int[columns.length];
for (int i = 0; i < columns.length; i++) {
Column col = indexColumns[i].column;
Column col = newIndexColumns[i].column;
columns[i] = col;
columnIds[i] = col.getColumnId();
}
......
......@@ -60,11 +60,11 @@ public class IndexCursor implements Cursor {
/**
* Re-evaluate the start and end values of the index search for rows.
*
* @param session the session
* @param s the session
* @param indexConditions the index conditions
*/
public void find(Session session, ObjectArray<IndexCondition> indexConditions) throws SQLException {
this.session = session;
public void find(Session s, ObjectArray<IndexCondition> indexConditions) throws SQLException {
this.session = s;
alwaysFalse = false;
start = end = null;
inList = null;
......@@ -79,16 +79,16 @@ public class IndexCursor implements Cursor {
if (condition.getCompareType() == Comparison.IN_LIST) {
if (start == null && end == null) {
this.inColumn = column;
inList = condition.getCurrentValueList(session);
inList = condition.getCurrentValueList(s);
inListIndex = 0;
}
} else if (condition.getCompareType() == Comparison.IN_QUERY) {
if (start == null && end == null) {
this.inColumn = column;
inResult = condition.getCurrentResult(session);
inResult = condition.getCurrentResult(s);
}
} else {
Value v = column.convert(condition.getCurrentValue(session));
Value v = column.convert(condition.getCurrentValue(s));
boolean isStart = condition.isStart();
boolean isEnd = condition.isEnd();
int id = column.getColumnId();
......@@ -125,7 +125,7 @@ public class IndexCursor implements Cursor {
return;
}
if (!alwaysFalse) {
cursor = index.find(session, start, end);
cursor = index.find(s, start, end);
}
}
......
......@@ -35,10 +35,10 @@ public class ViewIndex extends BaseIndex {
private final ObjectArray<Parameter> originalParameters;
private final SmallLRUCache<IntArray, CostElement> costCache = SmallLRUCache.newInstance(Constants.VIEW_INDEX_CACHE_SIZE);
private boolean recursive;
private int[] masks;
private int[] indexMasks;
private String planSQL;
private Query query;
private Session session;
private Session createSession;
public ViewIndex(TableView view, String querySQL, ObjectArray<Parameter> originalParameters, boolean recursive) {
initBaseIndex(view, 0, null, null, IndexType.createNonUnique(false));
......@@ -55,15 +55,15 @@ public class ViewIndex extends BaseIndex {
this.querySQL = index.querySQL;
this.originalParameters = index.originalParameters;
this.recursive = index.recursive;
this.masks = masks;
this.session = session;
this.indexMasks = masks;
this.createSession = session;
columns = new Column[0];
query = getQuery(session, masks);
planSQL = query.getPlanSQL();
}
public Session getSession() {
return session;
return createSession;
}
public String getPlanSQL() {
......@@ -107,7 +107,7 @@ public class ViewIndex extends BaseIndex {
return cachedCost.cost;
}
}
Query query = (Query) session.prepare(querySQL, true);
Query q = (Query) session.prepare(querySQL, true);
if (masks != null) {
IntArray paramIndex = new IntArray();
for (int i = 0; i < masks.length; i++) {
......@@ -121,28 +121,28 @@ public class ViewIndex extends BaseIndex {
for (int i = 0; i < len; i++) {
int idx = paramIndex.get(i);
int mask = masks[idx];
int nextParamIndex = query.getParameters().size() + view.getParameterOffset();
int nextParamIndex = q.getParameters().size() + view.getParameterOffset();
if ((mask & IndexCondition.EQUALITY) != 0) {
Parameter param = new Parameter(nextParamIndex);
query.addGlobalCondition(param, idx, Comparison.EQUAL);
q.addGlobalCondition(param, idx, Comparison.EQUAL);
} else {
if ((mask & IndexCondition.START) != 0) {
Parameter param = new Parameter(nextParamIndex);
query.addGlobalCondition(param, idx, Comparison.BIGGER_EQUAL);
q.addGlobalCondition(param, idx, Comparison.BIGGER_EQUAL);
}
if ((mask & IndexCondition.END) != 0) {
Parameter param = new Parameter(nextParamIndex);
query.addGlobalCondition(param, idx, Comparison.SMALLER_EQUAL);
q.addGlobalCondition(param, idx, Comparison.SMALLER_EQUAL);
}
}
}
if (recursive) {
return 10;
}
String sql = query.getPlanSQL();
query = (Query) session.prepare(sql, true);
String sql = q.getPlanSQL();
q = (Query) session.prepare(sql, true);
}
double cost = query.getCost();
double cost = q.getCost();
cachedCost = new CostElement();
cachedCost.evaluatedAt = System.currentTimeMillis();
cachedCost.cost = cost;
......@@ -181,7 +181,7 @@ public class ViewIndex extends BaseIndex {
}
}
// for equality, only one parameter is used (first == last)
if (last != null && masks[i] != IndexCondition.EQUALITY) {
if (last != null && indexMasks[i] != IndexCondition.EQUALITY) {
Value v = last.getValue(i);
if (v != null) {
Parameter param = paramList.get(idx++);
......@@ -194,9 +194,9 @@ public class ViewIndex extends BaseIndex {
}
private Query getQuery(Session session, int[] masks) throws SQLException {
Query query = (Query) session.prepare(querySQL, true);
Query q = (Query) session.prepare(querySQL, true);
if (masks == null) {
return query;
return q;
}
int firstIndexParam = originalParameters == null ? 0 : originalParameters.size();
firstIndexParam += view.getParameterOffset();
......@@ -221,24 +221,24 @@ public class ViewIndex extends BaseIndex {
int mask = masks[idx];
if ((mask & IndexCondition.EQUALITY) == IndexCondition.EQUALITY) {
Parameter param = new Parameter(firstIndexParam + i);
query.addGlobalCondition(param, idx, Comparison.EQUAL);
q.addGlobalCondition(param, idx, Comparison.EQUAL);
i++;
} else {
if ((mask & IndexCondition.START) == IndexCondition.START) {
Parameter param = new Parameter(firstIndexParam + i);
query.addGlobalCondition(param, idx, Comparison.BIGGER_EQUAL);
q.addGlobalCondition(param, idx, Comparison.BIGGER_EQUAL);
i++;
}
if ((mask & IndexCondition.END) == IndexCondition.END) {
Parameter param = new Parameter(firstIndexParam + i);
query.addGlobalCondition(param, idx, Comparison.SMALLER_EQUAL);
q.addGlobalCondition(param, idx, Comparison.SMALLER_EQUAL);
i++;
}
}
}
String sql = query.getPlanSQL();
query = (Query) session.prepare(sql, true);
return query;
String sql = q.getPlanSQL();
q = (Query) session.prepare(sql, true);
return q;
}
public void remove(Session session) throws SQLException {
......
......@@ -35,7 +35,7 @@ public class ResultTempTable implements ResultExternal {
private TableData table;
private SortOrder sort;
private Index index;
private Cursor cursor;
private Cursor resultCursor;
public ResultTempTable(Session session, SortOrder sort) throws SQLException {
this.session = session;
......@@ -137,16 +137,16 @@ public class ResultTempTable implements ResultExternal {
}
public Value[] next() throws SQLException {
if (!cursor.next()) {
if (!resultCursor.next()) {
return null;
}
Row row = cursor.get();
Row row = resultCursor.get();
ValueArray data = (ValueArray) row.getValue(0);
return data.getList();
}
public void reset() throws SQLException {
cursor = index.find(session, null, null);
resultCursor = index.find(session, null, null);
}
private Row convertToRow(Value[] values) {
......
......@@ -577,9 +577,9 @@ public class Recover extends Tool implements DataHandler {
sessionCommit.put(sessionId, pos);
}
} else {
int storageId = s.readInt();
int sId = s.readInt();
int recId = s.readInt();
int blockCount = s.readInt();
int bCount = s.readInt();
if (type != 'T') {
s.readDataPageNoSize();
}
......@@ -600,9 +600,9 @@ public class Recover extends Tool implements DataHandler {
case 'T':
containsUncommitted = true;
if (!onlySetSessionState) {
writer.println("// truncate session: "+sessionId+" storage: " + storageId + " pos: " + recId + " blockCount: "+blockCount);
writer.println("// truncate session: "+sessionId+" storage: " + sId + " pos: " + recId + " blockCount: "+bCount);
if (sessionCommit.get(sessionId) >= pos) {
setStorage(storageId);
setStorage(sId);
writer.println("TRUNCATE TABLE " + storageName + ";");
}
}
......@@ -610,10 +610,10 @@ public class Recover extends Tool implements DataHandler {
case 'I':
containsUncommitted = true;
if (!onlySetSessionState) {
writer.println("// insert session: "+sessionId+" storage: " + storageId + " pos: " + recId + " blockCount: "+blockCount);
if (storageId >= 0) {
writer.println("// insert session: "+sessionId+" storage: " + sId + " pos: " + recId + " blockCount: "+bCount);
if (sId >= 0) {
if (sessionCommit.get(sessionId) >= pos) {
setStorage(storageId);
setStorage(sId);
writeLogRecord(writer, s, true);
}
}
......@@ -622,10 +622,10 @@ public class Recover extends Tool implements DataHandler {
case 'D':
containsUncommitted = true;
if (!onlySetSessionState) {
writer.println("// delete session: "+sessionId+" storage: " + storageId + " pos: " + recId + " blockCount: "+blockCount);
if (storageId >= 0) {
writer.println("// delete session: "+sessionId+" storage: " + sId + " pos: " + recId + " blockCount: "+bCount);
if (sId >= 0) {
if (sessionCommit.get(sessionId) >= pos) {
setStorage(storageId);
setStorage(sId);
writeLogRecord(writer, s, false);
}
}
......@@ -634,7 +634,7 @@ public class Recover extends Tool implements DataHandler {
default:
containsUncommitted = true;
if (!onlySetSessionState) {
writer.println("// type?: "+type+" session: "+sessionId+" storage: " + storageId + " pos: " + recId + " blockCount: "+blockCount);
writer.println("// type?: "+type+" session: "+sessionId+" storage: " + sId + " pos: " + recId + " blockCount: "+bCount);
}
break;
}
......@@ -685,9 +685,9 @@ public class Recover extends Tool implements DataHandler {
writer.println("//");
int len = in.readInt();
for (int i = 0; i < len; i++) {
int storageId = in.readInt();
if (storageId != -1) {
writer.println("// pos: " + (i * DiskFile.BLOCKS_PER_PAGE) + " storage: " + storageId);
int sId = in.readInt();
if (sId != -1) {
writer.println("// pos: " + (i * DiskFile.BLOCKS_PER_PAGE) + " storage: " + sId);
}
}
while (true) {
......@@ -705,22 +705,22 @@ public class Recover extends Tool implements DataHandler {
private void dumpIndex(String fileName) {
PrintWriter writer = null;
FileStore store = null;
FileStore fileStore = null;
try {
setDatabaseName(fileName.substring(fileName.length() - Constants.SUFFIX_INDEX_FILE.length()));
writer = getWriter(fileName, ".txt");
store = FileStore.open(null, fileName, "r");
long length = store.length();
fileStore = FileStore.open(null, fileName, "r");
long length = fileStore.length();
int offset = FileStore.HEADER_LENGTH;
int blockSize = DiskFile.BLOCK_SIZE;
int blocks = (int) (length / blockSize);
blockCount = 1;
int[] pageOwners = new int[blocks / DiskFile.BLOCKS_PER_PAGE];
for (block = 0; block < blocks; block += blockCount) {
store.seek(offset + (long) block * blockSize);
fileStore.seek(offset + (long) block * blockSize);
byte[] buff = new byte[blockSize];
DataPage s = DataPage.create(this, buff);
store.readFully(buff, 0, blockSize);
fileStore.readFully(buff, 0, blockSize);
blockCount = s.readInt();
setStorage(-1);
recordLength = -1;
......@@ -746,7 +746,7 @@ public class Recover extends Tool implements DataHandler {
continue;
}
if (blockCount > 1) {
store.readFully(s.getBytes(), blockSize, blockCount * blockSize - blockSize);
fileStore.readFully(s.getBytes(), blockSize, blockCount * blockSize - blockSize);
}
try {
s.check(blockCount * blockSize);
......@@ -799,7 +799,7 @@ public class Recover extends Tool implements DataHandler {
e.printStackTrace();
} finally {
IOUtils.closeSilently(writer);
closeSilently(store);
closeSilently(fileStore);
}
}
......
......@@ -541,7 +541,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
/**
* Test method to create a simple result set.
*
* @param count the number of rows
* @param rowCount the number of rows
* @param ip an int
* @param bp a boolean
* @param fp a float
......@@ -551,24 +551,24 @@ public class TestFunctions extends TestBase implements AggregateFunction {
* @param sp a short
* @return a result set
*/
public static ResultSet simpleResultSet(Integer count, int ip, boolean bp, float fp, double dp, long lp,
public static ResultSet simpleResultSet(Integer rowCount, int ip, boolean bp, float fp, double dp, long lp,
byte byParam, short sp) throws SQLException {
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("ID", Types.INTEGER, 10, 0);
rs.addColumn("NAME", Types.VARCHAR, 255, 0);
if (count == null) {
if (rowCount == null) {
if (ip != 0 || bp || fp != 0.0 || dp != 0.0 || sp != 0 || lp != 0 || byParam != 0) {
throw new AssertionError("params not 0/false");
}
}
if (count != null) {
if (rowCount != null) {
if (ip != 1 || !bp || fp != 1.0 || dp != 1.0 || sp != 1 || lp != 1 || byParam != 1) {
throw new AssertionError("params not 1/true");
}
if (count.intValue() >= 1) {
if (rowCount.intValue() >= 1) {
rs.addRow(0, "Hello");
}
if (count.intValue() >= 2) {
if (rowCount.intValue() >= 2) {
rs.addRow(1, "World");
}
}
......
......@@ -61,8 +61,8 @@ public class TestBatchUpdates extends TestBase {
private void testExecuteCall() throws SQLException {
deleteDb("batchUpdates");
Connection conn = getConnection("batchUpdates");
Statement stat = conn.createStatement();
conn = getConnection("batchUpdates");
stat = conn.createStatement();
stat.execute("CREATE ALIAS updatePrices FOR \"" + getClass().getName() + ".updatePrices\"");
CallableStatement call = conn.prepareCall("{call updatePrices(?, ?)}");
call.setString(1, "Hello");
......@@ -93,10 +93,10 @@ public class TestBatchUpdates extends TestBase {
private void testException() throws SQLException {
deleteDb("batchUpdates");
Connection conn = getConnection("batchUpdates");
Statement stat = conn.createStatement();
conn = getConnection("batchUpdates");
stat = conn.createStatement();
stat.execute("create table test(id int primary key)");
PreparedStatement prep = conn.prepareStatement("insert into test values(?)");
prep = conn.prepareStatement("insert into test values(?)");
for (int i = 0; i < 700; i++) {
prep.setString(1, "x");
prep.addBatch();
......@@ -119,7 +119,7 @@ public class TestBatchUpdates extends TestBase {
private void testCoffee() throws SQLException {
deleteDb("batchUpdates");
this.conn = getConnection("batchUpdates");
conn = getConnection("batchUpdates");
stat = conn.createStatement();
DatabaseMetaData meta = conn.getMetaData();
if (!meta.supportsBatchUpdates()) {
......
......@@ -197,7 +197,7 @@ public class TestMetaData extends TestBase {
trace(name + "=" + value);
}
test(conn);
testMore();
// meta.getTablePrivileges()
......@@ -215,17 +215,17 @@ public class TestMetaData extends TestBase {
}
private void testColumnLobMeta() throws SQLException {
Statement stat = conn.createStatement();
stat = conn.createStatement();
stat.executeUpdate("CREATE TABLE t (blob BLOB, clob CLOB)");
stat.execute("INSERT INTO t VALUES('', '')");
ResultSet rs = stat.executeQuery("SELECT blob,clob FROM t");
ResultSetMetaData meta = rs.getMetaData();
ResultSetMetaData rsMeta = rs.getMetaData();
if (SysProperties.RETURN_LOB_OBJECTS) {
assertEquals("java.sql.Blob", meta.getColumnClassName(1));
assertEquals("java.sql.Clob", meta.getColumnClassName(2));
assertEquals("java.sql.Blob", rsMeta.getColumnClassName(1));
assertEquals("java.sql.Clob", rsMeta.getColumnClassName(2));
} else {
assertEquals("java.io.InputStream", meta.getColumnClassName(1));
assertEquals("java.io.Reader", meta.getColumnClassName(2));
assertEquals("java.io.InputStream", rsMeta.getColumnClassName(1));
assertEquals("java.io.Reader", rsMeta.getColumnClassName(2));
}
rs.next();
if (SysProperties.RETURN_LOB_OBJECTS) {
......@@ -239,50 +239,50 @@ public class TestMetaData extends TestBase {
}
private void testColumnMetaData() throws SQLException {
String statement = "select substring('Hello',0,1)";
ResultSet rs = conn.prepareStatement(statement).executeQuery();
String sql = "select substring('Hello',0,1)";
ResultSet rs = conn.prepareStatement(sql).executeQuery();
rs.next();
int type = rs.getMetaData().getColumnType(1);
assertEquals(Types.VARCHAR, type);
rs = conn.createStatement().executeQuery("SELECT COUNT(*) C FROM DUAL");
assertEquals("C", rs.getMetaData().getColumnName(1));
Statement stat = conn.createStatement();
stat = conn.createStatement();
stat.execute("create table a(x array)");
stat.execute("insert into a values((1, 2))");
rs = stat.executeQuery("SELECT x[1] FROM a");
ResultSetMetaData meta = rs.getMetaData();
assertEquals(Types.VARCHAR, meta.getColumnType(1));
ResultSetMetaData rsMeta = rs.getMetaData();
assertEquals(Types.VARCHAR, rsMeta.getColumnType(1));
rs.next();
// assertEquals(String.class.getName(), rs.getObject(1).getClass().getName());
stat.execute("drop table a");
}
private void testColumnPrecision() throws SQLException {
Statement stat = conn.createStatement();
stat = conn.createStatement();
stat.execute("CREATE TABLE ONE(X NUMBER(12,2), Y FLOAT)");
stat.execute("CREATE TABLE TWO AS SELECT * FROM ONE");
ResultSet rs;
ResultSetMetaData meta;
ResultSetMetaData rsMeta;
rs = stat.executeQuery("SELECT * FROM ONE");
meta = rs.getMetaData();
assertEquals(12, meta.getPrecision(1));
assertEquals(17, meta.getPrecision(2));
assertEquals(Types.DECIMAL, meta.getColumnType(1));
assertEquals(Types.DOUBLE, meta.getColumnType(2));
rsMeta = rs.getMetaData();
assertEquals(12, rsMeta.getPrecision(1));
assertEquals(17, rsMeta.getPrecision(2));
assertEquals(Types.DECIMAL, rsMeta.getColumnType(1));
assertEquals(Types.DOUBLE, rsMeta.getColumnType(2));
rs = stat.executeQuery("SELECT * FROM TWO");
meta = rs.getMetaData();
assertEquals(12, meta.getPrecision(1));
assertEquals(17, meta.getPrecision(2));
assertEquals(Types.DECIMAL, meta.getColumnType(1));
assertEquals(Types.DOUBLE, meta.getColumnType(2));
rsMeta = rs.getMetaData();
assertEquals(12, rsMeta.getPrecision(1));
assertEquals(17, rsMeta.getPrecision(2));
assertEquals(Types.DECIMAL, rsMeta.getColumnType(1));
assertEquals(Types.DOUBLE, rsMeta.getColumnType(2));
stat.execute("DROP TABLE ONE, TWO");
}
private void testColumnDefault() throws SQLException {
DatabaseMetaData meta = conn.getMetaData();
meta = conn.getMetaData();
ResultSet rs;
Statement stat = conn.createStatement();
stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(A INT, B INT DEFAULT NULL)");
rs = meta.getColumns(null, null, "TEST", null);
rs.next();
......@@ -296,9 +296,9 @@ public class TestMetaData extends TestBase {
}
private void testProcedureColumns() throws SQLException {
DatabaseMetaData meta = conn.getMetaData();
meta = conn.getMetaData();
ResultSet rs;
Statement stat = conn.createStatement();
stat = conn.createStatement();
stat.execute("CREATE ALIAS PROP FOR \"java.lang.System.getProperty(java.lang.String)\"");
stat.execute("CREATE ALIAS EXIT FOR \"java.lang.System.exit\"");
rs = meta.getProcedures(null, null, "EX%");
......@@ -330,12 +330,11 @@ public class TestMetaData extends TestBase {
}
private void testCrossReferences() throws SQLException {
DatabaseMetaData meta = conn.getMetaData();
meta = conn.getMetaData();
ResultSet rs;
Statement stat = conn.createStatement();
stat = conn.createStatement();
stat.execute("CREATE TABLE PARENT(A INT, B INT, PRIMARY KEY(A, B))");
stat
.execute("CREATE TABLE CHILD(ID INT PRIMARY KEY, PA INT, PB INT, CONSTRAINT AB FOREIGN KEY(PA, PB) REFERENCES PARENT(A, B))");
stat.execute("CREATE TABLE CHILD(ID INT PRIMARY KEY, PA INT, PB INT, CONSTRAINT AB FOREIGN KEY(PA, PB) REFERENCES PARENT(A, B))");
rs = meta.getCrossReference(null, "PUBLIC", "PARENT", null, "PUBLIC", "CHILD");
checkCrossRef(rs);
rs = meta.getImportedKeys(null, "PUBLIC", "CHILD");
......@@ -363,8 +362,8 @@ public class TestMetaData extends TestBase {
}
private void testTempTable() throws SQLException {
Connection conn = getConnection("metaData");
Statement stat = conn.createStatement();
conn = getConnection("metaData");
stat = conn.createStatement();
stat.execute("DROP TABLE IF EXISTS TEST_TEMP");
stat.execute("CREATE TEMP TABLE TEST_TEMP(ID INT PRIMARY KEY, NAME VARCHAR(255))");
stat.execute("CREATE INDEX IDX_NAME ON TEST_TEMP(NAME)");
......@@ -579,9 +578,9 @@ public class TestMetaData extends TestBase {
assertTrue(meta.usesLocalFiles());
}
private void test(Connection conn) throws SQLException {
DatabaseMetaData meta = conn.getMetaData();
Statement stat = conn.createStatement();
private void testMore() throws SQLException {
meta = conn.getMetaData();
stat = conn.createStatement();
ResultSet rs;
conn.setReadOnly(true);
......
......@@ -209,7 +209,7 @@ public class TestNativeSQL extends TestBase {
private void testPairs() {
for (int i = 0; i < PAIRS.length; i += 2) {
test(conn, PAIRS[i], PAIRS[i + 1]);
test(PAIRS[i], PAIRS[i + 1]);
}
}
......@@ -241,7 +241,7 @@ public class TestNativeSQL extends TestBase {
assertFalse(conn.isClosed());
}
private void test(Connection conn, String original, String expected) {
private void test(String original, String expected) {
trace("original: <" + original + ">");
trace("expected: <" + expected + ">");
try {
......
......@@ -166,7 +166,7 @@ public class TestResultSet extends TestBase {
assertFalse(meta.ownDeletesAreVisible(type));
assertFalse(meta.ownInsertsAreVisible(type));
}
Statement stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello')");
......@@ -182,7 +182,7 @@ public class TestResultSet extends TestBase {
}
private void testUpdatePrimaryKey() throws SQLException {
Statement stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello')");
......@@ -920,7 +920,7 @@ public class TestResultSet extends TestBase {
trace("Test CLOB");
ResultSet rs;
String string;
Statement stat = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
stat = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY,VALUE CLOB)");
stat.execute("INSERT INTO TEST VALUES(1,'Test')");
stat.execute("INSERT INTO TEST VALUES(2,'Hello')");
......
......@@ -66,22 +66,22 @@ public class TestStatement extends TestBase {
// ignore
}
FileObject trace = FileSystem.getInstance(fileName).openFileObject(fileName, "r");
long start = trace.length();
long lengthBefore = trace.length();
try {
stat.execute("ERROR");
} catch (SQLException e) {
// ignore
}
long error = trace.length();
assertSmaller(start, error);
start = error;
assertSmaller(lengthBefore, error);
lengthBefore = error;
try {
stat.execute("INSERT INTO TEST VALUES(1)");
} catch (SQLException e) {
// ignore
}
error = trace.length();
assertEquals(start, error);
assertEquals(lengthBefore, error);
stat.execute("DROP TABLE TEST IF EXISTS");
}
......
......@@ -60,17 +60,17 @@ public class TestConnectionPool extends TestBase {
JdbcConnectionPool man = JdbcConnectionPool.create(url, user, password);
Connection conn = man.getConnection();
int len = 1000;
long start = System.currentTimeMillis();
long time = System.currentTimeMillis();
for (int i = 0; i < len; i++) {
man.getConnection().close();
}
trace((int) (System.currentTimeMillis() - start));
trace((int) (System.currentTimeMillis() - time));
man.dispose();
start = System.currentTimeMillis();
time = System.currentTimeMillis();
for (int i = 0; i < len; i++) {
DriverManager.getConnection(url, user, password).close();
}
trace((int) (System.currentTimeMillis() - start));
trace((int) (System.currentTimeMillis() - time));
conn.close();
}
......
......@@ -182,8 +182,8 @@ public class TestCrashAPI extends TestBase {
throw e;
}
int len = random.getInt(50);
int start = random.getInt(statements.size() - len);
int end = start + len;
int first = random.getInt(statements.size() - len);
int end = first + len;
Statement stat = conn.createStatement();
stat.execute("SET LOCK_TIMEOUT 10");
stat.execute("SET WRITE_DELAY 0");
......@@ -197,7 +197,7 @@ public class TestCrashAPI extends TestBase {
}
}
stat.execute("SCRIPT NOPASSWORDS NOSETTINGS");
for (int i = start; i < end && i < statements.size(); i++) {
for (int i = first; i < end && i < statements.size(); i++) {
try {
stat.execute("SELECT * FROM TEST WHERE ID=1");
} catch (Throwable t) {
......
......@@ -228,14 +228,14 @@ public abstract class TestHalt extends TestBase {
// OP_DELETE = 1, OP_UPDATE = 2, OP_SELECT = 4;
// int flags = FLAG_NODELAY;
// FLAG_NO_DELAY = 1, FLAG_AUTO_COMMIT = 2, FLAG_SMALL_CACHE = 4;
int value = random.nextInt(1000);
int testValue = random.nextInt(1000);
// for Derby and HSQLDB
// String classPath = "-cp
// .;D:/data/java/hsqldb.jar;D:/data/java/derby.jar";
String selfDestruct = SelfDestructor.getPropertyString(60);
String[] procDef = new String[] { "java", selfDestruct, getPageStoreProperty(),
"-cp", getClassPath(),
getClass().getName(), "" + operations, "" + flags, "" + value};
getClass().getName(), "" + operations, "" + flags, "" + testValue};
traceOperation("start: " + StringUtils.arrayCombine(procDef, ' '));
Process p = Runtime.getRuntime().exec(procDef);
InputStream in = p.getInputStream();
......
......@@ -100,14 +100,14 @@ public class TestJoin extends TestBase {
execute("INSERT INTO TWO VALUES(3, 3)", null);
execute("INSERT INTO TWO VALUES(4, NULL)", null);
random = new Random();
long start = System.currentTimeMillis();
long startTime = System.currentTimeMillis();
for (int i = 0;; i++) {
paramCount = 0;
buff = new StringBuilder();
long time = System.currentTimeMillis();
if (time - start > 5000) {
if (time - startTime > 5000) {
printTime("i:" + i);
start = time;
startTime = time;
}
buff.append("SELECT ");
int tables = 1 + random.nextInt(5);
......@@ -279,27 +279,27 @@ public class TestJoin extends TestBase {
}
private String readResult(ResultSet rs) throws SQLException {
StringBuilder buff = new StringBuilder();
StringBuilder b = new StringBuilder();
ResultSetMetaData meta = rs.getMetaData();
int columnCount = meta.getColumnCount();
for (int i = 0; i < columnCount; i++) {
if (i > 0) {
buff.append(",");
b.append(",");
}
buff.append(StringUtils.toUpperEnglish(meta.getColumnLabel(i + 1)));
b.append(StringUtils.toUpperEnglish(meta.getColumnLabel(i + 1)));
}
buff.append(":\n");
String result = buff.toString();
b.append(":\n");
String result = b.toString();
ArrayList<String> list = New.arrayList();
while (rs.next()) {
buff = new StringBuilder();
b = new StringBuilder();
for (int i = 0; i < columnCount; i++) {
if (i > 0) {
buff.append(",");
b.append(",");
}
buff.append(rs.getString(i + 1));
b.append(rs.getString(i + 1));
}
list.add(buff.toString());
list.add(b.toString());
}
Collections.sort(list);
for (int i = 0; i < list.size(); i++) {
......
......@@ -30,7 +30,7 @@ public class TestRandomSQL extends TestBase {
private ArrayList<RuleHead> statements;
private int seed;
private boolean exitOnError = true;
private Bnf bnf;
private Bnf bnfSyntax;
private int success, total;
/**
......@@ -99,9 +99,9 @@ public class TestRandomSQL extends TestBase {
public TestBase init(TestAll conf) throws Exception {
super.init(conf);
bnf = Bnf.getInstance(null);
bnf.linkStatements();
statements = bnf.getStatements();
bnfSyntax = Bnf.getInstance(null);
bnfSyntax.linkStatements();
statements = bnfSyntax.getStatements();
// go backwards so we can append at the end
for (int i = statements.size() - 1; i >= 0; i--) {
......@@ -131,8 +131,8 @@ public class TestRandomSQL extends TestBase {
return this;
}
private void testWithSeed(Bnf config) throws SQLException {
config.getRandom().setSeed(seed);
private void testWithSeed(Bnf bnf) throws SQLException {
bnf.getRandom().setSeed(seed);
Connection conn = null;
try {
conn = connect();
......@@ -142,9 +142,9 @@ public class TestRandomSQL extends TestBase {
}
Statement stat = conn.createStatement();
for (int i = 0; i < statements.size(); i++) {
int sid = config.getRandom().nextInt(statements.size());
int sid = bnf.getRandom().nextInt(statements.size());
RuleHead r = statements.get(sid);
String rand = r.getRule().random(config, 0).trim();
String rand = r.getRule().random(bnf, 0).trim();
if (rand.length() > 0) {
try {
Thread.yield();
......@@ -184,7 +184,7 @@ public class TestRandomSQL extends TestBase {
} catch (SQLException e) {
processException("deleteDb", e);
}
testWithSeed(bnf);
testWithSeed(bnfSyntax);
} finally {
SysProperties.setScriptDirectory(old);
}
......@@ -203,8 +203,8 @@ public class TestRandomSQL extends TestBase {
exitOnError = false;
showSQL = false;
for (int a = 0; a < len; a++) {
int seed = RandomUtils.nextInt(Integer.MAX_VALUE);
testCase(seed);
int s = RandomUtils.nextInt(Integer.MAX_VALUE);
testCase(s);
}
}
......
......@@ -67,10 +67,10 @@ public class TestThreads extends TestBase implements Runnable {
int threadCount = 4;
Thread[] threads = new Thread[threadCount];
for (int i = 0; i < threadCount; i++) {
String table = random.nextBoolean() ? null : getRandomTable();
String t = random.nextBoolean() ? null : getRandomTable();
int op = random.nextInt(OP_TYPES);
op = i % 2 == 0 ? RECONNECT : CHECKPOINT;
threads[i] = new Thread(new TestThreads(this, op, table));
threads[i] = new Thread(new TestThreads(this, op, t));
}
for (int i = 0; i < threadCount; i++) {
threads[i].start();
......
......@@ -47,7 +47,7 @@ public class TestTimer extends TestBase {
Random random = new Random();
int max = 0;
int count = 0;
long start = System.currentTimeMillis();
long startTime = System.currentTimeMillis();
while (true) {
int action = random.nextInt(10);
int x = max == 0 ? 0 : random.nextInt(max);
......@@ -82,9 +82,9 @@ public class TestTimer extends TestBase {
int c = rs.getInt(1);
assertEquals(count, c);
long time = System.currentTimeMillis();
if (time > start + 5000) {
if (time > startTime + 5000) {
println("rows: " + count);
start = time;
startTime = time;
}
break;
default:
......
......@@ -55,13 +55,14 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener
}
public void test() throws Exception {
testReconnect(true);
testReconnect(false);
autoServer = true;
testReconnect();
autoServer = false;
testReconnect();
deleteDb("autoReconnect");
}
private void testReconnect(boolean autoServer) throws Exception {
this.autoServer = autoServer;
private void testReconnect() throws Exception {
deleteDb("autoReconnect");
if (autoServer) {
url = "jdbc:h2:" + baseDir + "/autoReconnect;" +
......@@ -197,7 +198,7 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener
// ignore
}
public void init(String url) {
public void init(String u) {
state = "init";
}
......
......@@ -47,9 +47,8 @@ public class TestClearReferences extends TestBase {
}
public void test() throws Exception {
String baseDir = "bin/org/h2";
ArrayList<Class < ? >> classes = New.arrayList();
check(classes, new File(baseDir));
check(classes, new File("bin/org/h2"));
for (Class< ? > clazz : classes) {
clearClass(clazz);
}
......
......@@ -137,7 +137,7 @@ public class TestCompress extends TestBase {
byte[] test = new byte[2 * pageSize];
compress.compress(buff, pageSize, test, 0);
for (int j = 0; j < 4; j++) {
long start = System.currentTimeMillis();
long time = System.currentTimeMillis();
for (int i = 0; i < 1000; i++) {
InputStream in = FileSystem.getInstance("memFS:").openFileInputStream("memFS:compress.h2.db");
int total = 0;
......@@ -150,7 +150,7 @@ public class TestCompress extends TestBase {
}
in.close();
}
System.out.println("compress: " + (System.currentTimeMillis() - start) + " ms");
System.out.println("compress: " + (System.currentTimeMillis() - time) + " ms");
}
for (int j = 0; j < 4; j++) {
......@@ -168,14 +168,14 @@ public class TestCompress extends TestBase {
}
in.close();
byte[] result = new byte[pageSize];
long start = System.currentTimeMillis();
long time = System.currentTimeMillis();
for (int i = 0; i < 1000; i++) {
for (int k = 0; k < comp.size(); k++) {
byte[] data = comp.get(k);
compress.expand(data, 0, data.length, result, 0, pageSize);
}
}
System.out.println("expand: " + (System.currentTimeMillis() - start) + " ms");
System.out.println("expand: " + (System.currentTimeMillis() - time) + " ms");
}
}
......@@ -214,11 +214,11 @@ public class TestCompress extends TestBase {
}
CompressTool utils = CompressTool.getInstance();
for (String a : new String[] { "LZF", "No", "Deflate" }) {
long start = System.currentTimeMillis();
long time = System.currentTimeMillis();
byte[] out = utils.compress(buff, a);
byte[] test = utils.expand(out);
if (testPerformance) {
System.out.println("p:" + pattern + " len: " + out.length + " time: " + (System.currentTimeMillis() - start) + " " + a);
System.out.println("p:" + pattern + " len: " + out.length + " time: " + (System.currentTimeMillis() - time) + " " + a);
}
assertEquals(buff.length, test.length);
assertEquals(buff, test);
......
......@@ -217,8 +217,8 @@ public class TestDataPage extends TestBase implements DataHandler {
return null;
}
public int getChecksum(byte[] data, int start, int end) {
return end - start;
public int getChecksum(byte[] data, int s, int e) {
return e - s;
}
public void checkPowerOff() {
......
......@@ -157,7 +157,7 @@ public class TestFile extends TestBase implements DataHandler {
// nothing to do
}
public int getChecksum(byte[] data, int start, int end) {
public int getChecksum(byte[] data, int s, int e) {
return 0;
}
......
......@@ -78,13 +78,13 @@ public class TestFileLock extends TestBase implements Runnable {
lock2.unlock();
}
private void test(boolean allowSockets) throws Exception {
private void test(boolean allowSocketsLock) throws Exception {
int threadCount = getSize(3, 5);
wait = getSize(20, 200);
Thread[] threads = new Thread[threadCount];
new File(FILE).delete();
for (int i = 0; i < threadCount; i++) {
threads[i] = new Thread(new TestFileLock(this, allowSockets));
threads[i] = new Thread(new TestFileLock(this, allowSocketsLock));
threads[i].start();
Thread.sleep(wait + (int) (Math.random() * wait));
}
......
......@@ -71,9 +71,9 @@ public class TestFileLockSerialized extends TestBase {
deleteDb("fileLockSerialized");
final String url = "jdbc:h2:" + baseDir + "/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE";
Connection c = DriverManager.getConnection(url);
c.createStatement().execute("create table test(id int) as select 1");
c.close();
Connection conn = DriverManager.getConnection(url);
conn.createStatement().execute("create table test(id int) as select 1");
conn.close();
final int len = 10;
final Exception[] ex = new Exception[1];
......@@ -147,9 +147,9 @@ public class TestFileLockSerialized extends TestBase {
while (!stop[0]) {
try {
Thread.sleep(10);
Connection conn = DriverManager.getConnection(writeUrl, "sa", "sa");
conn.createStatement().execute("select * from test");
conn.close();
Connection c = DriverManager.getConnection(writeUrl, "sa", "sa");
c.createStatement().execute("select * from test");
c.close();
} catch (Exception e) {
// ignore
}
......@@ -294,10 +294,10 @@ public class TestFileLockSerialized extends TestBase {
final String url = "jdbc:h2:" + baseDir + "/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;" +
"AUTO_RECONNECT=TRUE;MAX_LENGTH_INPLACE_LOB=8192;COMPRESS_LOB=DEFLATE;LOG=2;CACHE_SIZE=65536";
Connection c = DriverManager.getConnection(url);
c.createStatement().execute("create table test(id int)");
c.createStatement().execute("insert into test values(1)");
c.close();
Connection conn = DriverManager.getConnection(url);
conn.createStatement().execute("create table test(id int)");
conn.createStatement().execute("insert into test values(1)");
conn.close();
final long endTime = System.currentTimeMillis() + runTime;
final Exception[] ex = new Exception[1];
......
......@@ -24,7 +24,7 @@ import org.h2.value.ValueString;
public class TestOverflow extends TestBase {
private ArrayList<Value> values;
private int type;
private int dataType;
private BigInteger min, max;
private boolean successExpected;
......@@ -44,24 +44,24 @@ public class TestOverflow extends TestBase {
test(Value.SHORT, Short.MIN_VALUE, Short.MAX_VALUE);
}
private void test(int type, long min, long max) throws SQLException {
private void test(int type, long minValue, long maxValue) throws SQLException {
values = New.arrayList();
this.type = type;
this.min = new BigInteger("" + min);
this.max = new BigInteger("" + max);
this.dataType = type;
this.min = new BigInteger("" + minValue);
this.max = new BigInteger("" + maxValue);
add(0);
add(min);
add(max);
add(max - 1);
add(min + 1);
add(minValue);
add(maxValue);
add(maxValue - 1);
add(minValue + 1);
add(1);
add(-1);
Random random = new Random(1);
for (int i = 0; i < 40; i++) {
if (max > Integer.MAX_VALUE) {
if (maxValue > Integer.MAX_VALUE) {
add(random.nextLong());
} else {
add((random.nextBoolean() ? 1 : -1) * random.nextInt((int) max));
add((random.nextBoolean() ? 1 : -1) * random.nextInt((int) maxValue));
}
}
for (Value va : values) {
......@@ -127,7 +127,7 @@ public class TestOverflow extends TestBase {
}
private void add(long l) throws SQLException {
values.add(ValueString.get("" + l).convertTo(type));
values.add(ValueString.get("" + l).convertTo(dataType));
}
}
......@@ -325,15 +325,15 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
p = updateMany[random.nextInt(tableCount)];
p.setInt(1, i);
p.setInt(2, random.nextInt(50));
int start = random.nextInt(1 + i);
p.setInt(3, start);
p.setInt(4, start + random.nextInt(50));
int first = random.nextInt(1 + i);
p.setInt(3, first);
p.setInt(4, first + random.nextInt(50));
p.executeUpdate();
} else {
p = deleteMany[random.nextInt(tableCount)];
int start = random.nextInt(1 + i);
p.setInt(1, start);
p.setInt(2, start + random.nextInt(100));
int first = random.nextInt(1 + i);
p.setInt(1, first);
p.setInt(2, first + random.nextInt(100));
p.executeUpdate();
}
}
......
......@@ -354,10 +354,10 @@ public class TestTools extends TestBase {
private void testManagementDb() throws SQLException {
int count = getSize(2, 10);
for (int i = 0; i < count; i++) {
Server server = Server.createTcpServer("-tcpPort", "9192").start();
server.stop();
server = Server.createTcpServer("-tcpPassword", "abc", "-tcpPort", "9192").start();
server.stop();
Server tcpServer = Server.createTcpServer("-tcpPort", "9192").start();
tcpServer.stop();
tcpServer = Server.createTcpServer("-tcpPassword", "abc", "-tcpPort", "9192").start();
tcpServer.stop();
}
}
......@@ -494,13 +494,13 @@ public class TestTools extends TestBase {
private void testServer() throws SQLException {
Connection conn;
deleteDb("test");
Server server = Server.createTcpServer(
Server tcpServer = Server.createTcpServer(
"-baseDir", baseDir,
"-tcpPort", "9192",
"-tcpAllowOthers").start();
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9192/test", "sa", "");
conn.close();
server.stop();
tcpServer.stop();
Server.createTcpServer(
"-ifExists",
"-tcpPassword", "abc",
......
......@@ -122,7 +122,7 @@ public class TestValueHashMap extends TestBase implements DataHandler {
return null;
}
public int getChecksum(byte[] data, int start, int end) {
public int getChecksum(byte[] data, int s, int e) {
return 0;
}
......
......@@ -214,7 +214,7 @@ public class TestValueMemory extends TestBase implements DataHandler {
// nothing to do
}
public int getChecksum(byte[] data, int start, int end) {
public int getChecksum(byte[] data, int s, int e) {
return 0;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论