提交 4ddb2248 authored 作者: Thomas Mueller's avatar Thomas Mueller

Require Java 1.5 compiler

上级 c1394475
......@@ -596,7 +596,7 @@ kill -9 `jps -l | grep "org.h2.test.TestAll" | cut -d " " -f 1`
private void runTest(String className) {
try {
Class clazz = Class.forName(className);
Class< ? > clazz = Class.forName(className);
TestBase test = (TestBase) clazz.newInstance();
test.runTest(this);
} catch (Exception e) {
......
......@@ -1009,8 +1009,8 @@ public abstract class TestBase {
protected void assertEqualDatabases(Statement stat1, Statement stat2) throws SQLException {
ResultSet rs1 = stat1.executeQuery("SCRIPT NOPASSWORDS");
ResultSet rs2 = stat2.executeQuery("SCRIPT NOPASSWORDS");
ArrayList list1 = new ArrayList();
ArrayList list2 = new ArrayList();
ArrayList<String> list1 = new ArrayList<String>();
ArrayList<String> list2 = new ArrayList<String>();
while (rs1.next()) {
String s1 = rs1.getString(1);
list1.add(s1);
......@@ -1021,7 +1021,7 @@ public abstract class TestBase {
list2.add(s2);
}
for (int i = 0; i < list1.size(); i++) {
String s = (String) list1.get(i);
String s = list1.get(i);
if (!list2.remove(s)) {
fail("only found in first: " + s);
}
......
......@@ -52,8 +52,8 @@ public class BenchA implements Bench {
"CREATE TABLE ACCOUNTS(AID INT NOT NULL PRIMARY KEY, BID INT, ABALANCE DECIMAL(15,2), FILLER VARCHAR(84))",
"CREATE TABLE HISTORY(TID INT, BID INT, AID INT, DELTA DECIMAL(15,2), HTIME DATETIME, FILLER VARCHAR(40))" };
for (int i = 0; i < create.length; i++) {
db.update(create[i]);
for (String sql : create) {
db.update(sql);
}
PreparedStatement prep;
......
......@@ -75,8 +75,8 @@ public class BenchB implements Bench, Runnable {
"CREATE TABLE TELLERS(TID INT NOT NULL PRIMARY KEY, BID INT, TBALANCE INT, FILLER VARCHAR(84))",
"CREATE TABLE ACCOUNTS(AID INT NOT NULL PRIMARY KEY, BID INT, ABALANCE INT, FILLER VARCHAR(84))",
"CREATE TABLE HISTORY(TID INT, BID INT, AID INT, DELTA INT, TIME DATETIME, FILLER VARCHAR(22))" };
for (int i = 0; i < create.length; i++) {
db.update(create[i]);
for (String sql : create) {
db.update(sql);
}
PreparedStatement prep;
db.setAutoCommit(false);
......@@ -197,11 +197,11 @@ public class BenchB implements Bench, Runnable {
for (int i = 0; i < clients; i++) {
threads[i] = new Thread(new BenchB(this, i));
}
for (int i = 0; i < clients; i++) {
threads[i].start();
for (Thread t : threads) {
t.start();
}
for (int i = 0; i < clients; i++) {
threads[i].join();
for (Thread t : threads) {
t.join();
}
}
......
......@@ -129,11 +129,11 @@ public class BenchC implements Bench {
}
private void load() throws SQLException {
for (int i = 0; i < TABLES.length; i++) {
db.dropTable(TABLES[i]);
for (String sql : TABLES) {
db.dropTable(sql);
}
for (int i = 0; i < CREATE_SQL.length; i++) {
db.update(CREATE_SQL[i]);
for (String sql : CREATE_SQL) {
db.update(sql);
}
db.setAutoCommit(false);
loadItem();
......
......@@ -26,7 +26,7 @@ public class BenchCThread {
private Database db;
private int warehouseId;
private int terminalId;
private HashMap prepared = new HashMap();
private HashMap<String, PreparedStatement> prepared = new HashMap<String, PreparedStatement>();
private BenchCRandom random;
private BenchC bench;
......@@ -57,8 +57,7 @@ public class BenchCThread {
deck[i] = deck[j];
deck[j] = temp;
}
for (int i = 0; i < len; i++) {
int op = deck[i];
for (int op : deck) {
switch (op) {
case OP_NEW_ORDER:
processNewOrder();
......@@ -726,7 +725,7 @@ public class BenchCThread {
}
private PreparedStatement prepare(String sql) throws SQLException {
PreparedStatement prep = (PreparedStatement) prepared.get(sql);
PreparedStatement prep = prepared.get(sql);
if (prep == null) {
prep = db.prepare(sql);
prepared.put(sql, prep);
......
......@@ -16,7 +16,6 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;
import java.util.Random;
import java.util.StringTokenizer;
......@@ -34,7 +33,7 @@ class Database {
private TestPerformance test;
private int id;
private String name, url, user, password;
private ArrayList replace = new ArrayList();
private ArrayList<String[]> replace = new ArrayList<String[]>();
private String action;
private long startTime;
private Connection conn;
......@@ -42,7 +41,7 @@ class Database {
private boolean trace = true;
private long lastTrace;
private Random random = new Random(1);
private ArrayList results = new ArrayList();
private ArrayList<Object[]> results = new ArrayList<Object[]>();
private int totalTime;
private int executedStatements;
......@@ -73,7 +72,7 @@ class Database {
*
* @return the result array
*/
ArrayList getResults() {
ArrayList<Object[]> getResults() {
return results;
}
......@@ -102,7 +101,7 @@ class Database {
Thread.sleep(100);
} else if (url.startsWith("jdbc:hsqldb:hsql:")) {
if (!serverHSQLDB) {
Class c = Class.forName("org.hsqldb.Server");
Class< ? > c = Class.forName("org.hsqldb.Server");
Method m = c.getMethod("main", new Class[] { String[].class });
m.invoke(null, new Object[] { new String[] { "-database.0",
"data/mydb;hsqldb.default_table_type=cached", "-dbname.0", "xdb" } });
......@@ -239,8 +238,8 @@ class Database {
void setTranslations(Properties prop) {
String id = url.substring("jdbc:".length());
id = id.substring(0, id.indexOf(':'));
for (Iterator it = prop.keySet().iterator(); it.hasNext();) {
String key = (String) it.next();
for (Object k : prop.keySet()) {
String key = (String) k;
if (key.startsWith(id + ".")) {
String pattern = key.substring(id.length() + 1);
pattern = StringUtils.replaceAll(pattern, "_", " ");
......@@ -263,8 +262,7 @@ class Database {
}
private String getSQL(String sql) {
for (int i = 0; i < replace.size(); i++) {
String[] pair = (String[]) replace.get(i);
for (String[] pair : replace) {
String pattern = pair[0];
String replace = pair[1];
sql = StringUtils.replaceAll(sql, pattern, replace);
......
......@@ -94,7 +94,7 @@ public class TestPerformance {
prop.load(in);
in.close();
int size = Integer.parseInt(prop.getProperty("size"));
ArrayList dbs = new ArrayList();
ArrayList<Database> dbs = new ArrayList<Database>();
for (int i = 0; i < 100; i++) {
if (dbId != -1 && i != dbId) {
continue;
......@@ -108,7 +108,7 @@ public class TestPerformance {
}
}
}
ArrayList tests = new ArrayList();
ArrayList<Bench> tests = new ArrayList<Bench>();
for (int i = 0; i < 100; i++) {
String testString = prop.getProperty("test" + i);
if (testString != null) {
......@@ -121,7 +121,7 @@ public class TestPerformance {
if (dbs.size() == 0) {
return;
}
ArrayList results = ((Database) dbs.get(0)).getResults();
ArrayList<Object[]> results = dbs.get(0).getResults();
Connection conn = null;
PreparedStatement prep = null;
Statement stat = null;
......@@ -133,16 +133,14 @@ public class TestPerformance {
prep = conn
.prepareStatement("INSERT INTO RESULTS(TESTID, TEST, UNIT, DBID, DB, RESULT) VALUES(?, ?, ?, ?, ?, ?)");
for (int i = 0; i < results.size(); i++) {
Object[] res = (Object[]) results.get(i);
Object[] res = results.get(i);
prep.setInt(1, i);
prep.setString(2, res[0].toString());
prep.setString(3, res[1].toString());
for (int j = 0; j < dbs.size(); j++) {
Database db = (Database) dbs.get(j);
for (Database db : dbs) {
prep.setInt(4, db.getId());
prep.setString(5, db.getName());
ArrayList r = db.getResults();
Object[] v = (Object[]) r.get(i);
Object[] v = db.getResults().get(i);
prep.setString(6, v[2].toString());
prep.execute();
}
......@@ -215,14 +213,14 @@ public class TestPerformance {
}
}
private void testAll(ArrayList dbs, ArrayList tests, int size) throws Exception {
private void testAll(ArrayList<Database> dbs, ArrayList<Bench> tests, int size) throws Exception {
for (int i = 0; i < dbs.size(); i++) {
if (i > 0) {
Thread.sleep(1000);
}
// calls garbage collection
TestBase.getMemoryUsed();
Database db = (Database) dbs.get(i);
Database db = dbs.get(i);
System.out.println("Testing the performance of " + db.getName());
db.startServer();
Connection conn = db.openNewConnection();
......@@ -243,9 +241,8 @@ public class TestPerformance {
}
}
private void runDatabase(Database db, ArrayList tests, int size) throws Exception {
for (int j = 0; j < tests.size(); j++) {
Bench bench = (Bench) tests.get(j);
private void runDatabase(Database db, ArrayList<Bench> tests, int size) throws Exception {
for (Bench bench : tests) {
runTest(db, bench, size);
}
}
......
......@@ -479,7 +479,7 @@ public class Coverage {
}
}
private void setLine() throws IOException {
private void setLine() {
add += "Profile.visit(" + index + ");";
line = tokenizer.getLine();
}
......
......@@ -17,6 +17,7 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.h2.util.JdbcDriverUtils;
......@@ -33,7 +34,7 @@ public class Db {
private Connection conn;
private Statement stat;
private HashMap prepared = new HashMap();
private HashMap<String, PreparedStatement> prepared = new HashMap<String, PreparedStatement>();
/**
* Create a database object using the given connection.
......@@ -75,7 +76,7 @@ public class Db {
*/
public Prepared prepare(String sql) {
try {
PreparedStatement prep = (PreparedStatement) prepared.get(sql);
PreparedStatement prep = prepared.get(sql);
if (prep == null) {
prep = conn.prepareStatement(sql);
prepared.put(sql, prep);
......@@ -105,12 +106,12 @@ public class Db {
* @param rs the result set
* @return a list of maps
*/
static List query(ResultSet rs) throws SQLException {
List list = new ArrayList();
static List<Map<String, Object>> query(ResultSet rs) throws SQLException {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
ResultSetMetaData meta = rs.getMetaData();
int columnCount = meta.getColumnCount();
while (rs.next()) {
HashMap map = new HashMap();
HashMap<String, Object> map = new HashMap<String, Object>();
for (int i = 0; i < columnCount; i++) {
map.put(meta.getColumnLabel(i+1), rs.getObject(i+1));
}
......@@ -125,7 +126,7 @@ public class Db {
* @param sql the SQL statement
* @return a list of maps
*/
public List query(String sql) {
public List<Map<String, Object>> query(String sql) {
try {
return query(stat.executeQuery(sql));
} catch (SQLException e) {
......@@ -231,7 +232,7 @@ public class Db {
*
* @return the result list
*/
public List query() {
public List<Map<String, Object>> query() {
try {
return Db.query(prep.executeQuery());
} catch (SQLException e) {
......
......@@ -47,7 +47,7 @@ public class TaskProcess {
public void start(String[] args) {
try {
String selfDestruct = SelfDestructor.getPropertyString(60);
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<String>();
list.add("java");
list.add(selfDestruct);
list.add("-cp");
......
......@@ -123,7 +123,7 @@ public class TestCases extends TestBase {
conn.close();
}
private void testInvalidDatabaseName() throws SQLException {
private void testInvalidDatabaseName() {
if (config.memory) {
return;
}
......
......@@ -625,11 +625,11 @@ public class TestFunctions extends TestBase implements AggregateFunction {
}
//## Java 1.5 end ##
public void add(Object value) throws SQLException {
public void add(Object value) {
// ignore
}
public Object getResult() throws SQLException {
public Object getResult() {
return new BigDecimal("1.6");
}
......@@ -640,7 +640,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
return Types.DECIMAL;
}
public void init(Connection conn) throws SQLException {
public void init(Connection conn) {
// ignore
}
......
......@@ -76,7 +76,7 @@ public class TestLogFile extends TestBase {
deleteDb("logfile");
}
private void checkLogSize() throws SQLException {
private void checkLogSize() {
String[] files = new File(".").list();
for (int j = 0; j < files.length; j++) {
String name = files[j];
......
......@@ -275,7 +275,7 @@ public class TestRights extends TestBase {
executeSuccess("DROP TABLE TEST");
}
private void executeError(String sql) throws SQLException {
private void executeError(String sql) {
try {
stat.execute(sql);
fail("not admin");
......
......@@ -302,7 +302,7 @@ public class TestScript extends TestBase {
writeResult((ordered ? "rows (ordered): " : "rows: ") + i, null);
}
private String format(String[] row, int[] max) throws SQLException {
private String format(String[] row, int[] max) {
int length = max.length;
StringBuffer buff = new StringBuffer();
for (int i = 0; i < length; i++) {
......
......@@ -73,8 +73,8 @@ public class TestBatchUpdates extends TestBase {
call.addBatch();
int[] updateCounts = call.executeBatch();
int total = 0;
for (int i = 0; i < updateCounts.length; i++) {
total += updateCounts[i];
for (int t : updateCounts) {
total += t;
}
assertEquals(4, total);
conn.close();
......
......@@ -207,7 +207,7 @@ public class TestNativeSQL extends TestBase {
}
}
private void testPairs() throws SQLException {
private void testPairs() {
for (int i = 0; i < PAIRS.length; i += 2) {
test(conn, PAIRS[i], PAIRS[i + 1]);
}
......@@ -241,7 +241,7 @@ public class TestNativeSQL extends TestBase {
assertFalse(conn.isClosed());
}
private void test(Connection conn, String original, String expected) throws SQLException {
private void test(Connection conn, String original, String expected) {
trace("original: <" + original + ">");
trace("expected: <" + expected + ">");
try {
......
......@@ -778,7 +778,7 @@ public class TestPreparedStatement extends TestBase {
stat.execute("DROP TABLE TEST");
}
private int getLength() throws SQLException {
private int getLength() {
return getSize(LOB_SIZE, LOB_SIZE_BIG);
}
......
......@@ -1019,7 +1019,7 @@ public class TestResultSet extends TestBase {
stat.execute("DROP TABLE TEST");
}
private byte[] readAllBytes(InputStream in) throws SQLException {
private byte[] readAllBytes(InputStream in) {
if (in == null) {
return null;
}
......@@ -1039,7 +1039,7 @@ public class TestResultSet extends TestBase {
}
}
private void checkBytes(byte[] test, byte[] good) throws SQLException {
private void checkBytes(byte[] test, byte[] good) {
if (test == null || good == null) {
assertTrue(test == good);
} else {
......
......@@ -126,7 +126,7 @@ public class TestConnectionPool extends TestBase {
man.dispose();
}
private JdbcConnectionPool getConnectionPool(int poolSize) throws SQLException {
private JdbcConnectionPool getConnectionPool(int poolSize) {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL(getURL("connectionPool", true));
ds.setUser(getUser());
......
......@@ -188,7 +188,7 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener
// ignore
}
public void diskSpaceIsLow(long stillAvailable) throws SQLException {
public void diskSpaceIsLow(long stillAvailable) {
// ignore
}
......
......@@ -246,7 +246,7 @@ public class TestCrashAPI extends TestBase {
" " + t.getMessage(), t);
}
private Object callRandom(int seed, int id, int objectId, Object o, Method m) throws SQLException {
private Object callRandom(int seed, int id, int objectId, Object o, Method m) {
Class[] paramClasses = m.getParameterTypes();
Object[] params = new Object[paramClasses.length];
for (int i = 0; i < params.length; i++) {
......
......@@ -7,10 +7,8 @@
package org.h2.test.synth;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Random;
import org.h2.constant.SysProperties;
import org.h2.test.TestBase;
import org.h2.test.db.Db;
......@@ -42,7 +40,7 @@ public class TestFuzzOptimizations extends TestBase {
deleteDb("optimizations");
}
private void testInSelect() throws SQLException {
private void testInSelect() {
boolean old = SysProperties.optimizeInJoin;
Db db = new Db(conn);
db.execute("CREATE TABLE TEST(A INT, B INT)");
......@@ -72,7 +70,7 @@ public class TestFuzzOptimizations extends TestBase {
SysProperties.optimizeInJoin = old;
}
private void testGroupSorted() throws SQLException {
private void testGroupSorted() {
Db db = new Db(conn);
db.execute("CREATE TABLE TEST(A INT, B INT, C INT)");
Random random = new Random();
......
......@@ -123,7 +123,7 @@ public abstract class TestHalt extends TestBase {
*/
abstract void processAppRun() throws SQLException;
public void test() throws SQLException {
public void test() {
for (int i = 0;; i++) {
operations = OP_INSERT | i;
flags = i >> 4;
......
......@@ -235,11 +235,11 @@ public class TestJoin extends TestBase {
buff.append(" ");
}
private void execute(String sql, Object[] params) throws SQLException {
private void execute(String sql, Object[] params) {
execute(sql, params, false);
}
private void execute(String sql, Object[] params, boolean ignoreDifference) throws SQLException {
private void execute(String sql, Object[] params, boolean ignoreDifference) {
String first = null;
for (int i = 0; i < connections.size(); i++) {
Connection conn = (Connection) connections.get(i);
......
......@@ -9,10 +9,8 @@ package org.h2.test.synth;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Random;
import org.h2.store.FileLister;
import org.h2.test.TestBase;
import org.h2.test.unit.SelfDestructor;
......@@ -31,7 +29,7 @@ public class TestKillProcess {
*
* @param args the command line parameters
*/
public static void main(String[] args) throws SQLException {
public static void main(String[] args) {
SelfDestructor.startCountdown(60);
try {
Class.forName("org.h2.Driver");
......
......@@ -11,10 +11,8 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Random;
import org.h2.test.TestBase;
import org.h2.test.unit.SelfDestructor;
......@@ -72,7 +70,7 @@ public class TestKillRestart extends TestBase {
*
* @param args the command line parameters
*/
public static void main(String[] args) throws SQLException {
public static void main(String[] args) {
SelfDestructor.startCountdown(60);
String driver = "org.h2.Driver";
String url = "jdbc:h2:test", user = "sa", password = "sa";
......
......@@ -122,12 +122,12 @@ public class TestKillRestartMulti extends TestBase {
*
* @param args the command line parameters
*/
public static void main(String[] args) throws SQLException {
public static void main(String[] args) {
SelfDestructor.startCountdown(60);
new TestKillRestartMulti().test(args);
}
private void test(String[] args) throws SQLException {
private void test(String[] args) {
for (int i = 0; i < args.length; i++) {
if ("-url".equals(args[i])) {
url = args[++i];
......
......@@ -77,7 +77,7 @@ public class TestMultiNews extends TestMultiThread {
conn.close();
}
void finalTest() throws SQLException {
void finalTest() {
// nothing to do
}
......
......@@ -115,7 +115,7 @@ public class TestFileSystem extends TestBase {
conn.close();
}
private void testUserHome() throws SQLException {
private void testUserHome() {
FileSystem fs = FileSystem.getInstance("~/test");
String fileName = fs.getAbsolutePath("~/test");
String userDir = System.getProperty("user.home");
......
......@@ -7,7 +7,6 @@
package org.h2.test.unit;
import java.math.BigInteger;
import java.sql.SQLException;
import org.h2.test.TestBase;
/**
......@@ -24,7 +23,7 @@ public class TestMathUtils extends TestBase {
TestBase.createCaller().init().test();
}
public void test() throws SQLException {
public void test() {
testFactorial();
}
......
......@@ -90,7 +90,7 @@ public class TestOverflow extends TestBase {
}
}
private void testValues(Value va, Value vb) throws SQLException {
private void testValues(Value va, Value vb) {
BigInteger a = new BigInteger(va.getString());
BigInteger b = new BigInteger(vb.getString());
successExpected = inRange(a.negate());
......
......@@ -155,7 +155,7 @@ public class TestTools extends TestBase {
}
}
private String runServer(String[] args, int exitCode) throws SQLException {
private String runServer(String[] args, int exitCode) {
ByteArrayOutputStream buff = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(buff);
server = new Server();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论