提交 159fe23a authored 作者: Thomas Mueller Graf's avatar Thomas Mueller Graf

Formatting, code style, Javadocs

上级 524c1ed8
......@@ -11,4 +11,6 @@ package org.h2;
*/
public interface JdbcDriverBackwardsCompat {
// compatibility interface
}
......@@ -180,19 +180,25 @@ public class TimestampWithTimeZone implements Serializable, Cloneable {
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
TimestampWithTimeZone other = (TimestampWithTimeZone) obj;
if (dateValue != other.dateValue)
if (dateValue != other.dateValue) {
return false;
if (timeNanos != other.timeNanos)
}
if (timeNanos != other.timeNanos) {
return false;
if (timeZoneOffsetMins != other.timeZoneOffsetMins)
}
if (timeZoneOffsetMins != other.timeZoneOffsetMins) {
return false;
}
return true;
}
......
......@@ -226,8 +226,9 @@ public class CommandRemote implements CommandInterface {
for (ParameterInterface p : parameters) {
Value pVal = p.getParamValue();
if (pVal == null && cmdType == EXPLAIN)
if (pVal == null && cmdType == EXPLAIN) {
pVal = ValueNull.INSTANCE;
}
transfer.writeValue(pVal);
}
......
......@@ -55,9 +55,8 @@ public class AlterIndexRename extends DefineCommand {
if (!ifExists) {
throw DbException.get(ErrorCode.INDEX_NOT_FOUND_1,
newIndexName);
} else {
return 0;
}
return 0;
}
if (oldSchema.findIndex(session, newIndexName) != null ||
newIndexName.equals(oldIndexName)) {
......
......@@ -104,7 +104,7 @@ public class DropDatabase extends DefineCommand {
// ignore these. the ones we want to drop will get dropped when we drop
// their associated tables, and we will ignore the problematic ones
// that belong to session-local temp tables.
if (!((Sequence)obj).getBelongsToTable()) {
if (!((Sequence) obj).getBelongsToTable()) {
list.add(obj);
}
}
......
......@@ -92,9 +92,8 @@ public class AlterSequence extends SchemaCommand {
if (sequence == null) {
if (!ifExists) {
throw DbException.get(ErrorCode.SEQUENCE_NOT_FOUND_1, sequenceName);
} else {
return 0;
}
return 0;
}
}
if (table != null) {
......
......@@ -61,9 +61,10 @@ public class Explain extends Prepared {
@Override
protected void checkParameters() {
// Check params only in case of EXPLAIN ANALYZE
if (executeCommand)
if (executeCommand) {
super.checkParameters();
}
}
@Override
public ResultInterface query(int maxrows) {
......
......@@ -454,8 +454,7 @@ public class Database implements DataHandler {
}
reconnectLastLock = old;
reconnectChangePending = pending;
reconnectCheckNext = System.nanoTime() +
reconnectCheckDelayNs;
reconnectCheckNext = System.nanoTime() + reconnectCheckDelayNs;
return true;
} catch (Exception e) {
trace.error(e, "pending {0}", pending);
......
......@@ -37,6 +37,8 @@ public abstract class DbObjectBase implements DbObject {
private long modificationId;
private boolean temporary;
private String invalidateStackTrace;
/**
* Initialize some attributes of this object.
*
......@@ -126,7 +128,6 @@ public abstract class DbObjectBase implements DbObject {
return objectName;
}
private String invalidateStackTrace;
/**
* Set the main attributes to null to make sure the object is no longer
* used.
......
......@@ -8,7 +8,6 @@ package org.h2.engine;
import java.io.Closeable;
import java.util.ArrayList;
import org.h2.command.CommandInterface;
import org.h2.jdbc.JdbcConnection;
import org.h2.message.Trace;
import org.h2.store.DataHandler;
import org.h2.value.Value;
......
......@@ -283,8 +283,10 @@ public class CompareLike extends Condition {
private static boolean containsIgnoreCase(String src, String what) {
final int length = what.length();
if (length == 0)
return true; // Empty string is contained
if (length == 0) {
// Empty string is contained
return true;
}
final char firstLo = Character.toLowerCase(what.charAt(0));
final char firstUp = Character.toUpperCase(what.charAt(0));
......@@ -292,12 +294,14 @@ public class CompareLike extends Condition {
for (int i = src.length() - length; i >= 0; i--) {
// Quick check before calling the more expensive regionMatches() method:
final char ch = src.charAt(i);
if (ch != firstLo && ch != firstUp)
if (ch != firstLo && ch != firstUp) {
continue;
}
if (src.regionMatches(true, i, what, 0, length))
if (src.regionMatches(true, i, what, 0, length)) {
return true;
}
}
return false;
}
......
......@@ -199,8 +199,9 @@ public class Comparison extends Condition {
int resType = Value.getHigherOrder(colType, constType);
// If not the column values will need to be promoted
// to constant type, but vise versa, then let's do this here once.
if (constType != resType)
if (constType != resType) {
right = ValueExpression.get(r.convertTo(resType));
}
} else if (right instanceof Parameter) {
((Parameter) right).setColumn(
((ExpressionColumn) left).getColumn());
......
......@@ -83,7 +83,7 @@ public class Function extends Expression implements FunctionCall {
TRUNCATE = 27, SECURE_RAND = 28, HASH = 29, ENCRYPT = 30,
DECRYPT = 31, COMPRESS = 32, EXPAND = 33, ZERO = 34,
RANDOM_UUID = 35, COSH = 36, SINH = 37, TANH = 38, LN = 39,
BITGET=40;
BITGET = 40;
public static final int ASCII = 50, BIT_LENGTH = 51, CHAR = 52,
CHAR_LENGTH = 53, CONCAT = 54, DIFFERENCE = 55, HEXTORAW = 56,
......
......@@ -11,4 +11,6 @@ package org.h2.jdbc;
*/
public interface JdbcCallableStatementBackwardsCompat {
// compatibility interface
}
......@@ -11,4 +11,6 @@ package org.h2.jdbc;
*/
public interface JdbcConnectionBackwardsCompat {
// compatibility interface
}
......@@ -11,4 +11,6 @@ package org.h2.jdbc;
*/
public interface JdbcDatabaseMetaDataBackwardsCompat {
// compatibility interface
}
......@@ -11,4 +11,6 @@ package org.h2.jdbc;
*/
public interface JdbcResultSetBackwardsCompat {
// compatibility interface
}
......@@ -11,4 +11,6 @@ package org.h2.jdbc;
*/
public interface JdbcStatementBackwardsCompat {
// compatibility interface
}
......@@ -11,4 +11,6 @@ package org.h2.jdbcx;
*/
public interface JdbcConnectionPoolBackwardsCompat {
// compatibility interface
}
......@@ -11,4 +11,6 @@ package org.h2.jdbcx;
*/
public interface JdbcDataSourceBackwardsCompat {
// compatibility interface
}
......@@ -274,7 +274,6 @@ public class MVPrimaryIndex extends BaseIndex {
}
Value value = map.get(v);
Entry<Value, Value> e = new DataUtils.MapEntry<Value, Value>(v, value);
@SuppressWarnings("unchecked")
List<Entry<Value, Value>> list = Arrays.asList(e);
MVStoreCursor c = new MVStoreCursor(session, list.iterator(), v);
c.next();
......
......@@ -606,9 +606,9 @@ public class Schema extends DbObjectBase {
}
}
if (data.tableEngine != null) {
if (data.tableEngineParams == null)
if (data.tableEngineParams == null) {
data.tableEngineParams = this.tableEngineParams;
}
return database.getTableEngine(data.tableEngine).createTable(data);
}
return new RegularTable(data);
......
......@@ -16,7 +16,6 @@ import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.api.ErrorCode;
import org.h2.command.Command;
import org.h2.command.CommandInterface;
import org.h2.engine.ConnectionInfo;
import org.h2.engine.Constants;
import org.h2.engine.Engine;
......
......@@ -456,7 +456,7 @@ public class LobStorageBackend implements LobStorageInterface {
try {
init();
ValueLobDb v = null;
if(!old.isRecoveryReference()){
if (!old.isRecoveryReference()) {
long lobId = getNextLobId();
String sql = "INSERT INTO " + LOB_MAP + "(LOB, SEQ, POS, HASH, BLOCK) " +
"SELECT ?, SEQ, POS, HASH, BLOCK FROM " + LOB_MAP + " WHERE LOB = ?";
......@@ -476,7 +476,7 @@ public class LobStorageBackend implements LobStorageInterface {
reuse(sql, prep);
v = ValueLobDb.create(type, database, tableId, lobId, null, length);
}else{
} else {
//Recovery process, no need to copy LOB using normal infrastructure
v = ValueLobDb.create(type, database, tableId, oldLobId, null, length);
}
......
......@@ -34,28 +34,24 @@ public abstract class FileBase extends FileChannel {
public abstract int write(ByteBuffer src) throws IOException;
@Override
public int read(ByteBuffer dst, long position)
public synchronized int read(ByteBuffer dst, long position)
throws IOException {
synchronized(this) {
long oldPos = position();
position(position);
int len = read(dst);
position(oldPos);
return len;
}
}
@Override
public int write(ByteBuffer src, long position)
public synchronized int write(ByteBuffer src, long position)
throws IOException {
synchronized(this) {
long oldPos = position();
position(position);
int len = write(src);
position(oldPos);
return len;
}
}
@Override
public abstract FileChannel truncate(long size) throws IOException;
......
......@@ -14,8 +14,8 @@ import java.util.concurrent.Future;
import org.h2.command.dml.Query;
import org.h2.command.dml.Select;
import org.h2.command.dml.SelectUnion;
import org.h2.index.BaseIndex;
import org.h2.index.Cursor;
import org.h2.index.Index;
import org.h2.index.IndexCursor;
import org.h2.index.IndexLookupBatch;
import org.h2.index.ViewCursor;
......@@ -33,7 +33,7 @@ import org.h2.value.ValueLong;
/**
* Support for asynchronous batched index lookups on joins.
*
* @see Index#createLookupBatch(org.h2.table.TableFilter[], int)
* @see BaseIndex#createLookupBatch(org.h2.table.TableFilter[], int)
* @see IndexLookupBatch
* @author Sergi Vladykin
*/
......
......@@ -5,6 +5,9 @@
*/
package org.h2.table;
/**
* The table types.
*/
public enum TableType {
/**
......
......@@ -355,8 +355,8 @@ ShutdownHandler {
}
System.gc();
// Mac OS X: Console tool process did not stop on exit
String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if (OS.indexOf("mac") >= 0) {
String os = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if (os.indexOf("mac") >= 0) {
for (Thread t : Thread.getAllStackTraces().keySet()) {
if (t.getName().startsWith("AWT-")) {
t.interrupt();
......
......@@ -15,6 +15,8 @@ import org.h2.message.DbException;
* Single threaded lazy future.
*
* @author Sergi Vladykin
*
* @param <T> the result type
*/
public abstract class LazyFuture<T> implements Future<T> {
......
......@@ -158,9 +158,11 @@ public abstract class Value {
* The value type for string values with a fixed size.
*/
public static final int GEOMETRY = 22;
/**
* 23 was a short-lived experiment "TIMESTAMP UTC" which has been removed.
*/
/**
* The value type for TIMESTAMP WITH TIME ZONE values.
*/
......@@ -866,9 +868,8 @@ public abstract class Value {
java.util.UUID uuid = (java.util.UUID) object;
return ValueUuid.get(uuid.getMostSignificantBits(),
uuid.getLeastSignificantBits());
} else {
throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, getString());
}
throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, getString());
case TIMESTAMP_TZ:
throw DbException.get(
ErrorCode.DATA_CONVERSION_ERROR_1, getString());
......
......@@ -58,7 +58,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
//Arbonaut: 13.07.2016
// Fix for recovery tool.
private boolean isRecoveryReference = false;
private boolean isRecoveryReference;
private ValueLobDb(int type, DataHandler handler, int tableId, long lobId,
byte[] hmac, long precision) {
......
......@@ -25,8 +25,6 @@ import org.h2.util.StringUtils;
*/
public class ValueTimestampTimeZone extends Value {
private static final TimeZone GMT_TIMEZONE = TimeZone.getTimeZone("GMT");
/**
* The precision in digits.
*/
......@@ -43,6 +41,8 @@ public class ValueTimestampTimeZone extends Value {
*/
static final int DEFAULT_SCALE = 10;
private static final TimeZone GMT_TIMEZONE = TimeZone.getTimeZone("GMT");
/**
* A bit field with bits for the year, month, and day (see DateTimeUtils for
* encoding)
......
......@@ -70,8 +70,8 @@ public class DirectInsert {
(optimize ? "(optimized)" : ""));
long time = System.nanoTime();
stat.execute("CREATE TABLE TEST2 AS SELECT * FROM TEST");
System.out.printf("%.3f sec.\n",
(double)(System.nanoTime() - time) / TimeUnit.SECONDS.toNanos(1));
System.out.printf("%.3f sec.\n", (double) (System.nanoTime() - time) /
TimeUnit.SECONDS.toNanos(1));
stat.execute("INSERT INTO TEST2 SELECT * FROM TEST2");
stat.close();
conn.close();
......
......@@ -269,6 +269,11 @@ java org.h2.test.TestAll timer
*/
/**
* Set to true if any of the tests fail. Used to return an error code from the whole program.
*/
static boolean atLeastOneTestFailed;
/**
* Whether the MVStore storage is used.
*/
......@@ -415,11 +420,6 @@ java org.h2.test.TestAll timer
*/
ArrayList<TestBase> tests = New.arrayList();
/**
* Set to true if any of the tests fail. Used to return an error code from the whole program.
*/
static boolean atLeastOneTestFailed;
private Server server;
/**
......@@ -929,12 +929,13 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
// event queue watchdog for tests that get stuck when running in Jenkins CI
final java.util.Timer watchdog = new java.util.Timer();
// 5 minutes
watchdog.schedule(new TimerTask() {
@Override
public void run() {
ThreadDeadlockDetector.dumpAllThreadsAndLocks("test watchdog timed out");
}
}, 5 * 60 * 1000); // 5 minutes
}, 5 * 60 * 1000);
try {
test.runTest(this);
} finally {
......
......@@ -196,7 +196,7 @@ class Database {
}
} else if (url.startsWith("jdbc:hsqldb:")) {
// HSQLDB: use a WRITE_DELAY of 1 second
try (Statement s = newConn.createStatement()){
try (Statement s = newConn.createStatement()) {
s.execute("SET WRITE_DELAY 1");
}
}
......
......@@ -176,6 +176,7 @@ public class TestCompatibilityOracle extends TestBase {
stat.executeQuery("SELECT * FROM A WHERE ID IN ()");
fail();
} catch (SQLException e) {
// expected
} finally {
conn.close();
}
......
......@@ -1296,7 +1296,9 @@ public class TestFunctions extends TestBase implements AggregateFunction {
try {
ToDateParser.toDate("1-DEC-0000", "DD-MON-RRRR");
fail("Oracle to_date should reject year 0 (ORA-01841)");
} catch (Exception e) { }
} catch (Exception e) {
// expected
}
}
private void testToDate() throws ParseException {
......
......@@ -438,14 +438,14 @@ public class TestMultiThread extends TestBase implements Runnable {
private void testConcurrentUpdate() throws Exception {
deleteDb("lockMode");
final int OBJ_CNT = 10000;
final int objectCount = 10000;
final String url = getURL("lockMode;MULTI_THREADED=1;LOCK_TIMEOUT=10000", true);
final Connection conn = getConnection(url);
conn.createStatement().execute(
"CREATE TABLE IF NOT EXISTS ACCOUNT ( ID NUMBER(18,0) not null PRIMARY KEY, BALANCE NUMBER null)");
final PreparedStatement mergeAcctStmt = conn
.prepareStatement("MERGE INTO Account(id, balance) key (id) VALUES (?, ?)");
for (int i = 0; i < OBJ_CNT; i++) {
for (int i = 0; i < objectCount; i++) {
mergeAcctStmt.setLong(1, i);
mergeAcctStmt.setBigDecimal(2, BigDecimal.ZERO);
mergeAcctStmt.execute();
......@@ -463,7 +463,7 @@ public class TestMultiThread extends TestBase implements Runnable {
public Void call() throws Exception {
for (int j = 0; j < 1000; j++) {
updateAcctStmt.setDouble(1, Math.random());
updateAcctStmt.setLong(2, (int) (Math.random() * OBJ_CNT));
updateAcctStmt.setLong(2, (int) (Math.random() * objectCount));
updateAcctStmt.execute();
taskConn.commit();
}
......
......@@ -100,7 +100,8 @@ public class TestOutOfMemory extends TestBase {
stat = conn.createStatement();
stat.execute("select 1");
conn.close();
FileUtils.delete(filename); // release the static data this test generates
// release the static data this test generates
FileUtils.delete(filename);
}
private void testUpdateWhenNearlyOutOfMemory() throws SQLException {
......
......@@ -468,7 +468,7 @@ public class TestCallableStatement extends TestBase {
getClass().getName() + ".arrayIdentiy\"");
for (Object[] arrayToTest : arraysToTest) {
Array sqlInputArray = connection.createArrayOf("ignored",arrayToTest);
Array sqlInputArray = connection.createArrayOf("ignored", arrayToTest);
try {
try (CallableStatement callableStatement = connection.prepareCall("{call arrayIdentiy(?)}")) {
callableStatement.setArray(1, sqlInputArray);
......
......@@ -192,7 +192,8 @@ public class TestReorderWrites extends TestBase {
}
assertTrue(minSize < maxSize);
assertTrue(minWritten < maxWritten);
FileUtils.delete(fileName); // release the static data this test generates
// release the static data this test generates
FileUtils.delete(fileName);
}
}
......@@ -7,6 +7,9 @@ import org.h2.test.TestBase;
import org.h2.tools.DeleteDbFiles;
import org.h2.tools.Recover;
/**
* Tests BLOB/CLOB recovery.
*/
public class RecoverLobTest extends TestBase {
public static void main(String... a) throws Exception {
......@@ -16,7 +19,7 @@ public class RecoverLobTest extends TestBase {
@Override
public TestBase init() throws Exception {
TestBase tb = super.init();
config.mvStore=false;
config.mvStore = false;
return tb;
}
......
......@@ -131,7 +131,8 @@ public class TestBenchmark extends TestBase {
Statement stat;
String url = "mvstore";
if (mvStore) {
url += ";MV_STORE=TRUE"; // ;COMPRESS=TRUE";
// ;COMPRESS=TRUE";
url += ";MV_STORE=TRUE";
}
url = getURL(url, true);
......
......@@ -68,7 +68,9 @@ public class TestValue extends TestBase {
rs.addRow(new Object[]{null});
rs.next();
for (int type = Value.NULL; type < Value.TYPE_COUNT; type++) {
if (type != 23) { // a defunct experimental type
if (type == 23) {
// a defunct experimental type
} else {
Value v = DataType.readValue(null, rs, 1, type);
assertTrue(v == ValueNull.INSTANCE);
}
......
......@@ -283,9 +283,8 @@ class FileReorderWrites extends FileBase {
x += addOperation(
new FileWriteOperation(id++, position + len1, buf2));
return x;
} else {
return addOperation(new FileWriteOperation(id++, position, src));
}
return addOperation(new FileWriteOperation(id++, position, src));
}
private void checkError() throws IOException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论