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

Smaller changes (mainly for Android).

上级 7692231b
......@@ -49,7 +49,7 @@ public class CommandContainer extends Command {
long mod = prepared.getModificationMetaId();
prepared.setModificationMetaId(0);
ArrayList<Parameter> newParams = prepared.getParameters();
for (int i = 0; i < newParams.size(); i++) {
for (int i = 0, size = newParams.size(); i < size; i++) {
Parameter old = oldParams.get(i);
if (old.isValueSet()) {
Value v = old.getValue(session);
......
......@@ -651,7 +651,7 @@ public class Parser {
read(")");
read("=");
Expression expression = readExpression();
for (int i = 0; i < columns.size(); i++) {
for (int i = 0, size = columns.size(); i < size; i++) {
Column column = columns.get(i);
Function f = Function.getFunction(database, "ARRAY_GET");
f.setParameter(0, expression);
......
......@@ -105,7 +105,7 @@ public class Call extends Prepared {
}
public boolean isReadOnly() {
return expression.isEverything(ExpressionVisitor.READONLY);
return expression.isEverything(ExpressionVisitor.READONLY_VISITOR);
}
......
......@@ -200,7 +200,7 @@ public abstract class Query extends Prepared {
return false;
}
}
if (!isEverything(ExpressionVisitor.DETERMINISTIC) || !isEverything(ExpressionVisitor.INDEPENDENT)) {
if (!isEverything(ExpressionVisitor.DETERMINISTIC_VISITOR) || !isEverything(ExpressionVisitor.INDEPENDENT_VISITOR)) {
return false;
}
if (db.getModificationDataId() > lastEval && getMaxDataModificationId() > lastEval) {
......@@ -241,7 +241,7 @@ public abstract class Query extends Prepared {
}
Value[] params = getParameterValues();
long now = session.getDatabase().getModificationDataId();
if (isEverything(ExpressionVisitor.DETERMINISTIC)) {
if (isEverything(ExpressionVisitor.DETERMINISTIC_VISITOR)) {
if (lastResult != null && !lastResult.isClosed() && limit == lastLimit) {
if (sameResultAsLast(session, params, lastParameters, lastEvaluated)) {
lastResult = lastResult.createShallowCopy(session);
......
......@@ -874,7 +874,8 @@ public class Select extends Query {
}
public void fireBeforeSelectTriggers() {
for (TableFilter filter : filters) {
for (int i = 0, size = filters.size(); i < size; i++) {
TableFilter filter = filters.get(i);
filter.getTable().fire(session, Trigger.SELECT, true);
}
}
......@@ -908,7 +909,7 @@ public class Select extends Query {
}
Expression on = f.getJoinCondition();
if (on != null) {
if (!on.isEverything(ExpressionVisitor.EVALUATABLE)) {
if (!on.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR)) {
if (SysProperties.NESTED_JOINS) {
f.removeJoinCondition();
// need to check that all added are bound to a table
......@@ -932,7 +933,7 @@ public class Select extends Query {
}
on = f.getFilterCondition();
if (on != null) {
if (!on.isEverything(ExpressionVisitor.EVALUATABLE)) {
if (!on.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR)) {
f.removeFilterCondition();
addCondition(on);
}
......@@ -1105,7 +1106,7 @@ public class Select extends Query {
Expression comp;
Expression col = expressions.get(columnId);
col = col.getNonAliasExpression();
if (col.isEverything(ExpressionVisitor.QUERY_COMPARABLE)) {
if (col.isEverything(ExpressionVisitor.QUERY_COMPARABLE_VISITOR)) {
comp = new Comparison(session, comparisonType, col, param);
} else {
// add the parameters, so they can be set later
......@@ -1159,7 +1160,8 @@ public class Select extends Query {
if (isForUpdate) {
return false;
}
for (TableFilter f : filters) {
for (int i = 0, size = filters.size(); i < size; i++) {
TableFilter f = filters.get(i);
if (!f.getTable().isDeterministic()) {
return false;
}
......@@ -1167,7 +1169,8 @@ public class Select extends Query {
break;
}
case ExpressionVisitor.SET_MAX_DATA_MODIFICATION_ID: {
for (TableFilter f : filters) {
for (int i = 0, size = filters.size(); i < size; i++) {
TableFilter f = filters.get(i);
long m = f.getTable().getMaxDataModificationId();
visitor.addDataModificationId(m);
}
......@@ -1180,8 +1183,9 @@ public class Select extends Query {
break;
}
case ExpressionVisitor.GET_DEPENDENCIES: {
for (TableFilter filter : filters) {
Table table = filter.getTable();
for (int i = 0, size = filters.size(); i < size; i++) {
TableFilter f = filters.get(i);
Table table = f.getTable();
visitor.addDependency(table);
table.addDependencies(visitor.getDependencies());
}
......@@ -1191,7 +1195,8 @@ public class Select extends Query {
}
visitor.incrementQueryLevel(1);
boolean result = true;
for (Expression e : expressions) {
for (int i = 0, size = expressions.size(); i < size; i++) {
Expression e = expressions.get(i);
if (!e.isEverything(visitor)) {
result = false;
break;
......@@ -1208,7 +1213,7 @@ public class Select extends Query {
}
public boolean isReadOnly() {
return isEverything(ExpressionVisitor.READONLY);
return isEverything(ExpressionVisitor.READONLY_VISITOR);
}
......
......@@ -148,7 +148,7 @@ public class Database implements DataHandler {
private Mode mode = Mode.getInstance(Mode.REGULAR);
private boolean multiThreaded;
private int maxOperationMemory = SysProperties.DEFAULT_MAX_OPERATION_MEMORY;
private SmallLRUCache<String, String[]> lobFileListCache = SmallLRUCache.newInstance(128);
private SmallLRUCache<String, String[]> lobFileListCache;
private boolean autoServerMode;
private Server server;
private HashMap<TableLinkConnection, TableLinkConnection> linkConnections;
......@@ -672,7 +672,7 @@ public class Database implements DataHandler {
}
synchronized (infoSchema) {
if (!metaTablesInitialized) {
for (int type = 0; type < MetaTable.getMetaTableTypeCount(); type++) {
for (int type = 0, count = MetaTable.getMetaTableTypeCount(); type < count; type++) {
MetaTable m = new MetaTable(infoSchema, -1 - type, type);
infoSchema.add(m);
}
......@@ -1962,6 +1962,9 @@ public class Database implements DataHandler {
}
public SmallLRUCache<String, String[]> getLobFileListCache() {
if (lobFileListCache == null) {
lobFileListCache = SmallLRUCache.newInstance(128);
}
return lobFileListCache;
}
......
......@@ -469,7 +469,8 @@ public class Session extends SessionWithState {
rows.add(entry.getRow());
undoLog.removeLast(false);
}
for (Row r : rows) {
for (int i = 0, size = rows.size(); i < size; i++) {
Row r = rows.get(i);
r.commit();
}
}
......@@ -615,7 +616,9 @@ public class Session extends SessionWithState {
undoLog.add(log);
} else {
// see also UndoLogRecord.commit
for (Index index : table.getIndexes()) {
ArrayList<Index> indexes = table.getIndexes();
for (int i = 0, size = indexes.size(); i < size; i++) {
Index index = indexes.get(i);
index.commit(operation, row);
}
row.commit();
......
......@@ -6,6 +6,7 @@
*/
package org.h2.engine;
import java.util.ArrayList;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.index.Index;
......@@ -149,8 +150,9 @@ public class UndoLogRecord {
}
buff.writeLong(row.getKey());
buff.writeInt(row.getSessionId());
buff.writeInt(row.getColumnCount());
for (int i = 0; i < row.getColumnCount(); i++) {
int count = row.getColumnCount();
buff.writeInt(count);
for (int i = 0; i < count; i++) {
Value v = row.getValue(i);
buff.checkCapacity(buff.getValueLen(v));
buff.writeValue(v);
......@@ -260,7 +262,9 @@ public class UndoLogRecord {
* It commits the change to the indexes.
*/
public void commit() {
for (Index index : table.getIndexes()) {
ArrayList<Index> indexes = table.getIndexes();
for (int i = 0, size = indexes.size(); i < size; i++) {
Index index = indexes.get(i);
index.commit(operation, row);
}
}
......
......@@ -201,9 +201,10 @@ public class Aggregate extends Expression {
}
private SortOrder initOrder(Session session) {
int[] index = new int[orderList.size()];
int[] sortType = new int[orderList.size()];
for (int i = 0; i < orderList.size(); i++) {
int size = orderList.size();
int[] index = new int[size];
int[] sortType = new int[size];
for (int i = 0; i < size; i++) {
SelectOrderBy o = orderList.get(i);
index[i] = i + 1;
int order = o.descending ? SortOrder.DESCENDING : SortOrder.ASCENDING;
......@@ -240,9 +241,10 @@ public class Aggregate extends Expression {
if (v != ValueNull.INSTANCE) {
v = v.convertTo(Value.STRING);
if (orderList != null) {
Value[] array = new Value[1 + orderList.size()];
int size = orderList.size();
Value[] array = new Value[1 + size];
array[0] = v;
for (int i = 0; i < orderList.size(); i++) {
for (int i = 0; i < size; i++) {
SelectOrderBy o = orderList.get(i);
array[i + 1] = o.expression.getValue(session);
}
......
......@@ -284,7 +284,7 @@ public abstract class Expression {
* @param outerJoin if the expression is part of an outer join
*/
public void addFilterConditions(TableFilter filter, boolean outerJoin) {
if (!addedToFilter && !outerJoin && isEverything(ExpressionVisitor.EVALUATABLE)) {
if (!addedToFilter && !outerJoin && isEverything(ExpressionVisitor.EVALUATABLE_VISITOR)) {
filter.addFilterCondition(this, false);
addedToFilter = true;
}
......
......@@ -8,7 +8,9 @@ package org.h2.expression;
import java.util.HashSet;
import org.h2.constant.SysProperties;
import org.h2.engine.DbObject;
import org.h2.message.DbException;
import org.h2.table.ColumnResolver;
import org.h2.table.Table;
......@@ -25,6 +27,11 @@ public class ExpressionVisitor {
*/
public static final int INDEPENDENT = 0;
/**
* The visitor singleton for the type INDEPENDENT.
*/
public static final ExpressionVisitor INDEPENDENT_VISITOR = new ExpressionVisitor(INDEPENDENT);
/**
* Are all aggregates MIN(column), MAX(column), or COUNT(*) for the given
* table (getTable)?
......@@ -36,6 +43,11 @@ public class ExpressionVisitor {
*/
public static final int DETERMINISTIC = 2;
/**
* The visitor singleton for the type DETERMINISTIC.
*/
public static final ExpressionVisitor DETERMINISTIC_VISITOR = new ExpressionVisitor(DETERMINISTIC);
/**
* Can the expression be evaluated, that means are all columns set to
* 'evaluatable'?
......@@ -43,7 +55,12 @@ public class ExpressionVisitor {
public static final int EVALUATABLE = 3;
/**
* Request to set the latest modification id.
* The visitor singleton for the type EVALUATABLE.
*/
public static final ExpressionVisitor EVALUATABLE_VISITOR = new ExpressionVisitor(EVALUATABLE);
/**
* Request to set the latest modification id (addDataModificationId).
*/
public static final int SET_MAX_DATA_MODIFICATION_ID = 4;
......@@ -52,6 +69,11 @@ public class ExpressionVisitor {
*/
public static final int READONLY = 5;
/**
* The visitor singleton for the type EVALUATABLE.
*/
public static final ExpressionVisitor READONLY_VISITOR = new ExpressionVisitor(READONLY);
/**
* Does an expression have no relation to the given table filter
* (getResolver)?
......@@ -59,7 +81,7 @@ public class ExpressionVisitor {
public static final int NOT_FROM_RESOLVER = 6;
/**
* Request to get the set of dependencies.
* Request to get the set of dependencies (addDependency).
*/
public static final int GET_DEPENDENCIES = 7;
......@@ -71,6 +93,11 @@ public class ExpressionVisitor {
*/
public static final int QUERY_COMPARABLE = 8;
/**
* The visitor singleton for the type QUERY_COMPARABLE.
*/
public static final ExpressionVisitor QUERY_COMPARABLE_VISITOR = new ExpressionVisitor(QUERY_COMPARABLE);
private int queryLevel;
private Table table;
private int type;
......@@ -89,6 +116,16 @@ public class ExpressionVisitor {
* @return the new visitor
*/
public static ExpressionVisitor get(int type) {
if (SysProperties.CHECK) {
switch (type) {
case INDEPENDENT:
case DETERMINISTIC:
case EVALUATABLE:
case READONLY:
case QUERY_COMPARABLE:
throw DbException.throwInternalError("Singleton not used");
}
}
return new ExpressionVisitor(type);
}
......
......@@ -1356,8 +1356,9 @@ public class Function extends Expression implements FunctionCall {
}
private static String rawToHex(String s) {
StringBuilder buff = new StringBuilder(4 * s.length());
for (int i = 0; i < s.length(); i++) {
int length = s.length();
StringBuilder buff = new StringBuilder(4 * length);
for (int i = 0; i < length; i++) {
String hex = Integer.toHexString(s.charAt(i) & 0xffff);
for (int j = hex.length(); j < 4; j++) {
buff.append('0');
......
......@@ -505,10 +505,11 @@ public class FullText {
* @param columns the column list
*/
protected static void setColumns(int[] index, ArrayList<String> keys, ArrayList<String> columns) throws SQLException {
for (int i = 0; i < keys.size(); i++) {
for (int i = 0, keySize = keys.size(); i < keySize; i++) {
String key = keys.get(i);
int found = -1;
for (int j = 0; found == -1 && j < columns.size(); j++) {
int columnsSize = columns.size();
for (int j = 0; found == -1 && j < columnsSize; j++) {
String column = columns.get(j);
if (column.equals(key)) {
found = j;
......@@ -733,9 +734,10 @@ public class FullText {
if (data.indexOf('\'') < 0) {
return "'" + data + "'";
}
StringBuilder buff = new StringBuilder(data.length() + 2);
int len = data.length();
StringBuilder buff = new StringBuilder(len + 2);
buff.append('\'');
for (int i = 0; i < data.length(); i++) {
for (int i = 0; i < len; i++) {
char ch = data.charAt(i);
if (ch == '\'') {
buff.append(ch);
......
......@@ -313,17 +313,17 @@ public class IndexCondition {
*/
public boolean isEvaluatable() {
if (expression != null) {
return expression.isEverything(ExpressionVisitor.EVALUATABLE);
return expression.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR);
}
if (expressionList != null) {
for (Expression e : expressionList) {
if (!e.isEverything(ExpressionVisitor.EVALUATABLE)) {
if (!e.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR)) {
return false;
}
}
return true;
}
return expressionQuery.isEverything(ExpressionVisitor.EVALUATABLE);
return expressionQuery.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR);
}
}
......@@ -217,7 +217,7 @@ public class PageBtreeIndex extends PageIndex {
trace.debug(getName() + " remove " + row);
}
if (tableData.getContainsLargeObject()) {
for (int i = 0; i < row.getColumnCount(); i++) {
for (int i = 0, len = row.getColumnCount(); i < len; i++) {
Value v = row.getValue(i);
if (v.isLinked()) {
session.unlinkAtCommit(v);
......
......@@ -104,7 +104,7 @@ public class PageDataIndex extends PageIndex {
}
}
if (tableData.getContainsLargeObject()) {
for (int i = 0; i < row.getColumnCount(); i++) {
for (int i = 0, len = row.getColumnCount(); i < len; i++) {
Value v = row.getValue(i);
Value v2 = v.link(database, getId());
if (v2.isLinked()) {
......@@ -304,7 +304,7 @@ public class PageDataIndex extends PageIndex {
public void remove(Session session, Row row) {
if (tableData.getContainsLargeObject()) {
for (int i = 0; i < row.getColumnCount(); i++) {
for (int i = 0, len = row.getColumnCount(); i < len; i++) {
Value v = row.getValue(i);
if (v.isLinked()) {
session.unlinkAtCommit(v);
......
......@@ -45,7 +45,7 @@ public class ViewCursor implements Cursor {
}
current = table.getTemplateRow();
Value[] values = result.currentRow();
for (int i = 0; i < current.getColumnCount(); i++) {
for (int i = 0, len = current.getColumnCount(); i < len; i++) {
Value v = i < values.length ? values[i] : ValueNull.INSTANCE;
current.setValue(i, v);
}
......
......@@ -203,7 +203,8 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
debugCodeCall("clearParameters");
checkClosed();
ArrayList< ? extends ParameterInterface> parameters = command.getParameters();
for (ParameterInterface param : parameters) {
for (int i = 0, size = parameters.size(); i < size; i++) {
ParameterInterface param = parameters.get(i);
// can only delete old temp files if they are not in the batch
param.setValue(null, batchParameters == null);
}
......@@ -1068,12 +1069,13 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
// TODO batch: check what other database do if no parameters are set
batchParameters = New.arrayList();
}
int[] result = new int[batchParameters.size()];
int size = batchParameters.size();
int[] result = new int[size];
boolean error = false;
SQLException next = null;
checkClosedForWrite();
try {
for (int i = 0; i < batchParameters.size(); i++) {
for (int i = 0; i < size; i++) {
Value[] set = batchParameters.get(i);
ArrayList< ? extends ParameterInterface> parameters = command.getParameters();
for (int j = 0; j < set.length; j++) {
......@@ -1122,8 +1124,9 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
checkClosedForWrite();
try {
ArrayList< ? extends ParameterInterface> parameters = command.getParameters();
Value[] set = new Value[parameters.size()];
for (int i = 0; i < parameters.size(); i++) {
int size = parameters.size();
Value[] set = new Value[size];
for (int i = 0; i < size; i++) {
ParameterInterface param = parameters.get(i);
Value value = param.getParamValue();
set[i] = value;
......@@ -1494,7 +1497,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
ArrayList< ? extends ParameterInterface> oldParams = command.getParameters();
command = conn.prepareCommand(sqlStatement, fetchSize);
ArrayList< ? extends ParameterInterface> newParams = command.getParameters();
for (int i = 0; i < oldParams.size(); i++) {
for (int i = 0, size = oldParams.size(); i < size; i++) {
ParameterInterface old = oldParams.get(i);
Value value = old.getParamValue();
if (value != null) {
......
......@@ -622,9 +622,10 @@ public class JdbcStatement extends TraceObject implements Statement {
// TODO batch: check what other database do if no commands are set
batchCommands = New.arrayList();
}
int[] result = new int[batchCommands.size()];
int size = batchCommands.size();
int[] result = new int[size];
boolean error = false;
for (int i = 0; i < batchCommands.size(); i++) {
for (int i = 0; i < size; i++) {
String sql = batchCommands.get(i);
try {
result[i] = executeUpdateInternal(sql);
......
......@@ -100,7 +100,6 @@ public class TraceSystem implements TraceWriter {
public TraceSystem(String fileName) {
this.fileName = fileName;
updateLevel();
traces = SmallLRUCache.newInstance(100);
}
private void updateLevel() {
......@@ -126,6 +125,9 @@ public class TraceSystem implements TraceWriter {
* @return the trace object
*/
public synchronized Trace getTrace(String module) {
if (traces == null) {
traces = SmallLRUCache.newInstance(16);
}
Trace t = traces.get(module);
if (t == null) {
t = new Trace(writer, module);
......
......@@ -176,7 +176,7 @@ class ResultDiskBuffer implements ResultExternal {
private Value[] nextSorted() {
int next = -1;
for (int i = 0; i < tapes.size(); i++) {
for (int i = 0, size = tapes.size(); i < size; i++) {
ResultDiskTape tape = tapes.get(i);
if (tape.buffer.size() == 0 && tape.pos < tape.end) {
file.seek(tape.pos);
......
......@@ -49,12 +49,13 @@ public class RowList {
buff.checkCapacity(1 + Data.LENGTH_INT * 8);
buff.writeByte((byte) 1);
buff.writeInt(r.getMemory());
buff.writeInt(r.getColumnCount());
int columnCount = r.getColumnCount();
buff.writeInt(columnCount);
buff.writeLong(r.getKey());
buff.writeInt(r.getVersion());
buff.writeInt(r.isDeleted() ? 1 : 0);
buff.writeInt(r.getSessionId());
for (int i = 0; i < r.getColumnCount(); i++) {
for (int i = 0; i < columnCount; i++) {
Value v = r.getValue(i);
buff.checkCapacity(1);
if (v == null) {
......
......@@ -136,7 +136,7 @@ public class UpdatableRow {
}
private void setKey(PreparedStatement prep, int start, Value[] current) throws SQLException {
for (int i = 0; i < key.size(); i++) {
for (int i = 0, size = key.size(); i < size; i++) {
String col = key.get(i);
int idx = getColumnIndex(col);
Value v = current[idx];
......
......@@ -331,7 +331,7 @@ public class Schema extends DbObjectBase {
String hash = Integer.toHexString(obj.getName().hashCode()).toUpperCase();
String name = null;
synchronized (temporaryUniqueNames) {
for (int i = 1; i < hash.length(); i++) {
for (int i = 1, len = hash.length(); i < len; i++) {
name = prefix + hash.substring(0, i);
if (!map.containsKey(name) && !temporaryUniqueNames.contains(name)) {
break;
......
......@@ -22,7 +22,7 @@ public class PageFreeList extends Page {
private static final int DATA_START = 3;
private final PageStore store;
private final BitField used = new BitField();
private final BitField used;
private final int pageCount;
private boolean full;
private Data data;
......@@ -31,6 +31,7 @@ public class PageFreeList extends Page {
setPos(pageId);
this.store = store;
pageCount = (store.getPageSize() - DATA_START) * 8;
used = new BitField(pageCount);
used.set(0);
}
......
......@@ -382,8 +382,8 @@ public class PageStore implements CacheWriter {
private void writeBack() {
ArrayList<CacheObject> list = cache.getAllChanged();
Collections.sort(list);
for (CacheObject rec : list) {
writeBack(rec);
for (int i = 0, size = list.size(); i < size; i++) {
writeBack(list.get(i));
}
}
......@@ -1095,6 +1095,7 @@ public class PageStore implements CacheWriter {
* @param after all allocated pages are higher than this page
*/
void allocatePages(IntArray list, int pagesToAllocate, BitField exclude, int after) {
list.ensureCapacity(list.size() + pagesToAllocate);
for (int i = 0; i < pagesToAllocate; i++) {
int page = allocatePage(exclude, after);
after = page;
......
......@@ -112,7 +112,7 @@ public class Plan {
setEvaluatable(tableFilter, true);
Expression on = tableFilter.getJoinCondition();
if (on != null) {
if (!on.isEverything(ExpressionVisitor.EVALUATABLE)) {
if (!on.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR)) {
invalidPlan = true;
break;
}
......
......@@ -224,7 +224,7 @@ public class RegularTable extends TableBase {
long total = remaining;
Cursor cursor = scan.find(session, null, null);
long i = 0;
int bufferSize = Constants.DEFAULT_MAX_MEMORY_ROWS;
int bufferSize = (int) Math.min(rowCount, Constants.DEFAULT_MAX_MEMORY_ROWS);
ArrayList<Row> buffer = New.arrayList(bufferSize);
String n = getName() + ":" + index.getName();
int t = MathUtils.convertLongToInt(total);
......@@ -667,7 +667,8 @@ public class RegularTable extends TableBase {
public boolean canTruncate() {
if (getCheckForeignKeyConstraints() && database.getReferentialIntegrity()) {
ArrayList<Constraint> constraints = getConstraints();
for (int i = 0; constraints != null && i < constraints.size(); i++) {
if (constraints != null) {
for (int i = 0, size = constraints.size(); i < size; i++) {
Constraint c = constraints.get(i);
if (!(c.getConstraintType().equals(Constraint.REFERENTIAL))) {
continue;
......@@ -678,6 +679,7 @@ public class RegularTable extends TableBase {
}
}
}
}
return true;
}
......
......@@ -121,11 +121,13 @@ public abstract class Table extends SchemaObjectBase {
public void rename(String newName) {
super.rename(newName);
for (int i = 0; constraints != null && i < constraints.size(); i++) {
if (constraints != null) {
for (int i = 0, size = constraints.size(); i < size; i++) {
Constraint constraint = constraints.get(i);
constraint.rebuild();
}
}
}
/**
* Lock the table for the given session.
......@@ -470,14 +472,17 @@ public abstract class Table extends SchemaObjectBase {
* @throws SQLException if the column is referenced
*/
public void checkColumnIsNotReferenced(Column col) {
for (int i = 0; constraints != null && i < constraints.size(); i++) {
if (constraints != null) {
for (int i = 0, size = constraints.size(); i < size; i++) {
Constraint constraint = constraints.get(i);
if (constraint.containsColumn(col)) {
throw DbException.get(ErrorCode.COLUMN_MAY_BE_REFERENCED_1, constraint.getSQL());
}
}
}
ArrayList<Index> indexes = getIndexes();
for (int i = 0; indexes != null && i < indexes.size(); i++) {
if (indexes != null) {
for (int i = 0, size = indexes.size(); i < size; i++) {
Index index = indexes.get(i);
if (index.getColumns().length == 1) {
continue;
......@@ -490,6 +495,7 @@ public abstract class Table extends SchemaObjectBase {
}
}
}
}
public Row getTemplateRow() {
return new Row(new Value[columns.length], Row.MEMORY_CALCULATE);
......
......@@ -87,7 +87,7 @@ public class TableView extends Table {
tables = New.arrayList(query.getTables());
ArrayList<Expression> expressions = query.getExpressions();
ArrayList<Column> list = New.arrayList();
for (int i = 0; i < query.getColumnCount(); i++) {
for (int i = 0, count = query.getColumnCount(); i < count; i++) {
Expression expr = expressions.get(i);
String name = null;
if (columnNames != null && columnNames.length > i) {
......@@ -389,7 +389,7 @@ public class TableView extends Table {
if (recursive) {
return false;
}
return viewQuery.isEverything(ExpressionVisitor.DETERMINISTIC);
return viewQuery.isEverything(ExpressionVisitor.DETERMINISTIC_VISITOR);
}
public void setRecursiveResult(ResultInterface recursiveResult) {
......
......@@ -1217,6 +1217,7 @@ public class Recover extends Tool implements DataHandler {
sql = sql.substring("IF NOT EXISTS ".length());
}
boolean ignore = false;
// sql is modified in the loop
for (int i = 0; i < sql.length(); i++) {
char ch = sql.charAt(i);
if (ch == '\"') {
......
......@@ -209,7 +209,7 @@ public class Shell extends Tool implements Runnable {
listMode = !listMode;
println("Result list mode is now " + (listMode ? "on" : "off"));
} else if ("HISTORY".equals(upper)) {
for (int i = 0; i < history.size(); i++) {
for (int i = 0, size = history.size(); i < size; i++) {
String s = history.get(i);
s = s.replace('\n', ' ').replace('\r', ' ');
println("#" + (1 + i) + ": " + s);
......
......@@ -511,11 +511,13 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
* closed
*/
public int findColumn(String columnLabel) throws SQLException {
for (int i = 0; columnLabel != null && columns != null && i < columns.size(); i++) {
if (columnLabel != null && columns != null) {
for (int i = 0, size = columns.size(); i < size; i++) {
if (columnLabel.equalsIgnoreCase(getColumn(i).name)) {
return i + 1;
}
}
}
throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1, columnLabel).getSQLException();
}
......
......@@ -14,9 +14,17 @@ public final class BitField {
private static final int ADDRESS_BITS = 6;
private static final int BITS = 64;
private static final int ADDRESS_MASK = BITS - 1;
private long[] data = new long[10];
private long[] data;
private int maxLength;
public BitField() {
this(64);
}
public BitField(int capacity) {
data = new long[capacity >>> 3];
}
/**
* Get the index of the next bit that is not set.
*
......
......@@ -49,7 +49,9 @@ public class IntArray {
* @param value the value to append
*/
public void add(int value) {
checkCapacity();
if (size >= data.length) {
ensureCapacity(size + size);
}
data[size++] = value;
}
......@@ -83,9 +85,16 @@ public class IntArray {
size--;
}
private void checkCapacity() {
if (size >= data.length) {
int[] d = new int[Math.max(4, data.length * 2)];
/**
* Ensure the the underlying array is large enough for the given number of
* entries.
*
* @param minCapacity the minimum capacity
*/
public void ensureCapacity(int minCapacity) {
minCapacity = Math.max(4, minCapacity);
if (minCapacity >= data.length) {
int[] d = new int[minCapacity];
System.arraycopy(data, 0, d, 0, data.length);
data = d;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论