svnno****@sourc*****
svnno****@sourc*****
2010年 2月 1日 (月) 23:55:48 JST
Revision: 3756 http://sourceforge.jp/projects/jiemamy/svn/view?view=rev&revision=3756 Author: setoazusa Date: 2010-02-01 23:55:48 +0900 (Mon, 01 Feb 2010) Log Message: ----------- [GEN-101] H2向けdialectを作成しました。 Added Paths: ----------- hermes/jiemamy-dialect-h2/trunk/src/main/java/org/ hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/ hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/ hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/ hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/H2Dialect.java hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/H2IdentifierValidator.java hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/H2ReservedWordsChecker.java hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/internal/ hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/internal/H2Identifier.java hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/package-info.java hermes/jiemamy-dialect-h2/trunk/src/main/resources/META-INF/ hermes/jiemamy-dialect-h2/trunk/src/main/resources/META-INF/services/ hermes/jiemamy-dialect-h2/trunk/src/main/resources/META-INF/services/org.jiemamy.Dialect hermes/jiemamy-dialect-h2/trunk/src/test/java/org/ hermes/jiemamy-dialect-h2/trunk/src/test/java/org/jiemamy/ hermes/jiemamy-dialect-h2/trunk/src/test/java/org/jiemamy/dialect/ hermes/jiemamy-dialect-h2/trunk/src/test/java/org/jiemamy/dialect/h2/ hermes/jiemamy-dialect-h2/trunk/src/test/java/org/jiemamy/dialect/h2/H2DialectTest.java hermes/jiemamy-dialect-h2/trunk/src/test/java/org/jiemamy/dialect/h2/H2ReservedWordsCheckerTest.java hermes/jiemamy-dialect-h2/trunk/src/test/resources/h2.jer Added: hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/H2Dialect.java =================================================================== --- hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/H2Dialect.java (rev 0) +++ hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/H2Dialect.java 2010-02-01 14:55:48 UTC (rev 3756) @@ -0,0 +1,172 @@ +/* + * Copyright 2007-2010 Jiemamy Project and the Others. + * Created on 2008/07/12 + * + * This file is part of Jiemamy. + * + * 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 org.jiemamy.dialect.h2; + +import static org.jiemamy.model.datatype.DataTypeCategory.BLOB; +import static org.jiemamy.model.datatype.DataTypeCategory.BOOLEAN; +import static org.jiemamy.model.datatype.DataTypeCategory.CHARACTER; +import static org.jiemamy.model.datatype.DataTypeCategory.CLOB; +import static org.jiemamy.model.datatype.DataTypeCategory.DECIMAL; +import static org.jiemamy.model.datatype.DataTypeCategory.DOUBLE; +import static org.jiemamy.model.datatype.DataTypeCategory.FLOAT; +import static org.jiemamy.model.datatype.DataTypeCategory.INTEGER; +import static org.jiemamy.model.datatype.DataTypeCategory.OTHER; +import static org.jiemamy.model.datatype.DataTypeCategory.TIME; +import static org.jiemamy.model.datatype.DataTypeCategory.TIMESTAMP; +import static org.jiemamy.model.datatype.DataTypeCategory.VARCHAR; + +import java.util.List; + +import org.apache.commons.collections15.list.UnmodifiableList; + +import org.jiemamy.dialect.BuiltinDataTypeMold; +import org.jiemamy.dialect.internal.AbstractDialect; +import org.jiemamy.dialect.internal.BuiltinDataTypeMoldImpl; +import org.jiemamy.dialect.internal.impl.DefaultDialectInitializer; +import org.jiemamy.model.datatype.DataTypeCategory; +import org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter; +import org.jiemamy.model.datatype.adapter.SerialDataTypeAdapter; +import org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter; +import org.jiemamy.utils.CollectionsUtil; +import org.jiemamy.validator.Validator; + +/** + * H2 Databaeseに対するSQL方言実装クラス。 + * + * @author azusa + */ +public class H2Dialect extends AbstractDialect { + + private static List<BuiltinDataTypeMold> typeList; + + static { + List<BuiltinDataTypeMold> list = CollectionsUtil.newArrayList(); + list.add(new BuiltinDataTypeMoldImpl(VARCHAR, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(VARCHAR, "VARCHAR2", SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(VARCHAR, "NVARCHAR", SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(VARCHAR, "NVARCHAR2", SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(VARCHAR, "VARCHAR_CASESENSITIVE", SizedDataTypeAdapter.class)); + + list.add(new BuiltinDataTypeMoldImpl(OTHER, "LONGVARCHAR", SizedDataTypeAdapter.class)); + + list.add(new BuiltinDataTypeMoldImpl(CHARACTER, "CHAR", SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(CHARACTER, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(CHARACTER, "NCHAR", SizedDataTypeAdapter.class)); + + list.add(new BuiltinDataTypeMoldImpl(VARCHAR, "VARCHAR_IGNORECASE", SizedDataTypeAdapter.class)); + + list.add(new BuiltinDataTypeMoldImpl(BOOLEAN, "BOOLEAN")); + list.add(new BuiltinDataTypeMoldImpl(BOOLEAN, "BIT")); + list.add(new BuiltinDataTypeMoldImpl(BOOLEAN, "BOOLEAN")); + + list.add(new BuiltinDataTypeMoldImpl(OTHER, "TINYINT", SizedDataTypeAdapter.class)); + + list.add(new BuiltinDataTypeMoldImpl(OTHER, "SMALLINT", SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(OTHER, "YEAR", SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(OTHER, "INT2", SizedDataTypeAdapter.class)); + + list.add(new BuiltinDataTypeMoldImpl(INTEGER, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(INTEGER, "INT", SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(INTEGER, "MEDIUMINT", SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(INTEGER, "INT4", SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(INTEGER, "SIGNED", SizedDataTypeAdapter.class)); + + list.add(new BuiltinDataTypeMoldImpl(OTHER, "BIGINT", SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(OTHER, "INT8", SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(OTHER, "LONG", SizedDataTypeAdapter.class)); + + list.add(new BuiltinDataTypeMoldImpl(OTHER, "IDENTITY", SerialDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(OTHER, "SERIAL", SerialDataTypeAdapter.class)); + + list.add(new BuiltinDataTypeMoldImpl(DECIMAL, "NUMERIC", SerialDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DECIMAL, "NUMBER", SerialDataTypeAdapter.class)); + + list.add(new BuiltinDataTypeMoldImpl(FLOAT, "REAL", PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(FLOAT, "FLOAT4", PrecisionedDataTypeAdapter.class)); + + list.add(new BuiltinDataTypeMoldImpl(DOUBLE, "DOUBLE", PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DOUBLE, "DOUBLE PRECISION", PrecisionedDataTypeAdapter.class)); + + list.add(new BuiltinDataTypeMoldImpl(FLOAT, "FLOAT", PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(FLOAT, "FLOAT8", PrecisionedDataTypeAdapter.class)); + + list.add(new BuiltinDataTypeMoldImpl(TIME)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DATE)); + + list.add(new BuiltinDataTypeMoldImpl(TIMESTAMP, "TIMESTAMP")); + list.add(new BuiltinDataTypeMoldImpl(TIMESTAMP, "DATETIME")); + list.add(new BuiltinDataTypeMoldImpl(TIMESTAMP, "SMALLDATETIME")); + + list.add(new BuiltinDataTypeMoldImpl(OTHER, "BINARY")); + list.add(new BuiltinDataTypeMoldImpl(OTHER, "RAW")); + list.add(new BuiltinDataTypeMoldImpl(OTHER, "BYTEA")); + list.add(new BuiltinDataTypeMoldImpl(OTHER, "LONG RAW")); + + list.add(new BuiltinDataTypeMoldImpl(OTHER, "LONGVARBINARY")); + list.add(new BuiltinDataTypeMoldImpl(OTHER, "LONG RAW")); + + list.add(new BuiltinDataTypeMoldImpl(OTHER, "LONGVARBINARY")); + + list.add(new BuiltinDataTypeMoldImpl(OTHER, "UUID")); + list.add(new BuiltinDataTypeMoldImpl(OTHER, "OBJECT")); + list.add(new BuiltinDataTypeMoldImpl(OTHER, "JAVA_OBJECT")); + + list.add(new BuiltinDataTypeMoldImpl(BLOB, "BLOB")); + list.add(new BuiltinDataTypeMoldImpl(BLOB, "TINYBLOB")); + list.add(new BuiltinDataTypeMoldImpl(BLOB, "MEDIUMBLOB")); + list.add(new BuiltinDataTypeMoldImpl(BLOB, "LONGBLOB")); + list.add(new BuiltinDataTypeMoldImpl(BLOB, "IMAGE")); + list.add(new BuiltinDataTypeMoldImpl(BLOB, "OID")); + + list.add(new BuiltinDataTypeMoldImpl(CLOB, "CLOB")); + list.add(new BuiltinDataTypeMoldImpl(CLOB, "TINYTEXT")); + list.add(new BuiltinDataTypeMoldImpl(CLOB, "TEXT")); + list.add(new BuiltinDataTypeMoldImpl(CLOB, "MEDIUMTEXT")); + list.add(new BuiltinDataTypeMoldImpl(CLOB, "LONGTEXT")); + list.add(new BuiltinDataTypeMoldImpl(CLOB, "NTEXT")); + list.add(new BuiltinDataTypeMoldImpl(CLOB, "NCLOB")); + + list.add(new BuiltinDataTypeMoldImpl(OTHER, "ARRAY")); + + H2Dialect.typeList = UnmodifiableList.decorate(list); + } + + + /** + * インスタンスを生成する。 + */ + public H2Dialect() { + super(new DefaultDialectInitializer(typeList)); + } + + @Override + public String getConnectionUriTemplate() { + return "jdbc:h2:tcp://localhost:9092/"; + } + + public String getName() { + return "H2 Database"; + } + + @Override + public Validator getValidator() { + return new H2IdentifierValidator(); + } + +} Property changes on: hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/H2Dialect.java ___________________________________________________________________ Added: svn:eol-style + native Added: hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/H2IdentifierValidator.java =================================================================== --- hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/H2IdentifierValidator.java (rev 0) +++ hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/H2IdentifierValidator.java 2010-02-01 14:55:48 UTC (rev 3756) @@ -0,0 +1,37 @@ +/* + * Copyright 2007-2010 Jiemamy Project and the Others. + * Created on 2008/09/10 + * + * This file is part of Jiemamy. + * + * 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 org.jiemamy.dialect.h2; + +import org.jiemamy.validator.impl.AbstractIdentifierValidator; + +/** + * H2用識別子バリデータ。 + * + * @author azusa + */ +public class H2IdentifierValidator extends AbstractIdentifierValidator { + + /** + * インスタンスを生成する。 + */ + public H2IdentifierValidator() { + super("^[0-9-a-zA-Z_]+$", new H2ReservedWordsChecker()); + } + +} Property changes on: hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/H2IdentifierValidator.java ___________________________________________________________________ Added: svn:eol-style + native Added: hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/H2ReservedWordsChecker.java =================================================================== --- hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/H2ReservedWordsChecker.java (rev 0) +++ hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/H2ReservedWordsChecker.java 2010-02-01 14:55:48 UTC (rev 3756) @@ -0,0 +1,44 @@ +/* +F * Copyright 2007-2010 Jiemamy Project and the Others. + * Created on 2008/08/24 + * + * This file is part of Jiemamy. + * + * 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 org.jiemamy.dialect.h2; + +import java.util.Arrays; +import java.util.List; + +import org.jiemamy.dialect.internal.ReservedWordsChecker; + +/** + * H2の予約語をチェックするクラス。 + * + * @author azusa + */ +public class H2ReservedWordsChecker implements ReservedWordsChecker { + + private static final List<String> RESERVED_WORDS = + Arrays.asList("CROSS", "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "DISTINCT", "EXCEPT", "EXISTS", + "FALSE", "FOR", "FROM", "FULL", "GROUP", "HAVING", "INNER", "INTERSECT", "IS", "JOIN", "LIKE", + "LIMIT", "MINUS", "NATURAL", "NOT", "NULL", "ON", "ORDER", "PRIMARY", "ROWNUM", "SELECT", + "SYSDATE", "SYSTIME", "SYSTIMESTAMP", "TODAY", "TRUE", "UNION", "WHERE"); + + + public boolean isReserved(String name) { + return RESERVED_WORDS.contains(name); + } + +} Property changes on: hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/H2ReservedWordsChecker.java ___________________________________________________________________ Added: svn:eol-style + native Added: hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/internal/H2Identifier.java =================================================================== --- hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/internal/H2Identifier.java (rev 0) +++ hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/internal/H2Identifier.java 2010-02-01 14:55:48 UTC (rev 3756) @@ -0,0 +1,55 @@ +/* + * Copyright 2007-2010 Jiemamy Project and the Others. + * Created on 2009/02/12 + * + * This file is part of Jiemamy. + * + * 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 org.jiemamy.dialect.h2.internal; + +import org.jiemamy.internal.model.sql.Identifier; + +/** + * H2用識別子クラス。 + * + * <p>このクラスはイミュータブルである。</p> + * + * @author azusa + */ +public class H2Identifier extends Identifier { + + /** + * 識別子を返す。 + * + * @param string 識別子文字列 + * @return 識別子 + */ + public static H2Identifier of(String string) { + return new H2Identifier(string); + } + + /** + * インスタンスを生成する。 + * + * @param identifier 識別子文字列 + */ + protected H2Identifier(String identifier) { + super(identifier); + } + + @Override + public String toString() { + return "`" + super.toString() + "`"; + } +} Property changes on: hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/internal/H2Identifier.java ___________________________________________________________________ Added: svn:eol-style + native Added: hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/package-info.java =================================================================== --- hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/package-info.java (rev 0) +++ hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/package-info.java 2010-02-01 14:55:48 UTC (rev 3756) @@ -0,0 +1,7 @@ +/** + * H2用の {@link org.jiemamy.dialect.Dialect}インターフェイスの実装を提供するパッケージ。 + * + * @author azusa + */ +package org.jiemamy.dialect.h2; + Property changes on: hermes/jiemamy-dialect-h2/trunk/src/main/java/org/jiemamy/dialect/h2/package-info.java ___________________________________________________________________ Added: svn:eol-style + native Added: hermes/jiemamy-dialect-h2/trunk/src/main/resources/META-INF/services/org.jiemamy.Dialect =================================================================== --- hermes/jiemamy-dialect-h2/trunk/src/main/resources/META-INF/services/org.jiemamy.Dialect (rev 0) +++ hermes/jiemamy-dialect-h2/trunk/src/main/resources/META-INF/services/org.jiemamy.Dialect 2010-02-01 14:55:48 UTC (rev 3756) @@ -0,0 +1 @@ +org.jiemamy.dialect.h2.H2Dialect Property changes on: hermes/jiemamy-dialect-h2/trunk/src/main/resources/META-INF/services/org.jiemamy.Dialect ___________________________________________________________________ Added: svn:executable + * Added: hermes/jiemamy-dialect-h2/trunk/src/test/java/org/jiemamy/dialect/h2/H2DialectTest.java =================================================================== --- hermes/jiemamy-dialect-h2/trunk/src/test/java/org/jiemamy/dialect/h2/H2DialectTest.java (rev 0) +++ hermes/jiemamy-dialect-h2/trunk/src/test/java/org/jiemamy/dialect/h2/H2DialectTest.java 2010-02-01 14:55:48 UTC (rev 3756) @@ -0,0 +1,133 @@ +/* + * Copyright 2007-2010 Jiemamy Project and the Others. + * Created on 2010/01/30 + * + * This file is part of Jiemamy. + * + * 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 org.jiemamy.dialect.h2; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.util.List; + +import org.junit.Test; + +import org.jiemamy.Jiemamy; +import org.jiemamy.composer.exporter.DefaultSqlExportConfig; +import org.jiemamy.dialect.BuiltinDataTypeMold; +import org.jiemamy.dialect.DataTypeResolver; +import org.jiemamy.dialect.Dialect; +import org.jiemamy.model.RootModel; +import org.jiemamy.model.datatype.DataTypeCategory; +import org.jiemamy.model.sql.SqlStatement; +import org.jiemamy.serializer.JiemamySerializer; + +/** + * {@link H2Dialect}のテストクラス。 + * + * @since 0.3 + * @version $Id$ + * @author azusa + */ +public class H2DialectTest { + + Dialect dialect = new H2Dialect(); + + + /** + * rootModelを食わせた時に、SQLが生成される。 + * * + * @throws Exception 例外が発生した場合 + */ + @Test + public void newInstance() throws Exception { + RootModel rootModel; + Jiemamy jiemamy = Jiemamy.newInstance(); + JiemamySerializer serializer = jiemamy.getSerializer(); + rootModel = serializer.deserialize(getClass().getResourceAsStream("/h2.jer")); + + List<SqlStatement> statements = dialect.emitStatements(rootModel, new DefaultSqlExportConfig()); + for (SqlStatement sqlStatement : statements) { + //TODO assert + System.out.println(sqlStatement); + } + } + + /** + * toStringがFQCNを返す。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test01_toStringがFQCNを返す() throws Exception { + assertThat(dialect.toString(), is("org.jiemamy.dialect.h2.H2Dialect")); + } + + /** + * {@code null}を返してはいけないメソッドは{@code null}を返さない。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test02_nullを返してはいけないメソッドはnullを返さない() throws Exception { + assertThat(dialect.getDataTypeResolver(), is(notNullValue())); + assertThat(dialect.getValidator(), is(notNullValue())); + } + + /** + * {@link Dialect#getDataTypeResolver()}のテスト。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test03_DataTypeResolverのテスト() throws Exception { + DataTypeResolver dataTypeResolver = dialect.getDataTypeResolver(); + + // 完全一致な情報を与えると、そのままのモールドが得られる。 + BuiltinDataTypeMold mold = dataTypeResolver.findDataTypeMold(DataTypeCategory.INTEGER, "INTEGER"); + assertThat(mold.getCategory(), is(DataTypeCategory.INTEGER)); + assertThat(mold.getName(), is("INTEGER")); + + // 適当な情報を与えた場合、型名が一致したモールドが得られる。 + mold = dataTypeResolver.findDataTypeMold(DataTypeCategory.VARBIT, "INTEGER"); + assertThat(mold.getCategory(), is(DataTypeCategory.INTEGER)); + assertThat(mold.getName(), is("INTEGER")); + + // Oracleっぽい情報を与えても、H2用のモールドが得られる。 + mold = dataTypeResolver.findDataTypeMold(DataTypeCategory.DECIMAL, "BINARY_FLOAT"); + assertThat(mold.getCategory(), is(DataTypeCategory.DECIMAL)); + assertThat(mold.getName(), is("NUMERIC")); + + // 意味不明な情報を与えた場合、UNKNOWNが得られる。 + mold = dataTypeResolver.findDataTypeMold(DataTypeCategory.OTHER, "WONDERFUL"); + assertThat(mold.getCategory(), is(DataTypeCategory.OTHER)); + assertThat(mold.getName(), is("UNKNOWN")); + + mold = dataTypeResolver.findDataTypeMold(DataTypeCategory.INTEGER, "WONDERFUL"); + assertThat(mold.getCategory(), is(DataTypeCategory.INTEGER)); + assertThat(mold.getName(), is("INTEGER")); + + try { + dataTypeResolver.findDataTypeMold(null, null); + fail(); + } catch (IllegalArgumentException e) { + // success + } + + } +} Property changes on: hermes/jiemamy-dialect-h2/trunk/src/test/java/org/jiemamy/dialect/h2/H2DialectTest.java ___________________________________________________________________ Added: svn:eol-style + native Added: hermes/jiemamy-dialect-h2/trunk/src/test/java/org/jiemamy/dialect/h2/H2ReservedWordsCheckerTest.java =================================================================== --- hermes/jiemamy-dialect-h2/trunk/src/test/java/org/jiemamy/dialect/h2/H2ReservedWordsCheckerTest.java (rev 0) +++ hermes/jiemamy-dialect-h2/trunk/src/test/java/org/jiemamy/dialect/h2/H2ReservedWordsCheckerTest.java 2010-02-01 14:55:48 UTC (rev 3756) @@ -0,0 +1,55 @@ +/* + * Copyright 2007-2010 Jiemamy Project and the Others. + * Created on 2009/10/29 + * + * This file is part of Jiemamy. + * + * 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 org.jiemamy.dialect.h2; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +/** + * {@link org.jiemamy.dialect.h2.H2ReservedWordsChecker}のテスト。 + * + * @since 0.3 + * @version $Id$ + * @author azusa + */ +public class H2ReservedWordsCheckerTest { + + private H2ReservedWordsChecker checker = new H2ReservedWordsChecker(); + + + /** + * {@link org.jiemamy.dialect.h2.H2ReservedWordsChecker#isReserved(java.lang.String)} のためのテスト・メソッド。 + * @throws Exception 例外が発生した場合 + */ + @Test + public void 予約語に該当しない場合() throws Exception { + assertThat(checker.isReserved("COLUMN"), is(false)); + } + + /** + * {@link org.jiemamy.dialect.h2.H2ReservedWordsChecker#isReserved(java.lang.String)} のためのテスト・メソッド。 + * @throws Exception 例外が発生した場合 + */ + @Test + public void 予約語に該当する場合() throws Exception { + assertThat(checker.isReserved("CROSS"), is(true)); + } +} Property changes on: hermes/jiemamy-dialect-h2/trunk/src/test/java/org/jiemamy/dialect/h2/H2ReservedWordsCheckerTest.java ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Added: hermes/jiemamy-dialect-h2/trunk/src/test/resources/h2.jer =================================================================== --- hermes/jiemamy-dialect-h2/trunk/src/test/resources/h2.jer (rev 0) +++ hermes/jiemamy-dialect-h2/trunk/src/test/resources/h2.jer 2010-02-01 14:55:48 UTC (rev 3756) @@ -0,0 +1,225 @@ +<?xml version="1.0" encoding="UTF-8"?> +<jiemamy xmlns="http://jiemamy.org/xml/ns/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="9a7f2e3c-99b3-4902-87c9-bb9727eaa376" version="0.2" xsi:schemaLocation="http://jiemamy.org/xml/ns/core http://jiemamy.org/xml/0.2.0/jiemamy-core.xsd http://jiemamy.org/xml/ns/view null"> + <dialect>org.jiemamy.dialect.h2.H2Dialect</dialect> + <domains/> + <entities> + <table id="a8455041-ecfe-481a-9e9f-b2efabf96859"> + <name>EMP_TABLE</name> + <logicalName>社員</logicalName> + <attributes> + <column id="082e7f52-1e2e-4740-80e6-b658d415f967"> + <name>EMP_NO</name> + <logicalName>社員番号</logicalName> + <dataType> + <typeCategory>NUMERIC</typeCategory> + <typeName>NUMERIC</typeName> + <adapter class="org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter"> + <precision>4</precision> + </adapter> + </dataType> + <notNull id="350527d4-b56b-40e0-830b-3bf0f3a03d64"/> + </column> + <primaryKey id="3609a69c-e12f-4851-8426-8e3e1e815b5f"> + <columnRefs> + <columnRef ref="082e7f52-1e2e-4740-80e6-b658d415f967"/> + </columnRefs> + </primaryKey> + <column id="693ee1f3-f051-4521-ae4f-b593a2f266ee"> + <name>ENAME</name> + <logicalName>社員名</logicalName> + <dataType> + <typeCategory>VARCHAR</typeCategory> + <typeName>VARCHAR</typeName> + <adapter class="org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter"> + <size>10</size> + </adapter> + </dataType> + </column> + <column id="6e06804b-8f84-4d5c-9f95-9b7fb98a58cf"> + <name>JOB</name> + <logicalName>職種</logicalName> + <dataType> + <typeCategory>VARCHAR</typeCategory> + <typeName>VARCHAR</typeName> + <adapter class="org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter"> + <size>9</size> + </adapter> + </dataType> + </column> + <column id="dbc28d62-8e84-4de3-b9fc-5d916d879cfb"> + <name>MGR</name> + <logicalName>上司</logicalName> + <dataType> + <typeCategory>NUMERIC</typeCategory> + <typeName>NUMERIC</typeName> + <adapter class="org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter"> + <precision>4</precision> + </adapter> + </dataType> + </column> + <column id="b09bb40c-f753-44ea-9332-00c1aeb218ad"> + <name>HIRE_DATE</name> + <logicalName>入社日</logicalName> + <dataType> + <typeCategory>DATE</typeCategory> + <typeName>DATE</typeName> + </dataType> + </column> + <column id="5d96b8b2-8461-468b-8f3b-709a248d1689"> + <name>SAL</name> + <logicalName>給料</logicalName> + <dataType> + <typeCategory>NUMERIC</typeCategory> + <typeName>NUMERIC</typeName> + <adapter class="org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter"> + <precision>7</precision> + <scale>2</scale> + </adapter> + </dataType> + </column> + <column id="a2920820-d957-4f66-a154-2d0abec586cd"> + <name>COMM</name> + <logicalName>歩合給</logicalName> + <dataType> + <typeCategory>NUMERIC</typeCategory> + <typeName>NUMERIC</typeName> + <adapter class="org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter"> + <precision>7</precision> + <scale>2</scale> + </adapter> + </dataType> + </column> + <column id="e24e9179-0aaf-4cda-91ee-aaf401a044ed"> + <name>DEPT_NO</name> + <logicalName>部署番号</logicalName> + <dataType> + <typeCategory>NUMERIC</typeCategory> + <typeName>NUMERIC</typeName> + <adapter class="org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter"> + <precision>2</precision> + </adapter> + </dataType> + </column> + <column id="ddb86e5a-0bb6-48bd-ab79-d14309d31c30"> + <name>TSTAMP</name> + <logicalName>タイムスタンプ</logicalName> + <dataType> + <typeCategory>TIMESTAMP</typeCategory> + <typeName>TIMESTAMP</typeName> + </dataType> + </column> + <column id="f2fdd399-7432-4485-a4ab-538b0e24a443"> + <name>VERSIONNO</name> + <logicalName>バージョン番号</logicalName> + <dataType> + <typeCategory>NUMERIC</typeCategory> + <typeName>NUMERIC</typeName> + <adapter class="org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter"> + <precision>8</precision> + </adapter> + </dataType> + <notNull id="b3112c5a-24d2-40e1-ab7c-4854a9b7fab5"/> + </column> + <foreignKey id="aa36b4e9-b065-44aa-92fb-36cd05213a12"> + <columnRefs> + <columnRef ref="e24e9179-0aaf-4cda-91ee-aaf401a044ed"/> + </columnRefs> + <referenceColumns> + <columnRef ref="0f128699-bdfe-4a3d-ba3b-69aea6189680"/> + </referenceColumns> + </foreignKey> + </attributes> + <indexes/> + </table> + <table id="6c0aab65-3421-4b28-a76b-a6aafb9f7d87"> + <name>DEPT_TABLE</name> + <logicalName>部署</logicalName> + <attributes> + <column id="0f128699-bdfe-4a3d-ba3b-69aea6189680"> + <name>DEPT_ID</name> + <logicalName>部署番号</logicalName> + <dataType> + <typeCategory>INTEGER</typeCategory> + <typeName>INTEGER</typeName> + <adapter class="org.jiemamy.model.datatype.adapter.SerialDataTypeAdapter"> + <serial>true</serial> + </adapter> + </dataType> + </column> + <column id="2f43eeb1-745e-4432-9116-600976449274"> + <name>DNAME</name> + <logicalName>部署名</logicalName> + <dataType> + <typeCategory>VARCHAR</typeCategory> + <typeName>VARCHAR</typeName> + <adapter class="org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter"> + <size>14</size> + </adapter> + </dataType> + </column> + <column id="e1cdef10-8337-499b-b318-1334b530cb13"> + <name>LOC</name> + <logicalName>位置</logicalName> + <dataType> + <typeCategory>VARCHAR</typeCategory> + <typeName>VARCHAR</typeName> + <adapter class="org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter"> + <size>13</size> + </adapter> + </dataType> + </column> + <column id="6371f1f4-09ca-4d03-aa51-a508558975f5"> + <name>VERSIONNO</name> + <logicalName>バージョン番号</logicalName> + <dataType> + <typeCategory>NUMERIC</typeCategory> + <typeName>NUMERIC</typeName> + <adapter class="org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter"> + <precision>8</precision> + </adapter> + </dataType> + </column> + <column id="8a3f0016-3538-42c1-afb8-0120fa435957"> + <name>ACTIVE</name> + <logicalName>状態</logicalName> + <dataType> + <typeCategory>NUMERIC</typeCategory> + <typeName>NUMERIC</typeName> + <adapter class="org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter"> + <precision>1</precision> + </adapter> + </dataType> + </column> + <primaryKey id="ccc699bc-9609-44cd-a721-f5d11e73fe59"> + <columnRefs> + <columnRef ref="0f128699-bdfe-4a3d-ba3b-69aea6189680"/> + </columnRefs> + </primaryKey> + </attributes> + <indexes/> + </table> + </entities> + <dataSets/> + <view:diagramPresentations xmlns:view="http://jiemamy.org/xml/ns/view"> + <view:diagramPresentation id="a2536ff8-0f1c-4208-b9c0-6d6d856ab56a"> + <name>default</name> + <view:mode>PHYSICAL</view:mode> + <view:level>ATTRTYPE</view:level> + <view:nodeProfiles> + <view:nodeProfile id="4197f858-314b-44a3-b1bb-38badcea58ef"> + <view:nodeObjectRef ref="a8455041-ecfe-481a-9e9f-b2efabf96859"/> + <view:boundary height="-1" width="-1" x="81" y="71"/> + </view:nodeProfile> + <view:nodeProfile id="859f3c0a-3262-4be7-9e47-b90db96f589a"> + <view:nodeObjectRef ref="6c0aab65-3421-4b28-a76b-a6aafb9f7d87"/> + <view:boundary height="-1" width="-1" x="406" y="112"/> + </view:nodeProfile> + </view:nodeProfiles> + <view:connectionProfiles> + <view:connectionProfile id="5325ac7a-7a25-4ccd-bbc9-60ee44aab877"> + <view:connectionObjectRef ref="aa36b4e9-b065-44aa-92fb-36cd05213a12"/> + </view:connectionProfile> + </view:connectionProfiles> + </view:diagramPresentation> + </view:diagramPresentations> +</jiemamy> Property changes on: hermes/jiemamy-dialect-h2/trunk/src/test/resources/h2.jer ___________________________________________________________________ Added: svn:eol-style + native