提交 113996ea authored 作者: Thomas Mueller's avatar Thomas Mueller

Cleanup:

- Javadocs
- Work in progress
上级 daa2b0bf
......@@ -19,7 +19,6 @@ import org.h2.jaqu.bytecode.ClassReader;
import org.h2.jaqu.util.StatementLogger;
import org.h2.jaqu.util.JdbcUtils;
import org.h2.jaqu.util.Utils;
//import org.h2.util.JdbcUtils;
//## Java 1.5 end ##
/**
......@@ -38,8 +37,8 @@ public class Query<T> {
private final IdentityHashMap<Object, SelectColumn<T>> aliasMap = Utils.newIdentityHashMap();
private ArrayList<OrderExpression<T>> orderByList = Utils.newArrayList();
private Object[] groupByExpressions;
private long limit = 0;
private long offset = 0;
private long limit;
private long offset;
Query(Db db) {
this.db = db;
......@@ -65,6 +64,7 @@ public class Query<T> {
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
int whyTrue;
JdbcUtils.closeSilently(rs, true);
}
}
......@@ -122,10 +122,12 @@ public class Query<T> {
}
public <A> SetColumn<T, A> set(A field) {
int renameSetColumnClassToUpdateSetColumn;
return new SetColumn<T, A>(this, field);
}
public <A> IncrementColumn<T, A> increment(A field) {
int renameIncrementColumnClassToUpdateIncrementColumn;
return new IncrementColumn<T, A>(this, field);
}
......@@ -137,7 +139,7 @@ public class Query<T> {
from.appendSQL(stat);
stat.appendSQL(" SET ");
int i = 0;
for (Declaration declaration:declarations) {
for (Declaration declaration : declarations) {
if (i++ > 0) {
stat.appendSQL(", ");
}
......@@ -196,6 +198,7 @@ public class Query<T> {
try {
X value;
Object o = rs.getObject(1);
int convertHereIsProbablyWrong;
if (Clob.class.isAssignableFrom(o.getClass())) {
value = (X) Utils.convert(o, String.class);
} else
......@@ -325,6 +328,7 @@ public class Query<T> {
}
void addDeclarationToken(Declaration declaration) {
int todoWhatIsDeclaration;
declarations.add(declaration);
}
......
......@@ -82,8 +82,9 @@ public class SQLStatement {
ps.executeUpdate();
long identity = -1;
ResultSet rs = ps.getGeneratedKeys();
if (rs != null && rs.next())
if (rs != null && rs.next()) {
identity = rs.getLong(1);
}
JdbcUtils.closeSilently(rs);
return identity;
} catch (SQLException e) {
......@@ -101,8 +102,8 @@ public class SQLStatement {
}
}
private PreparedStatement prepare(boolean returnIdentity) {
PreparedStatement prep = db.prepare(getSQL(), returnIdentity);
private PreparedStatement prepare(boolean returnGeneratedKeys) {
PreparedStatement prep = db.prepare(getSQL(), returnGeneratedKeys);
for (int i = 0; i < params.size(); i++) {
Object o = params.get(i);
setValue(prep, i + 1, o);
......
/*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License, Version
* 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html). Initial Developer: H2 Group
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jaqu;
......@@ -10,6 +11,9 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* A class that implements this interface can be used as a database table.
*/
/**
* A class that implements the JaQu model mapping options.
* <p>
......@@ -116,8 +120,9 @@ import java.lang.annotation.Target;
* <pre>
* Db db = Db.open(&quot;jdbc:h2:mem:&quot;, &quot;sa&quot;, &quot;sa&quot;);
* DbInspector inspector = new DbInspector(db);
* List&lt;String&gt; models = inspector.generateModel(schema, table,
* packageName, annotateSchema, trimStrings);
* List&lt;String&gt; models =
* inspector.generateModel(schema, table, packageName,
* annotateSchema, trimStrings)
* </pre>
*
* OR you may use the <i>GenerateModels</i> tool to generate and save your
......@@ -134,33 +139,34 @@ import java.lang.annotation.Target;
* <b>Model Validation</b>
* <p>
* You may validate your model class with <i>DbInspector</i> object.<br>
* The DbInspector will report ERRORS, WARNINGS, and SUGGESTIONS to help you.
* The DbInspector will report ERRORS, WARNINGS, and
* SUGGESTIONS to help you.
*
* <pre>
* Db db = Db.open(&quot;jdbc:h2:mem:&quot;, &quot;sa&quot;, &quot;sa&quot;);
* Db db = Db.open(&quot;jdbc:h2:mem:&quot;,
* &quot;sa&quot;, &quot;sa&quot;);
* DbInspector inspector = new DbInspector(db);
* MyModel model = new MyModel();
* List&lt;Validation&gt; remarks = inspector.validateModel(model, throwOnError);
* for (Validation remark : remarks)
* List&lt;Validation&gt; remarks =
* inspector.validateModel(new MyModel(), throwOnError);
* for (Validation remark : remarks) {
* System.out.println(remark);
* }
* </pre>
*/
public interface Table {
static final int reviewWholeClassAndJavadocs = 0;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface JQDatabase {
/**
* If <b>version</b> is set to a <i>non-zero</i> value, JaQu will
* If version is set to a non-zero value, JaQu will
* maintain a "_jq_versions" table within your database. The
* <i>version</i> number will be used to call to a registered
* <i>DbUpgrader</i> implementation to perform relevant ALTERs or
* whatever.
* <p>
* <b>Default: <i>0</i></b>
* <p>
* <b>NOTE:</b><br>
* You must specify a <i>DbUpgrader</i> on your <i>Db</i> object to
* version number will be used to call to a registered
* DbUpgrader implementation to perform relevant ALTER statements.
* Default: 0.
* You must specify a DbUpgrader on your Db object to
* use this parameter.
*/
int version() default 0;
......@@ -170,17 +176,14 @@ public interface Table {
@Target(ElementType.TYPE)
public @interface JQSchema {
/**
* <b>schema</b> may be optionally specified. If it is not specified the
* schema will be ignored.
* <p>
* <b>Default: <i>Unspecified</i></b>
* The schema may be optionally specified. If it is not specified the
* schema will be ignored. Default: Unspecified.
*/
String name() default "";
}
/**
* Enumeration defining the 4 index types.
*
*/
public static enum IndexType {
STANDARD, UNIQUE, HASH, UNIQUE_HASH;
......@@ -190,17 +193,16 @@ public interface Table {
@Target(ElementType.TYPE)
public @interface JQIndex {
/**
* <b>standard</b> indexes may be optionally specified. If not specified,
* Standard indexes may be optionally specified. If not specified,
* these values will be ignored.
* <ul>
* <li>standard = "id, name"
* <li>standard = "id name"
* <li>standard = { "id name", "date" }
* </ul>
* Standard indexes may still be added in the <i>define()</i> method if
* Standard indexes may still be added in the define() method if
* the model class is not annotated with JQTable.
* <p>
* <b>Default: <i>Unspecified</i></b>
* Default: Unspecified.
*/
String[] standard() default {};
......@@ -337,8 +339,8 @@ public interface Table {
* If <b>version</b> is set to a <i>non-zero</i> value, JaQu will
* maintain a "_jq_versions" table within your database. The
* <i>version</i> number will be used to call to a registered
* <i>DbUpgrader</i> implementation to perform relevant ALTERs or
* whatever.
* <i>DbUpgrader</i> implementation to perform relevant ALTER
* statements.
* <p>
* <b>Default: <i>0</i></b>
* <p>
......
......@@ -19,6 +19,8 @@ import org.h2.jaqu.util.StringUtils;
*/
public class Validation {
private int todoReviewWholeClass;
public static Validation CONSIDER(String table, String type, String message) {
return new Validation(Level.CONSIDER, table, type, message);
}
......
......@@ -13,6 +13,8 @@ package org.h2.jaqu.util;
*/
public class ClassUtils {
int todoDelete;
private ClassUtils() {
// utility class
}
......@@ -31,5 +33,7 @@ public class ClassUtils {
throw new RuntimeException(e);
}
}
//## Java 1.5 end ##
}
......@@ -28,6 +28,8 @@ import org.h2.message.DbException;
*/
public class GenerateModels {
private static final int todoReview = 0;
/**
* The output stream where this tool writes to.
*/
......@@ -112,10 +114,11 @@ public class GenerateModels {
List<String> models = inspector.generateModel(schema, table,
packageName, annotateSchema, trimStrings);
File parentFile;
if (StringUtils.isNullOrEmpty(folder))
if (StringUtils.isNullOrEmpty(folder)) {
parentFile = new File(System.getProperty("user.dir"));
else
} else {
parentFile = new File(folder);
}
parentFile.mkdirs();
Pattern p = Pattern.compile("class ([a-zA-Z0-9]+)");
for (String model : models) {
......@@ -162,4 +165,5 @@ public class GenerateModels {
out.println(" -annotateSchema <boolean>");
out.println(" -trimStrings <boolean>");
}
}
......@@ -21,6 +21,8 @@ import javax.sql.XAConnection;
*/
public class JdbcUtils {
private static final int todoDeleteClass = 0;
private static final String[] DRIVERS = {
"h2:", "org.h2.Driver",
"Cache:", "com.intersys.jdbc.CacheDriver",
......
......@@ -18,6 +18,8 @@ import java.sql.SQLException;
*/
public class Message {
private int todoDelete;
private Message() {
// utility class
}
......
......@@ -30,6 +30,8 @@ package org.h2.jaqu.util;
*/
public class StatementBuilder {
private int todoDelete;
private final StringBuilder builder = new StringBuilder();
private int index;
......
......@@ -20,72 +20,67 @@ import java.util.concurrent.atomic.AtomicLong;
*/
public class StatementLogger {
public static boolean logStatements = false;
public static PrintWriter out = new PrintWriter(System.out);
public final static AtomicLong selectCount = new AtomicLong(0);
public final static AtomicLong createCount = new AtomicLong(0);
public final static AtomicLong insertCount = new AtomicLong(0);
public final static AtomicLong updateCount = new AtomicLong(0);
public final static AtomicLong mergeCount = new AtomicLong(0);
public final static AtomicLong deleteCount = new AtomicLong(0);
public static boolean logStatements;
private static PrintWriter out = new PrintWriter(System.out);
private static final AtomicLong SELECT_COUNT = new AtomicLong();
private static final AtomicLong CREATE_COUNT = new AtomicLong();
private static final AtomicLong INSERT_COUNT = new AtomicLong();
private static final AtomicLong UPDATE_COUNT = new AtomicLong();
private static final AtomicLong MERGE_COUNT = new AtomicLong();
private static final AtomicLong DELETE_COUNT = new AtomicLong();
public static void create(String statement) {
createCount.incrementAndGet();
CREATE_COUNT.incrementAndGet();
log(statement);
}
public static void insert(String statement) {
insertCount.incrementAndGet();
INSERT_COUNT.incrementAndGet();
log(statement);
}
public static void update(String statement) {
updateCount.incrementAndGet();
UPDATE_COUNT.incrementAndGet();
log(statement);
}
public static void merge(String statement) {
mergeCount.incrementAndGet();
MERGE_COUNT.incrementAndGet();
log(statement);
}
public static void delete(String statement) {
deleteCount.incrementAndGet();
DELETE_COUNT.incrementAndGet();
log(statement);
}
public static void select(String statement) {
selectCount.incrementAndGet();
SELECT_COUNT.incrementAndGet();
log(statement);
}
private static void log(String statement) {
if (logStatements)
if (logStatements) {
out.println(statement);
}
}
public static void printStats() {
out.println("JaQu Runtime Stats");
out.println("JaQu Runtime Statistics");
out.println("=======================");
printStat("CREATE", createCount);
printStat("INSERT", insertCount);
printStat("UPDATE", updateCount);
printStat("MERGE", mergeCount);
printStat("DELETE", deleteCount);
printStat("SELECT", selectCount);
printStat("CREATE", CREATE_COUNT);
printStat("INSERT", INSERT_COUNT);
printStat("UPDATE", UPDATE_COUNT);
printStat("MERGE", MERGE_COUNT);
printStat("DELETE", DELETE_COUNT);
printStat("SELECT", SELECT_COUNT);
}
private static void printStat(String name, AtomicLong value) {
if (value.get() > 0) {
DecimalFormat df = new DecimalFormat("###,###,###,###");
out.println(name + "=" + df.format(createCount.get()));
out.println(name + "=" + df.format(CREATE_COUNT.get()));
}
}
}
\ No newline at end of file
......@@ -12,6 +12,8 @@ package org.h2.jaqu.util;
*/
public class StringUtils {
private int todoDelete;
/**
* Replace all occurrences of the before string with the after string.
*
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论