提交 e857a250 authored 作者: Thomas Mueller's avatar Thomas Mueller

Cleanup:

- Let it compile with JDK 5
上级 dd7cdf0d
......@@ -14,6 +14,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
......@@ -27,6 +28,7 @@ import org.h2.jaqu.util.JdbcUtils;
import org.h2.jaqu.util.StringUtils;
import org.h2.jaqu.util.Utils;
import org.h2.jaqu.util.WeakIdentityHashMap;
//## Java 1.5 end ##
/**
* This class represents a connection to a database.
......@@ -48,7 +50,9 @@ public class Db {
Utils.newHashMap();
private final SQLDialect dialect;
private DbUpgrader dbUpgrader = new DefaultDbUpgrader();
private final Set<Class<?>> upgradeChecked = Utils.newConcurrentHashSet();
private final Set<Class<?>> upgradeChecked = Collections.synchronizedSet(new HashSet<Class<?>>());
private int todoDocumentNewFeaturesInHtmlFile;
public Db(Connection conn) {
this.conn = conn;
......@@ -56,6 +60,7 @@ public class Db {
}
SQLDialect getDialect(String clazz) {
int todo;
// TODO add special cases here
return new DefaultSQLDialect();
}
......@@ -119,6 +124,7 @@ public class Db {
public <T> void insert(T t) {
Class<?> clazz = t.getClass();
int upgradeDbSoundsWrongHere;
upgradeDb().define(clazz).createTableIfRequired(this).insert(this, t, false);
}
......@@ -295,10 +301,11 @@ public class Db {
}
}
PreparedStatement prepare(String sql, boolean returnKey) {
PreparedStatement prepare(String sql, boolean returnGeneratedKeys) {
try {
if (returnKey)
return conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
if (returnGeneratedKeys) {
return conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
}
return conn.prepareStatement(sql);
} catch (SQLException e) {
throw new RuntimeException(e);
......
......@@ -21,10 +21,10 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.h2.jaqu.Db;
import org.h2.jaqu.DbInspector;
import org.h2.message.DbException;
/**
* Generates JaQu models.
*
*/
public class GenerateModels {
......@@ -130,10 +130,8 @@ public class GenerateModels {
System.out.println("Generated " + classFile.getAbsolutePath());
}
}
} catch (SQLException s) {
throw s;
} catch (IOException i) {
throw new SQLException(i);
} catch (IOException io) {
throw DbException.convertIOException(io, "could not generate model").getSQLException();
} finally {
JdbcUtils.closeSilently(conn);
}
......
......@@ -22,8 +22,6 @@ import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
//## Java 1.5 end ##
......@@ -55,10 +53,6 @@ public class Utils {
return new HashSet<T>(list);
}
public static <T> Set<T> newConcurrentHashSet() {
return Collections.newSetFromMap(new ConcurrentHashMap<T, Boolean>());
}
public static <A, B> HashMap<A, B> newHashMap() {
return new HashMap<A, B>();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论