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

Cleanup:

- Improve Javadoc documentation
- Add Javadoc documentation (each class and interface method should be documented)
- I didn't want to use MessageFormat but I guess that's not an important change
上级 b94fe304
...@@ -6,25 +6,50 @@ ...@@ -6,25 +6,50 @@
*/ */
package org.h2.jaqu; package org.h2.jaqu;
import java.text.MessageFormat;
import org.h2.jaqu.TableDefinition.IndexDefinition; import org.h2.jaqu.TableDefinition.IndexDefinition;
import org.h2.jaqu.util.StatementBuilder; import org.h2.jaqu.util.StatementBuilder;
import org.h2.jaqu.util.StringUtils; import org.h2.jaqu.util.StringUtils;
/** /**
* Interface that defines points where JaQu can build different statements for * This interface defines points where JaQu can build different statements
* DB-specific SQL. * depending on the database used.
*
*/ */
public interface SQLDialect { public interface SQLDialect {
public String tableName(String schema, String table); /**
* Get the SQL snippet for the table name.
*
* @param schema the schema name, or null for no schema
* @param table the table name
* @return the SQL snippet
*/
String tableName(String schema, String table);
public String createIndex(String schema, String table, IndexDefinition index); /**
* Get the CREATE INDEX statement.
*
* @param schema the schema name
* @param table the table name
* @param index the index definition
* @return the SQL statement
*/
String createIndex(String schema, String table, IndexDefinition index);
public void appendLimit(SQLStatement stat, long limit); /**
* Append "LIMIT limit" to the SQL statement.
*
* @param stat the statement
* @param limit the limit
*/
void appendLimit(SQLStatement stat, long limit);
public void appendOffset(SQLStatement stat, long offset); /**
* Append "OFFSET offset" to the SQL statement.
*
* @param stat the statement
* @param offset the offset
*/
void appendOffset(SQLStatement stat, long offset);
/** /**
* Default implementation of an SQL dialect. * Default implementation of an SQL dialect.
...@@ -34,37 +59,40 @@ public interface SQLDialect { ...@@ -34,37 +59,40 @@ public interface SQLDialect {
@Override @Override
public String tableName(String schema, String table) { public String tableName(String schema, String table) {
if (StringUtils.isNullOrEmpty(schema)) if (StringUtils.isNullOrEmpty(schema)) {
return table; return table;
}
return schema + "." + table; return schema + "." + table;
} }
@Override @Override
public String createIndex(String schema, String table, IndexDefinition index) { public String createIndex(String schema, String table, IndexDefinition index) {
StatementBuilder cols = new StatementBuilder(); StatementBuilder buff = new StatementBuilder();
for (String col:index.columnNames) { buff.append("CREATE ");
cols.appendExceptFirst(", ");
cols.append(col);
}
String type;
switch(index.type) { switch(index.type) {
case STANDARD:
break;
case UNIQUE: case UNIQUE:
type = " UNIQUE "; buff.append("UNIQUE ");
break; break;
case HASH: case HASH:
type = " HASH "; buff.append("HASH ");
break; break;
case UNIQUE_HASH: case UNIQUE_HASH:
type = " UNIQUE HASH "; buff.append("UNIQUE HASH ");
break;
case STANDARD:
default:
type = " ";
break; break;
} }
buff.append("INDEX IF NOT EXISTS ");
return MessageFormat.format("CREATE{0}INDEX IF NOT EXISTS {1} ON {2}({3})", buff.append(index.indexName);
type, index.indexName, table, cols); buff.append(" ON ");
buff.append(table);
buff.append("(");
for (String col:index.columnNames) {
buff.appendExceptFirst(", ");
buff.append(col);
}
buff.append(")");
return buff.toString();
} }
@Override @Override
...@@ -76,5 +104,7 @@ public interface SQLDialect { ...@@ -76,5 +104,7 @@ public interface SQLDialect {
public void appendOffset(SQLStatement stat, long offset) { public void appendOffset(SQLStatement stat, long offset) {
stat.appendSQL(" OFFSET " + offset); stat.appendSQL(" OFFSET " + offset);
} }
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论