diff options
author | James Moger <james.moger@gmail.com> | 2011-08-17 16:26:14 -0400 |
---|---|---|
committer | James Moger <james.moger@gmail.com> | 2011-08-17 16:26:14 -0400 |
commit | ade7c03f54b79f8d3e65a79f9b8d11924694a79e (patch) | |
tree | 5476bdddccf577caf8a8b481c970ba70cf067a05 /src/com | |
parent | 05429c2cdf393730f17fb8fa51ee4b9e58e0a88f (diff) | |
download | iciql-ade7c03f54b79f8d3e65a79f9b8d11924694a79e.tar.gz iciql-ade7c03f54b79f8d3e65a79f9b8d11924694a79e.zip |
Launch H2 and HSQL servers in test suite and include tcp benchmarks.
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/iciql/Iciql.java | 2 | ||||
-rw-r--r-- | src/com/iciql/SQLDialect.java | 21 | ||||
-rw-r--r-- | src/com/iciql/SQLDialectDefault.java | 33 | ||||
-rw-r--r-- | src/com/iciql/SQLDialectDerby.java | 29 | ||||
-rw-r--r-- | src/com/iciql/SQLDialectH2.java | 20 | ||||
-rw-r--r-- | src/com/iciql/SQLDialectHSQL.java | 16 | ||||
-rw-r--r-- | src/com/iciql/SQLDialectMySQL.java | 4 | ||||
-rw-r--r-- | src/com/iciql/SQLDialectPostgreSQL.java | 5 |
8 files changed, 46 insertions, 84 deletions
diff --git a/src/com/iciql/Iciql.java b/src/com/iciql/Iciql.java index 7a0b58f..9ca8bf7 100644 --- a/src/com/iciql/Iciql.java +++ b/src/com/iciql/Iciql.java @@ -353,7 +353,7 @@ public interface Iciql { /**
* If true, this table is created as a memory table where data is
* persistent, but index data is kept in main memory. Valid only for H2
- * databases. Default: false.
+ * and HSQL databases. Default: false.
*/
boolean memoryTable() default false;
}
diff --git a/src/com/iciql/SQLDialect.java b/src/com/iciql/SQLDialect.java index 6e6be25..7c29d61 100644 --- a/src/com/iciql/SQLDialect.java +++ b/src/com/iciql/SQLDialect.java @@ -118,27 +118,6 @@ public interface SQLDialect { void appendLimitOffset(SQLStatement stat, long limit, long offset); /** - * Whether memory tables are supported. - * - * @return true if they are - */ - boolean supportsMemoryTables(); - - /** - * Whether IF NOT EXISTS notation is supported. - * - * @return true if they are - */ - boolean supportsIfNotExists(); - - /** - * Whether LIMIT/OFFSET notation is supported. - * - * @return true if they are - */ - boolean supportsLimitOffset(); - - /** * Returns the preferred DATETIME class for the database. * <p> * Either java.util.Date or java.sql.Timestamp diff --git a/src/com/iciql/SQLDialectDefault.java b/src/com/iciql/SQLDialectDefault.java index 4814fdd..58848c1 100644 --- a/src/com/iciql/SQLDialectDefault.java +++ b/src/com/iciql/SQLDialectDefault.java @@ -69,21 +69,6 @@ public class SQLDialectDefault implements SQLDialect { }
@Override
- public boolean supportsMemoryTables() {
- return false;
- }
-
- @Override
- public boolean supportsIfNotExists() {
- return true;
- }
-
- @Override
- public boolean supportsLimitOffset() {
- return true;
- }
-
- @Override
public String prepareTableName(String schemaName, String tableName) {
if (StringUtils.isNullOrEmpty(schemaName)) {
return tableName;
@@ -104,19 +89,15 @@ public class SQLDialectDefault implements SQLDialect { return;
}
+ protected <T> String prepareCreateTable(TableDefinition<T> def) {
+ return "CREATE TABLE";
+ }
+
@Override
public <T> void prepareCreateTable(SQLStatement stat, TableDefinition<T> def) {
- StatementBuilder buff;
- if (def.memoryTable && supportsMemoryTables()) {
- buff = new StatementBuilder("CREATE MEMORY TABLE ");
- } else {
- buff = new StatementBuilder("CREATE TABLE ");
- }
-
- if (supportsIfNotExists()) {
- buff.append("IF NOT EXISTS ");
- }
-
+ StatementBuilder buff = new StatementBuilder();
+ buff.append(prepareCreateTable(def));
+ buff.append(" ");
buff.append(prepareTableName(def.schemaName, def.tableName)).append('(');
boolean hasIdentityColumn = false;
diff --git a/src/com/iciql/SQLDialectDerby.java b/src/com/iciql/SQLDialectDerby.java index fd06844..f954a7c 100644 --- a/src/com/iciql/SQLDialectDerby.java +++ b/src/com/iciql/SQLDialectDerby.java @@ -38,28 +38,15 @@ public class SQLDialectDerby extends SQLDialectDefault { }
@Override
- public boolean supportsMemoryTables() {
- return false;
- }
-
- @Override
- public boolean supportsIfNotExists() {
- return false;
- }
-
- @Override
- public boolean supportsLimitOffset() {
- // FETCH/OFFSET added in 10.5
- return databaseVersion >= 10.5f;
- }
-
- @Override
public void appendLimitOffset(SQLStatement stat, long limit, long offset) {
- if (offset > 0) {
- stat.appendSQL(" OFFSET " + offset + (offset == 1 ? " ROW" : " ROWS"));
- }
- if (limit > 0) {
- stat.appendSQL(" FETCH NEXT " + limit + (limit == 1 ? " ROW" : " ROWS") + " ONLY");
+ // FETCH/OFFSET added in 10.5
+ if (databaseVersion >= 10.5f) {
+ if (offset > 0) {
+ stat.appendSQL(" OFFSET " + offset + (offset == 1 ? " ROW" : " ROWS"));
+ }
+ if (limit > 0) {
+ stat.appendSQL(" FETCH NEXT " + limit + (limit == 1 ? " ROW" : " ROWS") + " ONLY");
+ }
}
}
diff --git a/src/com/iciql/SQLDialectH2.java b/src/com/iciql/SQLDialectH2.java index 6f74b45..1da45f6 100644 --- a/src/com/iciql/SQLDialectH2.java +++ b/src/com/iciql/SQLDialectH2.java @@ -25,25 +25,33 @@ import com.iciql.util.StatementBuilder; */
public class SQLDialectH2 extends SQLDialectDefault {
+ /**
+ * CACHED tables are created by default. MEMORY tables are created upon
+ * request.
+ */
@Override
- public boolean supportsMemoryTables() {
- return true;
+ protected <T> String prepareCreateTable(TableDefinition<T> def) {
+ if (def.memoryTable) {
+ return "CREATE MEMORY TABLE IF NOT EXISTS";
+ } else {
+ return "CREATE CACHED TABLE IF NOT EXISTS";
+ }
}
@Override
- protected boolean prepareColumnDefinition(StatementBuilder buff, String dataType, boolean isAutoIncrement,
- boolean isPrimaryKey) {
+ protected boolean prepareColumnDefinition(StatementBuilder buff, String dataType,
+ boolean isAutoIncrement, boolean isPrimaryKey) {
String convertedType = convertSqlType(dataType);
boolean isIdentity = false;
if (isIntegerType(dataType)) {
if (isAutoIncrement && isPrimaryKey) {
buff.append("IDENTITY");
- isIdentity = true;
+ isIdentity = true;
} else if (isAutoIncrement) {
buff.append(convertedType);
buff.append(" AUTO_INCREMENT");
} else {
- buff.append(convertedType);
+ buff.append(convertedType);
}
} else {
buff.append(convertedType);
diff --git a/src/com/iciql/SQLDialectHSQL.java b/src/com/iciql/SQLDialectHSQL.java index 3d72ac2..9975be6 100644 --- a/src/com/iciql/SQLDialectHSQL.java +++ b/src/com/iciql/SQLDialectHSQL.java @@ -26,14 +26,22 @@ import com.iciql.util.StatementBuilder; */
public class SQLDialectHSQL extends SQLDialectDefault {
+ /**
+ * CACHED tables are created by default. MEMORY tables are created upon
+ * request.
+ */
@Override
- public boolean supportsMemoryTables() {
- return true;
+ protected <T> String prepareCreateTable(TableDefinition<T> def) {
+ if (def.memoryTable) {
+ return "CREATE MEMORY TABLE IF NOT EXISTS";
+ } else {
+ return "CREATE CACHED TABLE IF NOT EXISTS";
+ }
}
@Override
- protected boolean prepareColumnDefinition(StatementBuilder buff, String dataType, boolean isAutoIncrement,
- boolean isPrimaryKey) {
+ protected boolean prepareColumnDefinition(StatementBuilder buff, String dataType,
+ boolean isAutoIncrement, boolean isPrimaryKey) {
boolean isIdentity = false;
String convertedType = convertSqlType(dataType);
buff.append(convertedType);
diff --git a/src/com/iciql/SQLDialectMySQL.java b/src/com/iciql/SQLDialectMySQL.java index 0b2acf4..7fa1fa9 100644 --- a/src/com/iciql/SQLDialectMySQL.java +++ b/src/com/iciql/SQLDialectMySQL.java @@ -33,6 +33,10 @@ public class SQLDialectMySQL extends SQLDialectDefault { }
@Override
+ protected <T> String prepareCreateTable(TableDefinition<T> def) {
+ return "CREATE TABLE IF NOT EXISTS";
+ }
+ @Override
public String prepareColumnName(String name) {
return "`" + name + "`";
}
diff --git a/src/com/iciql/SQLDialectPostgreSQL.java b/src/com/iciql/SQLDialectPostgreSQL.java index 0874a49..5b3ec71 100644 --- a/src/com/iciql/SQLDialectPostgreSQL.java +++ b/src/com/iciql/SQLDialectPostgreSQL.java @@ -30,11 +30,6 @@ public class SQLDialectPostgreSQL extends SQLDialectDefault { }
@Override
- public boolean supportsIfNotExists() {
- return false;
- }
-
- @Override
public String convertSqlType(String sqlType) {
if ("DOUBLE".equals(sqlType)) {
return "DOUBLE PRECISION";
|