From f44168da2824063985f8ecfa1a75f9984e8f7fb0 Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 8 Aug 2011 12:25:12 -0400 Subject: [PATCH] Documentation. Moved dialects into separate package. --- docs/05_releases.mkd | 1 + src/com/iciql/Db.java | 6 +- src/com/iciql/QueryBetween.java | 24 +++- src/com/iciql/SQLDialect.java | 126 ------------------- src/com/iciql/TableDefinition.java | 10 +- src/com/iciql/dialect/DefaultSQLDialect.java | 86 +++++++++++++ src/com/iciql/dialect/H2Dialect.java | 50 ++++++++ src/com/iciql/dialect/package.html | 25 ++++ 8 files changed, 192 insertions(+), 136 deletions(-) create mode 100644 src/com/iciql/dialect/DefaultSQLDialect.java create mode 100644 src/com/iciql/dialect/H2Dialect.java create mode 100644 src/com/iciql/dialect/package.html diff --git a/docs/05_releases.mkd b/docs/05_releases.mkd index f2f14cc..b060fd2 100644 --- a/docs/05_releases.mkd +++ b/docs/05_releases.mkd @@ -9,6 +9,7 @@ - added UUID type support (H2 databases only) - added partial primitives support *(primitives may not be used for compile-time condition clauses)* - added *between(A y).and(A z)* condition syntax +- moved dialects into separate package ### Older Releases diff --git a/src/com/iciql/Db.java b/src/com/iciql/Db.java index 7873313..121e50c 100644 --- a/src/com/iciql/Db.java +++ b/src/com/iciql/Db.java @@ -34,10 +34,10 @@ import java.util.Set; import javax.sql.DataSource; import com.iciql.DbUpgrader.DefaultDbUpgrader; -import com.iciql.Iciql.IQVersion; import com.iciql.Iciql.IQTable; -import com.iciql.SQLDialect.DefaultSQLDialect; -import com.iciql.SQLDialect.H2Dialect; +import com.iciql.Iciql.IQVersion; +import com.iciql.dialect.DefaultSQLDialect; +import com.iciql.dialect.H2Dialect; import com.iciql.util.JdbcUtils; import com.iciql.util.StringUtils; import com.iciql.util.Utils; diff --git a/src/com/iciql/QueryBetween.java b/src/com/iciql/QueryBetween.java index 26ac40e..de09515 100644 --- a/src/com/iciql/QueryBetween.java +++ b/src/com/iciql/QueryBetween.java @@ -16,18 +16,38 @@ package com.iciql; +/** + * This class represents a "between y and z" condition. + */ public class QueryBetween { - + private Query query; private A x; private A y; + /** + * Construct a between condition. + * + * @param query + * the query + * @param x + * the alias + * @param y + * the lower bound of the between condition + */ public QueryBetween(Query query, A x, A y) { this.query = query; this.x = x; this.y = y; } - + + /** + * Set the upper bound of the between condition. + * + * @param z + * the upper bound of the between condition + * @return the query + */ public QueryWhere and(A z) { query.addConditionToken(new Condition(x, y, z, CompareType.BETWEEN)); return new QueryWhere(query); diff --git a/src/com/iciql/SQLDialect.java b/src/com/iciql/SQLDialect.java index 3cb9339..8291e53 100644 --- a/src/com/iciql/SQLDialect.java +++ b/src/com/iciql/SQLDialect.java @@ -18,12 +18,8 @@ package com.iciql; import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.SQLException; import com.iciql.TableDefinition.IndexDefinition; -import com.iciql.util.StatementBuilder; -import com.iciql.util.StringUtils; /** * This interface defines points where iciql can build different statements @@ -111,126 +107,4 @@ public interface SQLDialect { * @return true if they are */ boolean supportsLimitOffset(); - - /** - * Default implementation of an SQL dialect. - * Does not support merge nor index creation. - */ - public static class DefaultSQLDialect implements SQLDialect { - float databaseVersion; - String productName; - String productVersion; - - @Override - public String toString() { - return getClass().getName() + ": " + productName + " " + productVersion; - } - - @Override - public void configureDialect(Connection conn) { - loadIdentity(conn); - } - - protected void loadIdentity(Connection conn) { - try { - DatabaseMetaData data = conn.getMetaData(); - databaseVersion = Float.parseFloat(data.getDatabaseMajorVersion() + "." - + data.getDatabaseMinorVersion()); - productName = data.getDatabaseProductName(); - productVersion = data.getDatabaseProductVersion(); - } catch (SQLException e) { - throw new IciqlException(e); - } - } - - @Override - public boolean supportsMemoryTables() { - return false; - } - - @Override - public boolean supportsMerge() { - return false; - } - - @Override - public boolean supportsLimitOffset() { - return true; - } - - @Override - public String prepareTableName(String schema, String table) { - if (StringUtils.isNullOrEmpty(schema)) { - return table; - } - return schema + "." + table; - } - - @Override - public String prepareColumnName(String name) { - return name; - } - - @Override - public String prepareCreateIndex(String schema, String table, IndexDefinition index) { - throw new IciqlException("Dialect does not support index creation!"); - } - - @Override - public void appendLimit(SQLStatement stat, long limit) { - stat.appendSQL(" LIMIT " + limit); - } - - @Override - public void appendOffset(SQLStatement stat, long offset) { - stat.appendSQL(" OFFSET " + offset); - } - } - - - /** - * H2 database dialect. - */ - public static class H2Dialect extends DefaultSQLDialect { - - @Override - public boolean supportsMemoryTables() { - return true; - } - - @Override - public boolean supportsMerge() { - return true; - } - - @Override - public String prepareCreateIndex(String schema, String table, IndexDefinition index) { - StatementBuilder buff = new StatementBuilder(); - buff.append("CREATE "); - switch (index.type) { - case STANDARD: - break; - case UNIQUE: - buff.append("UNIQUE "); - break; - case HASH: - buff.append("HASH "); - break; - case UNIQUE_HASH: - buff.append("UNIQUE HASH "); - break; - } - buff.append("INDEX IF NOT EXISTS "); - buff.append(index.indexName); - buff.append(" ON "); - buff.append(table); - buff.append("("); - for (String col : index.columnNames) { - buff.appendExceptFirst(", "); - buff.append(col); - } - buff.append(")"); - return buff.toString(); - } - } } diff --git a/src/com/iciql/TableDefinition.java b/src/com/iciql/TableDefinition.java index f506484..7b3e1e4 100644 --- a/src/com/iciql/TableDefinition.java +++ b/src/com/iciql/TableDefinition.java @@ -50,17 +50,17 @@ import com.iciql.util.Utils; * the table type */ -class TableDefinition { +public class TableDefinition { /** * The meta data of an index. */ - static class IndexDefinition { - IndexType type; - String indexName; + public static class IndexDefinition { + public IndexType type; + public String indexName; - List columnNames; + public List columnNames; } /** diff --git a/src/com/iciql/dialect/DefaultSQLDialect.java b/src/com/iciql/dialect/DefaultSQLDialect.java new file mode 100644 index 0000000..517ae10 --- /dev/null +++ b/src/com/iciql/dialect/DefaultSQLDialect.java @@ -0,0 +1,86 @@ +package com.iciql.dialect; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.SQLException; + +import com.iciql.IciqlException; +import com.iciql.SQLDialect; +import com.iciql.SQLStatement; +import com.iciql.TableDefinition.IndexDefinition; +import com.iciql.util.StringUtils; + +/** + * Default implementation of an SQL dialect. Does not support merge nor index + * creation. + */ +public class DefaultSQLDialect implements SQLDialect { + float databaseVersion; + String productName; + String productVersion; + + @Override + public String toString() { + return getClass().getName() + ": " + productName + " " + productVersion; + } + + @Override + public void configureDialect(Connection conn) { + loadIdentity(conn); + } + + protected void loadIdentity(Connection conn) { + try { + DatabaseMetaData data = conn.getMetaData(); + databaseVersion = Float.parseFloat(data.getDatabaseMajorVersion() + "." + + data.getDatabaseMinorVersion()); + productName = data.getDatabaseProductName(); + productVersion = data.getDatabaseProductVersion(); + } catch (SQLException e) { + throw new IciqlException(e); + } + } + + @Override + public boolean supportsMemoryTables() { + return false; + } + + @Override + public boolean supportsMerge() { + return false; + } + + @Override + public boolean supportsLimitOffset() { + return true; + } + + @Override + public String prepareTableName(String schema, String table) { + if (StringUtils.isNullOrEmpty(schema)) { + return table; + } + return schema + "." + table; + } + + @Override + public String prepareColumnName(String name) { + return name; + } + + @Override + public String prepareCreateIndex(String schema, String table, IndexDefinition index) { + throw new IciqlException("Dialect does not support index creation!"); + } + + @Override + public void appendLimit(SQLStatement stat, long limit) { + stat.appendSQL(" LIMIT " + limit); + } + + @Override + public void appendOffset(SQLStatement stat, long offset) { + stat.appendSQL(" OFFSET " + offset); + } +} \ No newline at end of file diff --git a/src/com/iciql/dialect/H2Dialect.java b/src/com/iciql/dialect/H2Dialect.java new file mode 100644 index 0000000..e0a5035 --- /dev/null +++ b/src/com/iciql/dialect/H2Dialect.java @@ -0,0 +1,50 @@ +package com.iciql.dialect; + +import com.iciql.TableDefinition.IndexDefinition; +import com.iciql.util.StatementBuilder; + +/** + * H2 database dialect. + */ +public class H2Dialect extends DefaultSQLDialect { + + @Override + public boolean supportsMemoryTables() { + return true; + } + + @Override + public boolean supportsMerge() { + return true; + } + + @Override + public String prepareCreateIndex(String schema, String table, IndexDefinition index) { + StatementBuilder buff = new StatementBuilder(); + buff.append("CREATE "); + switch (index.type) { + case STANDARD: + break; + case UNIQUE: + buff.append("UNIQUE "); + break; + case HASH: + buff.append("HASH "); + break; + case UNIQUE_HASH: + buff.append("UNIQUE HASH "); + break; + } + buff.append("INDEX IF NOT EXISTS "); + buff.append(index.indexName); + buff.append(" ON "); + buff.append(table); + buff.append("("); + for (String col : index.columnNames) { + buff.appendExceptFirst(", "); + buff.append(col); + } + buff.append(")"); + return buff.toString(); + } +} \ No newline at end of file diff --git a/src/com/iciql/dialect/package.html b/src/com/iciql/dialect/package.html new file mode 100644 index 0000000..ad91873 --- /dev/null +++ b/src/com/iciql/dialect/package.html @@ -0,0 +1,25 @@ + + + + +Javadoc package documentation + + +The dialect classes for iciql. + + \ No newline at end of file -- 2.39.5