From f3faeb5d1ea631b0074441f97080e1f2a9145f4b Mon Sep 17 00:00:00 2001 From: James Moger Date: Wed, 10 Aug 2011 09:18:43 -0400 Subject: [PATCH] Moved dialects back to main package. Registered MySQL dialect. --- README.markdown | 1 + docs/00_index.mkd | 2 +- docs/05_releases.mkd | 3 +++ src/com/iciql/Db.java | 7 +++--- ...SQLDialect.java => SQLDialectDefault.java} | 25 ++++++++++++++----- .../H2Dialect.java => SQLDialectH2.java} | 22 +++++++++++++--- ...MySQLDialect.java => SQLDialectMySQL.java} | 24 ++++++++++++++---- src/com/iciql/TableDefinition.java | 8 +++--- src/com/iciql/dialect/package.html | 25 ------------------- 9 files changed, 68 insertions(+), 49 deletions(-) rename src/com/iciql/{dialect/DefaultSQLDialect.java => SQLDialectDefault.java} (70%) rename src/com/iciql/{dialect/H2Dialect.java => SQLDialectH2.java} (71%) rename src/com/iciql/{dialect/MySQLDialect.java => SQLDialectMySQL.java} (69%) delete mode 100644 src/com/iciql/dialect/package.html diff --git a/README.markdown b/README.markdown index c212bea..416bba2 100644 --- a/README.markdown +++ b/README.markdown @@ -18,6 +18,7 @@ iciql **is not**... Supported Databases ------- - [H2](http://h2database.com) +- [MySQL](http://mysql.com) - Support for others is planned and should only require creating a simple "dialect" class. License diff --git a/docs/00_index.mkd b/docs/00_index.mkd index 06bec5b..70048e7 100644 --- a/docs/00_index.mkd +++ b/docs/00_index.mkd @@ -36,7 +36,7 @@ select * from products ### Supported Databases -[H2](http://h2database.com) +[H2](http://h2database.com), [MySQL](http://mysql.com) Support for others is planned and should only require creating a simple "dialect" class. diff --git a/docs/05_releases.mkd b/docs/05_releases.mkd index e889f2f..7fb0113 100644 --- a/docs/05_releases.mkd +++ b/docs/05_releases.mkd @@ -7,6 +7,9 @@ **%VERSION%** ([zip](http://code.google.com/p/iciql/downloads/detail?name=%ZIP%)|[jar](http://code.google.com/p/iciql/downloads/detail?name=%JAR%))   *released %BUILDDATE%* - api change release (API v4) +- moved dialects back to main package +- refined dialect loading for pooled connections +- added a MySQL dialect - @IQColumn(allowNull=true) -> @IQColumn(nullable=true) - All columns are assumed NULLABLE unless explicitly set *@IQColumn(nullable = false)* - allow using objects to assign default values
diff --git a/src/com/iciql/Db.java b/src/com/iciql/Db.java index d6f70d1..c7801c2 100644 --- a/src/com/iciql/Db.java +++ b/src/com/iciql/Db.java @@ -37,8 +37,6 @@ import javax.sql.DataSource; import com.iciql.DbUpgrader.DefaultDbUpgrader; import com.iciql.Iciql.IQTable; 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; @@ -73,7 +71,8 @@ public class Db { // can register by... // 1. Connection class name // 2. DatabaseMetaData.getDatabaseProductName() - DIALECTS.put("h2", H2Dialect.class); + DIALECTS.put("H2", SQLDialectH2.class); + DIALECTS.put("MySQL", SQLDialectMySQL.class); } private Db(Connection conn) { @@ -114,7 +113,7 @@ public class Db { dialectClass = DIALECTS.get(databaseName); } else { // did not find a match, use default - dialectClass = DefaultSQLDialect.class; + dialectClass = SQLDialectDefault.class; } return instance(dialectClass); } diff --git a/src/com/iciql/dialect/DefaultSQLDialect.java b/src/com/iciql/SQLDialectDefault.java similarity index 70% rename from src/com/iciql/dialect/DefaultSQLDialect.java rename to src/com/iciql/SQLDialectDefault.java index f3f222e..760a1f4 100644 --- a/src/com/iciql/dialect/DefaultSQLDialect.java +++ b/src/com/iciql/SQLDialectDefault.java @@ -1,12 +1,25 @@ -package com.iciql.dialect; +/* + * 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. + */ + +package com.iciql; import java.sql.DatabaseMetaData; import java.sql.SQLException; -import com.iciql.IciqlException; -import com.iciql.SQLDialect; -import com.iciql.SQLStatement; -import com.iciql.TableDefinition; import com.iciql.TableDefinition.IndexDefinition; import com.iciql.util.StringUtils; @@ -14,7 +27,7 @@ import com.iciql.util.StringUtils; * Default implementation of an SQL dialect. Does not support merge nor index * creation. */ -public class DefaultSQLDialect implements SQLDialect { +public class SQLDialectDefault implements SQLDialect { float databaseVersion; String databaseName; String productVersion; diff --git a/src/com/iciql/dialect/H2Dialect.java b/src/com/iciql/SQLDialectH2.java similarity index 71% rename from src/com/iciql/dialect/H2Dialect.java rename to src/com/iciql/SQLDialectH2.java index 61babd7..c65c277 100644 --- a/src/com/iciql/dialect/H2Dialect.java +++ b/src/com/iciql/SQLDialectH2.java @@ -1,7 +1,21 @@ -package com.iciql.dialect; +/* + * 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. + */ + +package com.iciql; -import com.iciql.SQLStatement; -import com.iciql.TableDefinition; import com.iciql.TableDefinition.FieldDefinition; import com.iciql.TableDefinition.IndexDefinition; import com.iciql.util.StatementBuilder; @@ -9,7 +23,7 @@ import com.iciql.util.StatementBuilder; /** * H2 database dialect. */ -public class H2Dialect extends DefaultSQLDialect { +public class SQLDialectH2 extends SQLDialectDefault { @Override public boolean supportsMemoryTables() { diff --git a/src/com/iciql/dialect/MySQLDialect.java b/src/com/iciql/SQLDialectMySQL.java similarity index 69% rename from src/com/iciql/dialect/MySQLDialect.java rename to src/com/iciql/SQLDialectMySQL.java index e1ccaf3..837d77b 100644 --- a/src/com/iciql/dialect/MySQLDialect.java +++ b/src/com/iciql/SQLDialectMySQL.java @@ -1,15 +1,29 @@ -package com.iciql.dialect; +/* + * 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. + */ + +package com.iciql; -import com.iciql.SQLStatement; -import com.iciql.TableDefinition; import com.iciql.TableDefinition.FieldDefinition; import com.iciql.TableDefinition.IndexDefinition; import com.iciql.util.StatementBuilder; /** - * H2 database dialect. + * MySQL database dialect. */ -public class MySQLDialect extends DefaultSQLDialect { +public class SQLDialectMySQL extends SQLDialectDefault { @Override public boolean supportsMemoryTables() { diff --git a/src/com/iciql/TableDefinition.java b/src/com/iciql/TableDefinition.java index 5d934a5..c08a032 100644 --- a/src/com/iciql/TableDefinition.java +++ b/src/com/iciql/TableDefinition.java @@ -67,12 +67,12 @@ public class TableDefinition { * The meta data of a field. */ - public static class FieldDefinition { - public String columnName; + static class FieldDefinition { + String columnName; Field field; String dataType; int maxLength; - public boolean isPrimaryKey; + boolean isPrimaryKey; boolean isAutoIncrement; boolean trimString; boolean nullable; @@ -362,7 +362,7 @@ public class TableDefinition { * Optionally truncates strings to the maximum length and converts * java.lang.Enum types to Strings or Integers. */ - public Object getValue(Object obj, FieldDefinition field) { + Object getValue(Object obj, FieldDefinition field) { Object value = field.getValue(obj); if (value == null) { return value; diff --git a/src/com/iciql/dialect/package.html b/src/com/iciql/dialect/package.html deleted file mode 100644 index ad91873..0000000 --- a/src/com/iciql/dialect/package.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - -Javadoc package documentation - - -The dialect classes for iciql. - - \ No newline at end of file -- 2.39.5