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

Use generics

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