- added UUID type support (H2 databases only)\r
- added partial primitives support *(primitives may not be used for compile-time condition clauses)*\r
- added *between(A y).and(A z)* condition syntax\r
+- moved dialects into separate package\r
\r
### Older Releases\r
\r
import javax.sql.DataSource;\r
\r
import com.iciql.DbUpgrader.DefaultDbUpgrader;\r
-import com.iciql.Iciql.IQVersion;\r
import com.iciql.Iciql.IQTable;\r
-import com.iciql.SQLDialect.DefaultSQLDialect;\r
-import com.iciql.SQLDialect.H2Dialect;\r
+import com.iciql.Iciql.IQVersion;\r
+import com.iciql.dialect.DefaultSQLDialect;\r
+import com.iciql.dialect.H2Dialect;\r
import com.iciql.util.JdbcUtils;\r
import com.iciql.util.StringUtils;\r
import com.iciql.util.Utils;\r
\r
package com.iciql;\r
\r
+/**\r
+ * This class represents a "between y and z" condition.\r
+ */\r
public class QueryBetween<T, A> {\r
- \r
+\r
private Query<T> query;\r
private A x;\r
private A y;\r
\r
+ /**\r
+ * Construct a between condition.\r
+ * \r
+ * @param query\r
+ * the query\r
+ * @param x\r
+ * the alias\r
+ * @param y\r
+ * the lower bound of the between condition\r
+ */\r
public QueryBetween(Query<T> query, A x, A y) {\r
this.query = query;\r
this.x = x;\r
this.y = y;\r
}\r
- \r
+\r
+ /**\r
+ * Set the upper bound of the between condition.\r
+ * \r
+ * @param z\r
+ * the upper bound of the between condition\r
+ * @return the query\r
+ */\r
public QueryWhere<T> and(A z) {\r
query.addConditionToken(new Condition<A>(x, y, z, CompareType.BETWEEN));\r
return new QueryWhere<T>(query);\r
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
* @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();
- }
- }
}
* the table type\r
*/\r
\r
-class TableDefinition<T> {\r
+public class TableDefinition<T> {\r
\r
/**\r
* The meta data of an index.\r
*/\r
\r
- static class IndexDefinition {\r
- IndexType type;\r
- String indexName;\r
+ public static class IndexDefinition {\r
+ public IndexType type;\r
+ public String indexName;\r
\r
- List<String> columnNames;\r
+ public List<String> columnNames;\r
}\r
\r
/**\r
--- /dev/null
+package com.iciql.dialect;\r
+\r
+import java.sql.Connection;\r
+import java.sql.DatabaseMetaData;\r
+import java.sql.SQLException;\r
+\r
+import com.iciql.IciqlException;\r
+import com.iciql.SQLDialect;\r
+import com.iciql.SQLStatement;\r
+import com.iciql.TableDefinition.IndexDefinition;\r
+import com.iciql.util.StringUtils;\r
+\r
+/**\r
+ * Default implementation of an SQL dialect. Does not support merge nor index\r
+ * creation.\r
+ */\r
+public class DefaultSQLDialect implements SQLDialect {\r
+ float databaseVersion;\r
+ String productName;\r
+ String productVersion;\r
+\r
+ @Override\r
+ public String toString() {\r
+ return getClass().getName() + ": " + productName + " " + productVersion;\r
+ }\r
+\r
+ @Override\r
+ public void configureDialect(Connection conn) {\r
+ loadIdentity(conn);\r
+ }\r
+\r
+ protected void loadIdentity(Connection conn) {\r
+ try {\r
+ DatabaseMetaData data = conn.getMetaData();\r
+ databaseVersion = Float.parseFloat(data.getDatabaseMajorVersion() + "."\r
+ + data.getDatabaseMinorVersion());\r
+ productName = data.getDatabaseProductName();\r
+ productVersion = data.getDatabaseProductVersion();\r
+ } catch (SQLException e) {\r
+ throw new IciqlException(e);\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public boolean supportsMemoryTables() {\r
+ return false;\r
+ }\r
+\r
+ @Override\r
+ public boolean supportsMerge() {\r
+ return false;\r
+ }\r
+\r
+ @Override\r
+ public boolean supportsLimitOffset() {\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public String prepareTableName(String schema, String table) {\r
+ if (StringUtils.isNullOrEmpty(schema)) {\r
+ return table;\r
+ }\r
+ return schema + "." + table;\r
+ }\r
+\r
+ @Override\r
+ public String prepareColumnName(String name) {\r
+ return name;\r
+ }\r
+\r
+ @Override\r
+ public String prepareCreateIndex(String schema, String table, IndexDefinition index) {\r
+ throw new IciqlException("Dialect does not support index creation!");\r
+ }\r
+\r
+ @Override\r
+ public void appendLimit(SQLStatement stat, long limit) {\r
+ stat.appendSQL(" LIMIT " + limit);\r
+ }\r
+\r
+ @Override\r
+ public void appendOffset(SQLStatement stat, long offset) {\r
+ stat.appendSQL(" OFFSET " + offset);\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+package com.iciql.dialect;\r
+\r
+import com.iciql.TableDefinition.IndexDefinition;\r
+import com.iciql.util.StatementBuilder;\r
+\r
+/**\r
+ * H2 database dialect.\r
+ */\r
+public class H2Dialect extends DefaultSQLDialect {\r
+\r
+ @Override\r
+ public boolean supportsMemoryTables() {\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public boolean supportsMerge() {\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public String prepareCreateIndex(String schema, String table, IndexDefinition index) {\r
+ StatementBuilder buff = new StatementBuilder();\r
+ buff.append("CREATE ");\r
+ switch (index.type) {\r
+ case STANDARD:\r
+ break;\r
+ case UNIQUE:\r
+ buff.append("UNIQUE ");\r
+ break;\r
+ case HASH:\r
+ buff.append("HASH ");\r
+ break;\r
+ case UNIQUE_HASH:\r
+ buff.append("UNIQUE HASH ");\r
+ break;\r
+ }\r
+ buff.append("INDEX IF NOT EXISTS ");\r
+ buff.append(index.indexName);\r
+ buff.append(" ON ");\r
+ buff.append(table);\r
+ buff.append("(");\r
+ for (String col : index.columnNames) {\r
+ buff.appendExceptFirst(", ");\r
+ buff.append(col);\r
+ }\r
+ buff.append(")");\r
+ return buff.toString();\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!--
+ Copyright 2004-2011 H2 Group.
+ Copyright 2011 James Moger.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+<title>Javadoc package documentation</title>
+</head>
+<body>
+The dialect classes for iciql.
+</body>
+</html>
\ No newline at end of file