提交 2585b4ea authored 作者: Thomas Mueller's avatar Thomas Mueller

Various smaller changes (FindBugs)

上级 8b1510e3
......@@ -177,7 +177,7 @@ public class CreateView extends SchemaCommand {
* work with TableViews directly because they become invalid when we drop
* the parent view.
*/
private class DependentView {
private static class DependentView {
String viewName;
String createSql;
String createForceSql;
......
......@@ -64,7 +64,7 @@ public class Constants {
/**
* The minor version of this database.
*/
public static final int VERSION_MINOR = 3;
public static final int VERSION_MINOR = 2;
// Build.getLuceneVersion() uses an ugly hack to read this value
/**
......
......@@ -102,8 +102,6 @@ public class Function extends Expression implements FunctionCall {
private static final HashMap<String, FunctionInfo> FUNCTIONS = New.hashMap();
private static final HashMap<String, Integer> DATE_PART = New.hashMap();
private static final SimpleDateFormat FORMAT_DAYNAME = new SimpleDateFormat("EEEE", Locale.ENGLISH);
private static final SimpleDateFormat FORMAT_MONTHNAME = new SimpleDateFormat("MMMM", Locale.ENGLISH);
private static final char[] SOUNDEX_INDEX = new char[128];
protected Expression[] args;
......@@ -605,9 +603,8 @@ public class Function extends Expression implements FunctionCall {
result = ValueString.get(StringUtils.xmlText(v0.getString()));
break;
case DAY_NAME: {
synchronized (FORMAT_DAYNAME) {
result = ValueString.get(FORMAT_DAYNAME.format(v0.getDateNoCopy()));
}
SimpleDateFormat dayName = new SimpleDateFormat("EEEE", Locale.ENGLISH);
result = ValueString.get(dayName.format(v0.getDateNoCopy()));
break;
}
case DAY_OF_MONTH:
......@@ -629,9 +626,8 @@ public class Function extends Expression implements FunctionCall {
result = ValueInt.get(DateTimeUtils.getDatePart(v0.getDateNoCopy(), Calendar.MONTH));
break;
case MONTH_NAME: {
synchronized (FORMAT_MONTHNAME) {
result = ValueString.get(FORMAT_MONTHNAME.format(v0.getDateNoCopy()));
}
SimpleDateFormat monthName = new SimpleDateFormat("MMMM", Locale.ENGLISH);
result = ValueString.get(monthName.format(v0.getDateNoCopy()));
break;
}
case QUARTER:
......
......@@ -1142,7 +1142,7 @@ public class JdbcConnection extends TraceObject implements Connection {
*/
String translateSQL(String sql, boolean escapeProcessing) {
if (sql == null) {
throw DbException.getInvalidValueException("SQL", sql);
throw DbException.getInvalidValueException("SQL", null);
}
if (!escapeProcessing) {
return sql;
......
......@@ -8,6 +8,7 @@ package org.h2.server.web;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
......@@ -70,7 +71,9 @@ public class DbStarter implements ServletContextListener {
public void contextDestroyed(ServletContextEvent servletContextEvent) {
try {
conn.createStatement().execute("SHUTDOWN");
Statement stat = conn.createStatement();
stat.execute("SHUTDOWN");
stat.close();
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -276,7 +276,7 @@ public class FileLock implements Runnable {
// lock file modified in the future -
// wait for a bit longer than usual
try {
Thread.sleep(2 * sleep);
Thread.sleep(2 * (long) sleep);
} catch (Exception e) {
trace.debug(e, "sleep");
}
......
......@@ -100,6 +100,7 @@ public class LobStorage {
rs = stat.executeQuery("SELECT MAX(BLOCK) FROM " + LOB_DATA);
rs.next();
nextBlock = rs.getLong(1) + 1;
stat.close();
} catch (SQLException e) {
throw DbException.convert(e);
}
......@@ -602,11 +603,7 @@ public class LobStorage {
PreparedStatement prep = prepare("UPDATE " + LOBS + " SET TABLE = ? WHERE ID = ?");
prep.setInt(1, table);
prep.setLong(2, lobId);
int updateCount = prep.executeUpdate();
if (updateCount != 1) {
// can be zero when recovering
// throw DbException.throwInternalError("count: " + updateCount);
}
prep.executeUpdate();
} catch (SQLException e) {
throw DbException.convert(e);
}
......
......@@ -100,10 +100,9 @@ public abstract class Page extends CacheObject {
* @return the (new) array
*/
@SuppressWarnings("unchecked")
public
static <T> T[] insert(T[] old, int oldSize, int pos, T x) {
public static <T> T[] insert(T[] old, int oldSize, int pos, T x) {
T[] result;
if (old != null && old.length > oldSize) {
if (old.length > oldSize) {
result = old;
} else {
// according to a test, this is as fast as "new Row[..]"
......@@ -112,7 +111,7 @@ public abstract class Page extends CacheObject {
System.arraycopy(old, 0, result, 0, pos);
}
}
if (old != null && oldSize - pos > 0) {
if (oldSize - pos > 0) {
System.arraycopy(old, pos, result, pos + 1, oldSize - pos);
}
result[pos] = x;
......
......@@ -115,7 +115,7 @@ public class PageStreamTrunk extends Page {
if (index >= pageIds.length) {
return -1;
}
return pageIds[index++];
return pageIds[index];
}
public void write() {
......
......@@ -107,7 +107,9 @@ public class CreateCluster extends Tool {
boolean exists = true;
try {
connTarget = DriverManager.getConnection(urlTarget + ";IFEXISTS=TRUE;CLUSTER=" + Constants.CLUSTERING_ENABLED, user, password);
connTarget.createStatement().execute("DROP ALL OBJECTS DELETE FILES");
Statement stat = connTarget.createStatement();
stat.execute("DROP ALL OBJECTS DELETE FILES");
stat.close();
exists = false;
connTarget.close();
} catch (SQLException e) {
......
......@@ -86,7 +86,7 @@ public class Recover extends Tool implements DataHandler {
/**
* Statistic data
*/
class Stats {
static class Stats {
/**
* The empty space in bytes in a data leaf pages.
......
......@@ -123,6 +123,7 @@ public class MathUtils {
}
} catch (Exception e) {
// nanoTime not found, this is ok (only exists for JDK 1.5 and higher)
out.writeUTF(e.toString());
}
// memory
......
......@@ -36,6 +36,7 @@ public class Compact {
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World');");
stat.close();
conn.close();
System.out.println("Compacting...");
compact("data", "test", "sa", "");
......
......@@ -53,6 +53,8 @@ public class DirectInsert {
prep.execute();
}
conn.commit();
prep.close();
stat.close();
conn.close();
}
......@@ -65,6 +67,7 @@ public class DirectInsert {
stat.execute("CREATE TABLE TEST2 AS SELECT * FROM TEST");
System.out.printf("%.3f sec.\n", (System.currentTimeMillis() - time) / 1000.0);
stat.execute("INSERT INTO TEST2 SELECT * FROM TEST2");
stat.close();
conn.close();
}
......
......@@ -40,6 +40,7 @@ public class FileFunctions {
rs.next();
String text = rs.getString(1);
System.out.println("text: " + text);
stat.close();
conn.close();
}
......
......@@ -51,14 +51,14 @@ public class Function {
PreparedStatement prep;
prep = conn.prepareStatement("SELECT * FROM TABLE(X INT=?, O INT=?) J " +
"INNER JOIN TEST T ON J.X=T.ID ORDER BY J.O");
prep.setObject(1,
new Integer[] { new Integer(30), new Integer(20) });
prep.setObject(2,
new Integer[] { new Integer(1), new Integer(2) });
prep.setObject(1, new Integer[] { 30, 20 });
prep.setObject(2, new Integer[] { 1, 2 });
rs = prep.executeQuery();
while (rs.next()) {
System.out.println(rs.getInt(1));
}
prep.close();
rs.close();
// Using a custom function like table
stat.execute("CREATE ALIAS MATRIX FOR \"org.h2.samples.Function.getMatrix\" ");
......@@ -69,7 +69,8 @@ public class Function {
while (rs.next()) {
System.out.println(rs.getInt(1) + "/" + rs.getInt(2));
}
prep.close();
stat.close();
conn.close();
}
......
......@@ -69,7 +69,7 @@ public class FunctionMultiReturn {
System.out.println("(r=" + r + " a=" + a + ") : (x=" + x + ", y=" + y + ")");
}
rs = conn.createStatement().executeQuery("SELECT R, A, ARRAY_GET(E, 1), ARRAY_GET(E, 2) FROM (SELECT R, A, P2C_A(R, A) E FROM TEST)");
rs = stat.executeQuery("SELECT R, A, ARRAY_GET(E, 1), ARRAY_GET(E, 2) FROM (SELECT R, A, P2C_A(R, A) E FROM TEST)");
while (rs.next()) {
double r = rs.getDouble(1);
double a = rs.getDouble(2);
......@@ -77,7 +77,9 @@ public class FunctionMultiReturn {
double y = rs.getDouble(4);
System.out.println("(r="+r+" a="+a+") : (x=" + x + ", y="+y+")");
}
rs.close();
prep.close();
conn.close();
}
......
......@@ -41,6 +41,7 @@ public class HelloWorld {
while (rs.next()) {
System.out.println(rs.getString("name"));
}
stat.close();
conn.close();
}
......
......@@ -42,6 +42,7 @@ public class InitDatabaseFromJar {
stat.execute("CREATE TABLE TEST(NAME VARCHAR)");
stat.execute("INSERT INTO TEST VALUES('Hello World')");
stat.execute("SCRIPT TO 'script.sql'");
stat.close();
conn.close();
}
......@@ -57,10 +58,13 @@ public class InitDatabaseFromJar {
+ getClass().getPackage().getName());
} else {
RunScript.execute(conn, new InputStreamReader(in));
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
while (rs.next()) {
System.out.println(rs.getString(1));
}
rs.close();
stat.close();
conn.close();
}
}
......
......@@ -212,6 +212,8 @@ public class SQLInjection {
} else {
System.out.println("Access denied!");
}
rs.close();
prep.close();
}
/**
......@@ -250,6 +252,8 @@ public class SQLInjection {
} else {
System.out.println("Access denied!");
}
rs.close();
prep.close();
} catch (SQLException e) {
System.out.println(e);
}
......@@ -274,6 +278,8 @@ public class SQLInjection {
} else {
System.out.println("Access denied!");
}
rs.close();
prep.close();
} catch (Exception e) {
System.out.println(e);
}
......@@ -364,9 +370,11 @@ public class SQLInjection {
while (rs.next()) {
System.out.println(rs.getString(1) + ": " + rs.getString(2));
}
rs.close();
} catch (Exception e) {
System.out.println(e);
}
prep.close();
}
/**
......@@ -402,7 +410,10 @@ public class SQLInjection {
System.out.println("salt: " + rs.getString("SALT"));
System.out.println("hash: " + rs.getString("HASH"));
}
rs.close();
prep.close();
stat.execute("SET ALLOW_LITERALS ALL");
stat.close();
}
/**
......
......@@ -56,11 +56,15 @@ public class SecurePassword {
prep = conn.prepareStatement("insert into account(name) values(?)");
prep.setString(1, "Joe");
prep.execute();
prep.close();
prep = conn.prepareStatement(
"update account set hash=hash('SHA256', stringtoutf8(salt||?), 10) where name=?");
prep.setString(1, "secret");
prep.setString(2, "Joe");
prep.execute();
prep.close();
prep = conn.prepareStatement(
"select * from account where name=? and hash=hash('SHA256', stringtoutf8(salt||?), 10)");
prep.setString(1, "Joe");
......@@ -69,6 +73,9 @@ public class SecurePassword {
while (rs.next()) {
System.out.println(rs.getString("name"));
}
rs.close();
prep.close();
stat.close();
conn.close();
}
......
......@@ -80,6 +80,8 @@ public class ShowProgress implements DatabaseEventListener {
conn = DriverManager.getConnection("jdbc:h2:test;DATABASE_EVENT_LISTENER='" + getClass().getName() + "'", "sa", "");
time = System.currentTimeMillis() - time;
System.out.println("Done after " + time + " ms");
prep.close();
stat.close();
conn.close();
}
......
......@@ -49,6 +49,7 @@ public class TriggerPassData implements Trigger {
stat.execute("INSERT INTO TEST VALUES(1)");
stat.execute("CALL TRIGGER_SET('T1', 'World')");
stat.execute("INSERT INTO TEST VALUES(2)");
stat.close();
conn.close();
}
......
......@@ -47,6 +47,8 @@ public class TriggerSample {
rs = stat.executeQuery("SELECT AMOUNT FROM INVOICE_SUM");
rs.next();
System.out.println("The sum is " + rs.getBigDecimal(1));
rs.close();
stat.close();
conn.close();
}
......
......@@ -1150,7 +1150,7 @@ public abstract class TestBase {
*/
protected void assertEquals(Integer expected, Integer actual) {
if (expected == null || actual == null) {
assertTrue(expected == actual);
assertTrue(expected == null && actual == null);
} else {
assertEquals(expected.intValue(), actual.intValue());
}
......@@ -1247,8 +1247,6 @@ public abstract class TestBase {
}
// silly code - makes sure there are no warnings
reserve[0] = reserve[1];
// actually it is anyway garbage collected
reserve = null;
}
/**
......
......@@ -404,7 +404,7 @@ class Database {
*/
void log(String action, String scale, int value) {
if (test.collect) {
results.add(new Object[] { action, scale, new Integer(value) });
results.add(new Object[] { action, scale, Integer.valueOf(value) });
}
}
......
......@@ -216,7 +216,7 @@ public class TestCluster extends TestBase {
// try to connect in standalone mode - should fail
try {
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:"+port1+"/test", user, password);
DriverManager.getConnection("jdbc:h2:tcp://localhost:"+port1+"/test", user, password);
fail("should not be able to connect in standalone mode");
} catch (SQLException e) {
assertKnownException(e);
......
......@@ -389,7 +389,7 @@ public class TestFullText extends TestBase {
conn = getConnection("fullText");
stat = conn.createStatement();
rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('World', 0, 0)");
stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('World', 0, 0)");
stat.execute("CALL " + prefix + "DROP_ALL()");
......
......@@ -380,7 +380,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals("Hello", rs.getString(2));
assertFalse(rs.next());
rs = stat.executeQuery("CALL ADD_ROW(2, 'World')");
stat.executeQuery("CALL ADD_ROW(2, 'World')");
stat.execute("CREATE ALIAS SELECT_F FOR \"" + getClass().getName() + ".select\"");
rs = stat.executeQuery("CALL SELECT_F('SELECT * FROM TEST ORDER BY ID')");
......@@ -631,7 +631,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
* @return the test array
*/
public static Object[] getArray() {
return new Object[] { new Integer(0), "Hello" };
return new Object[] { 0, "Hello" };
}
/**
......
......@@ -496,8 +496,8 @@ public class TestOptimizations extends TestBase {
} else {
int value = random.nextInt();
stat.execute("insert into test values(" + i + ", " + value + ")");
map.put(new Integer(i), new Integer(value));
set.add(new Integer(value));
map.put(i, value);
set.add(value);
}
break;
case 6:
......
......@@ -31,7 +31,8 @@ public class TestQueryCache extends TestBase {
Connection conn = getConnection("queryCache;QUERY_CACHE_SIZE=10");
Statement stat = conn.createStatement();
stat.execute("create table test(id int, name varchar) as select x, space(100) from system_range(1, 1000)");
PreparedStatement prep = conn.prepareStatement("select count(*) from test t1, test t2");
PreparedStatement prep;
conn.prepareStatement("select count(*) from test t1, test t2");
long time;
ResultSet rs;
long first = 0;
......@@ -42,7 +43,7 @@ public class TestQueryCache extends TestBase {
// stat.execute("drop table x");
time = System.currentTimeMillis();
prep = conn.prepareStatement("select count(*) from test t1, test t2");
rs = prep.executeQuery();
prep.executeQuery();
rs = stat.executeQuery("select count(*) from test t1, test t2");
rs.next();
int c = rs.getInt(1);
......
......@@ -29,7 +29,7 @@ public class TestRecursiveQueries extends TestBase {
public void test() throws Exception {
deleteDb("recursiveQueries");
Connection conn = getConnection("recursiveQueries");
Statement stat = conn.createStatement();
Statement stat;
PreparedStatement prep, prep2;
ResultSet rs;
......
......@@ -224,13 +224,13 @@ public class TestRights extends TestBase {
conn.close();
try {
conn = getConnection("rights", "Test", getPassword("abc"));
getConnection("rights", "Test", getPassword("abc"));
fail("mixed case user name");
} catch (SQLException e) {
assertKnownException(e);
}
try {
conn = getConnection("rights", "TEST", getPassword("abc"));
getConnection("rights", "TEST", getPassword("abc"));
fail("wrong password");
} catch (SQLException e) {
assertKnownException(e);
......
......@@ -146,7 +146,6 @@ public class TestTransaction extends TestBase {
if (!config.memory) {
conn.close();
conn = getConnection("transaction");
stat = conn.createStatement();
}
stat = conn.createStatement();
try {
......@@ -194,7 +193,6 @@ public class TestTransaction extends TestBase {
if (!config.memory) {
conn.close();
conn = getConnection("transaction");
stat = conn.createStatement();
}
stat = conn.createStatement();
try {
......
......@@ -56,7 +56,7 @@ public class UpdateTest extends TestBase {
Product p2 = new Product();
Product pChang2 = db.from(p2).where(p2.productName).is("Chang").selectFirst();
assertEquals(19.5, pChang2.unitPrice);
assertEquals(new Integer(16), pChang2.unitsInStock);
assertEquals(16, pChang2.unitsInStock.intValue());
// undo update
pChang.unitPrice = 19.0;
......@@ -90,7 +90,7 @@ public class UpdateTest extends TestBase {
Product p2 = new Product();
Product pChang2 = db.from(p2).where(p2.productName).is("Chang").selectFirst();
assertEquals(19.5, pChang2.unitPrice);
assertEquals(new Integer(16), pChang2.unitsInStock);
assertEquals(16, pChang2.unitsInStock.intValue());
// undo update
pChang.unitPrice = 19.0;
......
......@@ -400,12 +400,12 @@ public class TestPreparedStatement extends TestBase {
stat.execute("CREATE TABLE TEST(ID INT, DATA BINARY, JAVA OTHER)");
prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?, ?)");
prep.setInt(1, 1);
prep.setObject(2, new Integer(11));
prep.setObject(2, 11);
prep.setObject(3, null);
prep.execute();
prep.setInt(1, 2);
prep.setObject(2, new Integer(101), Types.OTHER);
prep.setObject(3, new Integer(103), Types.OTHER);
prep.setObject(2, 101, Types.OTHER);
prep.setObject(3, 103, Types.OTHER);
prep.execute();
PreparedStatement p2 = conn.prepareStatement("SELECT * FROM TEST ORDER BY ID");
ResultSet rs = p2.executeQuery();
......@@ -678,7 +678,7 @@ public class TestPreparedStatement extends TestBase {
// some databases don't allow calling setObject with null (no data type)
prep.executeUpdate();
prep.setInt(1, 9);
prep.setObject(2, new Integer(-4), Types.VARCHAR);
prep.setObject(2, -4, Types.VARCHAR);
prep.executeUpdate();
prep.setInt(1, 10);
prep.setObject(2, "5", Types.INTEGER);
......@@ -797,7 +797,7 @@ public class TestPreparedStatement extends TestBase {
assertTrue(rs.getObject(1).equals(new Boolean(true)));
assertTrue(rs.getObject(2).equals("Abc"));
assertTrue(rs.getObject(3).equals(new BigDecimal("10.2")));
assertTrue(rs.getObject(4).equals(new Byte((byte) 0xff)));
assertTrue(rs.getObject(4).equals((byte) 0xff));
assertTrue(rs.getObject(5).equals(new Short(Short.MAX_VALUE)));
assertTrue(rs.getObject(6).equals(new Integer(Integer.MIN_VALUE)));
assertTrue(rs.getObject(7).equals(new Long(Long.MAX_VALUE)));
......@@ -809,7 +809,7 @@ public class TestPreparedStatement extends TestBase {
assertTrue(rs.getObject(12).equals(java.sql.Timestamp.valueOf("2001-02-03 04:05:06.123456789")));
assertTrue(rs.getObject(13).equals(java.sql.Timestamp.valueOf("2001-02-03 00:00:00")));
assertEquals(new byte[] { 10, 20, 30 }, (byte[]) rs.getObject(14));
assertTrue(rs.getObject(15).equals(new Character('a')));
assertTrue(rs.getObject(15).equals('a'));
assertTrue(rs.getObject(16).equals(java.sql.Date.valueOf("2001-01-02")));
assertTrue(rs.getObject(17) == null && rs.wasNull());
assertTrue(rs.getObject(18).equals(new Double(3.725)));
......
......@@ -1066,8 +1066,9 @@ public class TestResultSet extends TestBase {
prep.setObject(2, new Object[] { new Integer(1), new Integer(2) });
prep.execute();
prep.setInt(1, 2);
prep.setObject(2, new Object[] { new Integer(11), new Integer(12) });
prep.setObject(2, new Object[] { 11, 12 });
prep.execute();
prep.close();
rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
rs.next();
assertEquals(1, rs.getInt(1));
......
......@@ -275,7 +275,7 @@ public class TestUpdatableResultSet extends TestBase {
rs.updateDouble("DB", 1.725);
rs.updateFloat("R", (float) 2.5);
rs.updateLong("L", Long.MAX_VALUE);
rs.updateObject("O_I", new Integer(10));
rs.updateObject("O_I", 10);
rs.updateShort("SH", Short.MIN_VALUE);
// auml, ouml, uuml
rs.updateCharacterStream("CL", new StringReader("\u00ef\u00f6\u00fc"), 0);
......
......@@ -85,6 +85,7 @@ public class TestCrashAPI extends TestBase implements Runnable {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
maxWait++;
// ignore
}
}
......@@ -409,17 +410,17 @@ public class TestCrashAPI extends TestBase implements Runnable {
private Object getRandomParam(Class<?> type) {
if (type == int.class) {
return new Integer(random.getRandomInt());
return random.getRandomInt();
} else if (type == byte.class) {
return new Byte((byte) random.getRandomInt());
return (byte) random.getRandomInt();
} else if (type == short.class) {
return new Short((short) random.getRandomInt());
return (short) random.getRandomInt();
} else if (type == long.class) {
return new Long(random.getRandomLong());
return random.getRandomLong();
} else if (type == float.class) {
return new Float(random.getRandomDouble());
return (float) random.getRandomDouble();
} else if (type == boolean.class) {
return new Boolean(random.nextBoolean());
return random.nextBoolean();
} else if (type == double.class) {
return new Double(random.getRandomDouble());
} else if (type == String.class) {
......
......@@ -141,7 +141,7 @@ public class TestJoin extends TestBase {
String sql = buff.toString();
Object[] params = new Object[paramCount];
for (int j = 0; j < paramCount; j++) {
params[j] = random.nextInt(4) == 1 ? null : new Integer(random.nextInt(10) - 3);
params[j] = random.nextInt(4) == 1 ? null : random.nextInt(10) - 3;
}
try {
execute(sql, params);
......
......@@ -79,11 +79,11 @@ public class Value {
}
private static Double randomDouble(TestSynth config) {
return new Double(config.random().getInt(100) / 10.);
return config.random().getInt(100) / 10.;
}
private static Long randomLong(TestSynth config) {
return new Long(config.random().getInt(1000));
return Long.valueOf(config.random().getInt(1000));
}
private static Time randomTime(TestSynth config) {
......@@ -147,10 +147,10 @@ public class Value {
switch (type) {
case Types.REAL:
case Types.DOUBLE:
data = new Double(rs.getDouble(index));
data = rs.getDouble(index);
break;
case Types.BIGINT:
data = new Long(rs.getLong(index));
data = rs.getLong(index);
break;
case Types.DECIMAL:
case Types.NUMERIC:
......@@ -179,7 +179,7 @@ public class Value {
data = rs.getTimestamp(index);
break;
case Types.INTEGER:
data = new Integer(rs.getInt(index));
data = rs.getInt(index);
break;
case Types.NULL:
data = null;
......@@ -260,7 +260,7 @@ public class Value {
} else {
value = config.random().getRandomInt();
}
return new Integer(value);
return value;
}
private static byte[] randomBytes(TestSynth config, int max) {
......
--- special grammar and test cases ---------------------------------------------------------------------------------------------
create table test(d date, t time, ts timestamp);
> ok
insert into test values(date '2001-01-01', time '01:00:00', timestamp '2010-01-01 00:00:00');
> update count: 1
select ts + t x from test;
> X
> ---------------------
> 2010-01-01 01:00:00.0
> rows: 1
select ts + t + t - t x from test;
> X
> ---------------------
> 2010-01-01 01:00:00.0
> rows: 1
select ts + 0.5 * t + t - t x from test;
> X
> ---------------------
> 2010-01-01 00:30:00.0
> rows: 1
select ts + t / 0.5 x from test;
> X
> ---------------------
> 2010-01-01 02:00:00.0
> rows: 1
select d + t, t + d - t x from test;
> T + D X
> --------------------- ---------------------
> 2001-01-01 01:00:00.0 2001-01-01 00:00:00.0
> rows: 1
select 1 + d + 1, d - 1, 2 + ts + 2, ts - 2 from test;
> DATEADD('DAY', 1, DATEADD('DAY', 1, D)) DATEADD('DAY', -1, D) DATEADD('DAY', 2, DATEADD('DAY', 2, TS)) DATEADD('DAY', -2, TS)
> --------------------------------------- --------------------- ---------------------------------------- ----------------------
> 2001-01-03 00:00:00.0 2000-12-31 00:00:00.0 2010-01-05 00:00:00.0 2009-12-30 00:00:00.0
> rows: 1
select 1 + d + t + 1 from test;
> DATEADD('DAY', 1, (T + DATEADD('DAY', 1, D)))
> ---------------------------------------------
> 2001-01-03 01:00:00.0
> rows: 1
select ts - t - 2 from test;
> DATEADD('DAY', -2, (TS - T))
> ----------------------------
> 2009-12-29 23:00:00.0
> rows: 1
drop table test;
> ok
create table test(id int primary key);
> ok
......
......@@ -183,16 +183,16 @@ class Parser {
} else if (tokenType == NUMBER) {
String number = readToken().toLowerCase();
if (number.endsWith("f")) {
Float v = new Float(Float.parseFloat(number));
Float v = Float.parseFloat(number);
return new Arg(float.class, v);
} else if (number.endsWith("d") || number.indexOf("e") >= 0 || number.indexOf(".") >= 0) {
Double v = new Double(Double.parseDouble(number));
Double v = Double.parseDouble(number);
return new Arg(double.class, v);
} else if (number.endsWith("L") || number.endsWith("l")) {
Long v = new Long(Long.parseLong(number.substring(0, number.length() - 1)));
Long v = Long.parseLong(number.substring(0, number.length() - 1));
return new Arg(long.class, v);
} else {
Integer v = new Integer(Integer.parseInt(number));
Integer v = Integer.parseInt(number);
return new Arg(int.class, v);
}
} else if (tokenType == NAME) {
......@@ -241,7 +241,7 @@ class Parser {
read("short");
read(")");
String number = readToken();
return new Arg(short.class, new Short(Short.parseShort(number)));
return new Arg(short.class, Short.parseShort(number));
} else {
throw new RuntimeException("Value expected, got: " + readToken() + " in "
+ line);
......
......@@ -110,6 +110,7 @@ public class Player {
}
runLine(line.trim());
}
reader.close();
}
/**
......
......@@ -115,7 +115,7 @@ public class TestCache extends TestBase implements CacheWriter {
/**
* A simple cache object
*/
class Obj extends CacheObject {
static class Obj extends CacheObject {
Obj(int pos) {
setPos(pos);
......
......@@ -101,7 +101,6 @@ public class TestJmx extends TestBase {
conn.close();
conn = getConnection("jmx;jmx=true");
stat = conn.createStatement();
name = new ObjectName("org.h2:name=JMX,*");
Set<ObjectName> set = mbeanServer.queryNames(name, null);
......
......@@ -89,7 +89,7 @@ public class TestNetUtils extends TestBase {
/**
* A worker thread to test connecting.
*/
private class ConnectWorker extends Thread {
private static class ConnectWorker extends Thread {
private final boolean ssl;
private final AtomicInteger counter;
......
......@@ -49,7 +49,7 @@ public class TestOldVersion extends TestBase {
Server server = org.h2.tools.Server.createTcpServer("-tcpPort", "9001");
server.start();
try {
conn = driver.connect("jdbc:h2:tcp://localhost:9001/mem:test", null);
driver.connect("jdbc:h2:tcp://localhost:9001/mem:test", null);
} catch (SQLException e) {
assertEquals(ErrorCode.DRIVER_VERSION_ERROR_2, e.getErrorCode());
}
......
......@@ -715,7 +715,7 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
Random random = new Random(seed);
for (int i = 0; i < len; i++) {
int op = random.nextInt(3);
Integer x = new Integer(random.nextInt(100));
Integer x = random.nextInt(100);
switch (op) {
case 0:
if (!rows.contains(x)) {
......
......@@ -247,6 +247,7 @@ public class TestPageStoreCoverage extends TestBase {
f.setFileLength(16);
// create a new database
conn = getConnection("pageStore");
conn.close();
deleteDb("pageStore");
}
......
......@@ -153,7 +153,8 @@ public class TestReopen extends TestBase implements Recorder {
database.removeSession(null);
} catch (Exception e) {
int errorCode = 0;
if (e instanceof SQLException) {
if (e instanceof DbException) {
e = ((DbException) e).getSQLException();
errorCode = ((SQLException) e).getErrorCode();
}
if (errorCode == ErrorCode.WRONG_USER_OR_PASSWORD) {
......
......@@ -668,7 +668,7 @@ public class TestTools extends TestBase {
"-baseDir", getBaseDir(),
"-tcpPort", "9192").start();
try {
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9192/test2", "sa", "");
DriverManager.getConnection("jdbc:h2:tcp://localhost:9192/test2", "sa", "");
fail("should not be able to create new db");
} catch (SQLException e) {
assertKnownException(e);
......@@ -707,7 +707,7 @@ public class TestTools extends TestBase {
conn.close();
try {
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9192/../test", "sa", "");
DriverManager.getConnection("jdbc:h2:tcp://localhost:9192/../test", "sa", "");
fail("Should throw an exception!");
} catch (Throwable e) {
// Expected
......
......@@ -220,10 +220,10 @@ public class BuildBase {
} catch (IOException e) {
throw new RuntimeException(e);
}
if (line.length() == 0) {
line = last;
} else if (line.equals("exit") || line.equals("quit")) {
if (line == null || line.equals("exit") || line.equals("quit")) {
break;
} else if (line.length() == 0) {
line = last;
}
long time = System.currentTimeMillis();
try {
......
......@@ -17,7 +17,7 @@ public class Function implements Token {
//## Java 1.5 begin ##
// must be a new instance
private static final Long COUNT_STAR = new Long(0);
private static final Long COUNT_STAR = Long.valueOf(0);
protected Object[] x;
private String name;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论