aboutsummaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorJames Moger <james.moger@gmail.com>2011-08-08 12:25:12 -0400
committerJames Moger <james.moger@gmail.com>2011-08-08 12:25:12 -0400
commitf44168da2824063985f8ecfa1a75f9984e8f7fb0 (patch)
tree6501b13134a5644d5560f9cb3be835c576919266 /src/com
parentd5a74dcac41eeb96a656b7033e43d51b92f75d18 (diff)
downloadiciql-f44168da2824063985f8ecfa1a75f9984e8f7fb0.tar.gz
iciql-f44168da2824063985f8ecfa1a75f9984e8f7fb0.zip
Documentation. Moved dialects into separate package.
Diffstat (limited to 'src/com')
-rw-r--r--src/com/iciql/Db.java6
-rw-r--r--src/com/iciql/QueryBetween.java24
-rw-r--r--src/com/iciql/SQLDialect.java126
-rw-r--r--src/com/iciql/TableDefinition.java10
-rw-r--r--src/com/iciql/dialect/DefaultSQLDialect.java86
-rw-r--r--src/com/iciql/dialect/H2Dialect.java50
-rw-r--r--src/com/iciql/dialect/package.html25
7 files changed, 191 insertions, 136 deletions
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<T, A> {
-
+
private Query<T> 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<T> 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<T> and(A z) {
query.addConditionToken(new Condition<A>(x, y, z, CompareType.BETWEEN));
return new QueryWhere<T>(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<T> {
+public class TableDefinition<T> {
/**
* The meta data of an index.
*/
- static class IndexDefinition {
- IndexType type;
- String indexName;
+ public static class IndexDefinition {
+ public IndexType type;
+ public String indexName;
- List<String> columnNames;
+ public List<String> 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 @@
+<!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