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

Use generics

上级 7d2c7659
......@@ -69,8 +69,8 @@ public class RuleList implements Rule {
return get(idx).random(config, level + 1);
}
StringBuffer buff = new StringBuffer();
for (int i = 0; i < list.size(); i++) {
buff.append(get(i).random(config, level+1));
for (Rule r : list) {
buff.append(r.random(config, level+1));
}
return buff.toString();
}
......@@ -89,8 +89,8 @@ public class RuleList implements Rule {
public void setLinks(HashMap<String, RuleHead> ruleMap) {
if (!mapSet) {
for (int i = 0; i < list.size(); i++) {
get(i).setLinks(ruleMap);
for (Rule r : list) {
r.setLinks(ruleMap);
}
mapSet = true;
}
......@@ -102,15 +102,14 @@ public class RuleList implements Rule {
return false;
}
if (or) {
for (int i = 0; i < list.size(); i++) {
if (get(i).matchRemove(sentence)) {
for (Rule r : list) {
if (r.matchRemove(sentence)) {
return true;
}
}
return false;
}
for (int i = 0; i < list.size(); i++) {
Rule r = get(i);
for (Rule r : list) {
if (!r.matchRemove(sentence)) {
return false;
}
......@@ -121,14 +120,12 @@ public class RuleList implements Rule {
public void addNextTokenList(Sentence sentence) {
String old = sentence.getQuery();
if (or) {
for (int i = 0; i < list.size(); i++) {
for (Rule r : list) {
sentence.setQuery(old);
Rule r = get(i);
r.addNextTokenList(sentence);
}
} else {
for (int i = 0; i < list.size(); i++) {
Rule r = get(i);
for (Rule r : list) {
r.addNextTokenList(sentence);
if (!r.matchRemove(sentence)) {
break;
......
......@@ -351,8 +351,8 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
boolean dropIndex = false;
Column[] cols = index.getColumns();
for (int j = 0; j < cols.length; j++) {
if (cols[j] == oldColumn) {
for (Column c : cols) {
if (c == oldColumn) {
if (cols.length == 1) {
dropIndex = true;
} else {
......
......@@ -116,8 +116,8 @@ public class Optimizer {
Permutations p = new Permutations(filters, list, bruteForce);
for (int x = 0; !canStop(x) && p.next(); x++) {
// find out what filters are not used yet
for (int i = 0; i < filters.length; i++) {
filters[i].setUsed(false);
for (TableFilter f : filters) {
f.setUsed(false);
}
for (int i = 0; i < bruteForce; i++) {
list[i].setUsed(true);
......@@ -237,9 +237,9 @@ public class Optimizer {
for (int i = 0; i < f2.length - 1; i++) {
f2[i].addJoin(f2[i + 1], false, null);
}
for (int i = 0; i < f2.length; i++) {
PlanItem item = bestPlan.getItem(f2[i]);
f2[i].setPlanItem(item);
for (TableFilter f : f2) {
PlanItem item = bestPlan.getItem(f);
f.setPlanItem(item);
}
}
......
......@@ -171,13 +171,13 @@ public class ConnectionInfo implements Cloneable {
private void readProperties(Properties info) throws SQLException {
Object[] list = new Object[info.size()];
info.keySet().toArray(list);
for (int i = 0; i < list.length; i++) {
String key = StringUtils.toUpperEnglish(list[i].toString());
for (Object k : list) {
String key = StringUtils.toUpperEnglish(k.toString());
if (prop.containsKey(key)) {
throw Message.getSQLException(ErrorCode.DUPLICATE_PROPERTY_1, key);
}
if (isKnownSetting(key)) {
prop.put(key, info.get(list[i]));
prop.put(key, info.get(k));
}
}
}
......@@ -188,8 +188,7 @@ public class ConnectionInfo implements Cloneable {
String settings = url.substring(idx + 1);
url = url.substring(0, idx);
String[] list = StringUtils.arraySplit(settings, ';', false);
for (int i = 0; i < list.length; i++) {
String setting = list[i];
for (String setting : list) {
int equal = setting.indexOf('=');
if (equal < 0) {
throw getFormatException();
......
......@@ -643,8 +643,7 @@ public class Database implements DataHandler {
records.add(rec);
}
MetaRecord.sort(records);
for (int i = 0; i < records.size(); i++) {
MetaRecord rec = records.get(i);
for (MetaRecord rec : records) {
rec.execute(this, systemSession, eventListener);
}
// try to recompile the views that are invalid
......@@ -729,8 +728,7 @@ public class Database implements DataHandler {
private void removeUnusedStorages(Session session) throws SQLException {
if (persistent) {
ObjectArray<Storage> storages = getAllStorages();
for (int i = 0; i < storages.size(); i++) {
Storage storage = storages.get(i);
for (Storage storage : storages) {
if (storage != null && storage.getRecordReader() == null) {
storage.truncate(session);
}
......@@ -1104,8 +1102,7 @@ public class Database implements DataHandler {
traceSystem.getTrace(Trace.DATABASE).info("closing " + databaseName + " from shutdown hook");
Session[] all = new Session[userSessions.size()];
userSessions.toArray(all);
for (int i = 0; i < all.length; i++) {
Session s = all[i];
for (Session s : all) {
try {
// must roll back, otherwise the session is removed and
// the log file that contains its uncommitted operations as well
......@@ -1135,19 +1132,15 @@ public class Database implements DataHandler {
}
try {
if (systemSession != null) {
ObjectArray<Table> tablesAndViews = getAllTablesAndViews();
for (int i = 0; i < tablesAndViews.size(); i++) {
Table table = tablesAndViews.get(i);
for (Table table : getAllTablesAndViews()) {
table.close(systemSession);
}
ObjectArray<SchemaObject> sequences = getAllSchemaObjects(DbObject.SEQUENCE);
for (int i = 0; i < sequences.size(); i++) {
Sequence sequence = (Sequence) sequences.get(i);
for (SchemaObject obj : getAllSchemaObjects(DbObject.SEQUENCE)) {
Sequence sequence = (Sequence) obj;
sequence.close();
}
ObjectArray<SchemaObject> triggers = getAllSchemaObjects(DbObject.TRIGGER);
for (int i = 0; i < triggers.size(); i++) {
TriggerObject trigger = (TriggerObject) triggers.get(i);
for (SchemaObject obj : getAllSchemaObjects(DbObject.TRIGGER)) {
TriggerObject trigger = (TriggerObject) obj;
trigger.close();
}
meta.close(systemSession);
......@@ -1519,8 +1512,7 @@ public class Database implements DataHandler {
String prefix = FileUtils.normalize(databaseName) + ".";
String path = FileUtils.getParent(databaseName);
String[] list = FileUtils.listFiles(path);
for (int i = 0; i < list.length; i++) {
String name = list[i];
for (String name : list) {
if (name.endsWith(Constants.SUFFIX_LOB_FILE) && FileUtils.fileStartsWith(name, prefix)) {
name = name.substring(prefix.length());
name = name.substring(0, name.length() - Constants.SUFFIX_LOB_FILE.length());
......@@ -1538,8 +1530,7 @@ public class Database implements DataHandler {
String path = FileUtils.getParent(databaseName);
String prefix = FileUtils.normalize(databaseName);
String[] list = FileUtils.listFiles(path);
for (int i = 0; i < list.length; i++) {
String name = list[i];
for (String name : list) {
if (name.endsWith(Constants.SUFFIX_TEMP_FILE) && FileUtils.fileStartsWith(name, prefix)) {
// can't always delete the files, they may still be open
FileUtils.tryDelete(name);
......@@ -2218,9 +2209,7 @@ public class Database implements DataHandler {
* @return the table or null if no table is defined
*/
public Table getFirstUserTable() {
ObjectArray<Table> array = getAllTablesAndViews();
for (int i = 0; i < array.size(); i++) {
Table table = array.get(i);
for (Table table : getAllTablesAndViews()) {
if (table.getCreateSQL() != null) {
return table;
}
......@@ -2307,9 +2296,7 @@ public class Database implements DataHandler {
* afterwards are not flushed; 0 to flush all indexes
*/
public synchronized void flushIndexes(long maxLastChange) {
ObjectArray<SchemaObject> array = getAllSchemaObjects(DbObject.INDEX);
for (int i = 0; i < array.size(); i++) {
SchemaObject obj = array.get(i);
for (SchemaObject obj : getAllSchemaObjects(DbObject.INDEX)) {
if (obj instanceof BtreeIndex) {
BtreeIndex idx = (BtreeIndex) obj;
if (idx.getLastChange() == 0) {
......
......@@ -149,10 +149,8 @@ public class Engine {
// ignore
}
}
String[] keys = ci.getKeys();
session.setAllowLiterals(true);
for (int i = 0; i < keys.length; i++) {
String setting = keys[i];
for (String setting : ci.getKeys()) {
String value = ci.getProperty(setting);
try {
CommandInterface command = session.prepareCommand("SET " + Parser.quoteIdentifier(setting) + " "
......
......@@ -165,8 +165,7 @@ public class FunctionAlias extends DbObjectBase {
public JavaMethod findJavaMethod(Expression[] args) throws SQLException {
load();
int parameterCount = args.length;
for (int i = 0; i < javaMethods.length; i++) {
JavaMethod m = javaMethods[i];
for (JavaMethod m : javaMethods) {
int count = m.getParameterCount();
if (count == parameterCount || (m.isVarArgs() && count <= parameterCount + 1)) {
return m;
......
......@@ -11,7 +11,6 @@ import java.sql.SQLException;
import org.h2.message.Message;
import org.h2.message.Trace;
import org.h2.table.Table;
import org.h2.util.ObjectArray;
/**
* Represents a role. Roles can be granted to users, and to other roles.
......@@ -60,25 +59,19 @@ public class Role extends RightOwner {
}
public void removeChildrenAndResources(Session session) throws SQLException {
ObjectArray<User> users = database.getAllUsers();
for (int i = 0; i < users.size(); i++) {
User user = users.get(i);
for (User user : database.getAllUsers()) {
Right right = user.getRightForRole(this);
if (right != null) {
database.removeDatabaseObject(session, right);
}
}
ObjectArray<Role> roles = database.getAllRoles();
for (int i = 0; i < roles.size(); i++) {
Role r2 = roles.get(i);
for (Role r2 : database.getAllRoles()) {
Right right = r2.getRightForRole(this);
if (right != null) {
database.removeDatabaseObject(session, right);
}
}
ObjectArray<Right> rights = database.getAllRights();
for (int i = 0; i < rights.size(); i++) {
Right right = rights.get(i);
for (Right right : database.getAllRights()) {
if (right.getGrantee() == this) {
database.removeDatabaseObject(session, right);
}
......
......@@ -526,9 +526,8 @@ public class Session extends SessionWithState {
if (savepoints != null) {
String[] names = new String[savepoints.size()];
savepoints.keySet().toArray(names);
for (int i = 0; i < names.length; i++) {
String name = names[i];
Integer savepointIndex = savepoints.get(names[i]);
for (String name : names) {
Integer savepointIndex = savepoints.get(name);
if (savepointIndex.intValue() > index) {
savepoints.remove(name);
}
......@@ -633,8 +632,7 @@ public class Session extends SessionWithState {
}
if (locks.size() > 0) {
synchronized (database) {
for (int i = 0; i < locks.size(); i++) {
Table t = locks.get(i);
for (Table t : locks) {
t.unlock(this);
}
locks.clear();
......
......@@ -108,8 +108,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
trans.writeBytes(ci.getFilePasswordHash());
String[] keys = ci.getKeys();
trans.writeInt(keys.length);
for (int i = 0; i < keys.length; i++) {
String key = keys[i];
for (String key : keys) {
trans.writeString(key).writeString(ci.getProperty(key));
}
try {
......@@ -141,8 +140,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
// older servers don't support this feature
return;
}
for (int i = 0; i < transferList.size(); i++) {
Transfer transfer = transferList.get(i);
for (Transfer transfer : transferList) {
try {
Transfer trans = transfer.openNewConnection();
trans.init();
......@@ -376,8 +374,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
if (clientVersion >= Constants.TCP_PROTOCOL_VERSION_6) {
sessionId = ByteUtils.convertBytesToString(RandomUtils.getSecureBytes(32));
synchronized (this) {
for (int i = 0; i < transferList.size(); i++) {
Transfer transfer = transferList.get(i);
for (Transfer transfer : transferList) {
try {
traceOperation("SESSION_SET_ID", 0);
transfer.writeInt(SessionRemote.SESSION_SET_ID);
......@@ -470,8 +467,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
public void close() throws SQLException {
if (transferList != null) {
synchronized (this) {
for (int i = 0; i < transferList.size(); i++) {
Transfer transfer = transferList.get(i);
for (Transfer transfer : transferList) {
try {
traceOperation("SESSION_CLOSE", 0);
transfer.writeInt(SessionRemote.SESSION_CLOSE);
......
......@@ -28,8 +28,7 @@ public abstract class SessionWithState implements SessionInterface {
if (sessionState != null && sessionState.size() > 0) {
sessionStateUpdating = true;
try {
for (int i = 0; i < sessionState.size(); i++) {
String sql = sessionState.get(i);
for (String sql : sessionState) {
CommandInterface ci = prepareCommand(sql, Integer.MAX_VALUE);
ci.executeUpdate();
}
......
......@@ -189,16 +189,12 @@ public class User extends RightOwner {
public ObjectArray<DbObject> getChildren() {
ObjectArray<DbObject> children = ObjectArray.newInstance();
ObjectArray<Right> rights = database.getAllRights();
for (int i = 0; i < rights.size(); i++) {
Right right = rights.get(i);
for (Right right : database.getAllRights()) {
if (right.getGrantee() == this) {
children.add(right);
}
}
ObjectArray<Schema> schemas = database.getAllSchemas();
for (int i = 0; i < schemas.size(); i++) {
Schema schema = schemas.get(i);
for (Schema schema : database.getAllSchemas()) {
if (schema.getOwner() == this) {
children.add(schema);
}
......@@ -207,9 +203,7 @@ public class User extends RightOwner {
}
public void removeChildrenAndResources(Session session) throws SQLException {
ObjectArray<Right> rights = database.getAllRights();
for (int i = 0; i < rights.size(); i++) {
Right right = rights.get(i);
for (Right right : database.getAllRights()) {
if (right.getGrantee() == this) {
database.removeDatabaseObject(session, right);
}
......@@ -232,9 +226,7 @@ public class User extends RightOwner {
* @throws SQLException if this user owns a schema
*/
public void checkOwnsNoSchemas() throws SQLException {
ObjectArray<Schema> schemas = database.getAllSchemas();
for (int i = 0; i < schemas.size(); i++) {
Schema s = schemas.get(i);
for (Schema s : database.getAllSchemas()) {
if (this == s.getOwner()) {
throw Message.getSQLException(ErrorCode.CANNOT_DROP_2, new String[]{ getName(), s.getName() });
}
......
......@@ -739,9 +739,8 @@ public class FullText {
index.id = rs.getInt(1);
String columns = rs.getString(2);
if (columns != null) {
String[] list = StringUtils.arraySplit(columns, ',', true);
for (int i = 0; i < list.length; i++) {
indexList.add(list[i]);
for (String s : StringUtils.arraySplit(columns, ',', true)) {
indexList.add(s);
}
}
}
......@@ -813,8 +812,8 @@ public class FullText {
int rowId = rs.getInt(1);
prepInsertMap.setInt(1, rowId);
int[] wordIds = getWordIds(setting, row);
for (int i = 0; i < wordIds.length; i++) {
prepInsertMap.setInt(2, wordIds[i]);
for (int id : wordIds) {
prepInsertMap.setInt(2, id);
prepInsertMap.execute();
}
}
......@@ -830,8 +829,8 @@ public class FullText {
int rowId = rs.getInt(1);
prepDeleteMap.setInt(1, rowId);
int[] wordIds = getWordIds(setting, row);
for (int i = 0; i < wordIds.length; i++) {
prepDeleteMap.setInt(2, wordIds[i]);
for (int id : wordIds) {
prepDeleteMap.setInt(2, id);
prepDeleteMap.executeUpdate();
}
prepDeleteRow.setInt(1, hash);
......
......@@ -443,9 +443,8 @@ public class FullTextLucene extends FullText {
if (rs.next()) {
String columns = rs.getString(1);
if (columns != null) {
String[] list = StringUtils.arraySplit(columns, ',', true);
for (int i = 0; i < list.length; i++) {
indexList.add(list[i]);
for (String s : StringUtils.arraySplit(columns, ',', true)) {
indexList.add(s);
}
}
}
......
......@@ -194,8 +194,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
debugCodeCall("clearParameters");
checkClosed();
ObjectArray< ? extends ParameterInterface> parameters = command.getParameters();
for (int i = 0; i < parameters.size(); i++) {
ParameterInterface param = parameters.get(i);
for (ParameterInterface param : parameters) {
// can only delete old temp files if they are not in the batch
param.setValue(null, batchParameters == null);
}
......
......@@ -154,8 +154,7 @@ implements XAConnection, XAResource
//## Java 1.4 begin ##
void closedHandle() {
debugCode("closedHandle();");
for (int i = 0; i < listeners.size(); i++) {
ConnectionEventListener listener = listeners.get(i);
for (ConnectionEventListener listener : New.arrayList(listeners)) {
ConnectionEvent event = new ConnectionEvent(this);
listener.connectionClosed(event);
}
......
......@@ -224,12 +224,10 @@ public class TcpServerThread implements Runnable {
cache.addObject(id, command);
boolean isQuery = command.isQuery();
ObjectArray< ? extends ParameterInterface> params = command.getParameters();
int paramCount = params.size();
transfer.writeInt(getState(old)).writeBoolean(isQuery).writeBoolean(readonly)
.writeInt(paramCount);
.writeInt(params.size());
if (operation == SessionRemote.SESSION_PREPARE_READ_PARAMS) {
for (int i = 0; i < paramCount; i++) {
ParameterInterface p = params.get(i);
for (ParameterInterface p : params) {
ParameterRemote.writeMetaData(transfer, p);
}
}
......
......@@ -427,8 +427,7 @@ public class PgServerThread implements Runnable {
}
startMessage('D');
writeShort(columns);
for (int i = 0; i < columns; i++) {
String s = values[i];
for (String s : values) {
if (s == null) {
writeInt(-1);
} else {
......
......@@ -132,15 +132,15 @@ public class DbContents {
}
if (defaultSchema == null) {
String best = null;
for (int i = 0; i < schemas.length; i++) {
if ("dbo".equals(schemas[i].name)) {
for (DbSchema schema : schemas) {
if ("dbo".equals(schema.name)) {
// MS SQL Server
defaultSchema = schemas[i];
defaultSchema = schema;
break;
}
if (defaultSchema == null || best == null || schemas[i].name.length() < best.length()) {
best = schemas[i].name;
defaultSchema = schemas[i];
if (defaultSchema == null || best == null || schema.name.length() < best.length()) {
best = schema.name;
defaultSchema = schema;
}
}
}
......
......@@ -80,8 +80,7 @@ public class DbSchema {
tables = new DbTableOrView[list.size()];
list.toArray(tables);
if (tables.length < MAX_TABLES_LIST_COLUMNS) {
for (int i = 0; i < tables.length; i++) {
DbTableOrView tab = tables[i];
for (DbTableOrView tab : tables) {
tab.readColumns(meta);
}
}
......
......@@ -173,9 +173,7 @@ public class WebServer implements Service {
WebSession getSession(String sessionId) {
long now = System.currentTimeMillis();
if (lastTimeoutCheck + SESSION_TIMEOUT < now) {
Object[] list = sessions.keySet().toArray();
for (int i = 0; i < list.length; i++) {
String id = (String) list[i];
for (String id : New.arrayList(sessions.keySet())) {
WebSession session = sessions.get(id);
Long last = (Long) session.get("lastAccess");
if (last != null && last.longValue() + SESSION_TIMEOUT < now) {
......@@ -280,8 +278,8 @@ public class WebServer implements Service {
startDateTime = format.format(new Date());
}
trace(startDateTime);
for (int i = 0; i < LANGUAGES.length; i++) {
languages.add(LANGUAGES[i][0]);
for (String[] lang : LANGUAGES) {
languages.add(lang[0]);
}
updateURL();
}
......
......@@ -286,8 +286,7 @@ class WebThread extends Thread implements DatabaseEventListener {
private String getComboBox(String[] elements, String selected) {
StringBuffer buff = new StringBuffer();
for (int i = 0; i < elements.length; i++) {
String value = elements[i];
for (String value : elements) {
buff.append("<option value=\"");
buff.append(PageParser.escapeHtmlData(value));
buff.append("\"");
......@@ -303,8 +302,7 @@ class WebThread extends Thread implements DatabaseEventListener {
private String getComboBox(String[][] elements, String selected) {
StringBuffer buff = new StringBuffer();
for (int i = 0; i < elements.length; i++) {
String[] n = elements[i];
for (String[] n : elements) {
buff.append("<option value=\"");
buff.append(PageParser.escapeHtmlData(n[0]));
buff.append("\"");
......@@ -797,8 +795,7 @@ class WebThread extends Thread implements DatabaseEventListener {
}
boolean isOracle = schema.contents.isOracle;
boolean notManyTables = tables.length < DbSchema.MAX_TABLES_LIST_INDEXES;
for (int i = 0; i < tables.length; i++) {
DbTableOrView table = tables[i];
for (DbTableOrView table : tables) {
if (table.isView) {
continue;
}
......@@ -822,8 +819,7 @@ class WebThread extends Thread implements DatabaseEventListener {
}
}
tables = schema.tables;
for (int i = 0; i < tables.length; i++) {
DbTableOrView view = tables[i];
for (DbTableOrView view : tables) {
if (!view.isView) {
continue;
}
......@@ -881,8 +877,7 @@ class WebThread extends Thread implements DatabaseEventListener {
DbSchema defaultSchema = contents.defaultSchema;
treeIndex = addTablesAndViews(defaultSchema, true, buff, treeIndex);
DbSchema[] schemas = contents.schemas;
for (int i = 0; i < schemas.length; i++) {
DbSchema schema = schemas[i];
for (DbSchema schema : schemas) {
if (schema == defaultSchema || schema == null) {
continue;
}
......@@ -1360,8 +1355,7 @@ class WebThread extends Thread implements DatabaseEventListener {
DynamicClassLoader cl = new DynamicClassLoader("Java", data);
Class< ? > clazz = cl.loadClass("Java");
Method[] methods = clazz.getMethods();
for (int i = 0; i < methods.length; i++) {
Method m = methods[i];
for (Method m : methods) {
if (m.getName().equals("run")) {
return "" + m.invoke(null, new Object[0]);
}
......
......@@ -33,8 +33,8 @@ public class FileObjectSplit implements FileObject {
}
public void close() throws IOException {
for (int i = 0; i < list.length; i++) {
list[i].close();
for (FileObject f : list) {
f.close();
}
}
......@@ -123,8 +123,8 @@ public class FileObjectSplit implements FileObject {
}
public void sync() throws IOException {
for (int i = 0; i < list.length; i++) {
list[i].sync();
for (FileObject f : list) {
f.sync();
}
}
......
......@@ -73,8 +73,7 @@ public class IndexColumn {
* @param table the table from where to map the column names to columns
*/
public static void mapColumns(IndexColumn[] indexColumns, Table table) throws SQLException {
for (int i = 0; i < indexColumns.length; i++) {
IndexColumn col = indexColumns[i];
for (IndexColumn col : indexColumns) {
col.column = table.getColumn(col.columnName);
}
}
......
......@@ -91,8 +91,7 @@ public class Plan {
}
f.removeUnusableIndexConditions();
}
for (int i = 0; i < allFilters.length; i++) {
TableFilter f = allFilters[i];
for (TableFilter f : allFilters) {
setEvaluatable(f, false);
}
}
......@@ -106,8 +105,7 @@ public class Plan {
public double calculateCost(Session session) throws SQLException {
double cost = 1;
boolean invalidPlan = false;
for (int i = 0; i < allFilters.length; i++) {
TableFilter tableFilter = allFilters[i];
for (TableFilter tableFilter : allFilters) {
PlanItem item = tableFilter.getBestPlanItem(session);
planItems.put(tableFilter, item);
cost += cost * item.cost;
......@@ -123,8 +121,8 @@ public class Plan {
if (invalidPlan) {
cost = Double.POSITIVE_INFINITY;
}
for (int i = 0; i < allFilters.length; i++) {
setEvaluatable(allFilters[i], false);
for (TableFilter f : allFilters) {
setEvaluatable(f, false);
}
return cost;
}
......
......@@ -264,14 +264,14 @@ public abstract class Table extends SchemaObjectBase {
*/
public void addDependencies(HashSet<DbObject> dependencies) {
if (sequences != null) {
for (int i = 0; i < sequences.size(); i++) {
dependencies.add(sequences.get(i));
for (Sequence s : sequences) {
dependencies.add(s);
}
}
ExpressionVisitor visitor = ExpressionVisitor.get(ExpressionVisitor.GET_DEPENDENCIES);
visitor.setDependencies(dependencies);
for (int i = 0; i < columns.length; i++) {
columns[i].isEverything(visitor);
for (Column col : columns) {
col.isEverything(visitor);
}
}
......@@ -294,8 +294,7 @@ public abstract class Table extends SchemaObjectBase {
children.addAll(views);
}
ObjectArray<Right> rights = database.getAllRights();
for (int i = 0; i < rights.size(); i++) {
Right right = rights.get(i);
for (Right right : rights) {
if (right.getGrantedTable() == this) {
children.add(right);
}
......@@ -333,8 +332,7 @@ public abstract class Table extends SchemaObjectBase {
* @param newName the new column name
*/
public void renameColumn(Column column, String newName) throws SQLException {
for (int i = 0; i < columns.length; i++) {
Column c = columns[i];
for (Column c : columns) {
if (c == column) {
continue;
}
......@@ -401,9 +399,7 @@ public abstract class Table extends SchemaObjectBase {
constraints.remove(0);
database.removeSchemaObject(session, constraint);
}
ObjectArray<Right> rights = database.getAllRights();
for (int i = 0; i < rights.size(); i++) {
Right right = rights.get(i);
for (Right right : database.getAllRights()) {
if (right.getGrantedTable() == this) {
database.removeDatabaseObject(session, right);
}
......@@ -606,9 +602,8 @@ public abstract class Table extends SchemaObjectBase {
if (indexes != null) {
remove(indexes, index);
if (index.getIndexType().getPrimaryKey()) {
Column[] cols = index.getColumns();
for (int i = 0; i < cols.length; i++) {
cols[i].setPrimaryKey(false);
for (Column col : index.getColumns()) {
col.setPrimaryKey(false);
}
}
}
......@@ -724,8 +719,7 @@ public abstract class Table extends SchemaObjectBase {
private void fire(Session session, boolean beforeAction) throws SQLException {
if (triggers != null) {
for (int i = 0; i < triggers.size(); i++) {
TriggerObject trigger = triggers.get(i);
for (TriggerObject trigger : triggers) {
trigger.fire(session, beforeAction);
}
}
......@@ -755,8 +749,7 @@ public abstract class Table extends SchemaObjectBase {
private void fireConstraints(Session session, Row oldRow, Row newRow, boolean before) throws SQLException {
if (constraints != null) {
for (int i = 0; i < constraints.size(); i++) {
Constraint constraint = constraints.get(i);
for (Constraint constraint : constraints) {
if (constraint.isBefore() == before) {
constraint.checkRow(session, this, oldRow, newRow);
}
......@@ -778,8 +771,7 @@ public abstract class Table extends SchemaObjectBase {
private void fireRow(Session session, Row oldRow, Row newRow, boolean beforeAction) throws SQLException {
if (triggers != null) {
for (int i = 0; i < triggers.size(); i++) {
TriggerObject trigger = triggers.get(i);
for (TriggerObject trigger : triggers) {
trigger.fireRow(session, oldRow, newRow, beforeAction);
}
}
......
......@@ -77,8 +77,8 @@ public class TableData extends Table implements RecordReader {
}
indexes.add(scanIndex);
}
for (int i = 0; i < cols.length; i++) {
if (DataType.isLargeObject(cols[i].getType())) {
for (Column col : cols) {
if (DataType.isLargeObject(col.getType())) {
containsLargeObject = true;
memoryPerRow = Row.MEMORY_CALCULATE;
}
......@@ -91,8 +91,7 @@ public class TableData extends Table implements RecordReader {
}
public void close(Session session) throws SQLException {
for (int i = 0; i < indexes.size(); i++) {
Index index = indexes.get(i);
for (Index index : indexes) {
index.close(session);
}
}
......@@ -153,8 +152,7 @@ public class TableData extends Table implements RecordReader {
}
public Index getUniqueIndex() {
for (int i = 0; i < indexes.size(); i++) {
Index idx = indexes.get(i);
for (Index idx : indexes) {
if (idx.getIndexType().getUnique()) {
return idx;
}
......@@ -460,9 +458,8 @@ public class TableData extends Table implements RecordReader {
private String getDeadlockDetails(ObjectArray<Session> sessions) {
StringBuffer buff = new StringBuffer();
for (int i = 0; i < sessions.size(); i++) {
for (Session s : sessions) {
buff.append('\n');
Session s = sessions.get(i);
Table lock = s.getWaitForLock();
buff.append("Session ").append(s).append(" is waiting to lock ").append(lock);
buff.append(" while locking ");
......
......@@ -127,8 +127,7 @@ public class TableFilter implements ColumnResolver {
} else {
int len = table.getColumns().length;
int[] masks = new int[len];
for (int i = 0; i < indexConditions.size(); i++) {
IndexCondition condition = indexConditions.get(i);
for (IndexCondition condition : indexConditions) {
if (condition.isEvaluatable()) {
if (condition.isAlwaysFalse()) {
masks = null;
......@@ -253,8 +252,7 @@ public class TableFilter implements ColumnResolver {
return false;
} else if (state == BEFORE_FIRST) {
SearchRow start = null, end = null;
for (int i = 0; i < indexConditions.size(); i++) {
IndexCondition condition = indexConditions.get(i);
for (IndexCondition condition : indexConditions) {
if (condition.isAlwaysFalse()) {
alwaysFalse = true;
break;
......
......@@ -482,8 +482,7 @@ public class TableLink extends Table {
}
public Index getUniqueIndex() {
for (int i = 0; i < indexes.size(); i++) {
Index idx = indexes.get(i);
for (Index idx : indexes) {
if (idx.getIndexType().getUnique()) {
return idx;
}
......
......@@ -281,8 +281,7 @@ public class TableView extends Table {
* @param session the session
*/
public void recompile(Session session) throws SQLException {
for (int i = 0; i < tables.size(); i++) {
Table t = tables.get(i);
for (Table t : tables) {
t.removeView(this);
}
tables.clear();
......@@ -313,8 +312,7 @@ public class TableView extends Table {
private void removeViewFromTables() {
if (tables != null) {
for (int i = 0; i < tables.size(); i++) {
Table t = tables.get(i);
for (Table t : tables) {
t.removeView(this);
}
tables.clear();
......@@ -322,8 +320,7 @@ public class TableView extends Table {
}
private void addViewToTables() {
for (int i = 0; i < tables.size(); i++) {
Table t = tables.get(i);
for (Table t : tables) {
t.addView(this);
}
}
......
......@@ -142,8 +142,7 @@ public class ChangeFileEncryption extends Tool {
if (files.size() == 0 && !quiet) {
printNoDatabaseFilesFound(dir, db);
}
for (int i = 0; i < files.size(); i++) {
String fileName = files.get(i);
for (String fileName : files) {
String temp = dir + "/temp.db";
FileUtils.delete(temp);
FileUtils.rename(fileName, temp);
......@@ -152,8 +151,7 @@ public class ChangeFileEncryption extends Tool {
// if this worked, the operation will (hopefully) be successful
// TODO changeFileEncryption: this is a workaround!
// make the operation atomic (all files or none)
for (int i = 0; i < files.size(); i++) {
String fileName = files.get(i);
for (String fileName : files) {
change.process(fileName);
}
}
......
......@@ -187,8 +187,8 @@ public class Csv implements SimpleRowSource {
initRead();
SimpleResultSet result = new SimpleResultSet(this);
makeColumnNamesUnique();
for (int i = 0; i < columnNames.length; i++) {
result.addColumn(columnNames[i], Types.VARCHAR, Integer.MAX_VALUE, 0);
for (String columnName : columnNames) {
result.addColumn(columnName, Types.VARCHAR, Integer.MAX_VALUE, 0);
}
return result;
}
......
......@@ -91,8 +91,7 @@ public class DeleteDbFiles extends Tool {
if (files.size() == 0 && !quiet) {
printNoDatabaseFilesFound(dir, db);
}
for (int i = 0; i < files.size(); i++) {
String fileName = files.get(i);
for (String fileName : files) {
delete.process(fileName, quiet);
if (!quiet) {
out.println("Processed: " + fileName);
......
......@@ -114,9 +114,9 @@ public class MultiDimension {
buff.append(" D, TABLE(_FROM_ BIGINT=?, _TO_ BIGINT=?) WHERE ");
buff.append(StringUtils.quoteIdentifier(scalarColumn));
buff.append(" BETWEEN _FROM_ AND _TO_");
for (int i = 0; i < columns.length; i++) {
for (String col : columns) {
buff.append(" AND ");
buff.append(StringUtils.quoteIdentifier(columns[i]));
buff.append(StringUtils.quoteIdentifier(col));
buff.append("+1 BETWEEN ?+1 AND ?+1");
}
return buff.toString();
......
......@@ -1205,8 +1205,7 @@ public class Recover extends Tool implements DataHandler {
private void writeSchema(PrintWriter writer) {
MetaRecord.sort(schema);
for (int i = 0; i < schema.size(); i++) {
MetaRecord m = schema.get(i);
for (MetaRecord m : schema) {
writer.println(m.getSQL() + ";");
}
for (Map.Entry<Integer, String> entry : tableMap.entrySet()) {
......
......@@ -512,8 +512,7 @@ public class Shell extends Tool {
println(buff.toString());
}
if (rowCount == 0 && listMode) {
for (int i = 0; i < len; i++) {
String label = columns[i];
for (String label : columns) {
buff.append(label);
buff.append('\n');
}
......
......@@ -68,8 +68,7 @@ public class ClassUtils {
public static Class< ? > loadUserClass(String className) throws SQLException {
if (!ALLOW_ALL && !ALLOWED_CLASS_NAMES.contains(className)) {
boolean allowed = false;
for (int i = 0; i < ALLOWED_CLASS_NAME_PREFIXES.length; i++) {
String s = ALLOWED_CLASS_NAME_PREFIXES[i];
for (String s : ALLOWED_CLASS_NAME_PREFIXES) {
if (className.startsWith(s)) {
allowed = true;
}
......
......@@ -163,9 +163,7 @@ public class NetUtils {
InetAddress localhost = InetAddress.getLocalHost();
// localhost.getCanonicalHostName() is very very slow
String host = localhost.getHostAddress();
InetAddress[] list = InetAddress.getAllByName(host);
for (int i = 0; i < list.length; i++) {
InetAddress addr = list[i];
for (InetAddress addr : InetAddress.getAllByName(host)) {
if (test.equals(addr)) {
return true;
}
......
......@@ -142,8 +142,8 @@ public class RandomUtils {
"getAllByName", new Class[] { String.class })
.invoke(null, new Object[] { hostName });
Method getAddress = inetAddressClass.getMethod("getAddress", new Class[0]);
for (int i = 0; i < list.length; i++) {
out.write((byte[]) getAddress.invoke(list[i], new Object[0]));
for (Object o : list) {
out.write((byte[]) getAddress.invoke(o, new Object[0]));
}
} catch (Throwable e) {
// on some system, InetAddress is not supported
......
......@@ -73,9 +73,9 @@ public class StartBrowser {
} else {
String[] browsers = { "firefox", "mozilla-firefox", "mozilla", "konqueror", "netscape", "opera" };
boolean ok = false;
for (int i = 0; i < browsers.length; i++) {
for (String b : browsers) {
try {
rt.exec(new String[] { browsers[i], url });
rt.exec(new String[] { b, url });
ok = true;
break;
} catch (Exception e) {
......
......@@ -169,8 +169,7 @@ public class ValueHashMap<V> extends HashBase {
*/
public ObjectArray<Value> keys() {
ObjectArray<Value> list = ObjectArray.newInstance(size);
for (int i = 0; i < keys.length; i++) {
Value k = keys[i];
for (Value k : keys) {
if (k != null && k != ValueNull.DELETED) {
list.add(k);
}
......
......@@ -167,9 +167,7 @@ public class CompareMode {
}
}
if (result == null) {
Locale[] locales = Collator.getAvailableLocales();
for (int i = 0; i < locales.length; i++) {
Locale locale = locales[i];
for (Locale locale : Collator.getAvailableLocales()) {
if (compareLocaleNames(locale, name)) {
result = Collator.getInstance(locale);
break;
......
......@@ -400,8 +400,8 @@ public class Transfer {
case Value.ARRAY: {
Value[] list = ((ValueArray) v).getList();
writeInt(list.length);
for (int i = 0; i < list.length; i++) {
writeValue(list[i]);
for (Value value : list) {
writeValue(value);
}
break;
}
......
......@@ -37,8 +37,8 @@ public class ValueArray extends Value {
return hash;
}
int h = 1;
for (int i = 0; i < values.length;) {
h = h * 31 + values[i++].hashCode();
for (Value v : values) {
h = h * 31 + v.hashCode();
}
hash = h;
return h;
......@@ -127,8 +127,8 @@ public class ValueArray extends Value {
}
public int getDisplaySize() {
long size = 0;
for (int i = 0; i < values.length; i++) {
size += values[i].getDisplaySize();
for (Value v : values) {
size += v.getDisplaySize();
}
return MathUtils.convertLongToInt(size);
}
......@@ -154,8 +154,8 @@ public class ValueArray extends Value {
public int getMemory() {
int memory = 0;
for (int i = 0; i < values.length; i++) {
memory += values[i].getMemory();
for (Value v : values) {
memory += v.getMemory();
}
return memory;
}
......
......@@ -256,8 +256,7 @@ public class ValueLob extends Value {
String[] list = getFileList(handler, dir);
int fileCount = 0;
boolean[] used = new boolean[SysProperties.LOB_FILES_PER_DIRECTORY];
for (int i = 0; i < list.length; i++) {
String name = list[i];
for (String name : list) {
if (name.endsWith(Constants.SUFFIX_DB_FILE)) {
name = name.substring(name.lastIndexOf(File.separatorChar) + 1);
String n = name.substring(0, name.indexOf('.'));
......@@ -754,8 +753,7 @@ public class ValueLob extends Value {
String prefix = handler.getDatabasePath();
String dir = FileUtils.getParent(prefix);
String[] list = FileUtils.listFiles(dir);
for (int i = 0; i < list.length; i++) {
String name = list[i];
for (String name : list) {
if (name.startsWith(prefix + "." + tableId + ".") && name.endsWith(Constants.SUFFIX_LOB_FILE)) {
deleteFile(handler, name);
}
......@@ -772,8 +770,7 @@ public class ValueLob extends Value {
public static boolean existsLobFile(String prefix) throws SQLException {
String dir = FileUtils.getParent(prefix);
String[] list = FileUtils.listFiles(dir);
for (int i = 0; i < list.length; i++) {
String name = list[i];
for (String name: list) {
if (name.startsWith(prefix + ".") && name.endsWith(Constants.SUFFIX_LOB_FILE)) {
return true;
}
......@@ -782,12 +779,10 @@ public class ValueLob extends Value {
}
private static void removeAllForTable(DataHandler handler, String dir, int tableId) throws SQLException {
String[] list = FileUtils.listFiles(dir);
for (int i = 0; i < list.length; i++) {
if (FileUtils.isDirectory(list[i])) {
removeAllForTable(handler, list[i], tableId);
for (String name : FileUtils.listFiles(dir)) {
if (FileUtils.isDirectory(name)) {
removeAllForTable(handler, name, tableId);
} else {
String name = list[i];
if (name.endsWith(".t" + tableId + Constants.SUFFIX_LOB_FILE)) {
deleteFile(handler, name);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论