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

Replace ObjectArray with ArrayList.

上级 8094d423
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
package org.h2.command.ddl; package org.h2.command.ddl;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constraint.Constraint; import org.h2.constraint.Constraint;
import org.h2.constraint.ConstraintCheck; import org.h2.constraint.ConstraintCheck;
...@@ -28,7 +28,6 @@ import org.h2.table.IndexColumn; ...@@ -28,7 +28,6 @@ import org.h2.table.IndexColumn;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.ObjectArray;
/** /**
* This class represents the statement * This class represents the statement
...@@ -114,7 +113,7 @@ public class AlterTableAddConstraint extends SchemaCommand { ...@@ -114,7 +113,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
case PRIMARY_KEY: { case PRIMARY_KEY: {
IndexColumn.mapColumns(indexColumns, table); IndexColumn.mapColumns(indexColumns, table);
index = table.findPrimaryKey(); index = table.findPrimaryKey();
ObjectArray<Constraint> constraints = table.getConstraints(); ArrayList<Constraint> constraints = table.getConstraints();
for (int i = 0; constraints != null && i < constraints.size(); i++) { for (int i = 0; constraints != null && i < constraints.size(); i++) {
Constraint c = constraints.get(i); Constraint c = constraints.get(i);
if (Constraint.PRIMARY_KEY.equals(c.getConstraintType())) { if (Constraint.PRIMARY_KEY.equals(c.getConstraintType())) {
......
...@@ -31,7 +31,7 @@ import org.h2.table.Column; ...@@ -31,7 +31,7 @@ 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.table.TableView; import org.h2.table.TableView;
import org.h2.util.ObjectArray; import org.h2.util.New;
/** /**
* This class represents the statements * This class represents the statements
...@@ -207,7 +207,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -207,7 +207,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
Database db = session.getDatabase(); Database db = session.getDatabase();
String tempName = db.getTempTableName(session); String tempName = db.getTempTableName(session);
Column[] columns = table.getColumns(); Column[] columns = table.getColumns();
ObjectArray<Column> newColumns = ObjectArray.newInstance(); ArrayList<Column> newColumns = New.arrayList();
TableData newTable = cloneTableStructure(columns, db, tempName, newColumns); TableData newTable = cloneTableStructure(columns, db, tempName, newColumns);
List<String> views; List<String> views;
try { try {
...@@ -247,7 +247,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -247,7 +247,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
} }
} }
private TableData cloneTableStructure(Column[] columns, Database db, String tempName, ObjectArray<Column> newColumns) throws SQLException { private TableData cloneTableStructure(Column[] columns, Database db, String tempName, ArrayList<Column> newColumns) throws SQLException {
for (Column col : columns) { for (Column col : columns) {
newColumns.add(col.getClone()); newColumns.add(col.getClone());
} }
...@@ -314,7 +314,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -314,7 +314,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
execute(newTableSQL, true); execute(newTableSQL, true);
newTable = (TableData) newTableSchema.getTableOrView(session, newTableName); newTable = (TableData) newTableSchema.getTableOrView(session, newTableName);
ObjectArray<String> triggers = ObjectArray.newInstance(); ArrayList<String> triggers = New.arrayList();
for (DbObject child : table.getChildren()) { for (DbObject child : table.getChildren()) {
if (child instanceof Sequence) { if (child instanceof Sequence) {
continue; continue;
...@@ -427,7 +427,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -427,7 +427,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
private void dropSingleColumnIndexes() throws SQLException { private void dropSingleColumnIndexes() throws SQLException {
Database db = session.getDatabase(); Database db = session.getDatabase();
ObjectArray<Index> indexes = table.getIndexes(); ArrayList<Index> indexes = table.getIndexes();
for (int i = 0; i < indexes.size(); i++) { for (int i = 0; i < indexes.size(); i++) {
Index index = indexes.get(i); Index index = indexes.get(i);
if (index.getCreateSQL() == null) { if (index.getCreateSQL() == null) {
......
...@@ -21,7 +21,7 @@ import org.h2.schema.Sequence; ...@@ -21,7 +21,7 @@ import org.h2.schema.Sequence;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.IndexColumn; import org.h2.table.IndexColumn;
import org.h2.table.TableData; import org.h2.table.TableData;
import org.h2.util.ObjectArray; import org.h2.util.New;
import org.h2.value.DataType; import org.h2.value.DataType;
/** /**
...@@ -31,7 +31,7 @@ import org.h2.value.DataType; ...@@ -31,7 +31,7 @@ import org.h2.value.DataType;
public class CreateTable extends SchemaCommand { public class CreateTable extends SchemaCommand {
private CreateTableData data = new CreateTableData(); private CreateTableData data = new CreateTableData();
private ObjectArray<Prepared> constraintCommands = ObjectArray.newInstance(); private ArrayList<Prepared> constraintCommands = New.arrayList();
private IndexColumn[] pkColumns; private IndexColumn[] pkColumns;
private boolean ifNotExists; private boolean ifNotExists;
private boolean globalTemporary; private boolean globalTemporary;
...@@ -124,7 +124,7 @@ public class CreateTable extends SchemaCommand { ...@@ -124,7 +124,7 @@ public class CreateTable extends SchemaCommand {
} }
} }
} }
ObjectArray<Sequence> sequences = ObjectArray.newInstance(); ArrayList<Sequence> sequences = New.arrayList();
for (Column c : data.columns) { for (Column c : data.columns) {
if (c.isAutoIncrement()) { if (c.isAutoIncrement()) {
int objId = getObjectId(); int objId = getObjectId();
......
...@@ -6,10 +6,11 @@ ...@@ -6,10 +6,11 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import java.util.ArrayList;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.schema.Schema; import org.h2.schema.Schema;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.util.ObjectArray; import org.h2.util.New;
/** /**
* The data required to create a table. * The data required to create a table.
...@@ -34,7 +35,7 @@ public class CreateTableData { ...@@ -34,7 +35,7 @@ public class CreateTableData {
/** /**
* The column list. * The column list.
*/ */
public ObjectArray<Column> columns = ObjectArray.newInstance(); public ArrayList<Column> columns = New.arrayList();
/** /**
* Whether this is a temporary table. * Whether this is a temporary table.
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.command.ddl; package org.h2.command.ddl;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.DbObject; import org.h2.engine.DbObject;
import org.h2.engine.Role; import org.h2.engine.Role;
...@@ -15,7 +16,7 @@ import org.h2.engine.User; ...@@ -15,7 +16,7 @@ import org.h2.engine.User;
import org.h2.schema.Schema; import org.h2.schema.Schema;
import org.h2.schema.SchemaObject; import org.h2.schema.SchemaObject;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.util.ObjectArray; import org.h2.util.New;
/** /**
* This class represents the statement * This class represents the statement
...@@ -50,7 +51,7 @@ public class DropDatabase extends DefineCommand { ...@@ -50,7 +51,7 @@ public class DropDatabase extends DefineCommand {
db.removeDatabaseObject(session, schema); db.removeDatabaseObject(session, schema);
} }
} }
ObjectArray<Table> tables = db.getAllTablesAndViews(false); ArrayList<Table> tables = db.getAllTablesAndViews(false);
for (Table t : tables) { for (Table t : tables) {
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);
...@@ -67,7 +68,7 @@ public class DropDatabase extends DefineCommand { ...@@ -67,7 +68,7 @@ public class DropDatabase extends DefineCommand {
} }
} }
session.findLocalTempTable(null); session.findLocalTempTable(null);
ObjectArray<SchemaObject> list = ObjectArray.newInstance(); ArrayList<SchemaObject> list = New.arrayList();
list.addAll(db.getAllSchemaObjects(DbObject.SEQUENCE)); list.addAll(db.getAllSchemaObjects(DbObject.SEQUENCE));
// maybe constraints and triggers on system tables will be allowed in // maybe constraints and triggers on system tables will be allowed in
// the future // the future
...@@ -89,7 +90,7 @@ public class DropDatabase extends DefineCommand { ...@@ -89,7 +90,7 @@ public class DropDatabase extends DefineCommand {
db.removeDatabaseObject(session, role); db.removeDatabaseObject(session, role);
} }
} }
ObjectArray<DbObject> dbObjects = ObjectArray.newInstance(); ArrayList<DbObject> dbObjects = New.arrayList();
dbObjects.addAll(db.getAllRights()); dbObjects.addAll(db.getAllRights());
dbObjects.addAll(db.getAllFunctionAliases()); dbObjects.addAll(db.getAllFunctionAliases());
dbObjects.addAll(db.getAllAggregates()); dbObjects.addAll(db.getAllAggregates());
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.command.ddl; package org.h2.command.ddl;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constraint.Constraint; import org.h2.constraint.Constraint;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -16,7 +17,6 @@ import org.h2.index.Index; ...@@ -16,7 +17,6 @@ import org.h2.index.Index;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.schema.Schema; import org.h2.schema.Schema;
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
...@@ -51,7 +51,7 @@ public class DropIndex extends SchemaCommand { ...@@ -51,7 +51,7 @@ public class DropIndex extends SchemaCommand {
Table table = index.getTable(); Table table = index.getTable();
session.getUser().checkRight(index.getTable(), Right.ALL); session.getUser().checkRight(index.getTable(), Right.ALL);
Constraint pkConstraint = null; Constraint pkConstraint = null;
ObjectArray<Constraint> constraints = table.getConstraints(); ArrayList<Constraint> constraints = table.getConstraints();
for (int i = 0; constraints != null && i < constraints.size(); i++) { for (int i = 0; constraints != null && i < constraints.size(); i++) {
Constraint cons = constraints.get(i); Constraint cons = constraints.get(i);
if (cons.usesIndex(index)) { if (cons.usesIndex(index)) {
......
...@@ -14,6 +14,8 @@ import java.sql.Connection; ...@@ -14,6 +14,8 @@ import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
...@@ -49,7 +51,6 @@ import org.h2.table.Table; ...@@ -49,7 +51,6 @@ import org.h2.table.Table;
import org.h2.util.ByteUtils; import org.h2.util.ByteUtils;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.ObjectArray;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -171,10 +172,10 @@ public class ScriptCommand extends ScriptBase { ...@@ -171,10 +172,10 @@ public class ScriptCommand extends ScriptBase {
} }
add(agg.getCreateSQL(), false); add(agg.getCreateSQL(), false);
} }
ObjectArray<Table> tables = db.getAllTablesAndViews(false); ArrayList<Table> tables = db.getAllTablesAndViews(false);
// sort by id, so that views are after tables and views on views // sort by id, so that views are after tables and views on views
// after the base views // after the base views
tables.sort(new Comparator<Table>() { Collections.sort(tables, new Comparator<Table>() {
public int compare(Table t1, Table t2) { public int compare(Table t1, Table t2) {
return t1.getId() - t2.getId(); return t1.getId() - t2.getId();
} }
...@@ -206,7 +207,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -206,7 +207,7 @@ public class ScriptCommand extends ScriptBase {
} }
String tableType = table.getTableType(); String tableType = table.getTableType();
add(sql, false); add(sql, false);
ObjectArray<Constraint> constraints = table.getConstraints(); ArrayList<Constraint> constraints = table.getConstraints();
if (constraints != null) { if (constraints != null) {
for (Constraint constraint : constraints) { for (Constraint constraint : constraints) {
if (Constraint.PRIMARY_KEY.equals(constraint.getConstraintType())) { if (Constraint.PRIMARY_KEY.equals(constraint.getConstraintType())) {
...@@ -276,7 +277,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -276,7 +277,7 @@ public class ScriptCommand extends ScriptBase {
} }
} }
} }
ObjectArray<Index> indexes = table.getIndexes(); ArrayList<Index> indexes = table.getIndexes();
for (int j = 0; indexes != null && j < indexes.size(); j++) { for (int j = 0; indexes != null && j < indexes.size(); j++) {
Index index = indexes.get(j); Index index = indexes.get(j);
if (!index.getIndexType().getBelongsToConstraint()) { if (!index.getIndexType().getBelongsToConstraint()) {
...@@ -291,8 +292,8 @@ public class ScriptCommand extends ScriptBase { ...@@ -291,8 +292,8 @@ public class ScriptCommand extends ScriptBase {
add("DROP ALIAS IF EXISTS SYSTEM_COMBINE_BLOB", true); add("DROP ALIAS IF EXISTS SYSTEM_COMBINE_BLOB", true);
tempLobTableCreated = false; tempLobTableCreated = false;
} }
ObjectArray<SchemaObject> constraints = db.getAllSchemaObjects(DbObject.CONSTRAINT); ArrayList<SchemaObject> constraints = db.getAllSchemaObjects(DbObject.CONSTRAINT);
constraints.sort(new Comparator<SchemaObject>() { Collections.sort(constraints, new Comparator<SchemaObject>() {
public int compare(SchemaObject c1, SchemaObject c2) { public int compare(SchemaObject c1, SchemaObject c2) {
return ((Constraint) c1).compareTo((Constraint) c2); return ((Constraint) c1).compareTo((Constraint) c2);
} }
......
...@@ -39,7 +39,6 @@ import org.h2.table.IndexColumn; ...@@ -39,7 +39,6 @@ import org.h2.table.IndexColumn;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.ObjectArray;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.util.ValueHashMap; import org.h2.util.ValueHashMap;
...@@ -237,7 +236,7 @@ public class Select extends Query { ...@@ -237,7 +236,7 @@ public class Select extends Query {
if (groupIndex == null || groupByExpression == null) { if (groupIndex == null || groupByExpression == null) {
return null; return null;
} }
ObjectArray<Index> indexes = topTableFilter.getTable().getIndexes(); ArrayList<Index> indexes = topTableFilter.getTable().getIndexes();
for (int i = 0; indexes != null && i < indexes.size(); i++) { for (int i = 0; indexes != null && i < indexes.size(); i++) {
Index index = indexes.get(i); Index index = indexes.get(i);
if (index.getIndexType().isScan()) { if (index.getIndexType().isScan()) {
...@@ -406,7 +405,7 @@ public class Select extends Query { ...@@ -406,7 +405,7 @@ public class Select extends Query {
// sort just on constants - can use scan index // sort just on constants - can use scan index
return topTableFilter.getTable().getScanIndex(session); return topTableFilter.getTable().getScanIndex(session);
} }
ObjectArray<Index> list = topTableFilter.getTable().getIndexes(); ArrayList<Index> list = topTableFilter.getTable().getIndexes();
for (int i = 0; list != null && i < list.size(); i++) { for (int i = 0; list != null && i < list.size(); i++) {
Index index = list.get(i); Index index = list.get(i);
if (index.getCreateSQL() == null) { if (index.getCreateSQL() == null) {
......
...@@ -55,7 +55,6 @@ import org.h2.util.ClassUtils; ...@@ -55,7 +55,6 @@ import org.h2.util.ClassUtils;
import org.h2.util.FileUtils; import org.h2.util.FileUtils;
import org.h2.util.NetUtils; import org.h2.util.NetUtils;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.ObjectArray;
import org.h2.util.SmallLRUCache; import org.h2.util.SmallLRUCache;
import org.h2.util.SourceCompiler; import org.h2.util.SourceCompiler;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
...@@ -554,7 +553,7 @@ public class Database implements DataHandler { ...@@ -554,7 +553,7 @@ public class Database implements DataHandler {
systemUser.setAdmin(true); systemUser.setAdmin(true);
systemSession = new Session(this, systemUser, ++nextSessionId); systemSession = new Session(this, systemUser, ++nextSessionId);
CreateTableData data = new CreateTableData(); CreateTableData data = new CreateTableData();
ObjectArray<Column> cols = data.columns; ArrayList<Column> cols = data.columns;
Column columnId = new Column("ID", Value.INT); Column columnId = new Column("ID", Value.INT);
columnId.setNullable(false); columnId.setNullable(false);
cols.add(columnId); cols.add(columnId);
...@@ -1183,16 +1182,16 @@ public class Database implements DataHandler { ...@@ -1183,16 +1182,16 @@ public class Database implements DataHandler {
return i; return i;
} }
public ObjectArray<UserAggregate> getAllAggregates() { public ArrayList<UserAggregate> getAllAggregates() {
return ObjectArray.newInstance(aggregates.values()); return New.arrayList(aggregates.values());
} }
public ObjectArray<Comment> getAllComments() { public ArrayList<Comment> getAllComments() {
return ObjectArray.newInstance(comments.values()); return New.arrayList(comments.values());
} }
public ObjectArray<FunctionAlias> getAllFunctionAliases() { public ArrayList<FunctionAlias> getAllFunctionAliases() {
return ObjectArray.newInstance(functionAliases.values()); return New.arrayList(functionAliases.values());
} }
public int getAllowLiterals() { public int getAllowLiterals() {
...@@ -1202,12 +1201,12 @@ public class Database implements DataHandler { ...@@ -1202,12 +1201,12 @@ public class Database implements DataHandler {
return allowLiterals; return allowLiterals;
} }
public ObjectArray<Right> getAllRights() { public ArrayList<Right> getAllRights() {
return ObjectArray.newInstance(rights.values()); return New.arrayList(rights.values());
} }
public ObjectArray<Role> getAllRoles() { public ArrayList<Role> getAllRoles() {
return ObjectArray.newInstance(roles.values()); return New.arrayList(roles.values());
} }
/** /**
...@@ -1216,11 +1215,11 @@ public class Database implements DataHandler { ...@@ -1216,11 +1215,11 @@ public class Database implements DataHandler {
* @param type the object type * @param type the object type
* @return all objects of that type * @return all objects of that type
*/ */
public ObjectArray<SchemaObject> getAllSchemaObjects(int type) { public ArrayList<SchemaObject> getAllSchemaObjects(int type) {
if (type == DbObject.TABLE_OR_VIEW) { if (type == DbObject.TABLE_OR_VIEW) {
initMetaTables(); initMetaTables();
} }
ObjectArray<SchemaObject> list = ObjectArray.newInstance(); ArrayList<SchemaObject> list = New.arrayList();
for (Schema schema : schemas.values()) { for (Schema schema : schemas.values()) {
list.addAll(schema.getAll(type)); list.addAll(schema.getAll(type));
} }
...@@ -1233,32 +1232,32 @@ public class Database implements DataHandler { ...@@ -1233,32 +1232,32 @@ public class Database implements DataHandler {
* @param includeMeta whether to include the meta data tables * @param includeMeta whether to include the meta data tables
* @return all objects of that type * @return all objects of that type
*/ */
public ObjectArray<Table> getAllTablesAndViews(boolean includeMeta) { public ArrayList<Table> getAllTablesAndViews(boolean includeMeta) {
if (includeMeta) { if (includeMeta) {
initMetaTables(); initMetaTables();
} }
ObjectArray<Table> list = ObjectArray.newInstance(); ArrayList<Table> list = New.arrayList();
for (Schema schema : schemas.values()) { for (Schema schema : schemas.values()) {
list.addAll(schema.getAllTablesAndViews()); list.addAll(schema.getAllTablesAndViews());
} }
return list; return list;
} }
public ObjectArray<Schema> getAllSchemas() { public ArrayList<Schema> getAllSchemas() {
initMetaTables(); initMetaTables();
return ObjectArray.newInstance(schemas.values()); return New.arrayList(schemas.values());
} }
public ObjectArray<Setting> getAllSettings() { public ArrayList<Setting> getAllSettings() {
return ObjectArray.newInstance(settings.values()); return New.arrayList(settings.values());
} }
public ObjectArray<UserDataType> getAllUserDataTypes() { public ArrayList<UserDataType> getAllUserDataTypes() {
return ObjectArray.newInstance(userDataTypes.values()); return New.arrayList(userDataTypes.values());
} }
public ObjectArray<User> getAllUsers() { public ArrayList<User> getAllUsers() {
return ObjectArray.newInstance(users.values()); return New.arrayList(users.values());
} }
public String getCacheType() { public String getCacheType() {
...@@ -1346,7 +1345,7 @@ public class Database implements DataHandler { ...@@ -1346,7 +1345,7 @@ public class Database implements DataHandler {
} }
private synchronized void updateWithChildren(Session session, DbObject obj) throws SQLException { private synchronized void updateWithChildren(Session session, DbObject obj) throws SQLException {
ObjectArray<DbObject> list = obj.getChildren(); ArrayList<DbObject> list = obj.getChildren();
Comment comment = findComment(obj); Comment comment = findComment(obj);
if (comment != null) { if (comment != null) {
Message.throwInternalError(); Message.throwInternalError();
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
package org.h2.engine; package org.h2.engine;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.util.ObjectArray;
/** /**
* A database object such as a table, an index, or a user. * A database object such as a table, an index, or a user.
...@@ -116,7 +116,7 @@ public interface DbObject { ...@@ -116,7 +116,7 @@ public interface DbObject {
* *
* @return the list of children * @return the list of children
*/ */
ObjectArray<DbObject> getChildren(); ArrayList<DbObject> getChildren();
/** /**
* Get the database. * Get the database.
......
...@@ -7,12 +7,11 @@ ...@@ -7,12 +7,11 @@
package org.h2.engine; package org.h2.engine;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.message.Trace; import org.h2.message.Trace;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.util.ObjectArray;
/** /**
* The base class for all database objects. * The base class for all database objects.
...@@ -117,7 +116,7 @@ public abstract class DbObjectBase implements DbObject { ...@@ -117,7 +116,7 @@ public abstract class DbObjectBase implements DbObject {
return Parser.quoteIdentifier(objectName); return Parser.quoteIdentifier(objectName);
} }
public ObjectArray<DbObject> getChildren() { public ArrayList<DbObject> getChildren() {
return null; return null;
} }
......
...@@ -31,7 +31,6 @@ import org.h2.store.DataHandler; ...@@ -31,7 +31,6 @@ import org.h2.store.DataHandler;
import org.h2.store.InDoubtTransaction; import org.h2.store.InDoubtTransaction;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.ObjectArray;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueLob; import org.h2.value.ValueLob;
import org.h2.value.ValueLong; import org.h2.value.ValueLong;
...@@ -201,11 +200,11 @@ public class Session extends SessionWithState implements SessionFactory { ...@@ -201,11 +200,11 @@ public class Session extends SessionWithState implements SessionFactory {
return localTempTables.get(name); return localTempTables.get(name);
} }
public ObjectArray<Table> getLocalTempTables() { public ArrayList<Table> getLocalTempTables() {
if (localTempTables == null) { if (localTempTables == null) {
return ObjectArray.newInstance(); return New.arrayList();
} }
return ObjectArray.newInstance(localTempTables.values()); return New.arrayList(localTempTables.values());
} }
/** /**
......
...@@ -7,11 +7,12 @@ ...@@ -7,11 +7,12 @@
package org.h2.engine; package org.h2.engine;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.store.Data; import org.h2.store.Data;
import org.h2.store.FileStore; import org.h2.store.FileStore;
import org.h2.util.ObjectArray; import org.h2.util.New;
/** /**
* Each session keeps a undo log if rollback is required. * Each session keeps a undo log if rollback is required.
...@@ -20,7 +21,7 @@ public class UndoLog { ...@@ -20,7 +21,7 @@ public class UndoLog {
private Database database; private Database database;
// TODO undo log entry: a chain would probably be faster // TODO undo log entry: a chain would probably be faster
// and use less memory than an array // and use less memory than an array
private ObjectArray<UndoLogRecord> records = ObjectArray.newInstance(); private ArrayList<UndoLogRecord> records = New.arrayList();
private FileStore file; private FileStore file;
private Data rowBuff; private Data rowBuff;
private int memoryUndo; private int memoryUndo;
...@@ -97,7 +98,7 @@ public class UndoLog { ...@@ -97,7 +98,7 @@ public class UndoLog {
*/ */
public void removeLast(boolean trimToSize) { public void removeLast(boolean trimToSize) {
int i = records.size() - 1; int i = records.size() - 1;
UndoLogRecord r = (UndoLogRecord) records.remove(i); UndoLogRecord r = records.remove(i);
if (!r.isStored()) { if (!r.isStored()) {
memoryUndo--; memoryUndo--;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
package org.h2.engine; package org.h2.engine;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.message.Trace; import org.h2.message.Trace;
...@@ -19,7 +19,7 @@ import org.h2.table.Table; ...@@ -19,7 +19,7 @@ import org.h2.table.Table;
import org.h2.table.TableView; import org.h2.table.TableView;
import org.h2.util.ByteUtils; import org.h2.util.ByteUtils;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.ObjectArray; import org.h2.util.New;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
/** /**
...@@ -186,8 +186,8 @@ public class User extends RightOwner { ...@@ -186,8 +186,8 @@ public class User extends RightOwner {
return DbObject.USER; return DbObject.USER;
} }
public ObjectArray<DbObject> getChildren() { public ArrayList<DbObject> getChildren() {
ObjectArray<DbObject> children = ObjectArray.newInstance(); ArrayList<DbObject> children = New.arrayList();
for (Right right : database.getAllRights()) { for (Right right : database.getAllRights()) {
if (right.getGrantee() == this) { if (right.getGrantee() == this) {
children.add(right); children.add(right);
......
...@@ -300,13 +300,9 @@ public class Aggregate extends Expression { ...@@ -300,13 +300,9 @@ public class Aggregate extends Expression {
final SortOrder sortOrder = sort; final SortOrder sortOrder = sort;
Collections.sort(list, new Comparator<Value>() { Collections.sort(list, new Comparator<Value>() {
public int compare(Value v1, Value v2) { public int compare(Value v1, Value v2) {
try { Value[] a1 = ((ValueArray) v1).getList();
Value[] a1 = ((ValueArray) v1).getList(); Value[] a2 = ((ValueArray) v2).getList();
Value[] a2 = ((ValueArray) v2).getList(); return sortOrder.compare(a1, a2);
return sortOrder.compare(a1, a2);
} catch (SQLException e) {
throw Message.convertToInternal(e);
}
} }
}); });
} catch (Exception e) { } catch (Exception e) {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.index; package org.h2.index;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.DbObject; import org.h2.engine.DbObject;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -18,7 +19,6 @@ import org.h2.table.Column; ...@@ -18,7 +19,6 @@ import org.h2.table.Column;
import org.h2.table.IndexColumn; import org.h2.table.IndexColumn;
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;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
...@@ -265,7 +265,7 @@ public class MultiVersionIndex implements Index { ...@@ -265,7 +265,7 @@ public class MultiVersionIndex implements Index {
base.checkRename(); base.checkRename();
} }
public ObjectArray<DbObject> getChildren() { public ArrayList<DbObject> getChildren() {
return base.getChildren(); return base.getChildren();
} }
......
...@@ -202,7 +202,11 @@ class ResultDiskBuffer implements ResultExternal { ...@@ -202,7 +202,11 @@ class ResultDiskBuffer implements ResultExternal {
private int compareTapes(ResultDiskTape a, ResultDiskTape b) throws SQLException { private int compareTapes(ResultDiskTape a, ResultDiskTape b) throws SQLException {
Value[] va = a.buffer.get(0); Value[] va = a.buffer.get(0);
Value[] vb = b.buffer.get(0); Value[] vb = b.buffer.get(0);
return sort.compare(va, vb); try {
return sort.compare(va, vb);
} catch (Exception e) {
throw Message.convert(e);
}
} }
protected void finalize() { protected void finalize() {
......
...@@ -8,10 +8,12 @@ package org.h2.result; ...@@ -8,10 +8,12 @@ package org.h2.result;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.expression.Expression; import org.h2.expression.Expression;
import org.h2.util.MathUtils; import org.h2.message.Message;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -20,7 +22,7 @@ import org.h2.value.ValueNull; ...@@ -20,7 +22,7 @@ import org.h2.value.ValueNull;
/** /**
* A sort order represents an ORDER BY clause in a query. * A sort order represents an ORDER BY clause in a query.
*/ */
public class SortOrder { public class SortOrder implements Comparator<Value[]> {
/** /**
* This bit mask means the values should be sorted in ascending order. * This bit mask means the values should be sorted in ascending order.
...@@ -127,25 +129,29 @@ public class SortOrder { ...@@ -127,25 +129,29 @@ public class SortOrder {
* @param b the second expression list * @param b the second expression list
* @return the result of the comparison * @return the result of the comparison
*/ */
public int compare(Value[] a, Value[] b) throws SQLException { public int compare(Value[] a, Value[] b) {
for (int i = 0; i < len; i++) { try {
int idx = indexes[i]; for (int i = 0; i < len; i++) {
int type = sortTypes[i]; int idx = indexes[i];
Value ao = a[idx]; int type = sortTypes[i];
Value bo = b[idx]; Value ao = a[idx];
boolean aNull = ao == ValueNull.INSTANCE, bNull = bo == ValueNull.INSTANCE; Value bo = b[idx];
if (aNull || bNull) { boolean aNull = ao == ValueNull.INSTANCE, bNull = bo == ValueNull.INSTANCE;
if (aNull == bNull) { if (aNull || bNull) {
continue; if (aNull == bNull) {
continue;
}
return compareNull(aNull, bNull, type);
}
int comp = database.compare(ao, bo);
if (comp != 0) {
return (type & DESCENDING) == 0 ? comp : -comp;
} }
return compareNull(aNull, bNull, type);
}
int comp = database.compare(ao, bo);
if (comp != 0) {
return (type & DESCENDING) == 0 ? comp : -comp;
} }
return 0;
} catch (SQLException e) {
throw Message.convertToInternal(e);
} }
return 0;
} }
/** /**
...@@ -154,56 +160,10 @@ public class SortOrder { ...@@ -154,56 +160,10 @@ public class SortOrder {
* @param rows the list of rows * @param rows the list of rows
*/ */
public void sort(ArrayList<Value[]> rows) throws SQLException { public void sort(ArrayList<Value[]> rows) throws SQLException {
int todoUseArraySort; try {
sort(rows, 0, rows.size() - 1); Collections.sort(rows, this);
} } catch (Exception e) {
throw Message.convert(e);
private void swap(ArrayList<Value[]> rows, int a, int b) {
Value[] t = rows.get(a);
rows.set(a, rows.get(b));
rows.set(b, t);
}
private void sort(ArrayList<Value[]> rows, int l, int r) throws SQLException {
// quicksort
int i, j;
while (r - l > 10) {
// randomized pivot to avoid worst case
i = MathUtils.randomInt(r - l - 4) + l + 2;
if (compare(rows.get(l), rows.get(r)) > 0) {
swap(rows, l, r);
}
if (compare(rows.get(i), rows.get(l)) < 0) {
swap(rows, l, i);
} else if (compare(rows.get(i), rows.get(r)) > 0) {
swap(rows, i, r);
}
j = r - 1;
swap(rows, i, j);
Value[] p = rows.get(j);
i = l;
while (true) {
do {
++i;
} while (compare(rows.get(i), p) < 0);
do {
--j;
} while (compare(rows.get(j), p) > 0);
if (i >= j) {
break;
}
swap(rows, i, j);
}
swap(rows, i, r - 1);
sort(rows, l, i - 1);
l = i + 1;
}
for (i = l + 1; i <= r; i++) {
Value[] t = rows.get(i);
for (j = i - 1; j >= l && (compare(rows.get(j), t) > 0); j--) {
rows.set(j + 1, rows.get(j));
}
rows.set(j + 1, t);
} }
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.schema; package org.h2.schema;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import org.h2.command.ddl.CreateTableData; import org.h2.command.ddl.CreateTableData;
...@@ -25,7 +26,6 @@ import org.h2.table.Table; ...@@ -25,7 +26,6 @@ import org.h2.table.Table;
import org.h2.table.TableData; import org.h2.table.TableData;
import org.h2.table.TableLink; import org.h2.table.TableLink;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.ObjectArray;
/** /**
* A schema as created by the SQL statement * A schema as created by the SQL statement
...@@ -450,9 +450,9 @@ public class Schema extends DbObjectBase { ...@@ -450,9 +450,9 @@ public class Schema extends DbObjectBase {
* @param type the object type * @param type the object type
* @return a (possible empty) list of all objects * @return a (possible empty) list of all objects
*/ */
public ObjectArray<SchemaObject> getAll(int type) { public ArrayList<SchemaObject> getAll(int type) {
HashMap<String, SchemaObject> map = getMap(type); HashMap<String, SchemaObject> map = getMap(type);
return ObjectArray.newInstance(map.values()); return New.arrayList(map.values());
} }
/** /**
...@@ -460,8 +460,8 @@ public class Schema extends DbObjectBase { ...@@ -460,8 +460,8 @@ public class Schema extends DbObjectBase {
* *
* @return a (possible empty) list of all objects * @return a (possible empty) list of all objects
*/ */
public ObjectArray<Table> getAllTablesAndViews() { public ArrayList<Table> getAllTablesAndViews() {
return ObjectArray.newInstance(tablesAndViews.values()); return New.arrayList(tablesAndViews.values());
} }
/** /**
......
...@@ -49,7 +49,6 @@ import org.h2.util.FileUtils; ...@@ -49,7 +49,6 @@ import org.h2.util.FileUtils;
import org.h2.util.IntArray; import org.h2.util.IntArray;
import org.h2.util.IntIntHashMap; import org.h2.util.IntIntHashMap;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.ObjectArray;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.value.CompareMode; import org.h2.value.CompareMode;
...@@ -320,7 +319,7 @@ public class PageStore implements CacheWriter { ...@@ -320,7 +319,7 @@ public class PageStore implements CacheWriter {
} }
private void writeBack() throws SQLException { private void writeBack() throws SQLException {
ObjectArray<CacheObject> list = cache.getAllChanged(); ArrayList<CacheObject> list = cache.getAllChanged();
CacheObject.sort(list); CacheObject.sort(list);
for (CacheObject rec : list) { for (CacheObject rec : list) {
writeBack(rec); writeBack(rec);
...@@ -1199,7 +1198,7 @@ public class PageStore implements CacheWriter { ...@@ -1199,7 +1198,7 @@ public class PageStore implements CacheWriter {
private void openMetaIndex() throws SQLException { private void openMetaIndex() throws SQLException {
CreateTableData data = new CreateTableData(); CreateTableData data = new CreateTableData();
ObjectArray<Column> cols = data.columns; ArrayList<Column> cols = data.columns;
cols.add(new Column("ID", Value.INT)); cols.add(new Column("ID", Value.INT));
cols.add(new Column("TYPE", Value.INT)); cols.add(new Column("TYPE", Value.INT));
cols.add(new Column("PARENT", Value.INT)); cols.add(new Column("PARENT", Value.INT));
......
...@@ -9,7 +9,7 @@ package org.h2.table; ...@@ -9,7 +9,7 @@ package org.h2.table;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Expression; import org.h2.expression.Expression;
...@@ -22,7 +22,6 @@ import org.h2.message.Message; ...@@ -22,7 +22,6 @@ import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.LocalResult;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.schema.Schema; import org.h2.schema.Schema;
import org.h2.util.ObjectArray;
import org.h2.value.DataType; import org.h2.value.DataType;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
...@@ -124,7 +123,7 @@ public class FunctionTable extends Table { ...@@ -124,7 +123,7 @@ public class FunctionTable extends Table {
return new FunctionIndex(this, IndexColumn.wrap(columns)); return new FunctionIndex(this, IndexColumn.wrap(columns));
} }
public ObjectArray<Index> getIndexes() { public ArrayList<Index> getIndexes() {
return null; return null;
} }
......
...@@ -17,7 +17,6 @@ import java.sql.Timestamp; ...@@ -17,7 +17,6 @@ import java.sql.Timestamp;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
import org.h2.command.Command; import org.h2.command.Command;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.constraint.Constraint; import org.h2.constraint.Constraint;
...@@ -53,7 +52,6 @@ import org.h2.store.PageStore; ...@@ -53,7 +52,6 @@ import org.h2.store.PageStore;
import org.h2.tools.Csv; import org.h2.tools.Csv;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.ObjectArray;
import org.h2.util.Resources; import org.h2.util.Resources;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
...@@ -567,9 +565,9 @@ public class MetaTable extends Table { ...@@ -567,9 +565,9 @@ public class MetaTable extends Table {
return s; return s;
} }
private ObjectArray<Table> getAllTables(Session session) { private ArrayList<Table> getAllTables(Session session) {
ObjectArray<Table> tables = database.getAllTablesAndViews(true); ArrayList<Table> tables = database.getAllTablesAndViews(true);
ObjectArray<Table> tempTables = session.getLocalTempTables(); ArrayList<Table> tempTables = session.getLocalTempTables();
tables.addAll(tempTables); tables.addAll(tempTables);
return tables; return tables;
} }
...@@ -727,8 +725,8 @@ public class MetaTable extends Table { ...@@ -727,8 +725,8 @@ public class MetaTable extends Table {
if (!checkIndex(session, tableName, indexFrom, indexTo)) { if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue; continue;
} }
ObjectArray<Index> indexes = table.getIndexes(); ArrayList<Index> indexes = table.getIndexes();
ObjectArray<Constraint> constraints = table.getConstraints(); ArrayList<Constraint> constraints = table.getConstraints();
for (int j = 0; indexes != null && j < indexes.size(); j++) { for (int j = 0; indexes != null && j < indexes.size(); j++) {
Index index = indexes.get(j); Index index = indexes.get(j);
if (index.getCreateSQL() == null) { if (index.getCreateSQL() == null) {
...@@ -1713,11 +1711,11 @@ public class MetaTable extends Table { ...@@ -1713,11 +1711,11 @@ public class MetaTable extends Table {
return new MetaIndex(this, IndexColumn.wrap(columns), true); return new MetaIndex(this, IndexColumn.wrap(columns), true);
} }
public ObjectArray<Index> getIndexes() { public ArrayList<Index> getIndexes() {
if (metaIndex == null) { if (metaIndex == null) {
return null; return null;
} }
ObjectArray <Index>list = ObjectArray.newInstance(); ArrayList<Index>list = New.arrayList();
list.add(new MetaIndex(this, IndexColumn.wrap(columns), true)); list.add(new MetaIndex(this, IndexColumn.wrap(columns), true));
// TODO fixed scan index // TODO fixed scan index
list.add(metaIndex); list.add(metaIndex);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
package org.h2.table; package org.h2.table;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Expression; import org.h2.expression.Expression;
import org.h2.index.Index; import org.h2.index.Index;
...@@ -16,7 +16,6 @@ import org.h2.index.RangeIndex; ...@@ -16,7 +16,6 @@ import org.h2.index.RangeIndex;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.schema.Schema; import org.h2.schema.Schema;
import org.h2.util.ObjectArray;
import org.h2.value.Value; import org.h2.value.Value;
/** /**
...@@ -148,7 +147,7 @@ public class RangeTable extends Table { ...@@ -148,7 +147,7 @@ public class RangeTable extends Table {
} }
} }
public ObjectArray<Index> getIndexes() { public ArrayList<Index> getIndexes() {
return null; return null;
} }
......
...@@ -11,7 +11,6 @@ import java.util.ArrayList; ...@@ -11,7 +11,6 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constraint.Constraint; import org.h2.constraint.Constraint;
...@@ -36,7 +35,6 @@ import org.h2.schema.SchemaObjectBase; ...@@ -36,7 +35,6 @@ import org.h2.schema.SchemaObjectBase;
import org.h2.schema.Sequence; import org.h2.schema.Sequence;
import org.h2.schema.TriggerObject; import org.h2.schema.TriggerObject;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.ObjectArray;
import org.h2.value.CompareMode; import org.h2.value.CompareMode;
import org.h2.value.DataType; import org.h2.value.DataType;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -96,10 +94,10 @@ public abstract class Table extends SchemaObjectBase { ...@@ -96,10 +94,10 @@ public abstract class Table extends SchemaObjectBase {
private final HashMap<String, Column> columnMap = New.hashMap(); private final HashMap<String, Column> columnMap = New.hashMap();
private boolean persistIndexes; private boolean persistIndexes;
private boolean persistData; private boolean persistData;
private ObjectArray<TriggerObject> triggers; private ArrayList<TriggerObject> triggers;
private ObjectArray<Constraint> constraints; private ArrayList<Constraint> constraints;
private ObjectArray<Sequence> sequences; private ArrayList<Sequence> sequences;
private ObjectArray<TableView> views; private ArrayList<TableView> views;
private boolean checkForeignKeyConstraints = true; private boolean checkForeignKeyConstraints = true;
private boolean onCommitDrop, onCommitTruncate; private boolean onCommitDrop, onCommitTruncate;
private Row nullRow; private Row nullRow;
...@@ -217,7 +215,7 @@ public abstract class Table extends SchemaObjectBase { ...@@ -217,7 +215,7 @@ public abstract class Table extends SchemaObjectBase {
* *
* @return the list of indexes * @return the list of indexes
*/ */
public abstract ObjectArray<Index> getIndexes(); public abstract ArrayList<Index> getIndexes();
/** /**
* Check if this table is locked exclusively. * Check if this table is locked exclusively.
...@@ -291,9 +289,9 @@ public abstract class Table extends SchemaObjectBase { ...@@ -291,9 +289,9 @@ public abstract class Table extends SchemaObjectBase {
} }
} }
public ObjectArray<DbObject> getChildren() { public ArrayList<DbObject> getChildren() {
ObjectArray<DbObject> children = ObjectArray.newInstance(); ArrayList<DbObject> children = New.arrayList();
ObjectArray<Index> indexes = getIndexes(); ArrayList<Index> indexes = getIndexes();
if (indexes != null) { if (indexes != null) {
children.addAll(indexes); children.addAll(indexes);
} }
...@@ -309,7 +307,7 @@ public abstract class Table extends SchemaObjectBase { ...@@ -309,7 +307,7 @@ public abstract class Table extends SchemaObjectBase {
if (views != null) { if (views != null) {
children.addAll(views); children.addAll(views);
} }
ObjectArray<Right> rights = database.getAllRights(); ArrayList<Right> rights = database.getAllRights();
for (Right right : rights) { for (Right right : rights) {
if (right.getGrantedTable() == this) { if (right.getGrantedTable() == this) {
children.add(right); children.add(right);
...@@ -455,7 +453,7 @@ public abstract class Table extends SchemaObjectBase { ...@@ -455,7 +453,7 @@ public abstract class Table extends SchemaObjectBase {
throw Message.getSQLException(ErrorCode.COLUMN_MAY_BE_REFERENCED_1, constraint.getSQL()); throw Message.getSQLException(ErrorCode.COLUMN_MAY_BE_REFERENCED_1, constraint.getSQL());
} }
} }
ObjectArray<Index> indexes = getIndexes(); ArrayList<Index> indexes = getIndexes();
for (int i = 0; indexes != null && i < indexes.size(); i++) { for (int i = 0; indexes != null && i < indexes.size(); i++) {
Index index = indexes.get(i); Index index = indexes.get(i);
if (index.getColumns().length == 1) { if (index.getColumns().length == 1) {
...@@ -543,7 +541,7 @@ public abstract class Table extends SchemaObjectBase { ...@@ -543,7 +541,7 @@ public abstract class Table extends SchemaObjectBase {
PlanItem item = new PlanItem(); PlanItem item = new PlanItem();
item.setIndex(getScanIndex(session)); item.setIndex(getScanIndex(session));
item.cost = item.getIndex().getCost(session, null); item.cost = item.getIndex().getCost(session, null);
ObjectArray<Index> indexes = getIndexes(); ArrayList<Index> indexes = getIndexes();
for (int i = 1; indexes != null && masks != null && i < indexes.size(); i++) { for (int i = 1; indexes != null && masks != null && i < indexes.size(); i++) {
Index index = indexes.get(i); Index index = indexes.get(i);
double cost = index.getCost(session, masks); double cost = index.getCost(session, masks);
...@@ -561,7 +559,7 @@ public abstract class Table extends SchemaObjectBase { ...@@ -561,7 +559,7 @@ public abstract class Table extends SchemaObjectBase {
* @return the primary key index or null * @return the primary key index or null
*/ */
public Index findPrimaryKey() { public Index findPrimaryKey() {
ObjectArray<Index> indexes = getIndexes(); ArrayList<Index> indexes = getIndexes();
for (int i = 0; indexes != null && i < indexes.size(); i++) { for (int i = 0; indexes != null && i < indexes.size(); i++) {
Index idx = indexes.get(i); Index idx = indexes.get(i);
if (idx.getIndexType().isPrimaryKey()) { if (idx.getIndexType().isPrimaryKey()) {
...@@ -604,7 +602,7 @@ public abstract class Table extends SchemaObjectBase { ...@@ -604,7 +602,7 @@ public abstract class Table extends SchemaObjectBase {
} }
} }
private void remove(ObjectArray< ? extends DbObject> list, DbObject obj) { private void remove(ArrayList< ? extends DbObject> list, DbObject obj) {
if (list != null) { if (list != null) {
int i = list.indexOf(obj); int i = list.indexOf(obj);
if (i >= 0) { if (i >= 0) {
...@@ -619,7 +617,7 @@ public abstract class Table extends SchemaObjectBase { ...@@ -619,7 +617,7 @@ public abstract class Table extends SchemaObjectBase {
* @param index the index to remove * @param index the index to remove
*/ */
public void removeIndex(Index index) { public void removeIndex(Index index) {
ObjectArray<Index> indexes = getIndexes(); ArrayList<Index> indexes = getIndexes();
if (indexes != null) { if (indexes != null) {
remove(indexes, index); remove(indexes, index);
if (index.getIndexType().isPrimaryKey()) { if (index.getIndexType().isPrimaryKey()) {
...@@ -687,7 +685,7 @@ public abstract class Table extends SchemaObjectBase { ...@@ -687,7 +685,7 @@ public abstract class Table extends SchemaObjectBase {
} }
} }
public ObjectArray<Constraint> getConstraints() { public ArrayList<Constraint> getConstraints() {
return constraints; return constraints;
} }
...@@ -709,9 +707,9 @@ public abstract class Table extends SchemaObjectBase { ...@@ -709,9 +707,9 @@ public abstract class Table extends SchemaObjectBase {
triggers = add(triggers, trigger); triggers = add(triggers, trigger);
} }
private <T> ObjectArray<T> add(ObjectArray<T> list, T obj) { private <T> ArrayList<T> add(ArrayList<T> list, T obj) {
if (list == null) { if (list == null) {
list = ObjectArray.newInstance(); list = New.arrayList();
} }
// self constraints are two entries in the list // self constraints are two entries in the list
list.add(obj); list.add(obj);
...@@ -838,7 +836,7 @@ public abstract class Table extends SchemaObjectBase { ...@@ -838,7 +836,7 @@ public abstract class Table extends SchemaObjectBase {
* @return the index or null * @return the index or null
*/ */
public Index getIndexForColumn(Column column, boolean first) { public Index getIndexForColumn(Column column, boolean first) {
ObjectArray<Index> indexes = getIndexes(); ArrayList<Index> indexes = getIndexes();
for (int i = 1; indexes != null && i < indexes.size(); i++) { for (int i = 1; indexes != null && i < indexes.size(); i++) {
Index index = indexes.get(i); Index index = indexes.get(i);
if (index.canGetFirstOrLast()) { if (index.canGetFirstOrLast()) {
......
...@@ -8,6 +8,7 @@ package org.h2.table; ...@@ -8,6 +8,7 @@ package org.h2.table;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
...@@ -38,7 +39,6 @@ import org.h2.result.SortOrder; ...@@ -38,7 +39,6 @@ import org.h2.result.SortOrder;
import org.h2.schema.SchemaObject; import org.h2.schema.SchemaObject;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.ObjectArray;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.value.CompareMode; import org.h2.value.CompareMode;
...@@ -57,7 +57,7 @@ public class TableData extends Table { ...@@ -57,7 +57,7 @@ public class TableData extends Table {
private HashSet<Session> lockShared = New.hashSet(); private HashSet<Session> lockShared = New.hashSet();
private Trace traceLock; private Trace traceLock;
private boolean globalTemporary; private boolean globalTemporary;
private final ObjectArray<Index> indexes = ObjectArray.newInstance(); private final ArrayList<Index> indexes = New.arrayList();
private long lastModificationId; private long lastModificationId;
private boolean containsLargeObject; private boolean containsLargeObject;
private PageDataIndex mainIndex; private PageDataIndex mainIndex;
...@@ -168,7 +168,7 @@ public class TableData extends Table { ...@@ -168,7 +168,7 @@ public class TableData extends Table {
return null; return null;
} }
public ObjectArray<Index> getIndexes() { public ArrayList<Index> getIndexes() {
return indexes; return indexes;
} }
...@@ -221,7 +221,7 @@ public class TableData extends Table { ...@@ -221,7 +221,7 @@ public class TableData extends Table {
Cursor cursor = scan.find(session, null, null); Cursor cursor = scan.find(session, null, null);
long i = 0; long i = 0;
int bufferSize = Constants.DEFAULT_MAX_MEMORY_ROWS; int bufferSize = Constants.DEFAULT_MAX_MEMORY_ROWS;
ObjectArray<Row> buffer = ObjectArray.newInstance(bufferSize); ArrayList<Row> buffer = New.arrayList(bufferSize);
String n = getName() + ":" + index.getName(); String n = getName() + ":" + index.getName();
int t = MathUtils.convertLongToInt(total); int t = MathUtils.convertLongToInt(total);
while (cursor.next()) { while (cursor.next()) {
...@@ -294,10 +294,10 @@ public class TableData extends Table { ...@@ -294,10 +294,10 @@ public class TableData extends Table {
return true; return true;
} }
private void addRowsToIndex(Session session, ObjectArray<Row> list, Index index) throws SQLException { private void addRowsToIndex(Session session, ArrayList<Row> list, Index index) throws SQLException {
final Index idx = index; final Index idx = index;
try { try {
list.sort(new Comparator<Row>() { Collections.sort(list, new Comparator<Row>() {
public int compare(Row r1, Row r2) { public int compare(Row r1, Row r2) {
try { try {
return idx.compareRows(r1, r2); return idx.compareRows(r1, r2);
...@@ -685,7 +685,7 @@ public class TableData extends Table { ...@@ -685,7 +685,7 @@ public class TableData extends Table {
} }
public boolean canTruncate() { public boolean canTruncate() {
ObjectArray<Constraint> constraints = getConstraints(); ArrayList<Constraint> constraints = getConstraints();
for (int i = 0; constraints != null && i < constraints.size(); i++) { for (int i = 0; constraints != null && i < constraints.size(); i++) {
Constraint c = constraints.get(i); Constraint c = constraints.get(i);
if (!(c.getConstraintType().equals(Constraint.REFERENTIAL))) { if (!(c.getConstraintType().equals(Constraint.REFERENTIAL))) {
......
...@@ -30,7 +30,6 @@ import org.h2.schema.Schema; ...@@ -30,7 +30,6 @@ import org.h2.schema.Schema;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.ObjectArray;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.value.DataType; import org.h2.value.DataType;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -49,7 +48,7 @@ public class TableLink extends Table { ...@@ -49,7 +48,7 @@ public class TableLink extends Table {
private String driver, url, user, password, originalSchema, originalTable, qualifiedTableName; private String driver, url, user, password, originalSchema, originalTable, qualifiedTableName;
private TableLinkConnection conn; private TableLinkConnection conn;
private HashMap<String, PreparedStatement> preparedMap = New.hashMap(); private HashMap<String, PreparedStatement> preparedMap = New.hashMap();
private final ObjectArray<Index> indexes = ObjectArray.newInstance(); private final ArrayList<Index> indexes = New.arrayList();
private final boolean emitUpdates; private final boolean emitUpdates;
private LinkedIndex linkedIndex; private LinkedIndex linkedIndex;
private SQLException connectException; private SQLException connectException;
...@@ -191,10 +190,10 @@ public class TableLink extends Table { ...@@ -191,10 +190,10 @@ public class TableLink extends Table {
rs = null; rs = null;
} }
String pkName = ""; String pkName = "";
ObjectArray<Column> list; ArrayList<Column> list;
if (rs != null && rs.next()) { if (rs != null && rs.next()) {
// the problem is, the rows are not sorted by KEY_SEQ // the problem is, the rows are not sorted by KEY_SEQ
list = ObjectArray.newInstance(); list = New.arrayList();
do { do {
int idx = rs.getInt("KEY_SEQ"); int idx = rs.getInt("KEY_SEQ");
if (pkName == null) { if (pkName == null) {
...@@ -224,7 +223,7 @@ public class TableLink extends Table { ...@@ -224,7 +223,7 @@ public class TableLink extends Table {
rs = null; rs = null;
} }
String indexName = null; String indexName = null;
list = ObjectArray.newInstance(); list = New.arrayList();
IndexType indexType = null; IndexType indexType = null;
if (rs != null) { if (rs != null) {
while (rs.next()) { while (rs.next()) {
...@@ -285,7 +284,7 @@ public class TableLink extends Table { ...@@ -285,7 +284,7 @@ public class TableLink extends Table {
return columnName; return columnName;
} }
private void addIndex(ObjectArray<Column> list, IndexType indexType) { private void addIndex(ArrayList<Column> list, IndexType indexType) {
Column[] cols = new Column[list.size()]; Column[] cols = new Column[list.size()];
list.toArray(cols); list.toArray(cols);
Index index = new LinkedIndex(this, 0, IndexColumn.wrap(cols), indexType); Index index = new LinkedIndex(this, 0, IndexColumn.wrap(cols), indexType);
...@@ -472,7 +471,7 @@ public class TableLink extends Table { ...@@ -472,7 +471,7 @@ public class TableLink extends Table {
return url.startsWith("jdbc:oracle:"); return url.startsWith("jdbc:oracle:");
} }
public ObjectArray<Index> getIndexes() { public ArrayList<Index> getIndexes() {
return indexes; return indexes;
} }
......
...@@ -26,7 +26,6 @@ import org.h2.schema.Schema; ...@@ -26,7 +26,6 @@ import org.h2.schema.Schema;
import org.h2.util.IntArray; import org.h2.util.IntArray;
import org.h2.util.MemoryUtils; import org.h2.util.MemoryUtils;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.ObjectArray;
import org.h2.util.SmallLRUCache; import org.h2.util.SmallLRUCache;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
...@@ -268,7 +267,7 @@ public class TableView extends Table { ...@@ -268,7 +267,7 @@ public class TableView extends Table {
return item.getIndex(); return item.getIndex();
} }
public ObjectArray<Index> getIndexes() { public ArrayList<Index> getIndexes() {
return null; return null;
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.util; package org.h2.util;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
/** /**
* The cache keeps frequently used objects in the main memory. * The cache keeps frequently used objects in the main memory.
...@@ -18,7 +19,7 @@ public interface Cache { ...@@ -18,7 +19,7 @@ public interface Cache {
* *
* @return the list of objects * @return the list of objects
*/ */
ObjectArray<CacheObject> getAllChanged(); ArrayList<CacheObject> getAllChanged();
/** /**
* Clear the cache. * Clear the cache.
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.util; package org.h2.util;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.WeakHashMap; import java.util.WeakHashMap;
...@@ -122,7 +123,7 @@ public class CacheLRU implements Cache { ...@@ -122,7 +123,7 @@ public class CacheLRU implements Cache {
private void removeOld() throws SQLException { private void removeOld() throws SQLException {
int i = 0; int i = 0;
ObjectArray<CacheObject> changed = ObjectArray.newInstance(); ArrayList<CacheObject> changed = New.arrayList();
int mem = sizeMemory; int mem = sizeMemory;
int rc = recordCount; int rc = recordCount;
boolean flushed = false; boolean flushed = false;
...@@ -287,11 +288,11 @@ public class CacheLRU implements Cache { ...@@ -287,11 +288,11 @@ public class CacheLRU implements Cache {
// } // }
// } // }
public ObjectArray<CacheObject> getAllChanged() { public ArrayList<CacheObject> getAllChanged() {
// if(Database.CHECK) { // if(Database.CHECK) {
// testConsistency(); // testConsistency();
// } // }
ObjectArray<CacheObject> list = ObjectArray.newInstance(); ArrayList<CacheObject> list = New.arrayList();
CacheObject rec = head.cacheNext; CacheObject rec = head.cacheNext;
while (rec != head) { while (rec != head) {
if (rec.isChanged()) { if (rec.isChanged()) {
...@@ -370,7 +371,7 @@ public class CacheLRU implements Cache { ...@@ -370,7 +371,7 @@ public class CacheLRU implements Cache {
// //
// public ObjectArray getAllChanged() { // public ObjectArray getAllChanged() {
// Iterator it = values().iterator(); // Iterator it = values().iterator();
// ObjectArray list = ObjectArray.newInstance(); // ObjectArray list = New.arrayList();
// while(it.hasNext()) { // while(it.hasNext()) {
// Record rec = (Record)it.next(); // Record rec = (Record)it.next();
// if(rec.isChanged()) { // if(rec.isChanged()) {
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
*/ */
package org.h2.util; package org.h2.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
...@@ -80,8 +82,8 @@ public abstract class CacheObject { ...@@ -80,8 +82,8 @@ public abstract class CacheObject {
* *
* @param recordList the list of cache objects * @param recordList the list of cache objects
*/ */
public static void sort(ObjectArray<CacheObject> recordList) { public static void sort(ArrayList<CacheObject> recordList) {
recordList.sort(new CacheComparator()); Collections.sort(recordList, new CacheComparator());
} }
public void setPos(int pos) { public void setPos(int pos) {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.util; package org.h2.util;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Map; import java.util.Map;
/** /**
...@@ -44,7 +45,7 @@ class CacheSecondLevel implements Cache { ...@@ -44,7 +45,7 @@ class CacheSecondLevel implements Cache {
return ret; return ret;
} }
public ObjectArray<CacheObject> getAllChanged() { public ArrayList<CacheObject> getAllChanged() {
return baseCache.getAllChanged(); return baseCache.getAllChanged();
} }
......
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.util;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import org.h2.constant.SysProperties;
/**
* The object array is basically the same as ArrayList.
* It is a bit faster than ArrayList in some versions of Java.
*
* @param <T> the element type
*/
public class ObjectArray<T> implements Iterable<T> {
private static final int CAPACITY_INIT = 4, CAPACITY_SHRINK = 256;
int size;
private T[] data;
private ObjectArray(int capacity) {
data = createArray(capacity);
}
private ObjectArray(Collection<T> collection) {
size = collection.size();
data = createArray(size);
Iterator<T> it = collection.iterator();
for (int i = 0; i < size; i++) {
data[i] = it.next();
}
}
/**
* Create a new object with the given initial capacity.
*
* @param capacity the initial capacity
* @return the object
*/
public static <T> ObjectArray<T> newInstance(int capacity) {
return new ObjectArray<T>(capacity);
}
/**
* Create a new object with the given values.
*
* @param list the initial elements
* @return the object
*/
public static <T> ObjectArray<T> newInstance(T... list) {
ObjectArray<T> t = new ObjectArray<T>(CAPACITY_INIT);
for (T x : list) {
t.add(x);
}
return t;
}
/**
* Create a new object with the default initial capacity.
*
* @return the object
*/
public static <T> ObjectArray<T> newInstance() {
return new ObjectArray<T>(CAPACITY_INIT);
}
/**
* Create a new object with all elements of the given collection.
*
* @param collection the collection with all elements
* @return the object
*/
public static <T> ObjectArray<T> newInstance(Collection<T> collection) {
return new ObjectArray<T>(collection);
}
@SuppressWarnings("unchecked")
private T[] createArray(int capacity) {
return (T[]) new Object[capacity > 1 ? capacity : 1];
}
private void throwException(int index) {
throw new ArrayIndexOutOfBoundsException("i=" + index + " size=" + size);
}
/**
* Append an object at the end of the list.
*
* @param value the value
*/
public void add(T value) {
if (size >= data.length) {
ensureCapacity(size);
}
data[size++] = value;
}
/**
* Get the object at the given index.
*
* @param index the index
* @return the value
*/
public T get(int index) {
if (SysProperties.CHECK2 && index >= size) {
throwException(index);
}
return data[index];
}
/**
* Remove the object at the given index.
*
* @param index the index
* @return the removed object
*/
public Object remove(int index) {
// TODO performance: the app should (where possible)
// remove from end to start, to avoid O(n^2)
if (SysProperties.CHECK2 && index >= size) {
throwException(index);
}
Object value = data[index];
System.arraycopy(data, index + 1, data, index, size - index - 1);
size--;
data[size] = null;
// TODO optimization / lib: could shrink ObjectArray on element remove
return value;
}
/**
* Remove a number of elements from the given start and end index.
*
* @param from the start index
* @param to the end index
*/
public void removeRange(int from, int to) {
if (SysProperties.CHECK2 && (to > size || from > to)) {
throw new ArrayIndexOutOfBoundsException("to=" + to + " from="+from+" size=" + size);
}
System.arraycopy(data, to, data, from, size - to);
size -= to - from;
for (int i = size + (to - from) - 1; i >= size; i--) {
data[i] = null;
}
}
/**
* Fill the list with empty elements until it reaches the given size.
*
* @param size the new size
*/
public void setSize(int size) {
ensureCapacity(size);
this.size = size;
}
private void ensureCapacity(int i) {
while (i >= data.length) {
T[] d = createArray(Math.max(CAPACITY_INIT, data.length * 2));
System.arraycopy(data, 0, d, 0, size);
data = d;
}
}
/**
* Shrink the array to the required size.
*/
public void trimToSize() {
T[] d = createArray(size);
System.arraycopy(data, 0, d, 0, size);
data = d;
}
/**
* Insert an element at the given position. The element at this position and
* all elements with a higher index move one element.
*
* @param index the index where to insert the object
* @param value the object to insert
*/
public void add(int index, T value) {
if (SysProperties.CHECK2 && index > size) {
throwException(index);
}
ensureCapacity(size);
if (index == size) {
add(value);
} else {
System.arraycopy(data, index, data, index + 1, size - index);
data[index] = value;
size++;
}
}
/**
* Update the object at the given index.
*
* @param index the index
* @param value the new value
*/
public void set(int index, T value) {
if (SysProperties.CHECK2 && index >= size) {
throwException(index);
}
data[index] = value;
}
/**
* Get the size of the list.
*
* @return the size
*/
public int size() {
return size;
}
/**
* Convert this list to an array. The target array must be big enough.
*
* @param array the target array
* @return the array
*/
public T[] toArray(T[] array) {
System.arraycopy(data, 0, array, 0, size);
return array;
}
/**
* Remove all elements from the list.
*/
public void clear() {
if (data.length > CAPACITY_SHRINK) {
data = createArray(CAPACITY_INIT);
} else {
for (int i = 0; i < size; i++) {
data[i] = null;
}
}
size = 0;
}
/**
* Get the index of the given object, or -1 if not found.
*
* @param o the object to search
* @return the index
*/
public int indexOf(Object o) {
for (int i = 0; i < size; i++) {
if (data[i] == o) {
return i;
}
}
return -1;
}
/**
* Add all objects from the given list.
*
* @param list the list
*/
public void addAll(ObjectArray< ? extends T> list) {
for (int i = 0; i < list.size; i++) {
add(list.data[i]);
}
}
private void swap(int l, int r) {
T t = data[r];
data[r] = data[l];
data[l] = t;
}
/**
* Sort the elements using the given comparator.
*
* @param comp the comparator
*/
public void sort(Comparator<T> comp) {
sort(comp, 0, size - 1);
}
/**
* Sort using the quicksort algorithm.
*
* @param comp the comparator
* @param l the first element (left)
* @param r the last element (right)
*/
private void sort(Comparator<T> comp, int left, int right) {
T[] d = data;
while (right - left > 12) {
// randomized pivot to avoid worst case
int i = MathUtils.randomInt(right - left - 4) + left + 2;
// d[left]: smallest, d[i]: highest, d[right]: median
if (comp.compare(d[left], d[i]) > 0) {
swap(left, i);
}
if (comp.compare(d[left], d[right]) > 0) {
swap(left, right);
}
if (comp.compare(d[right], d[i]) > 0) {
swap(right, i);
}
T p = d[right];
i = left - 1;
int j = right;
while (true) {
do {
++i;
} while (comp.compare(d[i], p) < 0);
do {
--j;
} while (comp.compare(d[j], p) > 0);
if (i >= j) {
break;
}
swap(i, j);
}
swap(i, right);
sort(comp, left, i - 1);
left = i + 1;
}
for (int j, i = left + 1; i <= right; i++) {
T t = data[i];
for (j = i - 1; j >= left && (comp.compare(data[j], t) > 0); j--) {
data[j + 1] = data[j];
}
data[j + 1] = t;
}
}
/**
* The iterator for this list.
*/
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 RuntimeException();
}
}
public Iterator<T> iterator() {
return new ObjectArrayIterator();
}
public String toString() {
StatementBuilder buff = new StatementBuilder("{");
for (int i = 0; i < size; i++) {
buff.appendExceptFirst(", ");
T t = get(i);
buff.append(t == null ? "" : t.toString());
}
return buff.append('}').toString();
}
}
...@@ -288,10 +288,10 @@ java org.h2.test.TestAll timer ...@@ -288,10 +288,10 @@ java org.h2.test.TestAll timer
/* /*
check client jar file size check client jar file size
simplify Message / ErrorCode / Resource simplify Message / ErrorCode / Resource
remove ObjectArray, BitField remove BitField
flatten package hierarchy flatten package hierarchy (remove constant package)
Constants.FILE_BLOCK_SIZE and others Constants.FILE_BLOCK_SIZE and others
simplify SysProperties simplify SysProperties; combine with Constants
remove SortedProperties remove SortedProperties
remove TempFileDeleter (UndoLog, ResultDiskBuffer, RowList, ValueLob) remove TempFileDeleter (UndoLog, ResultDiskBuffer, RowList, ValueLob)
combine small classes (StringCache / utils...) combine small classes (StringCache / utils...)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
package org.h2.dev.util; package org.h2.dev.util;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.message.Message; import org.h2.message.Message;
...@@ -16,7 +16,7 @@ import org.h2.util.CacheHead; ...@@ -16,7 +16,7 @@ import org.h2.util.CacheHead;
import org.h2.util.CacheObject; import org.h2.util.CacheObject;
import org.h2.util.CacheWriter; import org.h2.util.CacheWriter;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.ObjectArray; import org.h2.util.New;
/** /**
* A cache implementation based on the 2Q algorithm. * A cache implementation based on the 2Q algorithm.
...@@ -175,7 +175,7 @@ class CacheTQ implements Cache { ...@@ -175,7 +175,7 @@ class CacheTQ implements Cache {
private void removeOld() throws SQLException { private void removeOld() throws SQLException {
int i = 0; int i = 0;
ObjectArray<CacheObject> changed = ObjectArray.newInstance(); ArrayList<CacheObject> changed = New.arrayList();
int si = sizeIn, sm = sizeMain, rc = recordCount; int si = sizeIn, sm = sizeMain, rc = recordCount;
CacheObject inNext = headIn.cacheNext, mainNext = headMain.cacheNext; CacheObject inNext = headIn.cacheNext, mainNext = headMain.cacheNext;
while (((si * 4 > maxIn * 3) || (sm * 4 > maxMain * 3)) while (((si * 4 > maxIn * 3) || (sm * 4 > maxMain * 3))
...@@ -276,8 +276,8 @@ class CacheTQ implements Cache { ...@@ -276,8 +276,8 @@ class CacheTQ implements Cache {
} }
} }
public ObjectArray<CacheObject> getAllChanged() { public ArrayList<CacheObject> getAllChanged() {
ObjectArray<CacheObject> list = ObjectArray.newInstance(); ArrayList<CacheObject> list = New.arrayList();
for (CacheObject o = headMain.cacheNext; o != headMain; o = o.cacheNext) { for (CacheObject o = headMain.cacheNext; o != headMain; o = o.cacheNext) {
if (o.isChanged()) { if (o.isChanged()) {
list.add(o); list.add(o);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论