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

Cleanup:

- Mainly Javadoc changes.
上级 6216db17
/* /*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License, Version * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License, Version
* 1.0, and under the Eclipse Public License, Version 1.0 * 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html). Initial Developer: James Moger * (http://h2database.com/html/license.html). Initial Developer: James Moger
*/ */
package org.h2.jaqu; package org.h2.jaqu;
import org.h2.jaqu.Table.JQDatabase; import org.h2.jaqu.Table.JQDatabase;
/** /**
* Interface which defines a class to handle table changes based on model * Interface which defines a class to handle table changes based on model
* versions. An implementation of <i>DbUpgrader</i> must be annotated with the * versions. An implementation of <i>DbUpgrader</i> must be annotated with the
* <i>JQDatabase</i> annotation, which defines the expected database version * <i>JQDatabase</i> annotation, which defines the expected database version
* number. * number.
*/ */
public interface DbUpgrader { public interface DbUpgrader {
/** /**
* Defines method interface to handle database upgrades. This method is only * Defines method interface to handle database upgrades. This method is only
* called if your <i>DbUpgrader</i> implementation is annotated with * called if your <i>DbUpgrader</i> implementation is annotated with
* JQDatabase. * JQDatabase.
* *
* @param db the database * @param db the database
* @param fromVersion the old version * @param fromVersion the old version
* @param toVersion the new version * @param toVersion the new version
* @return true for successful upgrade. If the upgrade is successful, the * @return true for successful upgrade. If the upgrade is successful, the
* version registry is automatically updated. * version registry is automatically updated.
*/ */
boolean upgradeDatabase(Db db, int fromVersion, int toVersion); boolean upgradeDatabase(Db db, int fromVersion, int toVersion);
/** /**
* Defines method interface to handle table upgrades. * Defines method interface to handle table upgrades.
* *
* @param db the database * @param db the database
* @param schema the schema * @param schema the schema
* @param table the table * @param table the table
* @param fromVersion the old version * @param fromVersion the old version
* @param toVersion the new version * @param toVersion the new version
* @return true for successful upgrade. If the upgrade is successful, the * @return true for successful upgrade. If the upgrade is successful, the
* version registry is automatically updated. * version registry is automatically updated.
*/ */
boolean upgradeTable(Db db, String schema, String table, int fromVersion, int toVersion); boolean upgradeTable(Db db, String schema, String table, int fromVersion, int toVersion);
/** /**
* The default database upgrader. It throws runtime exception instead of * The default database upgrader. It throws runtime exception instead of
* handling upgrade requests. * handling upgrade requests.
*/ */
@JQDatabase(version = 0) @JQDatabase(version = 0)
public static class DefaultDbUpgrader implements DbUpgrader { public static class DefaultDbUpgrader implements DbUpgrader {
public boolean upgradeDatabase(Db db, int fromVersion, int toVersion) { public boolean upgradeDatabase(Db db, int fromVersion, int toVersion) {
throw new RuntimeException("Please provide your own DbUpgrader implementation."); throw new RuntimeException("Please provide your own DbUpgrader implementation.");
} }
public boolean upgradeTable(Db db, String schema, String table, int fromVersion, int toVersion) { public boolean upgradeTable(Db db, String schema, String table, int fromVersion, int toVersion) {
throw new RuntimeException("Please provide your own DbUpgrader implementation."); throw new RuntimeException("Please provide your own DbUpgrader implementation.");
} }
} }
} }
/* /*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License, * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0 * Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html). * (http://h2database.com/html/license.html).
* Initial Developer: James Moger * Initial Developer: James Moger
*/ */
package org.h2.jaqu; package org.h2.jaqu;
import org.h2.jaqu.Table.JQColumn; import org.h2.jaqu.Table.JQColumn;
import org.h2.jaqu.Table.JQTable; import org.h2.jaqu.Table.JQTable;
/** /**
* Model class for JaQu to track db and table versions. * A JaQu system table to track database and table versions.
* */
*/ @JQTable(name = "_jq_versions", primaryKey = "schemaName tableName", memoryTable = true)
@JQTable(name = "_jq_versions", primaryKey = "schemaName tableName", memoryTable = true) public class DbVersion {
public class DbVersion {
@JQColumn(name = "schemaName", allowNull = false)
@JQColumn(name = "schemaName", allowNull = false) String schema = "";
String schema;
@JQColumn(name = "tableName", allowNull = false)
@JQColumn(name = "tableName", allowNull = false) String table = "";
String table;
@JQColumn(name = "version")
@JQColumn(name = "version") Integer version;
Integer version;
private int todoReviewWholeClass;
public DbVersion() {
} public DbVersion() {
// nothing to do
/** }
* Constructor for defining a version entry.
* (SCHEMA="" && TABLE="") == DATABASE /**
* * Constructor for defining a version entry. Both the schema and the table
* @param version * are empty strings, which means this is the row for the 'database'.
*/ *
public DbVersion(int version) { * @param version the database version
this.schema = ""; */
this.table = ""; public DbVersion(int version) {
this.version = version; this.schema = "";
} this.table = "";
} this.version = version;
}
}
/* /*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License, * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0 * Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html). * (http://h2database.com/html/license.html).
* Initial Developer: James Moger * Initial Developer: James Moger
*/ */
package org.h2.jaqu; package org.h2.jaqu;
/** /**
* Classes implementing this interface can be used as a declaration in an * Classes implementing this interface can be used as a declaration in an
* update statement. * update statement.
*/ */
public interface Declaration { public interface Declaration {
/**
* Append the SQL to the given statement using the given query. final static int renameClassToUpdateDeclaration = 0;
*
* @param stat the statement to append the SQL to /**
*/ * Append the SQL to the given statement using the given query.
//## Java 1.5 begin ## *
void appendSQL(SQLStatement stat); * @param stat the statement to append the SQL to
//## Java 1.5 end ## */
} //## Java 1.5 begin ##
void appendSQL(SQLStatement stat);
//## Java 1.5 end ##
}
...@@ -27,17 +27,17 @@ public class Define { ...@@ -27,17 +27,17 @@ public class Define {
checkInDefine(); checkInDefine();
currentTableDefinition.addIndex(IndexType.STANDARD, columns); currentTableDefinition.addIndex(IndexType.STANDARD, columns);
} }
public static void uniqueIndex(Object... columns) { public static void uniqueIndex(Object... columns) {
checkInDefine(); checkInDefine();
currentTableDefinition.addIndex(IndexType.UNIQUE, columns); currentTableDefinition.addIndex(IndexType.UNIQUE, columns);
} }
public static void hashIndex(Object column) { public static void hashIndex(Object column) {
checkInDefine(); checkInDefine();
currentTableDefinition.addIndex(IndexType.HASH, new Object [] { column }); currentTableDefinition.addIndex(IndexType.HASH, new Object [] { column });
} }
public static void uniqueHashIndex(Object column) { public static void uniqueHashIndex(Object column) {
checkInDefine(); checkInDefine();
currentTableDefinition.addIndex(IndexType.UNIQUE_HASH, new Object [] { column }); currentTableDefinition.addIndex(IndexType.UNIQUE_HASH, new Object [] { column });
......
/* /*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License, * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0 * Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html). * (http://h2database.com/html/license.html).
* Initial Developer: James Moger * Initial Developer: James Moger
*/ */
package org.h2.jaqu; package org.h2.jaqu;
/** /**
* This class represents "SET column = (column + 1)" in an UPDATE statement. * This class represents "SET column = (column + 1)" in an UPDATE statement.
* *
* @param <T> the query type * @param <T> the query type
* @param <A> the new value data type * @param <A> the new value data type
*/ */
//## Java 1.5 begin ## //## Java 1.5 begin ##
public class IncrementColumn<T, A> implements Declaration { public class IncrementColumn<T, A> implements Declaration {
private Query<T> query; private Query<T> query;
private A x; private A x;
private A y; private A y;
IncrementColumn(Query<T> query, A x) { IncrementColumn(Query<T> query, A x) {
this.query = query; this.query = query;
this.x = x; this.x = x;
} }
public Query<T> by(A y) { public Query<T> by(A y) {
query.addDeclarationToken(this); query.addDeclarationToken(this);
this.y = y; this.y = y;
return query; return query;
} }
public void appendSQL(SQLStatement stat) { public void appendSQL(SQLStatement stat) {
query.appendSQL(stat, x); query.appendSQL(stat, x);
stat.appendSQL("=("); stat.appendSQL("=(");
query.appendSQL(stat, x); query.appendSQL(stat, x);
int todoSomethingWrongHere; int todoSomethingWrongHere;
if (y instanceof Number) { if (y instanceof Number) {
Number n = (Number) y; Number n = (Number) y;
if (n.doubleValue() > 0) { if (n.doubleValue() > 0) {
stat.appendSQL("+"); stat.appendSQL("+");
} }
} }
stat.appendSQL(y.toString()); stat.appendSQL(y.toString());
stat.appendSQL(")"); stat.appendSQL(")");
} }
} }
//## Java 1.5 end ## //## Java 1.5 end ##
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论