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

Use generics

上级 16a375cc
...@@ -205,9 +205,7 @@ public class CommandRemote implements CommandInterface { ...@@ -205,9 +205,7 @@ public class CommandRemote implements CommandInterface {
} }
private void checkParameters() throws SQLException { private void checkParameters() throws SQLException {
int len = parameters.size(); for (ParameterInterface p : parameters) {
for (int i = 0; i < len; i++) {
ParameterInterface p = parameters.get(i);
p.checkSet(); p.checkSet();
} }
} }
...@@ -215,8 +213,7 @@ public class CommandRemote implements CommandInterface { ...@@ -215,8 +213,7 @@ public class CommandRemote implements CommandInterface {
private void sendParameters(Transfer transfer) throws IOException, SQLException { private void sendParameters(Transfer transfer) throws IOException, SQLException {
int len = parameters.size(); int len = parameters.size();
transfer.writeInt(len); transfer.writeInt(len);
for (int i = 0; i < len; i++) { for (ParameterInterface p : parameters) {
ParameterInterface p = parameters.get(i);
transfer.writeValue(p.getParamValue()); transfer.writeValue(p.getParamValue());
} }
} }
...@@ -226,10 +223,9 @@ public class CommandRemote implements CommandInterface { ...@@ -226,10 +223,9 @@ public class CommandRemote implements CommandInterface {
return; return;
} }
synchronized (session) { synchronized (session) {
for (int i = 0; i < transferList.size(); i++) { session.traceOperation("COMMAND_CLOSE", id);
for (Transfer transfer : transferList) {
try { try {
Transfer transfer = transferList.get(i);
session.traceOperation("COMMAND_CLOSE", id);
transfer.writeInt(SessionRemote.COMMAND_CLOSE).writeInt(id); transfer.writeInt(SessionRemote.COMMAND_CLOSE).writeInt(id);
} catch (IOException e) { } catch (IOException e) {
trace.error("close", e); trace.error("close", e);
...@@ -237,10 +233,8 @@ public class CommandRemote implements CommandInterface { ...@@ -237,10 +233,8 @@ public class CommandRemote implements CommandInterface {
} }
} }
session = null; session = null;
int len = parameters.size();
try { try {
for (int i = 0; i < len; i++) { for (ParameterInterface p : parameters) {
ParameterInterface p = parameters.get(i);
Value v = p.getParamValue(); Value v = p.getParamValue();
if (v != null) { if (v != null) {
v.close(); v.close();
......
...@@ -450,9 +450,7 @@ public class Parser { ...@@ -450,9 +450,7 @@ public class Parser {
p.setValue(expr.getValue(session)); p.setValue(expr.getValue(session));
} while (readIf(",")); } while (readIf(","));
read("}"); read("}");
int len = parameters.size(); for (Parameter p : parameters) {
for (int i = 0; i < len; i++) {
Parameter p = parameters.get(i);
p.checkSet(); p.checkSet();
} }
parameters.clear(); parameters.clear();
...@@ -3778,10 +3776,10 @@ public class Parser { ...@@ -3778,10 +3776,10 @@ public class Parser {
Schema schema = getSchema(); Schema schema = getSchema();
TableData recursiveTable; TableData recursiveTable;
read("("); read("(");
String[] cols = parseColumnList();
ObjectArray<Column> columns = ObjectArray.newInstance(); ObjectArray<Column> columns = ObjectArray.newInstance();
for (int i = 0; i < cols.length; i++) { String[] cols = parseColumnList();
columns.add(new Column(cols[i], Value.STRING)); for (String c : cols) {
columns.add(new Column(c, Value.STRING));
} }
int id = database.allocateObjectId(true, true); int id = database.allocateObjectId(true, true);
recursiveTable = schema.createTable(tempViewName, id, columns, false, true, false, Index.EMPTY_HEAD, session); recursiveTable = schema.createTable(tempViewName, id, columns, false, true, false, Index.EMPTY_HEAD, session);
......
...@@ -287,9 +287,7 @@ public class AlterTableAddConstraint extends SchemaCommand { ...@@ -287,9 +287,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
} }
private Index getUniqueIndex(Table t, IndexColumn[] cols) { private Index getUniqueIndex(Table t, IndexColumn[] cols) {
ObjectArray<Index> list = t.getIndexes(); for (Index idx : t.getIndexes()) {
for (int i = 0; i < list.size(); i++) {
Index idx = list.get(i);
if (canUseUniqueIndex(idx, t, cols)) { if (canUseUniqueIndex(idx, t, cols)) {
return idx; return idx;
} }
...@@ -298,11 +296,9 @@ public class AlterTableAddConstraint extends SchemaCommand { ...@@ -298,11 +296,9 @@ public class AlterTableAddConstraint extends SchemaCommand {
} }
private Index getIndex(Table t, IndexColumn[] cols) { private Index getIndex(Table t, IndexColumn[] cols) {
ObjectArray<Index> list = t.getIndexes(); for (Index idx : t.getIndexes()) {
for (int i = 0; i < list.size(); i++) { if (canUseIndex(idx, t, cols)) {
Index existingIndex = list.get(i); return idx;
if (canUseIndex(existingIndex, t, cols)) {
return existingIndex;
} }
} }
return null; return null;
...@@ -317,13 +313,13 @@ public class AlterTableAddConstraint extends SchemaCommand { ...@@ -317,13 +313,13 @@ public class AlterTableAddConstraint extends SchemaCommand {
return false; return false;
} }
HashSet<Column> set = New.hashSet(); HashSet<Column> set = New.hashSet();
for (int i = 0; i < cols.length; i++) { for (IndexColumn c : cols) {
set.add(cols[i].column); set.add(c.column);
} }
for (int j = 0; j < indexCols.length; j++) { for (Column c : indexCols) {
// all columns of the index must be part of the list, // all columns of the index must be part of the list,
// but not all columns of the list need to be part of the index // but not all columns of the list need to be part of the index
if (!set.contains(indexCols[j])) { if (!set.contains(c)) {
return false; return false;
} }
} }
......
...@@ -199,9 +199,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -199,9 +199,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
} }
private void checkNoViews() throws SQLException { private void checkNoViews() throws SQLException {
ObjectArray<DbObject> children = table.getChildren(); for (DbObject child : table.getChildren()) {
for (int i = 0; i < children.size(); i++) {
DbObject child = children.get(i);
if (child.getType() == DbObject.TABLE_OR_VIEW) { if (child.getType() == DbObject.TABLE_OR_VIEW) {
throw Message.getSQLException(ErrorCode.OPERATION_NOT_SUPPORTED_WITH_VIEWS_2, new String[] { throw Message.getSQLException(ErrorCode.OPERATION_NOT_SUPPORTED_WITH_VIEWS_2, new String[] {
table.getName(), child.getName() }); table.getName(), child.getName() });
...@@ -214,9 +212,8 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -214,9 +212,8 @@ public class AlterTableAlterColumn extends SchemaCommand {
String tempName = db.getTempTableName(session.getId()); String tempName = db.getTempTableName(session.getId());
Column[] columns = table.getColumns(); Column[] columns = table.getColumns();
ObjectArray<Column> newColumns = ObjectArray.newInstance(); ObjectArray<Column> newColumns = ObjectArray.newInstance();
for (int i = 0; i < columns.length; i++) { for (Column col : columns) {
Column col = columns[i].getClone(); newColumns.add(col.getClone());
newColumns.add(col);
} }
if (type == DROP) { if (type == DROP) {
int position = oldColumn.getColumnId(); int position = oldColumn.getColumnId();
...@@ -245,8 +242,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -245,8 +242,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
StringBuffer buff = new StringBuffer(); StringBuffer buff = new StringBuffer();
buff.append(newTable.getCreateSQL()); buff.append(newTable.getCreateSQL());
StringBuffer columnList = new StringBuffer(); StringBuffer columnList = new StringBuffer();
for (int i = 0; i < newColumns.size(); i++) { for (Column nc : newColumns) {
Column nc = newColumns.get(i);
if (columnList.length() > 0) { if (columnList.length() > 0) {
columnList.append(", "); columnList.append(", ");
} }
...@@ -269,10 +265,8 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -269,10 +265,8 @@ public class AlterTableAlterColumn extends SchemaCommand {
String newTableSQL = buff.toString(); String newTableSQL = buff.toString();
execute(newTableSQL, true); execute(newTableSQL, true);
newTable = (TableData) newTable.getSchema().getTableOrView(session, newTable.getName()); newTable = (TableData) newTable.getSchema().getTableOrView(session, newTable.getName());
ObjectArray<DbObject> children = table.getChildren();
ObjectArray<String> triggers = ObjectArray.newInstance(); ObjectArray<String> triggers = ObjectArray.newInstance();
for (int i = 0; i < children.size(); i++) { for (DbObject child : table.getChildren()) {
DbObject child = children.get(i);
if (child instanceof Sequence) { if (child instanceof Sequence) {
continue; continue;
} else if (child instanceof Index) { } else if (child instanceof Index) {
...@@ -309,24 +303,21 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -309,24 +303,21 @@ public class AlterTableAlterColumn extends SchemaCommand {
} }
String tableName = table.getName(); String tableName = table.getName();
table.setModified(); table.setModified();
for (int i = 0; i < columns.length; i++) { for (Column col : columns) {
// if we don't do that, the sequence is dropped when the table is // if we don't do that, the sequence is dropped when the table is
// dropped // dropped
Sequence seq = columns[i].getSequence(); Sequence seq = col.getSequence();
if (seq != null) { if (seq != null) {
table.removeSequence(session, seq); table.removeSequence(session, seq);
columns[i].setSequence(null); col.setSequence(null);
} }
} }
for (int i = 0; i < triggers.size(); i++) { for (String sql : triggers) {
String sql = triggers.get(i);
execute(sql, true); execute(sql, true);
} }
execute("DROP TABLE " + table.getSQL(), true); execute("DROP TABLE " + table.getSQL(), true);
db.renameSchemaObject(session, newTable, tableName); db.renameSchemaObject(session, newTable, tableName);
children = newTable.getChildren(); for (DbObject child : newTable.getChildren()) {
for (int i = 0; i < children.size(); i++) {
DbObject child = children.get(i);
if (child instanceof Sequence) { if (child instanceof Sequence) {
continue; continue;
} }
...@@ -378,9 +369,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -378,9 +369,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
} }
private void checkNullable() throws SQLException { private void checkNullable() throws SQLException {
ObjectArray<Index> indexes = table.getIndexes(); for (Index index : table.getIndexes()) {
for (int i = 0; i < indexes.size(); i++) {
Index index = indexes.get(i);
if (index.getColumnIndex(oldColumn) < 0) { if (index.getColumnIndex(oldColumn) < 0) {
continue; continue;
} }
......
...@@ -13,7 +13,6 @@ import org.h2.engine.Right; ...@@ -13,7 +13,6 @@ import org.h2.engine.Right;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.util.ObjectArray;
/** /**
* This class represents the statement * This class represents the statement
...@@ -49,9 +48,7 @@ public class AlterTableRenameColumn extends DefineCommand { ...@@ -49,9 +48,7 @@ public class AlterTableRenameColumn extends DefineCommand {
table.renameColumn(column, newName); table.renameColumn(column, newName);
table.setModified(); table.setModified();
db.update(session, table); db.update(session, table);
ObjectArray<DbObject> children = table.getChildren(); for (DbObject child : table.getChildren()) {
for (int i = 0; i < children.size(); i++) {
DbObject child = children.get(i);
if (child.getCreateSQL() != null) { if (child.getCreateSQL() != null) {
db.update(session, child); db.update(session, child);
} }
......
...@@ -15,7 +15,6 @@ import org.h2.result.LocalResult; ...@@ -15,7 +15,6 @@ import org.h2.result.LocalResult;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableData; import org.h2.table.TableData;
import org.h2.util.ObjectArray;
/** /**
* This class represents the statement * This class represents the statement
...@@ -33,10 +32,8 @@ public class Analyze extends DefineCommand { ...@@ -33,10 +32,8 @@ public class Analyze extends DefineCommand {
session.commit(true); session.commit(true);
Database db = session.getDatabase(); Database db = session.getDatabase();
session.getUser().checkAdmin(); session.getUser().checkAdmin();
ObjectArray<Table> tables = db.getAllTablesAndViews();
// TODO do we need to lock the table? // TODO do we need to lock the table?
for (int i = 0; i < tables.size(); i++) { for (Table table : db.getAllTablesAndViews()) {
Table table = tables.get(i);
if (!(table instanceof TableData)) { if (!(table instanceof TableData)) {
continue; continue;
} }
......
...@@ -121,19 +121,16 @@ public class CreateTable extends SchemaCommand { ...@@ -121,19 +121,16 @@ public class CreateTable extends SchemaCommand {
} }
} }
if (pkColumns != null) { if (pkColumns != null) {
int len = pkColumns.length; for (Column c : columns) {
for (int i = 0; i < columns.size(); i++) { for (IndexColumn idxCol : pkColumns) {
Column c = columns.get(i); if (c.getName().equals(idxCol.columnName)) {
for (int j = 0; j < len; j++) {
if (c.getName().equals(pkColumns[j].columnName)) {
c.setNullable(false); c.setNullable(false);
} }
} }
} }
} }
ObjectArray<Sequence> sequences = ObjectArray.newInstance(); ObjectArray<Sequence> sequences = ObjectArray.newInstance();
for (int i = 0; i < columns.size(); i++) { for (Column c : columns) {
Column c = columns.get(i);
if (c.getAutoIncrement()) { if (c.getAutoIncrement()) {
int objId = getObjectId(true, true); int objId = getObjectId(true, true);
c.convertAutoIncrementToSequence(session, getSchema(), objId, temporary); c.convertAutoIncrementToSequence(session, getSchema(), objId, temporary);
...@@ -160,16 +157,13 @@ public class CreateTable extends SchemaCommand { ...@@ -160,16 +157,13 @@ public class CreateTable extends SchemaCommand {
db.addSchemaObject(session, table); db.addSchemaObject(session, table);
} }
try { try {
for (int i = 0; i < columns.size(); i++) { for (Column c : columns) {
Column c = columns.get(i);
c.prepareExpression(session); c.prepareExpression(session);
} }
for (int i = 0; i < sequences.size(); i++) { for (Sequence sequence : sequences) {
Sequence sequence = sequences.get(i);
table.addSequence(sequence); table.addSequence(sequence);
} }
for (int i = 0; i < constraintCommands.size(); i++) { for (Prepared command : constraintCommands) {
Prepared command = constraintCommands.get(i);
command.update(); command.update();
} }
if (asQuery != null) { if (asQuery != null) {
......
...@@ -45,28 +45,23 @@ public class DropDatabase extends DefineCommand { ...@@ -45,28 +45,23 @@ public class DropDatabase extends DefineCommand {
session.commit(true); session.commit(true);
Database db = session.getDatabase(); Database db = session.getDatabase();
// TODO local temp tables are not removed // TODO local temp tables are not removed
ObjectArray<Schema> schemas = db.getAllSchemas(); for (Schema schema : db.getAllSchemas()) {
for (int i = 0; i < schemas.size(); i++) {
Schema schema = schemas.get(i);
if (schema.canDrop()) { if (schema.canDrop()) {
db.removeDatabaseObject(session, schema); db.removeDatabaseObject(session, schema);
} }
} }
ObjectArray<Table> tables = db.getAllTablesAndViews(); ObjectArray<Table> tables = db.getAllTablesAndViews();
for (int i = 0; i < tables.size(); i++) { for (Table t : tables) {
Table t = tables.get(i);
if (t.getName() != null && Table.VIEW.equals(t.getTableType())) { if (t.getName() != null && Table.VIEW.equals(t.getTableType())) {
db.removeSchemaObject(session, t); db.removeSchemaObject(session, t);
} }
} }
for (int i = 0; i < tables.size(); i++) { for (Table t : tables) {
Table t = tables.get(i);
if (t.getName() != null && Table.TABLE_LINK.equals(t.getTableType())) { if (t.getName() != null && Table.TABLE_LINK.equals(t.getTableType())) {
db.removeSchemaObject(session, t); db.removeSchemaObject(session, t);
} }
} }
for (int i = 0; i < tables.size(); i++) { for (Table t : tables) {
Table t = tables.get(i);
if (t.getName() != null && Table.TABLE.equals(t.getTableType())) { if (t.getName() != null && Table.TABLE.equals(t.getTableType())) {
db.removeSchemaObject(session, t); db.removeSchemaObject(session, t);
} }
...@@ -79,20 +74,15 @@ public class DropDatabase extends DefineCommand { ...@@ -79,20 +74,15 @@ public class DropDatabase extends DefineCommand {
list.addAll(db.getAllSchemaObjects(DbObject.CONSTRAINT)); list.addAll(db.getAllSchemaObjects(DbObject.CONSTRAINT));
list.addAll(db.getAllSchemaObjects(DbObject.TRIGGER)); list.addAll(db.getAllSchemaObjects(DbObject.TRIGGER));
list.addAll(db.getAllSchemaObjects(DbObject.CONSTANT)); list.addAll(db.getAllSchemaObjects(DbObject.CONSTANT));
for (int i = 0; i < list.size(); i++) { for (SchemaObject obj : list) {
SchemaObject obj = list.get(i);
db.removeSchemaObject(session, obj); db.removeSchemaObject(session, obj);
} }
ObjectArray<User> users = db.getAllUsers(); for (User user : db.getAllUsers()) {
for (int i = 0; i < users.size(); i++) {
User user = users.get(i);
if (user != session.getUser()) { if (user != session.getUser()) {
db.removeDatabaseObject(session, user); db.removeDatabaseObject(session, user);
} }
} }
ObjectArray<Role> roles = db.getAllRoles(); for (Role role : db.getAllRoles()) {
for (int i = 0; i < roles.size(); i++) {
Role role = roles.get(i);
String sql = role.getCreateSQL(); String sql = role.getCreateSQL();
// the role PUBLIC must not be dropped // the role PUBLIC must not be dropped
if (sql != null) { if (sql != null) {
...@@ -104,8 +94,7 @@ public class DropDatabase extends DefineCommand { ...@@ -104,8 +94,7 @@ public class DropDatabase extends DefineCommand {
dbObjects.addAll(db.getAllFunctionAliases()); dbObjects.addAll(db.getAllFunctionAliases());
dbObjects.addAll(db.getAllAggregates()); dbObjects.addAll(db.getAllAggregates());
dbObjects.addAll(db.getAllUserDataTypes()); dbObjects.addAll(db.getAllUserDataTypes());
for (int i = 0; i < dbObjects.size(); i++) { for (DbObject obj : dbObjects) {
DbObject obj = dbObjects.get(i);
String sql = obj.getCreateSQL(); String sql = obj.getCreateSQL();
// the role PUBLIC must not be dropped // the role PUBLIC must not be dropped
if (sql != null) { if (sql != null) {
......
...@@ -88,8 +88,7 @@ public class GrantRevoke extends DefineCommand { ...@@ -88,8 +88,7 @@ public class GrantRevoke extends DefineCommand {
session.commit(true); session.commit(true);
Database db = session.getDatabase(); Database db = session.getDatabase();
if (roleNames != null) { if (roleNames != null) {
for (int i = 0; i < roleNames.size(); i++) { for (String name : roleNames) {
String name = roleNames.get(i);
Role grantedRole = db.findRole(name); Role grantedRole = db.findRole(name);
if (grantedRole == null) { if (grantedRole == null) {
throw Message.getSQLException(ErrorCode.ROLE_NOT_FOUND_1, name); throw Message.getSQLException(ErrorCode.ROLE_NOT_FOUND_1, name);
...@@ -116,8 +115,7 @@ public class GrantRevoke extends DefineCommand { ...@@ -116,8 +115,7 @@ public class GrantRevoke extends DefineCommand {
private void grantRight() throws SQLException { private void grantRight() throws SQLException {
Database db = session.getDatabase(); Database db = session.getDatabase();
for (int i = 0; i < tables.size(); i++) { for (Table table : tables) {
Table table = tables.get(i);
Right right = grantee.getRightForTable(table); Right right = grantee.getRightForTable(table);
if (right == null) { if (right == null) {
int id = getObjectId(true, true); int id = getObjectId(true, true);
...@@ -149,8 +147,7 @@ public class GrantRevoke extends DefineCommand { ...@@ -149,8 +147,7 @@ public class GrantRevoke extends DefineCommand {
} }
private void revokeRight() throws SQLException { private void revokeRight() throws SQLException {
for (int i = 0; i < tables.size(); i++) { for (Table table : tables) {
Table table = tables.get(i);
Right right = grantee.getRightForTable(table); Right right = grantee.getRightForTable(table);
if (right == null) { if (right == null) {
continue; continue;
......
...@@ -254,8 +254,7 @@ public abstract class Query extends Prepared { ...@@ -254,8 +254,7 @@ public abstract class Query extends Prepared {
*/ */
void initOrder(ObjectArray<Expression> expressions, ObjectArray<String> expressionSQL, ObjectArray<SelectOrderBy> orderList, int visible, void initOrder(ObjectArray<Expression> expressions, ObjectArray<String> expressionSQL, ObjectArray<SelectOrderBy> orderList, int visible,
boolean mustBeInResult) throws SQLException { boolean mustBeInResult) throws SQLException {
for (int i = 0; i < orderList.size(); i++) { for (SelectOrderBy o : orderList) {
SelectOrderBy o = orderList.get(i);
Expression e = o.expression; Expression e = o.expression;
if (e == null) { if (e == null) {
continue; continue;
......
...@@ -126,9 +126,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -126,9 +126,7 @@ public class ScriptCommand extends ScriptBase {
} }
Database db = session.getDatabase(); Database db = session.getDatabase();
if (settings) { if (settings) {
ObjectArray<Setting> settingList = db.getAllSettings(); for (Setting setting : db.getAllSettings()) {
for (int i = 0; i < settingList.size(); i++) {
Setting setting = settingList.get(i);
if (setting.getName().equals(SetTypes.getTypeName(SetTypes.CREATE_BUILD))) { if (setting.getName().equals(SetTypes.getTypeName(SetTypes.CREATE_BUILD))) {
// don't add CREATE_BUILD to the script // don't add CREATE_BUILD to the script
// (it is only set when creating the database) // (it is only set when creating the database)
...@@ -140,45 +138,32 @@ public class ScriptCommand extends ScriptBase { ...@@ -140,45 +138,32 @@ public class ScriptCommand extends ScriptBase {
if (out != null) { if (out != null) {
add("", true); add("", true);
} }
ObjectArray<User> users = db.getAllUsers(); for (User user : db.getAllUsers()) {
for (int i = 0; i < users.size(); i++) {
User user = users.get(i);
add(user.getCreateSQL(passwords, true), false); add(user.getCreateSQL(passwords, true), false);
} }
ObjectArray<Role> roles = db.getAllRoles(); for (Role role : db.getAllRoles()) {
for (int i = 0; i < roles.size(); i++) {
Role role = roles.get(i);
add(role.getCreateSQL(true), false); add(role.getCreateSQL(true), false);
} }
ObjectArray<Schema> schemas = db.getAllSchemas(); for (Schema schema : db.getAllSchemas()) {
for (int i = 0; i < schemas.size(); i++) {
Schema schema = schemas.get(i);
add(schema.getCreateSQL(), false); add(schema.getCreateSQL(), false);
} }
ObjectArray<UserDataType> datatypes = db.getAllUserDataTypes(); for (UserDataType datatype : db.getAllUserDataTypes()) {
for (int i = 0; i < datatypes.size(); i++) {
UserDataType datatype = datatypes.get(i);
if (drop) { if (drop) {
add(datatype.getDropSQL(), false); add(datatype.getDropSQL(), false);
} }
add(datatype.getCreateSQL(), false); add(datatype.getCreateSQL(), false);
} }
ObjectArray<SchemaObject> constants = db.getAllSchemaObjects(DbObject.CONSTANT); for (SchemaObject obj : db.getAllSchemaObjects(DbObject.CONSTANT)) {
for (int i = 0; i < constants.size(); i++) { Constant constant = (Constant) obj;
Constant constant = (Constant) constants.get(i);
add(constant.getCreateSQL(), false); add(constant.getCreateSQL(), false);
} }
ObjectArray<FunctionAlias> functionAliases = db.getAllFunctionAliases(); for (FunctionAlias alias : db.getAllFunctionAliases()) {
for (int i = 0; i < functionAliases.size(); i++) {
FunctionAlias alias = functionAliases.get(i);
if (drop) { if (drop) {
add(alias.getDropSQL(), false); add(alias.getDropSQL(), false);
} }
add(alias.getCreateSQL(), false); add(alias.getCreateSQL(), false);
} }
ObjectArray<UserAggregate> aggregates = db.getAllAggregates(); for (UserAggregate agg : db.getAllAggregates()) {
for (int i = 0; i < aggregates.size(); i++) {
UserAggregate agg = aggregates.get(i);
if (drop) { if (drop) {
add(agg.getDropSQL(), false); add(agg.getDropSQL(), false);
} }
...@@ -192,8 +177,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -192,8 +177,7 @@ public class ScriptCommand extends ScriptBase {
return t1.getId() - t2.getId(); return t1.getId() - t2.getId();
} }
}); });
for (int i = 0; i < tables.size(); i++) { for (Table table : tables) {
Table table = tables.get(i);
table.lock(session, false, false); table.lock(session, false, false);
String sql = table.getCreateSQL(); String sql = table.getCreateSQL();
if (sql == null) { if (sql == null) {
...@@ -204,16 +188,14 @@ public class ScriptCommand extends ScriptBase { ...@@ -204,16 +188,14 @@ public class ScriptCommand extends ScriptBase {
add(table.getDropSQL(), false); add(table.getDropSQL(), false);
} }
} }
ObjectArray<SchemaObject> sequences = db.getAllSchemaObjects(DbObject.SEQUENCE); for (SchemaObject obj : db.getAllSchemaObjects(DbObject.SEQUENCE)) {
for (int i = 0; i < sequences.size(); i++) { Sequence sequence = (Sequence) obj;
Sequence sequence = (Sequence) sequences.get(i);
if (drop && !sequence.getBelongsToTable()) { if (drop && !sequence.getBelongsToTable()) {
add(sequence.getDropSQL(), false); add(sequence.getDropSQL(), false);
} }
add(sequence.getCreateSQL(), false); add(sequence.getCreateSQL(), false);
} }
for (int i = 0; i < tables.size(); i++) { for (Table table : tables) {
Table table = tables.get(i);
table.lock(session, false, false); table.lock(session, false, false);
String sql = table.getCreateSQL(); String sql = table.getCreateSQL();
if (sql == null) { if (sql == null) {
...@@ -309,23 +291,18 @@ public class ScriptCommand extends ScriptBase { ...@@ -309,23 +291,18 @@ public class ScriptCommand extends ScriptBase {
return ((Constraint) c1).compareTo((Constraint) c2); return ((Constraint) c1).compareTo((Constraint) c2);
} }
}); });
for (int i = 0; i < constraints.size(); i++) { for (SchemaObject obj : constraints) {
Constraint constraint = (Constraint) constraints.get(i); Constraint constraint = (Constraint) obj;
add(constraint.getCreateSQLWithoutIndexes(), false); add(constraint.getCreateSQLWithoutIndexes(), false);
} }
ObjectArray<SchemaObject> triggers = db.getAllSchemaObjects(DbObject.TRIGGER); for (SchemaObject obj : db.getAllSchemaObjects(DbObject.TRIGGER)) {
for (int i = 0; i < triggers.size(); i++) { TriggerObject trigger = (TriggerObject) obj;
TriggerObject trigger = (TriggerObject) triggers.get(i);
add(trigger.getCreateSQL(), false); add(trigger.getCreateSQL(), false);
} }
ObjectArray<Right> rights = db.getAllRights(); for (Right right : db.getAllRights()) {
for (int i = 0; i < rights.size(); i++) {
Right right = rights.get(i);
add(right.getCreateSQL(), false); add(right.getCreateSQL(), false);
} }
ObjectArray<Comment> comments = db.getAllComments(); for (Comment comment : db.getAllComments()) {
for (int i = 0; i < comments.size(); i++) {
Comment comment = comments.get(i);
add(comment.getCreateSQL(), false); add(comment.getCreateSQL(), false);
} }
if (out != null) { if (out != null) {
......
...@@ -291,8 +291,8 @@ public class Select extends Query { ...@@ -291,8 +291,8 @@ public class Select extends Query {
return 0; return 0;
} }
int count = 0; int count = 0;
for (int i = 0; i < groupByExpression.length; i++) { for (boolean b : groupByExpression) {
if (groupByExpression[i]) { if (b) {
++count; ++count;
} }
} }
...@@ -345,8 +345,8 @@ public class Select extends Query { ...@@ -345,8 +345,8 @@ public class Select extends Query {
groups.put(defaultGroup, new HashMap<Expression, Object>()); groups.put(defaultGroup, new HashMap<Expression, Object>());
} }
ObjectArray<Value> keys = groups.keys(); ObjectArray<Value> keys = groups.keys();
for (int i = 0; i < keys.size(); i++) { for (Value v : keys) {
ValueArray key = (ValueArray) keys.get(i); ValueArray key = (ValueArray) v;
currentGroup = groups.get(key); currentGroup = groups.get(key);
Value[] keyValues = key.getList(); Value[] keyValues = key.getList();
Value[] row = new Value[columnCount]; Value[] row = new Value[columnCount];
...@@ -380,10 +380,8 @@ public class Select extends Query { ...@@ -380,10 +380,8 @@ public class Select extends Query {
if (sort == null) { if (sort == null) {
return null; return null;
} }
int[] indexes = sort.getIndexes();
ObjectArray<Column> sortColumns = ObjectArray.newInstance(); ObjectArray<Column> sortColumns = ObjectArray.newInstance();
for (int i = 0; i < indexes.length; i++) { for (int idx : sort.getIndexes()) {
int idx = indexes[i];
if (idx < 0 || idx >= expressions.size()) { if (idx < 0 || idx >= expressions.size()) {
throw Message.getInvalidValueException("" + (idx + 1), "ORDER BY"); throw Message.getInvalidValueException("" + (idx + 1), "ORDER BY");
} }
...@@ -685,16 +683,14 @@ public class Select extends Query { ...@@ -685,16 +683,14 @@ public class Select extends Query {
} }
} }
groupByExpression = new boolean[expressions.size()]; groupByExpression = new boolean[expressions.size()];
for (int i = 0; i < groupIndex.length; i++) { for (int gi : groupIndex) {
groupByExpression[groupIndex[i]] = true; groupByExpression[gi] = true;
} }
group = null; group = null;
} }
// map columns in select list and condition // map columns in select list and condition
for (int i = 0; i < filters.size(); i++) { for (TableFilter f : filters) {
TableFilter f = filters.get(i); for (Expression expr : expressions) {
for (int j = 0; j < expressions.size(); j++) {
Expression expr = expressions.get(j);
expr.mapColumns(f, 0); expr.mapColumns(f, 0);
} }
if (condition != null) { if (condition != null) {
...@@ -795,19 +791,17 @@ public class Select extends Query { ...@@ -795,19 +791,17 @@ public class Select extends Query {
public HashSet<Table> getTables() { public HashSet<Table> getTables() {
HashSet<Table> set = New.hashSet(); HashSet<Table> set = New.hashSet();
for (int i = 0; i < filters.size(); i++) { for (TableFilter filter : filters) {
TableFilter filter = filters.get(i);
set.add(filter.getTable()); set.add(filter.getTable());
} }
return set; return set;
} }
private double preparePlan() throws SQLException { private double preparePlan() throws SQLException {
TableFilter[] topArray = new TableFilter[topFilters.size()]; TableFilter[] topArray = new TableFilter[topFilters.size()];
topFilters.toArray(topArray); topFilters.toArray(topArray);
for (int i = 0; i < topArray.length; i++) { for (TableFilter t : topArray) {
topArray[i].setFullCondition(condition); t.setFullCondition(condition);
} }
Optimizer optimizer = new Optimizer(topArray, condition, session); Optimizer optimizer = new Optimizer(topArray, condition, session);
...@@ -845,8 +839,7 @@ public class Select extends Query { ...@@ -845,8 +839,7 @@ public class Select extends Query {
} }
// this is only important for subqueries, so they know // this is only important for subqueries, so they know
// the result columns are evaluatable // the result columns are evaluatable
for (int i = 0; i < expressions.size(); i++) { for (Expression e : expressions) {
Expression e = expressions.get(i);
e.setEvaluatable(f, true); e.setEvaluatable(f, true);
} }
f = f.getJoin(); f = f.getJoin();
...@@ -995,8 +988,7 @@ public class Select extends Query { ...@@ -995,8 +988,7 @@ public class Select extends Query {
} }
public void mapColumns(ColumnResolver resolver, int level) throws SQLException { public void mapColumns(ColumnResolver resolver, int level) throws SQLException {
for (int i = 0; i < expressions.size(); i++) { for (Expression e : expressions) {
Expression e = expressions.get(i);
e.mapColumns(resolver, level); e.mapColumns(resolver, level);
} }
if (condition != null) { if (condition != null) {
...@@ -1005,8 +997,7 @@ public class Select extends Query { ...@@ -1005,8 +997,7 @@ public class Select extends Query {
} }
public void setEvaluatable(TableFilter tableFilter, boolean b) { public void setEvaluatable(TableFilter tableFilter, boolean b) {
for (int i = 0; i < expressions.size(); i++) { for (Expression e : expressions) {
Expression e = expressions.get(i);
e.setEvaluatable(tableFilter, b); e.setEvaluatable(tableFilter, b);
} }
if (condition != null) { if (condition != null) {
...@@ -1061,8 +1052,7 @@ public class Select extends Query { ...@@ -1061,8 +1052,7 @@ public class Select extends Query {
} }
public void updateAggregate(Session s) throws SQLException { public void updateAggregate(Session s) throws SQLException {
for (int i = 0; i < expressions.size(); i++) { for (Expression e : expressions) {
Expression e = expressions.get(i);
e.updateAggregate(s); e.updateAggregate(s);
} }
if (condition != null) { if (condition != null) {
...@@ -1076,8 +1066,7 @@ public class Select extends Query { ...@@ -1076,8 +1066,7 @@ public class Select extends Query {
public boolean isEverything(ExpressionVisitor visitor) { public boolean isEverything(ExpressionVisitor visitor) {
switch(visitor.getType()) { switch(visitor.getType()) {
case ExpressionVisitor.SET_MAX_DATA_MODIFICATION_ID: { case ExpressionVisitor.SET_MAX_DATA_MODIFICATION_ID: {
for (int i = 0; i < filters.size(); i++) { for (TableFilter f : filters) {
TableFilter f = filters.get(i);
long m = f.getTable().getMaxDataModificationId(); long m = f.getTable().getMaxDataModificationId();
visitor.addDataModificationId(m); visitor.addDataModificationId(m);
} }
...@@ -1090,8 +1079,7 @@ public class Select extends Query { ...@@ -1090,8 +1079,7 @@ public class Select extends Query {
break; break;
} }
case ExpressionVisitor.GET_DEPENDENCIES: { case ExpressionVisitor.GET_DEPENDENCIES: {
for (int i = 0; i < filters.size(); i++) { for (TableFilter filter : filters) {
TableFilter filter = filters.get(i);
Table table = filter.getTable(); Table table = filter.getTable();
visitor.addDependency(table); visitor.addDependency(table);
table.addDependencies(visitor.getDependencies()); table.addDependencies(visitor.getDependencies());
...@@ -1102,8 +1090,7 @@ public class Select extends Query { ...@@ -1102,8 +1090,7 @@ public class Select extends Query {
} }
visitor.incrementQueryLevel(1); visitor.incrementQueryLevel(1);
boolean result = true; boolean result = true;
for (int i = 0; i < expressions.size(); i++) { for (Expression e : expressions) {
Expression e = expressions.get(i);
if (!e.isEverything(visitor)) { if (!e.isEverything(visitor)) {
result = false; result = false;
break; break;
......
...@@ -158,9 +158,7 @@ public class TransactionCommand extends Prepared { ...@@ -158,9 +158,7 @@ public class TransactionCommand extends Prepared {
// throttle, to allow testing concurrent // throttle, to allow testing concurrent
// execution of shutdown and query // execution of shutdown and query
session.throttle(); session.throttle();
Session[] sessions = db.getSessions(false); for (Session s : db.getSessions(false)) {
for (int i = 0; i < sessions.length; i++) {
Session s = sessions[i];
if (db.isMultiThreaded()) { if (db.isMultiThreaded()) {
synchronized (s) { synchronized (s) {
s.rollback(); s.rollback();
......
...@@ -299,8 +299,8 @@ public class ConstraintReferential extends Constraint { ...@@ -299,8 +299,8 @@ public class ConstraintReferential extends Constraint {
return; return;
} }
boolean constraintColumnsEqual = oldRow != null; boolean constraintColumnsEqual = oldRow != null;
for (int i = 0; i < columns.length; i++) { for (IndexColumn col : columns) {
int idx = columns[i].column.getColumnId(); int idx = col.column.getColumnId();
Value v = newRow.getValue(idx); Value v = newRow.getValue(idx);
if (v == ValueNull.INSTANCE) { if (v == ValueNull.INSTANCE) {
// return early if one of the columns is NULL // return early if one of the columns is NULL
...@@ -606,13 +606,13 @@ public class ConstraintReferential extends Constraint { ...@@ -606,13 +606,13 @@ public class ConstraintReferential extends Constraint {
} }
public boolean containsColumn(Column col) { public boolean containsColumn(Column col) {
for (int i = 0; i < columns.length; i++) { for (IndexColumn c : columns) {
if (columns[i].column == col) { if (c.column == col) {
return true; return true;
} }
} }
for (int i = 0; i < refColumns.length; i++) { for (IndexColumn c : refColumns) {
if (refColumns[i].column == col) { if (c.column == col) {
return true; return true;
} }
} }
......
...@@ -128,8 +128,8 @@ public class ConstraintUnique extends Constraint { ...@@ -128,8 +128,8 @@ public class ConstraintUnique extends Constraint {
} }
public boolean containsColumn(Column col) { public boolean containsColumn(Column col) {
for (int i = 0; i < columns.length; i++) { for (IndexColumn c : columns) {
if (columns[i].column == col) { if (c.column == col) {
return true; return true;
} }
} }
......
...@@ -585,9 +585,7 @@ public class Database implements DataHandler { ...@@ -585,9 +585,7 @@ public class Database implements DataHandler {
} catch (Exception e) { } catch (Exception e) {
if (recovery) { if (recovery) {
traceSystem.getTrace(Trace.DATABASE).error("opening index", e); traceSystem.getTrace(Trace.DATABASE).error("opening index", e);
ArrayList<Storage> list = New.arrayList(storageMap.values()); for (Storage s : New.arrayList(storageMap.values())) {
for (int i = 0; i < list.size(); i++) {
Storage s = list.get(i);
if (s.getDiskFile() == fileIndex) { if (s.getDiskFile() == fileIndex) {
removeStorage(s.getId(), fileIndex); removeStorage(s.getId(), fileIndex);
} }
...@@ -695,9 +693,7 @@ public class Database implements DataHandler { ...@@ -695,9 +693,7 @@ public class Database implements DataHandler {
boolean recompileSuccessful; boolean recompileSuccessful;
do { do {
recompileSuccessful = false; recompileSuccessful = false;
ObjectArray<Table> list = getAllTablesAndViews(); for (Table obj : getAllTablesAndViews()) {
for (int i = 0; i < list.size(); i++) {
Table obj = list.get(i);
if (obj instanceof TableView) { if (obj instanceof TableView) {
TableView view = (TableView) obj; TableView view = (TableView) obj;
if (view.getInvalid()) { if (view.getInvalid()) {
...@@ -716,9 +712,7 @@ public class Database implements DataHandler { ...@@ -716,9 +712,7 @@ public class Database implements DataHandler {
// when opening a database, views are initialized before indexes, // when opening a database, views are initialized before indexes,
// so they may not have the optimal plan yet // so they may not have the optimal plan yet
// this is not a problem, it is just nice to see the newest plan // this is not a problem, it is just nice to see the newest plan
ObjectArray<Table> list = getAllTablesAndViews(); for (Table obj : getAllTablesAndViews()) {
for (int i = 0; i < list.size(); i++) {
Table obj = list.get(i);
if (obj instanceof TableView) { if (obj instanceof TableView) {
TableView view = (TableView) obj; TableView view = (TableView) obj;
if (!view.getInvalid()) { if (!view.getInvalid()) {
...@@ -1630,10 +1624,8 @@ public class Database implements DataHandler { ...@@ -1630,10 +1624,8 @@ public class Database implements DataHandler {
return null; return null;
default: default:
} }
ObjectArray<Table> list = getAllTablesAndViews();
HashSet<DbObject> set = New.hashSet(); HashSet<DbObject> set = New.hashSet();
for (int i = 0; i < list.size(); i++) { for (Table t : getAllTablesAndViews()) {
Table t = list.get(i);
if (except == t) { if (except == t) {
continue; continue;
} }
...@@ -1649,9 +1641,7 @@ public class Database implements DataHandler { ...@@ -1649,9 +1641,7 @@ public class Database implements DataHandler {
private String getFirstInvalidTable(Session session) { private String getFirstInvalidTable(Session session) {
String conflict = null; String conflict = null;
try { try {
ObjectArray<Table> list = getAllTablesAndViews(); for (Table t : getAllTablesAndViews()) {
for (int i = 0; i < list.size(); i++) {
Table t = list.get(i);
conflict = t.getSQL(); conflict = t.getSQL();
session.prepare(t.getCreateSQL()); session.prepare(t.getCreateSQL());
} }
...@@ -1971,7 +1961,9 @@ public class Database implements DataHandler { ...@@ -1971,7 +1961,9 @@ public class Database implements DataHandler {
log.setDisabled(!logData); log.setDisabled(!logData);
log.checkpoint(); log.checkpoint();
} }
traceSystem.getTrace(Trace.DATABASE).error("SET LOG " + level, null); if (level == 0) {
traceSystem.getTrace(Trace.DATABASE).error("SET LOG " + level, null);
}
logLevel = level; logLevel = level;
} }
......
...@@ -649,9 +649,7 @@ public class Session extends SessionWithState { ...@@ -649,9 +649,7 @@ public class Session extends SessionWithState {
private void cleanTempTables(boolean closeSession) throws SQLException { private void cleanTempTables(boolean closeSession) throws SQLException {
if (localTempTables != null && localTempTables.size() > 0) { if (localTempTables != null && localTempTables.size() > 0) {
ObjectArray<Table> list = ObjectArray.newInstance(localTempTables.values()); for (Table table : ObjectArray.newInstance(localTempTables.values())) {
for (int i = 0; i < list.size(); i++) {
Table table = list.get(i);
if (closeSession || table.getOnCommitDrop()) { if (closeSession || table.getOnCommitDrop()) {
modificationId++; modificationId++;
table.setModified(); table.setModified();
......
...@@ -19,7 +19,6 @@ import org.h2.result.Row; ...@@ -19,7 +19,6 @@ import org.h2.result.Row;
import org.h2.store.DataPage; import org.h2.store.DataPage;
import org.h2.store.FileStore; import org.h2.store.FileStore;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.util.ObjectArray;
import org.h2.value.Value; import org.h2.value.Value;
/** /**
...@@ -212,9 +211,7 @@ public class UndoLogRecord { ...@@ -212,9 +211,7 @@ public class UndoLogRecord {
* It commits the change to the indexes. * It commits the change to the indexes.
*/ */
public void commit() throws SQLException { public void commit() throws SQLException {
ObjectArray<Index> list = table.getIndexes(); for (Index index : table.getIndexes()) {
for (int i = 0; i < list.size(); i++) {
Index index = list.get(i);
index.commit(operation, row); index.commit(operation, row);
} }
} }
......
...@@ -276,9 +276,7 @@ public class DiskFile implements CacheWriter { ...@@ -276,9 +276,7 @@ public class DiskFile implements CacheWriter {
public void initFromSummary(byte[] summary) { public void initFromSummary(byte[] summary) {
synchronized (database) { synchronized (database) {
if (summary == null || summary.length == 0) { if (summary == null || summary.length == 0) {
ObjectArray<Storage> list = database.getAllStorages(); for (Storage s : database.getAllStorages()) {
for (int i = 0; i < list.size(); i++) {
Storage s = list.get(i);
if (s != null && s.getDiskFile() == this) { if (s != null && s.getDiskFile() == this) {
database.removeStorage(s.getId(), this); database.removeStorage(s.getId(), this);
} }
...@@ -428,8 +426,7 @@ public class DiskFile implements CacheWriter { ...@@ -428,8 +426,7 @@ public class DiskFile implements CacheWriter {
database.checkPowerOff(); database.checkPowerOff();
ObjectArray<CacheObject> list = cache.getAllChanged(); ObjectArray<CacheObject> list = cache.getAllChanged();
CacheObject.sort(list); CacheObject.sort(list);
for (int i = 0; i < list.size(); i++) { for (CacheObject rec : list) {
Record rec = (Record) list.get(i);
writeBack(rec); writeBack(rec);
} }
for (int i = 0; i < fileBlockCount; i++) { for (int i = 0; i < fileBlockCount; i++) {
...@@ -1072,9 +1069,8 @@ public class DiskFile implements CacheWriter { ...@@ -1072,9 +1069,8 @@ public class DiskFile implements CacheWriter {
int storageId = storage.getId(); int storageId = storage.getId();
// make sure the cache records of this storage are not flushed to disk // make sure the cache records of this storage are not flushed to disk
// afterwards // afterwards
ObjectArray<CacheObject> list = cache.getAllChanged(); for (CacheObject obj : cache.getAllChanged()) {
for (int i = 0; i < list.size(); i++) { Record r = (Record) obj;
Record r = (Record) list.get(i);
if (r.getStorageId() == storageId) { if (r.getStorageId() == storageId) {
r.setChanged(false); r.setChanged(false);
} }
......
...@@ -265,8 +265,7 @@ public class PageStore implements CacheWriter { ...@@ -265,8 +265,7 @@ public class PageStore implements CacheWriter {
database.checkPowerOff(); database.checkPowerOff();
ObjectArray<CacheObject> list = cache.getAllChanged(); ObjectArray<CacheObject> list = cache.getAllChanged();
CacheObject.sort(list); CacheObject.sort(list);
for (int i = 0; i < list.size(); i++) { for (CacheObject rec : list) {
CacheObject rec = list.get(i);
writeBack(rec); writeBack(rec);
} }
int todoFlushBeforeReopen; int todoFlushBeforeReopen;
......
...@@ -805,9 +805,7 @@ public class MetaTable extends Table { ...@@ -805,9 +805,7 @@ public class MetaTable extends Table {
break; break;
} }
case SETTINGS: { case SETTINGS: {
ObjectArray<Setting> list = database.getAllSettings(); for (Setting s : database.getAllSettings()) {
for (int i = 0; i < list.size(); i++) {
Setting s = list.get(i);
String value = s.getStringValue(); String value = s.getStringValue();
if (value == null) { if (value == null) {
value = "" + s.getIntValue(); value = "" + s.getIntValue();
......
...@@ -278,8 +278,7 @@ public class TableData extends Table implements RecordReader { ...@@ -278,8 +278,7 @@ public class TableData extends Table implements RecordReader {
} catch (Exception e) { } catch (Exception e) {
throw Message.convert(e); throw Message.convert(e);
} }
for (int i = 0; i < list.size(); i++) { for (Row row : list) {
Row row = list.get(i);
index.add(session, row); index.add(session, row);
} }
list.clear(); list.clear();
...@@ -640,9 +639,8 @@ public class TableData extends Table implements RecordReader { ...@@ -640,9 +639,8 @@ public class TableData extends Table implements RecordReader {
} }
} }
if (SysProperties.CHECK) { if (SysProperties.CHECK) {
ObjectArray<SchemaObject> list = database.getAllSchemaObjects(DbObject.INDEX); for (SchemaObject obj : database.getAllSchemaObjects(DbObject.INDEX)) {
for (int i = 0; i < list.size(); i++) { Index index = (Index) obj;
Index index = (Index) list.get(i);
if (index.getTable() == this) { if (index.getTable() == this) {
Message.throwInternalError("index not dropped: " + index.getName()); Message.throwInternalError("index not dropped: " + index.getName());
} }
......
...@@ -106,14 +106,12 @@ public class Backup extends Tool { ...@@ -106,14 +106,12 @@ public class Backup extends Tool {
fileOut = FileUtils.openFileOutputStream(zipFileName, false); fileOut = FileUtils.openFileOutputStream(zipFileName, false);
ZipOutputStream zipOut = new ZipOutputStream(fileOut); ZipOutputStream zipOut = new ZipOutputStream(fileOut);
String base = ""; String base = "";
for (int i = 0; i < list.size(); i++) { for (String fileName : list) {
String fileName = list.get(i);
if (fileName.endsWith(Constants.SUFFIX_DATA_FILE)) { if (fileName.endsWith(Constants.SUFFIX_DATA_FILE)) {
base = FileUtils.getParent(fileName); base = FileUtils.getParent(fileName);
} }
} }
for (int i = 0; i < list.size(); i++) { for (String fileName : list) {
String fileName = list.get(i);
String f = FileUtils.getAbsolutePath(fileName); String f = FileUtils.getAbsolutePath(fileName);
if (!f.startsWith(base)) { if (!f.startsWith(base)) {
Message.throwInternalError(f + " does not start with " + base); Message.throwInternalError(f + " does not start with " + base);
......
...@@ -180,8 +180,7 @@ public class ConvertTraceFile extends Tool { ...@@ -180,8 +180,7 @@ public class ConvertTraceFile extends Tool {
if (timeTotal == 0) { if (timeTotal == 0) {
timeTotal = 1; timeTotal = 1;
} }
for (int i = 0; i < list.size(); i++) { for (Stat stat : list) {
Stat stat = list.get(i);
StringBuffer buff = new StringBuffer(100); StringBuffer buff = new StringBuffer(100);
buff.append("-- "); buff.append("-- ");
buff.append(padNumberLeft(100 * stat.time / timeTotal, 3)); buff.append(padNumberLeft(100 * stat.time / timeTotal, 3));
......
...@@ -64,6 +64,7 @@ public class New { ...@@ -64,6 +64,7 @@ public class New {
* Create a new HashSet. * Create a new HashSet.
* *
* @param <T> the type * @param <T> the type
* @param c the collection
* @return the object * @return the object
*/ */
public static <T> HashSet<T> hashSet(Collection<T> c) { public static <T> HashSet<T> hashSet(Collection<T> c) {
......
...@@ -18,7 +18,7 @@ import org.h2.constant.SysProperties; ...@@ -18,7 +18,7 @@ import org.h2.constant.SysProperties;
* *
* @param <T> the element type * @param <T> the element type
*/ */
public class ObjectArray<T> { public class ObjectArray<T> implements Iterable<T> {
private static final int CAPACITY_INIT = 4, CAPACITY_SHRINK = 256; private static final int CAPACITY_INIT = 4, CAPACITY_SHRINK = 256;
private T[] data; private T[] data;
...@@ -41,6 +41,7 @@ public class ObjectArray<T> { ...@@ -41,6 +41,7 @@ public class ObjectArray<T> {
* Create a new object with the given initial capacity. * Create a new object with the given initial capacity.
* *
* @param capacity the initial capacity * @param capacity the initial capacity
* @return the object
*/ */
public static <T> ObjectArray<T> newInstance(int capacity) { public static <T> ObjectArray<T> newInstance(int capacity) {
return new ObjectArray<T>(CAPACITY_INIT); return new ObjectArray<T>(CAPACITY_INIT);
...@@ -48,6 +49,8 @@ public class ObjectArray<T> { ...@@ -48,6 +49,8 @@ public class ObjectArray<T> {
/** /**
* Create a new object with the default initial capacity. * Create a new object with the default initial capacity.
*
* @return the object
*/ */
public static <T> ObjectArray<T> newInstance() { public static <T> ObjectArray<T> newInstance() {
return new ObjectArray<T>(CAPACITY_INIT); return new ObjectArray<T>(CAPACITY_INIT);
...@@ -57,6 +60,7 @@ public class ObjectArray<T> { ...@@ -57,6 +60,7 @@ public class ObjectArray<T> {
* Create a new object with all elements of the given collection. * Create a new object with all elements of the given collection.
* *
* @param collection the collection with all elements * @param collection the collection with all elements
* @return the object
*/ */
public static <T> ObjectArray<T> newInstance(Collection<T> collection) { public static <T> ObjectArray<T> newInstance(Collection<T> collection) {
return new ObjectArray<T>(collection); return new ObjectArray<T>(collection);
...@@ -316,6 +320,29 @@ public class ObjectArray<T> { ...@@ -316,6 +320,29 @@ public class ObjectArray<T> {
} }
} }
/**
* The iterator for this list.
*/
private class ObjectArrayIterator implements Iterator<T> {
private int index;
public boolean hasNext() {
return index < size;
}
public T next() {
return get(index++);
}
public void remove() {
throw new UnsupportedOperationException();
}
}
public Iterator<T> iterator() {
return new ObjectArrayIterator();
}
// public void sortInsertion(Comparator comp) { // public void sortInsertion(Comparator comp) {
// for (int i = 1, j; i < size(); i++) { // for (int i = 1, j; i < size(); i++) {
// Object t = get(i); // Object t = get(i);
......
...@@ -37,6 +37,14 @@ extends HashMap ...@@ -37,6 +37,14 @@ extends HashMap
this.size = size; this.size = size;
} }
/**
* Create a new object with all elements of the given collection.
*
* @param <K> the key type
* @param <V> the value type
* @param size the number of elements
* @return the object
*/
public static <K, V> SmallLRUCache<K, V> newInstance(int size) { public static <K, V> SmallLRUCache<K, V> newInstance(int size) {
return new SmallLRUCache<K, V>(size); return new SmallLRUCache<K, V>(size);
} }
......
...@@ -39,6 +39,7 @@ public class ValueHashMap<V> extends HashBase { ...@@ -39,6 +39,7 @@ public class ValueHashMap<V> extends HashBase {
* The data handler is used to compare values. * The data handler is used to compare values.
* *
* @param handler the data handler * @param handler the data handler
* @return the object
*/ */
public static <T> ValueHashMap<T> newInstance(DataHandler handler) { public static <T> ValueHashMap<T> newInstance(DataHandler handler) {
return new ValueHashMap<T>(handler); return new ValueHashMap<T>(handler);
......
...@@ -464,7 +464,7 @@ kill -9 `jps -l | grep "org.h2.test.TestAll" | cut -d " " -f 1` ...@@ -464,7 +464,7 @@ kill -9 `jps -l | grep "org.h2.test.TestAll" | cut -d " " -f 1`
beforeTest(); beforeTest();
// db // db
new TestScriptSimple().runTest(this); // new TestScriptSimple().runTest(this);
new TestScript().runTest(this); new TestScript().runTest(this);
new TestAlter().runTest(this); new TestAlter().runTest(this);
new TestAutoRecompile().runTest(this); new TestAutoRecompile().runTest(this);
......
...@@ -589,4 +589,4 @@ handing bonita placed euros embeds reliability singular unregister quotas ...@@ -589,4 +589,4 @@ handing bonita placed euros embeds reliability singular unregister quotas
overall httpdocs tigris eclemma separates underscore yajsw she her truncating overall httpdocs tigris eclemma separates underscore yajsw she her truncating
relocating smtps smtp osde joist catching guesses delimiters shortlist sheet relocating smtps smtp osde joist catching guesses delimiters shortlist sheet
rowspan cheat partitioning datepart dreamsource toussi locates fred rowspan cheat partitioning datepart dreamsource toussi locates fred
longnvarchar collate localdb nan bootclasspath bcp retrotranslator longnvarchar collate localdb nan bootclasspath bcp retrotranslator iterable
\ No newline at end of file \ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论