提交 29abf234 authored 作者: andrei's avatar andrei

Merge remote-tracking branch 'h2database/master' into TestOutOfMemory

......@@ -548,7 +548,7 @@ public class Parser {
}
private DbException getSyntaxError() {
if (expectedList == null || expectedList.size() == 0) {
if (expectedList == null || expectedList.isEmpty()) {
return DbException.getSyntaxError(sqlCommand, parseIndex);
}
StatementBuilder buff = new StatementBuilder();
......@@ -3023,7 +3023,7 @@ public class Parser {
// this can occur when parsing expressions only (for
// example check constraints)
throw getSyntaxError();
} else if (parameters.size() > 0) {
} else if (!parameters.isEmpty()) {
throw DbException
.get(ErrorCode.CANNOT_MIX_INDEXED_AND_UNINDEXED_PARAMS);
}
......@@ -4725,7 +4725,7 @@ public class Parser {
int scale, displaySize;
Column column;
String columnName = "C" + (i + 1);
if (rows.size() == 0) {
if (rows.isEmpty()) {
if (type == Value.UNKNOWN) {
type = Value.STRING;
}
......
......@@ -120,7 +120,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
ArrayList<Constraint> constraints = table.getConstraints();
for (int i = 0; constraints != null && i < constraints.size(); i++) {
Constraint c = constraints.get(i);
if (Constraint.PRIMARY_KEY.equals(c.getConstraintType())) {
if (Constraint.Type.PRIMARY_KEY == c.getConstraintType()) {
throw DbException.get(ErrorCode.SECOND_PRIMARY_KEY);
}
}
......
......@@ -119,7 +119,7 @@ public class CreateTable extends SchemaCommand {
}
if (asQuery != null) {
asQuery.prepare();
if (data.columns.size() == 0) {
if (data.columns.isEmpty()) {
generateColumnsFromQuery();
} else if (data.columns.size() != asQuery.getColumnCount()) {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
......
......@@ -98,7 +98,7 @@ public class CreateView extends SchemaCommand {
querySQL = selectSQL;
} else {
ArrayList<Parameter> params = select.getParameters();
if (params != null && params.size() > 0) {
if (params != null && !params.isEmpty()) {
throw DbException.getUnsupportedException("parameters in views");
}
querySQL = select.getPlanSQL();
......
......@@ -57,7 +57,7 @@ public class DropIndex extends SchemaCommand {
Constraint cons = constraints.get(i);
if (cons.usesIndex(index)) {
// can drop primary key index (for compatibility)
if (Constraint.PRIMARY_KEY.equals(cons.getConstraintType())) {
if (Constraint.Type.PRIMARY_KEY == cons.getConstraintType()) {
pkConstraint = cons;
} else {
throw DbException.get(
......
......@@ -77,7 +77,7 @@ public class DropTable extends SchemaCommand {
if (dropAction == ConstraintActionType.RESTRICT) {
StatementBuilder buff = new StatementBuilder();
CopyOnWriteArrayList<TableView> dependentViews = table.getDependentViews();
if (dependentViews != null && dependentViews.size() > 0) {
if (dependentViews != null && !dependentViews.isEmpty()) {
for (TableView v : dependentViews) {
buff.appendExceptFirst(", ");
buff.append(v.getName());
......@@ -86,7 +86,7 @@ public class DropTable extends SchemaCommand {
if (session.getDatabase()
.getSettings().standardDropTableRestrict) {
final List<Constraint> constraints = table.getConstraints();
if (constraints != null && constraints.size() > 0) {
if (constraints != null && !constraints.isEmpty()) {
for (Constraint c : constraints) {
if (c.getTable() != table) {
buff.appendExceptFirst(", ");
......
......@@ -243,7 +243,7 @@ public class Insert extends Prepared implements ResultTarget {
if (sortedInsertMode) {
buff.append("SORTED ");
}
if (list.size() > 0) {
if (!list.isEmpty()) {
buff.append("VALUES ");
int row = 0;
if (list.size() > 1) {
......@@ -274,14 +274,14 @@ public class Insert extends Prepared implements ResultTarget {
@Override
public void prepare() {
if (columns == null) {
if (list.size() > 0 && list.get(0).length == 0) {
if (!list.isEmpty() && list.get(0).length == 0) {
// special case where table is used as a sequence
columns = new Column[0];
} else {
columns = table.getColumns();
}
}
if (list.size() > 0) {
if (!list.isEmpty()) {
for (Expression[] expr : list) {
if (expr.length != columns.length) {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
......
......@@ -84,7 +84,7 @@ public class Merge extends Prepared {
session.getUser().checkRight(targetTable, Right.INSERT);
session.getUser().checkRight(targetTable, Right.UPDATE);
setCurrentRowNumber(0);
if (valuesExpressionList.size() > 0) {
if (!valuesExpressionList.isEmpty()) {
// process values in list
count = 0;
for (int x = 0, size = valuesExpressionList.size(); x < size; x++) {
......@@ -221,7 +221,7 @@ public class Merge extends Prepared {
buff.append(')');
}
buff.append('\n');
if (valuesExpressionList.size() > 0) {
if (!valuesExpressionList.isEmpty()) {
buff.append("VALUES ");
int row = 0;
for (Expression[] expr : valuesExpressionList) {
......@@ -249,14 +249,14 @@ public class Merge extends Prepared {
@Override
public void prepare() {
if (columns == null) {
if (valuesExpressionList.size() > 0 && valuesExpressionList.get(0).length == 0) {
if (!valuesExpressionList.isEmpty() && valuesExpressionList.get(0).length == 0) {
// special case where table is used as a sequence
columns = new Column[0];
} else {
columns = targetTable.getColumns();
}
}
if (valuesExpressionList.size() > 0) {
if (!valuesExpressionList.isEmpty()) {
for (Expression[] expr : valuesExpressionList) {
if (expr.length != columns.length) {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
......
......@@ -315,7 +315,7 @@ public class MergeUsing extends Prepared {
buff.append(')');
}
buff.append('\n');
if (valuesExpressionList.size() > 0) {
if (!valuesExpressionList.isEmpty()) {
buff.append("VALUES ");
int row = 0;
for (Expression[] expr : valuesExpressionList) {
......@@ -376,7 +376,7 @@ public class MergeUsing extends Prepared {
onCondition.createIndexConditions(session, targetTableFilter);
if (columns == null) {
if (valuesExpressionList.size() > 0
if (!valuesExpressionList.isEmpty()
&& valuesExpressionList.get(0).length == 0) {
// special case where table is used as a sequence
columns = new Column[0];
......@@ -384,7 +384,7 @@ public class MergeUsing extends Prepared {
columns = targetTable.getColumns();
}
}
if (valuesExpressionList.size() > 0) {
if (!valuesExpressionList.isEmpty()) {
for (Expression[] expr : valuesExpressionList) {
if (expr.length != columns.length) {
throw DbException
......
......@@ -82,7 +82,7 @@ public class Replace extends Prepared {
session.getUser().checkRight(table, Right.INSERT);
session.getUser().checkRight(table, Right.UPDATE);
setCurrentRowNumber(0);
if (list.size() > 0) {
if (!list.isEmpty()) {
count = 0;
for (int x = 0, size = list.size(); x < size; x++) {
setCurrentRowNumber(x + 1);
......@@ -208,7 +208,7 @@ public class Replace extends Prepared {
}
buff.append(')');
buff.append('\n');
if (list.size() > 0) {
if (!list.isEmpty()) {
buff.append("VALUES ");
int row = 0;
for (Expression[] expr : list) {
......@@ -236,14 +236,14 @@ public class Replace extends Prepared {
@Override
public void prepare() {
if (columns == null) {
if (list.size() > 0 && list.get(0).length == 0) {
if (!list.isEmpty() && list.get(0).length == 0) {
// special case where table is used as a sequence
columns = new Column[0];
} else {
columns = table.getColumns();
}
}
if (list.size() > 0) {
if (!list.isEmpty()) {
for (Expression[] expr : list) {
if (expr.length != columns.length) {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
......
......@@ -284,8 +284,7 @@ public class ScriptCommand extends ScriptBase {
final ArrayList<Constraint> constraints = table.getConstraints();
if (constraints != null) {
for (Constraint constraint : constraints) {
if (Constraint.PRIMARY_KEY.equals(
constraint.getConstraintType())) {
if (Constraint.Type.PRIMARY_KEY == constraint.getConstraintType()) {
add(constraint.getCreateSQLWithoutIndexes(), false);
}
}
......@@ -336,7 +335,7 @@ public class ScriptCommand extends ScriptBase {
if (constraint.getTable().isHidden()) {
continue;
}
if (!Constraint.PRIMARY_KEY.equals(constraint.getConstraintType())) {
if (Constraint.Type.PRIMARY_KEY != constraint.getConstraintType()) {
add(constraint.getCreateSQLWithoutIndexes(), false);
}
}
......
......@@ -24,25 +24,24 @@ import org.h2.table.Table;
public abstract class Constraint extends SchemaObjectBase implements
Comparable<Constraint> {
/**
* The constraint type name for check constraints.
*/
public static final String CHECK = "CHECK";
/**
* The constraint type name for referential constraints.
*/
public static final String REFERENTIAL = "REFERENTIAL";
/**
* The constraint type name for unique constraints.
*/
public static final String UNIQUE = "UNIQUE";
/**
* The constraint type name for primary key constraints.
*/
public static final String PRIMARY_KEY = "PRIMARY KEY";
public enum Type {
/**
* The constraint type for check constraints.
*/
CHECK,
/**
* The constraint type for primary key constraints.
*/
PRIMARY_KEY,
/**
* The constraint type for unique constraints.
*/
UNIQUE,
/**
* The constraint type for referential constraints.
*/
REFERENTIAL
}
/**
* The table for which this constraint is defined.
......@@ -60,7 +59,7 @@ public abstract class Constraint extends SchemaObjectBase implements
*
* @return the name
*/
public abstract String getConstraintType();
public abstract Type getConstraintType();
/**
* Check if this row fulfils the constraint.
......@@ -155,29 +154,12 @@ public abstract class Constraint extends SchemaObjectBase implements
return null;
}
private int getConstraintTypeOrder() {
String constraintType = getConstraintType();
if (CHECK.equals(constraintType)) {
return 0;
} else if (PRIMARY_KEY.equals(constraintType)) {
return 1;
} else if (UNIQUE.equals(constraintType)) {
return 2;
} else if (REFERENTIAL.equals(constraintType)) {
return 3;
} else {
throw DbException.throwInternalError("type: " + constraintType);
}
}
@Override
public int compareTo(Constraint other) {
if (this == other) {
return 0;
}
int thisType = getConstraintTypeOrder();
int otherType = other.getConstraintTypeOrder();
return thisType - otherType;
return Integer.compare(getConstraintType().ordinal(), other.getConstraintType().ordinal());
}
@Override
......
......@@ -36,8 +36,8 @@ public class ConstraintCheck extends Constraint {
}
@Override
public String getConstraintType() {
return Constraint.CHECK;
public Type getConstraintType() {
return Constraint.Type.CHECK;
}
public void setTableFilter(TableFilter filter) {
......
......@@ -50,8 +50,8 @@ public class ConstraintReferential extends Constraint {
}
@Override
public String getConstraintType() {
return Constraint.REFERENTIAL;
public Type getConstraintType() {
return Constraint.Type.REFERENTIAL;
}
private static void appendAction(StatementBuilder buff, ConstraintActionType action) {
......
......@@ -34,8 +34,8 @@ public class ConstraintUnique extends Constraint {
}
@Override
public String getConstraintType() {
return primaryKey ? Constraint.PRIMARY_KEY : Constraint.UNIQUE;
public Type getConstraintType() {
return primaryKey ? Constraint.Type.PRIMARY_KEY : Constraint.Type.UNIQUE;
}
@Override
......
......@@ -1212,7 +1212,7 @@ public class Database implements DataHandler {
trace.info("disconnecting session #{0}", session.getId());
}
}
if (userSessions.size() == 0 &&
if (userSessions.isEmpty() &&
session != systemSession && session != lobSession) {
if (closeDelay == 0) {
close(false);
......@@ -1275,7 +1275,7 @@ public class Database implements DataHandler {
}
closing = true;
stopServer();
if (userSessions.size() > 0) {
if (!userSessions.isEmpty()) {
if (!fromShutdownHook) {
return;
}
......@@ -1290,7 +1290,7 @@ public class Database implements DataHandler {
// set it to null, to make sure it's called only once
eventListener = null;
e.closingDatabase();
if (userSessions.size() > 0) {
if (!userSessions.isEmpty()) {
// if a connection was opened, we can't close the database
return;
}
......
......@@ -63,7 +63,7 @@ public class Engine implements SessionFactory {
}
database = new Database(ci, cipher);
opened = true;
if (database.getAllUsers().size() == 0) {
if (database.getAllUsers().isEmpty()) {
// users is the last thing we add, so if no user is around,
// the database is new (or not initialized correctly)
user = new User(database, database.allocateObjectId(),
......
......@@ -163,7 +163,7 @@ public class FunctionAlias extends SchemaObjectBase {
list.add(javaMethod);
}
}
if (list.size() == 0) {
if (list.isEmpty()) {
throw DbException.get(
ErrorCode.PUBLIC_STATIC_JAVA_METHOD_NOT_FOUND_1,
methodName + " (" + className + ")");
......
......@@ -251,7 +251,7 @@ public class Session extends SessionWithState {
}
}
public String getParsingCreateViewName() {
if (viewNameStack.size() == 0) {
if (viewNameStack.isEmpty()) {
return null;
}
return viewNameStack.peek();
......@@ -652,7 +652,7 @@ public class Session extends SessionWithState {
// increment the data mod count, so that other sessions
// see the changes
// TODO should not rely on locking
if (locks.size() > 0) {
if (!locks.isEmpty()) {
for (int i = 0, size = locks.size(); i < size; i++) {
Table t = locks.get(i);
if (t instanceof MVTable) {
......@@ -726,10 +726,10 @@ public class Session extends SessionWithState {
}
temporaryLobs.clear();
}
if (temporaryResultLobs != null && temporaryResultLobs.size() > 0) {
if (temporaryResultLobs != null && !temporaryResultLobs.isEmpty()) {
long keepYoungerThan = System.nanoTime() -
TimeUnit.MILLISECONDS.toNanos(database.getSettings().lobTimeout);
while (temporaryResultLobs.size() > 0) {
while (!temporaryResultLobs.isEmpty()) {
TimeoutValue tv = temporaryResultLobs.getFirst();
if (onTimeout && tv.created >= keepYoungerThan) {
break;
......@@ -743,7 +743,7 @@ public class Session extends SessionWithState {
}
private void checkCommitRollback() {
if (commitOrRollbackDisabled && locks.size() > 0) {
if (commitOrRollbackDisabled && !locks.isEmpty()) {
throw DbException.get(ErrorCode.COMMIT_ROLLBACK_NOT_ALLOWED);
}
}
......@@ -783,7 +783,7 @@ public class Session extends SessionWithState {
transaction.commit();
transaction = null;
}
if (locks.size() > 0 || needCommit) {
if (!locks.isEmpty() || needCommit) {
database.commit(this);
}
cleanTempTables(false);
......@@ -990,7 +990,7 @@ public class Session extends SessionWithState {
DbException.throwInternalError();
}
}
if (locks.size() > 0) {
if (!locks.isEmpty()) {
// don't use the enhanced for loop to save memory
for (int i = 0, size = locks.size(); i < size; i++) {
Table t = locks.get(i);
......
......@@ -482,7 +482,7 @@ public class SessionRemote extends SessionWithState implements DataHandler {
public void removeServer(IOException e, int i, int count) {
trace.debug(e, "removing server because of exception");
transferList.remove(i);
if (transferList.size() == 0 && autoReconnect(count)) {
if (transferList.isEmpty() && autoReconnect(count)) {
return;
}
checkClosed();
......@@ -653,7 +653,7 @@ public class SessionRemote extends SessionWithState implements DataHandler {
@Override
public boolean isClosed() {
return transferList == null || transferList.size() == 0;
return transferList == null || transferList.isEmpty();
}
/**
......
......@@ -24,7 +24,7 @@ abstract class SessionWithState implements SessionInterface {
* Re-create the session state using the stored sessionState list.
*/
protected void recreateSessionState() {
if (sessionState != null && sessionState.size() > 0) {
if (sessionState != null && !sessionState.isEmpty()) {
sessionStateUpdating = true;
try {
for (String sql : sessionState) {
......
......@@ -328,7 +328,7 @@ public class Aggregate extends Expression {
Value v = data.getValue(session.getDatabase(), dataType, distinct);
if (type == AggregateType.GROUP_CONCAT) {
ArrayList<Value> list = ((AggregateDataGroupConcat) data).getList();
if (list == null || list.size() == 0) {
if (list == null || list.isEmpty()) {
return ValueNull.INSTANCE;
}
if (groupConcatOrderList != null) {
......
......@@ -1326,7 +1326,7 @@ public class Function extends Expression implements FunctionCall {
if (s2 == null) {
s2 = "";
}
result = ValueString.get(replace(s0, s1, s2),
result = ValueString.get(StringUtils.replaceAll(s0, s1, s2),
database.getMode().treatEmptyStringsAsNull);
}
break;
......@@ -1471,7 +1471,7 @@ public class Function extends Expression implements FunctionCall {
v1 == null ? null : v1.getString()));
break;
case ADD_MONTHS:
result = ValueTimestamp.get(DateTimeUtils.addMonths(v0.getTimestamp(), v1.getInt()));
result = dateadd("MONTH", v1.getInt(), v0);
break;
case TRANSLATE: {
String matching = v1.getString();
......@@ -1980,13 +1980,6 @@ public class Function extends Expression implements FunctionCall {
return s.substring(start, start + length);
}
private static String replace(String s, String replace, String with) {
if (s == null || replace == null || with == null) {
return null;
}
return StringUtils.replaceAll(s, replace, with);
}
private static String repeat(String s, int count) {
StringBuilder buff = new StringBuilder(s.length() * count);
while (count-- > 0) {
......
......@@ -624,7 +624,7 @@ public class FullText {
}
}
}
if (rIds == null || rIds.size() == 0) {
if (rIds == null || rIds.isEmpty()) {
return result;
}
PreparedStatement prepSelectRowById = setting.prepare(conn, SELECT_ROW_BY_ID);
......@@ -913,7 +913,7 @@ public class FullText {
for (int i = 0; rs.next(); i++) {
columnTypes[i] = rs.getInt("DATA_TYPE");
}
if (keyList.size() == 0) {
if (keyList.isEmpty()) {
rs = meta.getPrimaryKeys(null,
StringUtils.escapeMetaDataPattern(schemaName),
tableName);
......@@ -921,7 +921,7 @@ public class FullText {
keyList.add(rs.getString("COLUMN_NAME"));
}
}
if (keyList.size() == 0) {
if (keyList.isEmpty()) {
throw throwException("No primary key for table " + tableName);
}
ArrayList<String> indexList = New.arrayList();
......@@ -938,7 +938,7 @@ public class FullText {
Collections.addAll(indexList, StringUtils.arraySplit(columns, ',', true));
}
}
if (indexList.size() == 0) {
if (indexList.isEmpty()) {
indexList.addAll(columnList);
}
index.keys = new int[keyList.size()];
......
......@@ -505,7 +505,7 @@ public class FullTextLucene extends FullText {
for (int i = 0; rs.next(); i++) {
columnTypes[i] = rs.getInt("DATA_TYPE");
}
if (keyList.size() == 0) {
if (keyList.isEmpty()) {
rs = meta.getPrimaryKeys(null,
StringUtils.escapeMetaDataPattern(schemaName),
tableName);
......@@ -513,7 +513,7 @@ public class FullTextLucene extends FullText {
keyList.add(rs.getString("COLUMN_NAME"));
}
}
if (keyList.size() == 0) {
if (keyList.isEmpty()) {
throw throwException("No primary key for table " + tableName);
}
ArrayList<String> indexList = New.arrayList();
......@@ -530,7 +530,7 @@ public class FullTextLucene extends FullText {
StringUtils.arraySplit(cols, ',', true));
}
}
if (indexList.size() == 0) {
if (indexList.isEmpty()) {
indexList.addAll(columnList);
}
keys = new int[keyList.size()];
......
......@@ -202,7 +202,7 @@ public class JdbcXAConnection extends TraceObject implements XAConnection,
}
rs.close();
Xid[] result = list.toArray(new Xid[0]);
if (list.size() > 0) {
if (!list.isEmpty()) {
prepared = true;
}
return result;
......
......@@ -241,7 +241,7 @@ public class Trace {
*/
public static String formatParams(
ArrayList<? extends ParameterInterface> parameters) {
if (parameters.size() == 0) {
if (parameters.isEmpty()) {
return "";
}
StatementBuilder buff = new StatementBuilder();
......
......@@ -1479,7 +1479,7 @@ public final class MVStore {
for (Chunk c : modified) {
meta.put(Chunk.getMetaKey(c.id), c.asString());
}
if (modified.size() == 0) {
if (modified.isEmpty()) {
break;
}
}
......@@ -1782,7 +1782,7 @@ public final class MVStore {
synchronized (this) {
old = compactGetOldChunks(targetFillRate, write);
}
if (old == null || old.size() == 0) {
if (old == null || old.isEmpty()) {
return false;
}
compactRewrite(old);
......@@ -1838,7 +1838,7 @@ public final class MVStore {
c.collectPriority = (int) (c.getFillRate() * 1000 / age);
old.add(c);
}
if (old.size() == 0) {
if (old.isEmpty()) {
return null;
}
......@@ -2287,7 +2287,7 @@ public final class MVStore {
keep = c;
}
}
if (remove.size() > 0) {
if (!remove.isEmpty()) {
// remove the youngest first, so we don't create gaps
// (in case we remove many chunks)
Collections.sort(remove, Collections.reverseOrder());
......
......@@ -467,7 +467,7 @@ public class MVTable extends TableBase {
if (constraints != null) {
for (int i = 0, size = constraints.size(); i < size; i++) {
Constraint c = constraints.get(i);
if (!(c.getConstraintType().equals(Constraint.REFERENTIAL))) {
if (c.getConstraintType() != Constraint.Type.REFERENTIAL) {
continue;
}
ConstraintReferential ref = (ConstraintReferential) c;
......@@ -610,7 +610,7 @@ public class MVTable extends TableBase {
remaining--;
}
sortRows(buffer, index);
if (bufferNames.size() > 0) {
if (!bufferNames.isEmpty()) {
String mapName = store.nextTemporaryMapName();
index.addRowsToBuffer(buffer, mapName);
bufferNames.add(mapName);
......
......@@ -305,7 +305,7 @@ public class SpatialDataType implements DataType {
*/
public int[] getExtremes(ArrayList<Object> list) {
list = getNotNull(list);
if (list.size() == 0) {
if (list.isEmpty()) {
return null;
}
SpatialKey bounds = (SpatialKey) createBoundingBox(list.get(0));
......
......@@ -118,7 +118,7 @@ public class UpdatableRow {
}
private boolean isIndexUsable(ArrayList<String> indexColumns) {
if (indexColumns.size() == 0) {
if (indexColumns.isEmpty()) {
return false;
}
for (String c : indexColumns) {
......
......@@ -182,7 +182,7 @@ public class CipherFactory {
boolean ecdhAnonRemoved = algorithms.remove("ECDH_anon");
if (dhAnonRemoved || ecdhAnonRemoved) {
String string = Arrays.toString(algorithms.toArray(new String[algorithms.size()]));
return (algorithms.size() > 0) ? string.substring(1, string.length() - 1): "";
return (!algorithms.isEmpty()) ? string.substring(1, string.length() - 1): "";
}
return list;
}
......
......@@ -886,7 +886,7 @@ public class PgServerThread implements Runnable {
}
stat.execute("set search_path = PUBLIC, pg_catalog");
HashSet<Integer> typeSet = server.getTypeSet();
if (typeSet.size() == 0) {
if (typeSet.isEmpty()) {
try (ResultSet rs = stat.executeQuery("select oid from pg_catalog.pg_type")) {
while (rs.next()) {
typeSet.add(rs.getInt(1));
......
......@@ -98,7 +98,7 @@ public class PageParser {
result.append("?items?");
list = New.arrayList();
}
if (list.size() == 0) {
if (list.isEmpty()) {
parseBlockUntil("</c:forEach>");
}
for (Object o : list) {
......
......@@ -1869,7 +1869,7 @@ public class WebApp {
String setting = attributes.getProperty("name", "");
server.removeSetting(setting);
ArrayList<ConnectionInfo> settings = server.getSettings();
if (settings.size() > 0) {
if (!settings.isEmpty()) {
attributes.put("setting", settings.get(0));
}
server.saveProperties(null);
......
......@@ -206,7 +206,7 @@ class WebSession {
"${text.admin.notConnected}" : conn.getMetaData().getURL());
m.put("user", conn == null ?
"-" : conn.getMetaData().getUserName());
m.put("lastQuery", commandHistory.size() == 0 ?
m.put("lastQuery", commandHistory.isEmpty() ?
"" : commandHistory.get(0));
m.put("executing", executingStatement == null ?
"${text.admin.no}" : "${text.admin.yes}");
......
......@@ -1407,7 +1407,7 @@ public class PageStore implements CacheWriter {
isEmpty &= log.recover(PageLog.RECOVERY_STAGE_REDO);
boolean setReadOnly = false;
if (!database.isReadOnly()) {
if (log.getInDoubtTransactions().size() == 0) {
if (log.getInDoubtTransactions().isEmpty()) {
log.recoverEnd();
int firstUncommittedSection = getFirstUncommittedSection();
log.removeUntil(firstUncommittedSection);
......
......@@ -868,8 +868,7 @@ public class MetaTable extends Table {
Constraint constraint = constraints.get(k);
if (constraint.usesIndex(index)) {
if (index.getIndexType().isPrimaryKey()) {
if (constraint.getConstraintType().equals(
Constraint.PRIMARY_KEY)) {
if (constraint.getConstraintType() == Constraint.Type.PRIMARY_KEY) {
constraintName = constraint.getName();
}
} else {
......@@ -1544,7 +1543,7 @@ public class MetaTable extends Table {
for (SchemaObject obj : database.getAllSchemaObjects(
DbObject.CONSTRAINT)) {
Constraint constraint = (Constraint) obj;
if (!(constraint.getConstraintType().equals(Constraint.REFERENTIAL))) {
if (constraint.getConstraintType() != Constraint.Type.REFERENTIAL) {
continue;
}
ConstraintReferential ref = (ConstraintReferential) constraint;
......@@ -1597,7 +1596,7 @@ public class MetaTable extends Table {
for (SchemaObject obj : database.getAllSchemaObjects(
DbObject.CONSTRAINT)) {
Constraint constraint = (Constraint) obj;
String constraintType = constraint.getConstraintType();
Constraint.Type constraintType = constraint.getConstraintType();
String checkExpression = null;
IndexColumn[] indexColumns = null;
Table table = constraint.getTable();
......@@ -1613,12 +1612,12 @@ public class MetaTable extends Table {
if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue;
}
if (constraintType.equals(Constraint.CHECK)) {
if (constraintType == Constraint.Type.CHECK) {
checkExpression = ((ConstraintCheck) constraint).getExpression().getSQL();
} else if (constraintType.equals(Constraint.UNIQUE) ||
constraintType.equals(Constraint.PRIMARY_KEY)) {
} else if (constraintType == Constraint.Type.UNIQUE ||
constraintType == Constraint.Type.PRIMARY_KEY) {
indexColumns = ((ConstraintUnique) constraint).getColumns();
} else if (constraintType.equals(Constraint.REFERENTIAL)) {
} else if (constraintType == Constraint.Type.REFERENTIAL) {
indexColumns = ((ConstraintReferential) constraint).getColumns();
}
String columnList = null;
......@@ -1638,7 +1637,7 @@ public class MetaTable extends Table {
// CONSTRAINT_NAME
identifier(constraint.getName()),
// CONSTRAINT_TYPE
constraintType,
constraintType.toString(),
// TABLE_CATALOG
catalog,
// TABLE_SCHEMA
......
......@@ -671,7 +671,7 @@ public class RegularTable extends TableBase {
lockExclusiveSession = null;
}
synchronized (database) {
if (lockSharedSessions.size() > 0) {
if (!lockSharedSessions.isEmpty()) {
lockSharedSessions.remove(s);
}
if (!waitingSessions.isEmpty()) {
......@@ -746,7 +746,7 @@ public class RegularTable extends TableBase {
if (constraints != null) {
for (int i = 0, size = constraints.size(); i < size; i++) {
Constraint c = constraints.get(i);
if (!(c.getConstraintType().equals(Constraint.REFERENTIAL))) {
if (c.getConstraintType() != Constraint.Type.REFERENTIAL) {
continue;
}
ConstraintReferential ref = (ConstraintReferential) c;
......
......@@ -529,20 +529,20 @@ public abstract class Table extends SchemaObjectBase {
@Override
public void removeChildrenAndResources(Session session) {
while (dependentViews.size() > 0) {
while (!dependentViews.isEmpty()) {
TableView view = dependentViews.get(0);
dependentViews.remove(0);
database.removeSchemaObject(session, view);
}
while (synonyms != null && synonyms.size() > 0) {
while (synonyms != null && !synonyms.isEmpty()) {
TableSynonym synonym = synonyms.remove(0);
database.removeSchemaObject(session, synonym);
}
while (triggers != null && triggers.size() > 0) {
while (triggers != null && !triggers.isEmpty()) {
TriggerObject trigger = triggers.remove(0);
database.removeSchemaObject(session, trigger);
}
while (constraints != null && constraints.size() > 0) {
while (constraints != null && !constraints.isEmpty()) {
Constraint constraint = constraints.remove(0);
database.removeSchemaObject(session, constraint);
}
......@@ -554,7 +554,7 @@ public abstract class Table extends SchemaObjectBase {
database.removeMeta(session, getId());
// must delete sequences later (in case there is a power failure
// before removing the table object)
while (sequences != null && sequences.size() > 0) {
while (sequences != null && !sequences.isEmpty()) {
Sequence sequence = sequences.remove(0);
// only remove if no other table depends on this sequence
// this is possible when calling ALTER TABLE ALTER COLUMN
......@@ -975,8 +975,8 @@ public abstract class Table extends SchemaObjectBase {
* @return if there are any triggers or rows defined
*/
public boolean fireRow() {
return (constraints != null && constraints.size() > 0) ||
(triggers != null && triggers.size() > 0);
return (constraints != null && !constraints.isEmpty()) ||
(triggers != null && !triggers.isEmpty());
}
/**
......
......@@ -197,7 +197,7 @@ public class TableFilter implements ColumnResolver {
if (select != null) {
sortOrder = select.getSortOrder();
}
if (indexConditions.size() == 0) {
if (indexConditions.isEmpty()) {
item1 = new PlanItem();
item1.setIndex(table.getScanIndex(s, null, filters, filter,
sortOrder, allColumnsSet));
......@@ -854,7 +854,7 @@ public class TableFilter implements ColumnResolver {
}
}
planBuff.append(index.getPlanSQL());
if (indexConditions.size() > 0) {
if (!indexConditions.isEmpty()) {
planBuff.append(": ");
for (IndexCondition condition : indexConditions) {
planBuff.appendExceptFirst("\n AND ");
......
......@@ -173,7 +173,7 @@ public class TableLink extends Table {
try (Statement stat = conn.getConnection().createStatement()) {
rs = stat.executeQuery("SELECT * FROM " +
qualifiedTableName + " T WHERE 1=0");
if (columnList.size() == 0) {
if (columnList.isEmpty()) {
// alternative solution
ResultSetMetaData rsMeta = rs.getMetaData();
for (i = 0; i < rsMeta.getColumnCount();) {
......@@ -501,7 +501,7 @@ public class TableLink extends Table {
if (trace.isDebugEnabled()) {
StatementBuilder buff = new StatementBuilder();
buff.append(getName()).append(":\n").append(sql);
if (params != null && params.size() > 0) {
if (params != null && !params.isEmpty()) {
buff.append(" {");
int i = 1;
for (Value v : params) {
......
......@@ -114,7 +114,7 @@ public class Backup extends Tool {
} else {
list = FileLister.getDatabaseFiles(directory, db, true);
}
if (list.size() == 0) {
if (list.isEmpty()) {
if (!quiet) {
printNoDatabaseFilesFound(directory, db);
}
......
......@@ -170,7 +170,7 @@ public class ChangeFileEncryption extends Tool {
ArrayList<String> files = FileLister.getDatabaseFiles(dir, db, true);
FileLister.tryUnlockDatabase(files, "encryption");
files = FileLister.getDatabaseFiles(dir, db, false);
if (files.size() == 0 && !quiet) {
if (files.isEmpty() && !quiet) {
printNoDatabaseFilesFound(dir, db);
}
// first, test only if the file can be renamed
......
......@@ -343,7 +343,7 @@ public class Csv implements SimpleRowSource {
String v = readValue();
if (v == null) {
if (endOfLine) {
if (endOfFile || list.size() > 0) {
if (endOfFile || !list.isEmpty()) {
break;
}
} else {
......
......@@ -84,7 +84,7 @@ public class DeleteDbFiles extends Tool {
*/
private void process(String dir, String db, boolean quiet) {
ArrayList<String> files = FileLister.getDatabaseFiles(dir, db, true);
if (files.size() == 0 && !quiet) {
if (files.isEmpty() && !quiet) {
printNoDatabaseFilesFound(dir, db);
}
for (String fileName : files) {
......
......@@ -330,7 +330,7 @@ public class Recover extends Tool implements DataHandler {
private void process(String dir, String db) {
ArrayList<String> list = FileLister.getDatabaseFiles(dir, db, true);
if (list.size() == 0) {
if (list.isEmpty()) {
printNoDatabaseFilesFound(dir, db);
}
for (String fileName : list) {
......
......@@ -243,7 +243,7 @@ public class Shell extends Tool implements Runnable {
s = s.replace('\n', ' ').replace('\r', ' ');
println("#" + (1 + i) + ": " + s);
}
if (history.size() > 0) {
if (!history.isEmpty()) {
println("To re-run a statement, type the number and press and enter");
} else {
println("No history");
......
......@@ -116,7 +116,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
*/
public void addColumn(String name, int sqlType, String sqlTypeName,
int precision, int scale) {
if (rows != null && rows.size() > 0) {
if (rows != null && !rows.isEmpty()) {
throw new IllegalStateException(
"Cannot add a column after adding rows");
}
......
......@@ -71,7 +71,7 @@ public class AbbaDetector {
System.out.println(thread + " " + indent +
"sync " + getObjectName(o));
}
if (stack.size() > 0) {
if (!stack.isEmpty()) {
markHigher(o, stack);
}
stack.push(o);
......
......@@ -163,7 +163,7 @@ public class CacheLRU implements Cache {
if (rc <= Constants.CACHE_MIN_RECORDS) {
break;
}
if (changed.size() == 0) {
if (changed.isEmpty()) {
if (mem <= maxMemory) {
break;
}
......@@ -209,7 +209,7 @@ public class CacheLRU implements Cache {
remove(check.getPos());
}
}
if (changed.size() > 0) {
if (!changed.isEmpty()) {
if (!flushed) {
writer.flushLog();
}
......
......@@ -525,7 +525,7 @@ public class DateTimeUtils {
if (month == 2) {
maxDay = c.isLeapYear(year) ? 29 : 28;
} else {
maxDay = 30 + ((month + (month > 7 ? 1 : 0)) & 1);
maxDay = NORMAL_DAYS_PER_MONTH[month];
}
if (day < 1 || day > maxDay) {
throw e;
......@@ -1222,26 +1222,6 @@ public class DateTimeUtils {
return dateValue(y, m + 3, (int) d);
}
/**
* Adds the number of months to the date. If the resulting month's number of
* days is less than the original's day-of-month, the resulting
* day-of-months gets adjusted accordingly: <br>
* 30.04.2007 - 2 months = 28.02.2007
*
* @param refDate the original date
* @param nrOfMonthsToAdd the number of months to add
* @return the new timestamp
*/
public static Timestamp addMonths(Timestamp refDate, int nrOfMonthsToAdd) {
Calendar calendar = DateTimeUtils.createGregorianCalendar();
calendar.setTime(refDate);
calendar.add(Calendar.MONTH, nrOfMonthsToAdd);
Timestamp resultDate = new Timestamp(calendar.getTimeInMillis());
resultDate.setNanos(refDate.getNanos());
return resultDate;
}
/**
* Append a date to the string builder.
*
......
......@@ -253,7 +253,7 @@ public class Profiler implements Runnable {
line = line.substring(3).trim();
stack.add(line);
}
if (stack.size() > 0) {
if (!stack.isEmpty()) {
String[] s = stack.toArray(new String[0]);
list.add(s);
}
......
......@@ -82,7 +82,6 @@ public class TestFunctions extends TestBase implements AggregateFunction {
testIfNull();
testToDate();
testToDateException();
testAddMonths();
testDataType();
testVersion();
testFunctionTable();
......@@ -1428,39 +1427,6 @@ public class TestFunctions extends TestBase implements AggregateFunction {
date.setTime(c.getTimeInMillis());
}
private void testAddMonths() throws ParseException {
Timestamp date;
Timestamp expected;
// 01-Aug-03 + 3 months = 01-Nov-03
date = new Timestamp(
new SimpleDateFormat("yyyy-MM-dd").parse("2003-08-01").getTime());
expected = new Timestamp(
new SimpleDateFormat("yyyy-MM-dd").parse("2003-11-01").getTime());
assertEquals(expected, DateTimeUtils.addMonths(new Timestamp(date.getTime()), 3));
// 31-Jan-03 + 1 month = 28-Feb-2003
date = new Timestamp(
new SimpleDateFormat("yyyy-MM-dd").parse("2003-01-31").getTime());
expected = new Timestamp(
new SimpleDateFormat("yyyy-MM-dd").parse("2003-02-28").getTime());
assertEquals(expected, DateTimeUtils.addMonths(new Timestamp(date.getTime()), 1));
// 21-Aug-2003 - 3 months = 21-May-2003
date = new Timestamp(
new SimpleDateFormat("yyyy-MM-dd").parse("2003-08-21").getTime());
expected = new Timestamp(
new SimpleDateFormat("yyyy-MM-dd").parse("2003-05-21").getTime());
assertEquals(expected, DateTimeUtils.addMonths(new Timestamp(date.getTime()), -3));
// 21-Aug-2003 00:00:00:333 - 3 months = 21-May-2003 00:00:00:333
date = new Timestamp(
new SimpleDateFormat("yyyy-MM-dd SSS").parse("2003-08-21 333").getTime());
expected = new Timestamp(
new SimpleDateFormat("yyyy-MM-dd SSS").parse("2003-05-21 333").getTime());
assertEquals(expected, DateTimeUtils.addMonths(new Timestamp(date.getTime()), -3));
}
private void testToCharFromDateTime() throws SQLException {
deleteDb("functions");
Connection conn = getConnection("functions");
......
......@@ -135,7 +135,7 @@ public class TestScript extends TestBase {
"set", "table", "transaction-id", "truncate-value", "user" }) {
testScript("functions/system/" + s + ".sql");
}
for (String s : new String[] { "current_date", "current_timestamp",
for (String s : new String[] { "add_months", "current_date", "current_timestamp",
"current-time", "dateadd", "datediff", "dayname",
"day-of-month", "day-of-week", "day-of-year", "extract",
"formatdatetime", "hour", "minute", "month", "monthname",
......
-- Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
-- 01-Aug-03 + 3 months = 01-Nov-03
SELECT ADD_MONTHS('2003-08-01', 3) AS R;
> R
> ---------------------
> 2003-11-01 00:00:00.0
> rows: 1
-- 31-Jan-03 + 1 month = 28-Feb-2003
SELECT ADD_MONTHS('2003-01-31', 1) AS R;
> R
> ---------------------
> 2003-02-28 00:00:00.0
> rows: 1
-- 21-Aug-2003 - 3 months = 21-May-2003
SELECT ADD_MONTHS('2003-08-21', -3) AS R;
> R
> ---------------------
> 2003-05-21 00:00:00.0
> rows: 1
-- 21-Aug-2003 00:00:00.333 - 3 months = 21-May-2003 00:00:00.333
SELECT ADD_MONTHS('2003-08-21 00:00:00.333', -3) AS R;
> R
> -----------------------
> 2003-05-21 00:00:00.333
> rows: 1
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论