提交 3bad54e3 authored 作者: Sergi Vladykin's avatar Sergi Vladykin

Compilation for Java 7 fixed, cleanup + code style.

上级 7102cc38
......@@ -30,7 +30,7 @@ public abstract class Command implements CommandInterface {
/**
* The last start time.
*/
protected long startTime_nanos;
protected long startTimeNanos;
/**
* The trace module.
......@@ -127,7 +127,7 @@ public abstract class Command implements CommandInterface {
*/
void start() {
if (trace.isInfoEnabled() || session.getDatabase().getQueryStatistics()) {
startTime_nanos = System.nanoTime();
startTimeNanos = System.nanoTime();
}
}
......@@ -162,10 +162,10 @@ public abstract class Command implements CommandInterface {
}
}
}
if (trace.isInfoEnabled() && startTime_nanos > 0) {
long time_ms = (System.nanoTime() - startTime_nanos) / 1000 / 1000;
if (time_ms > Constants.SLOW_QUERY_LIMIT_MS) {
trace.info("slow query: {0} ms", time_ms);
if (trace.isInfoEnabled() && startTimeNanos > 0) {
long timeMillis = (System.nanoTime() - startTimeNanos) / 1000 / 1000;
if (timeMillis > Constants.SLOW_QUERY_LIMIT_MS) {
trace.info("slow query: {0} ms", timeMillis);
}
}
}
......@@ -180,7 +180,7 @@ public abstract class Command implements CommandInterface {
*/
@Override
public ResultInterface executeQuery(int maxrows, boolean scrollable) {
startTime_nanos = 0;
startTimeNanos = 0;
long start = 0;
Database database = session.getDatabase();
Object sync = database.isMultiThreaded() ? (Object) session : (Object) database;
......
......@@ -96,7 +96,7 @@ public class CommandContainer extends Command {
session.setLastScopeIdentity(ValueNull.INSTANCE);
prepared.checkParameters();
int updateCount = prepared.update();
prepared.trace(startTime_nanos, updateCount);
prepared.trace(startTimeNanos, updateCount);
setProgress(DatabaseEventListener.STATE_STATEMENT_END);
return updateCount;
}
......@@ -108,7 +108,7 @@ public class CommandContainer extends Command {
start();
prepared.checkParameters();
ResultInterface result = prepared.query(maxrows);
prepared.trace(startTime_nanos, result.getRowCount());
prepared.trace(startTimeNanos, result.getRowCount());
setProgress(DatabaseEventListener.STATE_STATEMENT_END);
return result;
}
......
......@@ -1885,8 +1885,9 @@ public class Parser {
read(")");
return command;
}
if (readIf("WITH"))
if (readIf("WITH")) {
return parseWith();
}
Select select = parseSelectSimple();
return select;
}
......
......@@ -302,20 +302,20 @@ public abstract class Prepared {
* Print information about the statement executed if info trace level is
* enabled.
*
* @param startTime_nanos when the statement was started
* @param startTimeNanos when the statement was started
* @param rowCount the query or update row count
*/
void trace(long startTime_nanos, int rowCount) {
if (session.getTrace().isInfoEnabled() && startTime_nanos > 0) {
long deltaTime_nanos = System.nanoTime() - startTime_nanos;
void trace(long startTimeNanos, int rowCount) {
if (session.getTrace().isInfoEnabled() && startTimeNanos > 0) {
long deltaTimeNanos = System.nanoTime() - startTimeNanos;
String params = Trace.formatParams(parameters);
session.getTrace().infoSQL(sqlStatement, params, rowCount, deltaTime_nanos / 1000 / 1000);
session.getTrace().infoSQL(sqlStatement, params, rowCount, deltaTimeNanos / 1000 / 1000);
}
// startTime_nanos can be zero for the command that actually turns on statistics
if (session.getDatabase().getQueryStatistics() && startTime_nanos != 0) {
long deltaTime_nanos = System.nanoTime() - startTime_nanos;
if (session.getDatabase().getQueryStatistics() && startTimeNanos != 0) {
long deltaTimeNanos = System.nanoTime() - startTimeNanos;
session.getDatabase().getQueryStatisticsData().
update(toString(), deltaTime_nanos, rowCount);
update(toString(), deltaTimeNanos, rowCount);
}
}
......
......@@ -54,11 +54,11 @@ public class QueryStatisticsData {
* Update query statistics.
*
* @param sqlStatement the statement being executed
* @param executionTime_nanos the time in nanoseconds the query/update took to
* @param executionTimeNanos the time in nanoseconds the query/update took to
* execute
* @param rowCount the query or update row count
*/
public synchronized void update(String sqlStatement, long executionTime_nanos,
public synchronized void update(String sqlStatement, long executionTimeNanos,
int rowCount) {
QueryEntry entry = map.get(sqlStatement);
if (entry == null) {
......@@ -66,7 +66,7 @@ public class QueryStatisticsData {
entry.sqlStatement = sqlStatement;
map.put(sqlStatement, entry);
}
entry.update(executionTime_nanos, rowCount);
entry.update(executionTimeNanos, rowCount);
// Age-out the oldest entries if the map gets too big.
// Test against 1.5 x max-size so we don't do this too often
......@@ -114,17 +114,17 @@ public class QueryStatisticsData {
/**
* The minimum execution time, in nanoseconds.
*/
public long executionTimeMin_nanos;
public long executionTimeMinNanos;
/**
* The maximum execution time, in nanoseconds.
*/
public long executionTimeMax_nanos;
public long executionTimeMaxNanos;
/**
* The total execution time.
*/
public long executionTimeCumulative_nanos;
public long executionTimeCumulativeNanos;
/**
* The minimum number of rows.
......@@ -144,7 +144,7 @@ public class QueryStatisticsData {
/**
* The mean execution time.
*/
public double executionTimeMean_nanos;
public double executionTimeMeanNanos;
/**
* The mean number of rows.
......@@ -155,19 +155,19 @@ public class QueryStatisticsData {
// http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
// http://www.johndcook.com/standard_deviation.html
private double executionTimeM2_nanos;
private double executionTimeM2Nanos;
private double rowCountM2;
/**
* Update the statistics entry.
*
* @param time_nanos the execution time in nanos
* @param timeNanos the execution time in nanos
* @param rows the number of rows
*/
void update(long time_nanos, int rows) {
void update(long timeNanos, int rows) {
count++;
executionTimeMin_nanos = Math.min(time_nanos, executionTimeMin_nanos);
executionTimeMax_nanos = Math.max(time_nanos, executionTimeMax_nanos);
executionTimeMinNanos = Math.min(timeNanos, executionTimeMinNanos);
executionTimeMaxNanos = Math.max(timeNanos, executionTimeMaxNanos);
rowCountMin = Math.min(rows, rowCountMin);
rowCountMax = Math.max(rows, rowCountMax);
......@@ -175,18 +175,18 @@ public class QueryStatisticsData {
rowCountMean += rowDelta / count;
rowCountM2 += rowDelta * (rows - rowCountMean);
double timeDelta = time_nanos - executionTimeMean_nanos;
executionTimeMean_nanos += timeDelta / count;
executionTimeM2_nanos += timeDelta * (time_nanos - executionTimeMean_nanos);
double timeDelta = timeNanos - executionTimeMeanNanos;
executionTimeMeanNanos += timeDelta / count;
executionTimeM2Nanos += timeDelta * (timeNanos - executionTimeMeanNanos);
executionTimeCumulative_nanos += time_nanos;
executionTimeCumulativeNanos += timeNanos;
rowCountCumulative += rows;
lastUpdateTime = System.currentTimeMillis();
}
public double getExecutionTimeStandardDeviation() {
// population standard deviation
return Math.sqrt(executionTimeM2_nanos / count);
return Math.sqrt(executionTimeM2Nanos / count);
}
public double getRowCountStandardDeviation() {
......
......@@ -78,7 +78,7 @@ public class Session extends SessionWithState {
private int lockTimeout;
private Value lastIdentity = ValueLong.get(0);
private Value lastScopeIdentity = ValueLong.get(0);
private Value lastTriggerIdentity = null;
private Value lastTriggerIdentity;
private int firstUncommittedLog = Session.LOG_WRITTEN;
private int firstUncommittedPos = Session.LOG_WRITTEN;
private HashMap<String, Savepoint> savepoints;
......
......@@ -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;
......
......@@ -7,7 +7,6 @@ package org.h2.index;
import java.util.HashSet;
import java.util.Iterator;
import org.h2.engine.Constants;
import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.mvstore.MVStore;
......@@ -187,7 +186,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
*/
public static long getCostRangeIndex(int[] masks, long rowCount, Column[] columns) {
// Never use spatial tree index without spatial filter
if(columns.length == 0) {
if (columns.length == 0) {
return Long.MAX_VALUE;
}
for (Column column : columns) {
......
......@@ -37,16 +37,13 @@ import org.h2.api.ErrorCode;
import org.h2.command.CommandInterface;
import org.h2.engine.ConnectionInfo;
import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.engine.Mode;
import org.h2.engine.Session;
import org.h2.engine.SessionInterface;
import org.h2.engine.SessionRemote;
import org.h2.engine.SysProperties;
import org.h2.message.DbException;
import org.h2.message.TraceObject;
import org.h2.result.ResultInterface;
import org.h2.schema.Schema;
import org.h2.util.CloseWatcher;
import org.h2.util.JdbcUtils;
import org.h2.util.Utils;
......
......@@ -1834,13 +1834,13 @@ public class MetaTable extends Table {
// EXECUTION_COUNT
"" + entry.count,
// MIN_EXECUTION_TIME
"" + entry.executionTimeMin_nanos / 1000d / 1000,
"" + entry.executionTimeMinNanos / 1000d / 1000,
// MAX_EXECUTION_TIME
"" + entry.executionTimeMax_nanos / 1000d / 1000,
"" + entry.executionTimeMaxNanos / 1000d / 1000,
// CUMULATIVE_EXECUTION_TIME
"" + entry.executionTimeCumulative_nanos / 1000d / 1000,
"" + entry.executionTimeCumulativeNanos / 1000d / 1000,
// AVERAGE_EXECUTION_TIME
"" + entry.executionTimeMean_nanos / 1000d / 1000,
"" + entry.executionTimeMeanNanos / 1000d / 1000,
// STD_DEV_EXECUTION_TIME
"" + entry.getExecutionTimeStandardDeviation() / 1000d / 1000,
// MIN_ROW_COUNT
......
......@@ -914,8 +914,7 @@ public abstract class Value {
if (object instanceof java.util.UUID) {
java.util.UUID uuid = (java.util.UUID) object;
return ValueUuid.get(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
}
else {
} else {
throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, getString());
}
case TIMESTAMP_TZ:
......
......@@ -294,14 +294,14 @@ public class ValueTimestampTimeZone extends Value {
// even if the DST database changes.
// convert to minutes and add timezone offset
long a = DateTimeUtils.convertDateValueToMillis(TimeZone.getTimeZone("UTC"), dateValue) / ( 1000L * 60L );
long ma = timeNanos / ( 1000L * 1000L * 1000L * 60L );
long a = DateTimeUtils.convertDateValueToMillis(TimeZone.getTimeZone("UTC"), dateValue) / (1000L * 60L);
long ma = timeNanos / (1000L * 1000L * 1000L * 60L);
a += ma;
a -= timeZoneOffsetMins;
// convert to minutes and add timezone offset
long b = DateTimeUtils.convertDateValueToMillis(TimeZone.getTimeZone("UTC"), t.dateValue) / ( 1000L * 60L );
long mb = t.timeNanos / ( 1000L * 1000L * 1000L * 60L );
long b = DateTimeUtils.convertDateValueToMillis(TimeZone.getTimeZone("UTC"), t.dateValue) / (1000L * 60L);
long mb = t.timeNanos / (1000L * 1000L * 1000L * 60L);
b += mb;
b -= t.timeZoneOffsetMins;
......@@ -311,8 +311,8 @@ public class ValueTimestampTimeZone extends Value {
return c;
}
// compare time
long na = timeNanos - ( ma * 1000L * 1000L * 1000L * 60L );
long nb = t.timeNanos - ( mb * 1000L * 1000L * 1000L * 60L );
long na = timeNanos - (ma * 1000L * 1000L * 1000L * 60L);
long nb = t.timeNanos - (mb * 1000L * 1000L * 1000L * 60L);
return MathUtils.compareLong(na, nb);
}
......
......@@ -53,6 +53,7 @@ import org.h2.test.db.TestPowerOff;
import org.h2.test.db.TestQueryCache;
import org.h2.test.db.TestReadOnly;
import org.h2.test.db.TestRecursiveQueries;
import org.h2.test.db.TestReplace;
import org.h2.test.db.TestRights;
import org.h2.test.db.TestRowFactory;
import org.h2.test.db.TestRunscript;
......@@ -717,6 +718,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest(new TestView());
addTest(new TestViewAlterTable());
addTest(new TestViewDropView());
addTest(new TestReplace());
// jaqu
addTest(new AliasMapTest());
......
......@@ -171,8 +171,7 @@ public class TestCompatibilityOracle extends TestBase {
try {
stat.executeQuery("SELECT * FROM A WHERE ID IN ()");
fail();
}
catch (SQLException e) {
} catch (SQLException e) {
} finally {
conn.close();
}
......
......@@ -1294,7 +1294,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
}
try {
ToDateParser.toDate("1-DEC-0000","DD-MON-RRRR");
ToDateParser.toDate("1-DEC-0000", "DD-MON-RRRR");
fail("Oracle to_date should reject year 0 (ORA-01841)");
} catch (Exception e) { }
}
......@@ -2016,10 +2016,11 @@ public class TestFunctions extends TestBase implements AggregateFunction {
final String formatted;
try (final ResultSet rs = stat.executeQuery("select to_char(current_timestamp(9), 'YYYY MM DD HH24 MI SS FF3') from dual")) {
final ResultSet rs = stat.executeQuery(
"select to_char(current_timestamp(9), 'YYYY MM DD HH24 MI SS FF3') from dual");
rs.next();
formatted = rs.getString(1);
}
rs.close();
Date after = new Date();
......@@ -2036,19 +2037,19 @@ public class TestFunctions extends TestBase implements AggregateFunction {
conn.setAutoCommit(false);
Statement stat = conn.createStatement();
final Timestamp first;
try (final ResultSet rs = stat.executeQuery("select CURRENT_TIMESTAMP from DUAL")) {
Timestamp first;
ResultSet rs = stat.executeQuery("select CURRENT_TIMESTAMP from DUAL");
rs.next();
first = rs.getTimestamp(1);
}
rs.close();
Thread.sleep(1);
final Timestamp second;
try (final ResultSet rs = stat.executeQuery("select CURRENT_TIMESTAMP from DUAL")) {
Timestamp second;
rs = stat.executeQuery("select CURRENT_TIMESTAMP from DUAL");
rs.next();
second = rs.getTimestamp(1);
}
rs.close();
assertEquals(first, second);
}
......@@ -2059,19 +2060,19 @@ public class TestFunctions extends TestBase implements AggregateFunction {
conn.setAutoCommit(true);
Statement stat = conn.createStatement();
final Timestamp first;
try (final ResultSet rs = stat.executeQuery("select CURRENT_TIMESTAMP from DUAL")) {
Timestamp first;
ResultSet rs = stat.executeQuery("select CURRENT_TIMESTAMP from DUAL");
rs.next();
first = rs.getTimestamp(1);
}
rs.close();
Thread.sleep(1);
final Timestamp second;
try (final ResultSet rs = stat.executeQuery("select CURRENT_TIMESTAMP from DUAL")) {
Timestamp second;
rs = stat.executeQuery("select CURRENT_TIMESTAMP from DUAL");
rs.next();
second = rs.getTimestamp(1);
}
rs.close();
assertTrue(second.after(first));
}
......
......@@ -329,6 +329,9 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
}
/**
*
*/
public static class TestViewGeneratedKeys implements Trigger {
PreparedStatement prepInsert;
......
......@@ -57,7 +57,7 @@ public class UpdateTest extends TestBase {
Product p2 = new Product();
Product pChang2 = db.from(p2).where(p2.productName).is("Chang")
.selectFirst();
assertEquals((Double)19.5, pChang2.unitPrice);
assertEquals((Double) 19.5, pChang2.unitPrice);
assertEquals(16, pChang2.unitsInStock.intValue());
// undo update
......@@ -95,7 +95,7 @@ public class UpdateTest extends TestBase {
Product p2 = new Product();
Product pChang2 = db.from(p2).where(p2.productName).is("Chang")
.selectFirst();
assertEquals((Double)19.5, pChang2.unitPrice);
assertEquals((Double) 19.5, pChang2.unitPrice);
assertEquals(16, pChang2.unitsInStock.intValue());
// undo update
......@@ -136,7 +136,7 @@ public class UpdateTest extends TestBase {
// confirm the data was properly updated
Product revised = db.from(p).where(p.productId).is(1).selectFirst();
assertEquals("updated", revised.productName);
assertEquals((Double)(original.unitPrice + 3.14), revised.unitPrice);
assertEquals((Double) (original.unitPrice + 3.14), revised.unitPrice);
assertEquals(original.unitsInStock + 2, revised.unitsInStock.intValue());
// restore the data
......
......@@ -31,7 +31,6 @@ public class TestBenchmark extends TestBase {
@Override
public void test() throws Exception {
;
// TODO this test is currently disabled
test(true);
......
......@@ -67,7 +67,7 @@ public class TestStreamStore extends TestBase {
if (max == -1) {
assertTrue(map.isEmpty());
} else {
assertEquals(map.lastKey(), (Long)max);
assertEquals(map.lastKey(), (Long) max);
}
}
}
......
......@@ -5,10 +5,8 @@
*/
package org.h2.test.unit;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
......
......@@ -89,21 +89,21 @@ public class TestTimeStampWithTimeZone extends TestBase {
private void test2() {
ValueTimestampTimeZone a = ValueTimestampTimeZone.parse("1970-01-01 12:00:00.00+00:15");
ValueTimestampTimeZone b = ValueTimestampTimeZone.parse("1970-01-01 12:00:01.00+01:15");
int c= a.compareTo(b, null);
int c = a.compareTo(b, null);
assertEquals(c, 1);
}
private void test3() {
ValueTimestampTimeZone a = ValueTimestampTimeZone.parse("1970-01-02 00:00:02.00+01:15");
ValueTimestampTimeZone b = ValueTimestampTimeZone.parse("1970-01-01 23:00:01.00+00:15");
int c= a.compareTo(b, null);
int c = a.compareTo(b, null);
assertEquals(c, 1);
}
private void test4() {
ValueTimestampTimeZone a = ValueTimestampTimeZone.parse("1970-01-02 00:00:01.00+01:15");
ValueTimestampTimeZone b = ValueTimestampTimeZone.parse("1970-01-01 23:00:01.00+00:15");
int c= a.compareTo(b, null);
int c = a.compareTo(b, null);
assertEquals(c, 0);
}
......
......@@ -15,7 +15,6 @@ import java.sql.Timestamp;
import java.sql.Types;
import java.util.UUID;
import org.h2.api.ErrorCode;
import org.h2.jdbc.JdbcSQLException;
import org.h2.message.DbException;
import org.h2.test.TestBase;
import org.h2.test.utils.AssertThrows;
......@@ -292,11 +291,11 @@ public class TestValue extends TestBase {
ValueJavaObject valObj = ValueJavaObject.getNoCopy(origUUID, null, null);
Value valUUID = valObj.convertTo(Value.UUID);
assertTrue(valUUID instanceof ValueUuid);
assertTrue((valUUID.getString().equals(uuidStr)));
assertTrue(valUUID.getString().equals(uuidStr));
assertTrue(valUUID.getObject().equals(origUUID));
ValueJavaObject vo_string = ValueJavaObject.getNoCopy(new String("This is not a ValueUuid object"), null, null);
assertThrows(DbException.class, vo_string).convertTo(Value.UUID);
ValueJavaObject voString = ValueJavaObject.getNoCopy(new String("This is not a ValueUuid object"), null, null);
assertThrows(DbException.class, voString).convertTo(Value.UUID);
}
private void testModulusDouble() {
......
......@@ -111,7 +111,6 @@ public final class ImmutableArray<K> implements Iterable<K> {
* @param array the data
* @return the new immutable array
*/
@SuppressWarnings("unchecked")
public static <K> ImmutableArray<K> create(K... array) {
return new ImmutableArray<K>(array);
}
......
......@@ -151,7 +151,6 @@ public final class ImmutableArray2<K> implements Iterable<K> {
* @param array the data
* @return the new immutable array
*/
@SuppressWarnings("unchecked")
public static <K> ImmutableArray2<K> create(K... array) {
return new ImmutableArray2<K>(array, array.length);
}
......
......@@ -84,7 +84,6 @@ public abstract class ImmutableArray3<K> implements Iterable<K> {
* @param array the data
* @return the new immutable array
*/
@SuppressWarnings("unchecked")
public static <K> ImmutableArray3<K> create(K... array) {
return new Plain<K>(array);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论