svnno****@sourc*****
svnno****@sourc*****
2009年 2月 19日 (木) 20:16:10 JST
Revision: 2689 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2689 Author: daisuke_m Date: 2009-02-19 20:16:10 +0900 (Thu, 19 Feb 2009) Log Message: ----------- BuiltinDataTypeMold導入し、BuiltinDataTypeの生成方法変更。 / モデル正規化ロジック導入。 / vestaテーブルダイアログで、PKの設定ができるように修正。 Modified Paths: -------------- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/SerializationTest.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/ArtemisJiemamyFactory.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/FactoryExtension.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/generic/GenericDialect.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomParser.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/AttributeComparator.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/builder/DataTypeBuilder.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/builder/ModelBuilder.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/ColumnUtil.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/ForeignKeyUtil.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/KeyConstraintUtil.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/RootModelUtil.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/TableUtil.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/PrimaryKeyValidator.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ArtemisJiemamyFactoryTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/datatype/BuiltinDataTypeImplTest.java artemis/trunk/jiemamy-dialect-mysql/src/main/java/org/jiemamy/dialect/mysql/MySqlDialect.java artemis/trunk/jiemamy-dialect-postgresql/src/main/java/org/jiemamy/dialect/postgresql/PostgresqlDialect.java artemis/trunk/jiemamy-dialect-sql99/src/main/java/org/jiemamy/dialect/sql99/Sql99Dialect.java artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/ArtemisViewTest.java vesta/trunk/jiemamy-vesta/pull.bat vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/JiemamyPlugin.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditor.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditorPaletteFactory.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/MultiDiagramEditor.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDomainTab.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogColumnTab.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyFactory.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/dialect/Dialect.java Added Paths: ----------- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/BuiltinDataTypeMoldImpl.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataTypeImpl.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DateUtil.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataType.java Removed Paths: ------------- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/AvailableTypeInfoImpl.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataTypeImpl.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/builder/ModelBuilderTest.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataType.java -------------- next part -------------- Modified: artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/SerializationTest.java =================================================================== --- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/SerializationTest.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/SerializationTest.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -224,7 +224,6 @@ for (Problem problem : problems1) { logger.error(problem.getMessage()); } - assertThat(problems1.size(), is(0)); // 一応バリデーションを行っておく // rootModel1 -> xml1 String xml1 = convertRootModelToXml(serializer1, rootModel1); @@ -235,7 +234,6 @@ for (Problem problem : problems2) { logger.warn(problem.getMessage()); } - assertThat(problems2.size(), is(0)); // 一応バリデーションを行っておく // rootModel2 -> xml2 String xml2 = convertRootModelToXml(serializer2, rootModel2); @@ -258,6 +256,8 @@ DetailedDiff diff = new DetailedDiff(new Diff(xml1, xml2)); assertThat(diff.getAllDifferences().toString(), diff.similar(), is(true)); assertEquals(EqualsUtil.rightGTree, EqualsUtil.leftGTree); + assertThat(problems1.size(), is(0)); // 一応バリデーションを行っておく + assertThat(problems2.size(), is(0)); // 一応バリデーションを行っておく } /** @@ -281,7 +281,6 @@ for (Problem problem : problem1) { logger.error(problem.getMessage()); } - assertThat(problem1.size(), is(0)); // 一応バリデーションを行っておく // rootModel1 -> xml2 String xml2 = convertRootModelToXml(serializer2, rootModel1); @@ -289,7 +288,6 @@ // xml1 -> rootModel2 RootModel rootModel2 = convertXmlToRootModel(xml2, serializer2); Collection<Problem> problem2 = validator.validate(rootModel2); - assertThat(problem2.toString(), problem2.size(), is(0)); // 一応バリデーションを行っておく // 参考のため、targetディレクトリに出力XMLを記録 FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) @@ -309,6 +307,8 @@ DetailedDiff diff = new DetailedDiff(new Diff(xml1, xml2)); assertThat(diff.getAllDifferences().toString(), diff.similar(), is(true)); assertEquals(EqualsUtil.rightGTree, EqualsUtil.leftGTree); + assertThat(problem1.size(), is(0)); // 一応バリデーションを行っておく + assertThat(problem2.size(), is(0)); // 一応バリデーションを行っておく } private String convertRootModelToXml(JiemamySerializer serializer, RootModel rootModel) Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/ArtemisJiemamyFactory.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/ArtemisJiemamyFactory.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/ArtemisJiemamyFactory.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -23,12 +23,19 @@ import org.apache.commons.lang.Validate; +import org.jiemamy.dialect.Dialect.BuiltinDataTypeMold; import org.jiemamy.model.JiemamyElement; import org.jiemamy.model.RootModel; import org.jiemamy.model.attribute.ColumnModel; import org.jiemamy.model.attribute.ColumnRef; +import org.jiemamy.model.datatype.BuiltinDataType; +import org.jiemamy.model.datatype.BuiltinDataTypeImpl; import org.jiemamy.model.datatype.DomainModel; import org.jiemamy.model.datatype.DomainRef; +import org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter; +import org.jiemamy.model.datatype.adapter.SerialDataTypeAdapter; +import org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter; +import org.jiemamy.model.datatype.adapter.TimezonedDataTypeAdapter; import org.jiemamy.model.entity.TableModel; import org.jiemamy.model.entity.TableRef; import org.jiemamy.serializer.JiemamyDomSerializer; @@ -124,7 +131,19 @@ /** * {@inheritDoc} */ - public synchronized <T>T newModel(Class<T> clazz) { + public BuiltinDataType newBuiltinDataType(BuiltinDataTypeMold mold) { + BuiltinDataTypeImpl dataType = new BuiltinDataTypeImpl(mold.getCategory(), mold.getTypeName()); + dataType.registerAdapter(new SizedDataTypeAdapter()); + dataType.registerAdapter(new PrecisionedDataTypeAdapter()); + dataType.registerAdapter(new SerialDataTypeAdapter()); + dataType.registerAdapter(new TimezonedDataTypeAdapter()); + return dataType; + } + + /** + * {@inheritDoc} + */ + public synchronized <T extends JiemamyElement>T newModel(Class<T> clazz) { checkInitialized(); if (hasRootModel() == true && clazz == RootModel.class) { throw new IllegalStateException(); @@ -136,9 +155,7 @@ if (clazz == RootModel.class) { rootModel = (RootModel) model; } - if (model instanceof JiemamyElement) { - implementation.getReferenceResolver().add((JiemamyElement) model); - } + implementation.getReferenceResolver().add(model); return model; } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/FactoryExtension.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/FactoryExtension.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/FactoryExtension.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -57,16 +57,10 @@ import org.jiemamy.model.dataset.DataSetModelImpl; import org.jiemamy.model.dataset.RecordModel; import org.jiemamy.model.dataset.RecordModelImpl; -import org.jiemamy.model.datatype.BuiltinDataType; -import org.jiemamy.model.datatype.BuiltinDataTypeImpl; import org.jiemamy.model.datatype.DomainModel; import org.jiemamy.model.datatype.DomainModelImpl; import org.jiemamy.model.datatype.DomainRef; import org.jiemamy.model.datatype.DomainRefImpl; -import org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter; -import org.jiemamy.model.datatype.adapter.SerialDataTypeAdapter; -import org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter; -import org.jiemamy.model.datatype.adapter.TimezonedDataTypeAdapter; import org.jiemamy.model.entity.EntityModel; import org.jiemamy.model.entity.TableModel; import org.jiemamy.model.entity.TableModelImpl; @@ -356,19 +350,6 @@ } }, /***/ - BUILTIN(BuiltinDataType.class) { - - @Override - public <T>T newInstance(Jiemamy jiemamy, UUID id) { - BuiltinDataTypeImpl dataType = new BuiltinDataTypeImpl(); - dataType.registerAdapter(new SizedDataTypeAdapter()); - dataType.registerAdapter(new PrecisionedDataTypeAdapter()); - dataType.registerAdapter(new SerialDataTypeAdapter()); - dataType.registerAdapter(new TimezonedDataTypeAdapter()); - return (T) dataType; - } - }, - /***/ INDEX(IndexModel.class) { @Override @@ -404,7 +385,7 @@ private final Class<?> clazz; - ModelStrategy(Class<?> clazz) { + ModelStrategy(Class<? extends JiemamyElement> clazz) { assert clazz.isInterface(); this.clazz = clazz; } Deleted: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/AvailableTypeInfoImpl.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/AvailableTypeInfoImpl.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/AvailableTypeInfoImpl.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -1,84 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2009/02/17 - * - * 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; - -import java.util.Arrays; -import java.util.Collection; - -import org.jiemamy.dialect.Dialect.AvailableTypeInfo; -import org.jiemamy.model.datatype.DataTypeCategory; - -/** - * TODO for daisuke - * - * @author daisuke - */ -public class AvailableTypeInfoImpl implements AvailableTypeInfo { - - private final DataTypeCategory category; - - private final String typeName; - - private final Class<?>[] adapters; - - - /** - * インスタンスを生成する。 - * - * @param category - * @param adapters - */ - public AvailableTypeInfoImpl(DataTypeCategory category, Class<?>... adapters) { - this(category, category.name(), adapters); - } - - /** - * インスタンスを生成する。 - * @param category - * @param typeName - * @param adapters - */ - public AvailableTypeInfoImpl(DataTypeCategory category, String typeName, Class<?>... adapters) { - this.category = category; - this.typeName = typeName; - this.adapters = adapters; - } - - /** - * {@inheritDoc} - */ - public Collection<Class<?>> getAdapterClasses() { - return Arrays.asList(adapters); - } - - /** - * {@inheritDoc} - */ - public DataTypeCategory getCategory() { - return category; - } - - /** - * {@inheritDoc} - */ - public String getTypeName() { - return typeName; - } - -} Copied: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/BuiltinDataTypeMoldImpl.java (from rev 2688, artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/AvailableTypeInfoImpl.java) =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/BuiltinDataTypeMoldImpl.java (rev 0) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/BuiltinDataTypeMoldImpl.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -0,0 +1,84 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/02/17 + * + * 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; + +import java.util.Arrays; +import java.util.Collection; + +import org.jiemamy.dialect.Dialect.BuiltinDataTypeMold; +import org.jiemamy.model.datatype.DataTypeCategory; + +/** + * TODO for daisuke + * + * @author daisuke + */ +public class BuiltinDataTypeMoldImpl implements BuiltinDataTypeMold { + + private final DataTypeCategory category; + + private final String typeName; + + private final Class<?>[] adapters; + + + /** + * インスタンスを生成する。 + * + * @param category + * @param adapters + */ + public BuiltinDataTypeMoldImpl(DataTypeCategory category, Class<?>... adapters) { + this(category, category.name(), adapters); + } + + /** + * インスタンスを生成する。 + * @param category + * @param typeName + * @param adapters + */ + public BuiltinDataTypeMoldImpl(DataTypeCategory category, String typeName, Class<?>... adapters) { + this.category = category; + this.typeName = typeName; + this.adapters = adapters; + } + + /** + * {@inheritDoc} + */ + public DataTypeCategory getCategory() { + return category; + } + + /** + * {@inheritDoc} + */ + public Collection<Class<?>> getSupportedAdapterClasses() { + return Arrays.asList(adapters); + } + + /** + * {@inheritDoc} + */ + public String getTypeName() { + return typeName; + } + +} Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/BuiltinDataTypeMoldImpl.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -29,6 +29,7 @@ import org.jiemamy.JiemamyFactory; import org.jiemamy.ReferenceResolver; +import org.jiemamy.dialect.Dialect.BuiltinDataTypeMold; import org.jiemamy.model.datatype.BuiltinDataType; import org.jiemamy.model.datatype.DataType; import org.jiemamy.model.datatype.DataTypeCategory; @@ -112,16 +113,17 @@ */ public BuiltinDataType resolveDataType(JiemamyFactory factory, int sqlType, String typeName) { Validate.notNull(factory); - BuiltinDataType builtinDataType = factory.newModel(BuiltinDataType.class); + DataTypeCategory category; try { category = DataTypeCategory.valueOf(typeName); } catch (IllegalArgumentException e) { category = DataTypeCategory.fromSqlType(sqlType); } - builtinDataType.setCategory(category); - builtinDataType.setTypeName(typeName); - return builtinDataType; + // FIXME ここでモールド生成していいんか + BuiltinDataTypeMold mold = new BuiltinDataTypeMoldImpl(category, typeName); + + return factory.newBuiltinDataType(mold); } /** Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/generic/GenericDialect.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/generic/GenericDialect.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/generic/GenericDialect.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -25,7 +25,7 @@ import org.apache.commons.collections15.list.UnmodifiableList; import org.jiemamy.AllValidator; -import org.jiemamy.dialect.AvailableTypeInfoImpl; +import org.jiemamy.dialect.BuiltinDataTypeMoldImpl; import org.jiemamy.dialect.ConnectionAdvisor; import org.jiemamy.dialect.DataTypeResolver; import org.jiemamy.dialect.DefaultConnectionAdvisor; @@ -56,28 +56,28 @@ private ConnectionAdvisor advisor = new DefaultConnectionAdvisor(); - private static final List<AvailableTypeInfo> allDataTypes; + private static final List<BuiltinDataTypeMold> allDataTypes; static { - List<AvailableTypeInfo> list = CollectionsUtil.newArrayList(); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.CHARACTER, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.VARCHAR, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.CLOB, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.BLOB, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.BIT, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.VARBIT, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.NUMERIC, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.DECIMAL, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.INTEGER)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.SMALLINT)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.FLOAT, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.REAL, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.DOUBLE, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.BOOLEAN)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.DATE)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.TIME, TimezonedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.TIMESTAMP, TimezonedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.INTERVAL)); + List<BuiltinDataTypeMold> list = CollectionsUtil.newArrayList(); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.CHARACTER, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.VARCHAR, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.CLOB, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BLOB, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BIT, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.VARBIT, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.NUMERIC, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DECIMAL, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.INTEGER)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.SMALLINT)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.FLOAT, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.REAL, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DOUBLE, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BOOLEAN)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DATE)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.TIME, TimezonedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.TIMESTAMP, TimezonedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.INTERVAL)); allDataTypes = UnmodifiableList.decorate(list); } @@ -107,7 +107,7 @@ /** * {@inheritDoc} */ - public List<AvailableTypeInfo> getAllDataTypes() { + public List<BuiltinDataTypeMold> getAllDataTypes() { // FIXME 適当 return allDataTypes; } Deleted: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataTypeImpl.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataTypeImpl.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataTypeImpl.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -1,84 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2008/12/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.model.datatype; - -import org.apache.commons.lang.Validate; -import org.apache.commons.lang.builder.ReflectionToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; - -import org.jiemamy.model.AbstractAdaptable; - -/** - * {@link DataType}の実装クラス。 - * @author daisuke - */ -public class BuiltinDataTypeImpl extends AbstractAdaptable implements BuiltinDataType { - - private DataTypeCategory category; - - private String typeName; - - - /** - * {@inheritDoc} - */ - public DataTypeCategory getCategory() { - return category; - } - - /** - * {@inheritDoc} - */ - public String getTypeName() { - if (typeName == null) { - return category.toString(); - } - return typeName; - } - - /** - * {@inheritDoc} - */ - public void setCategory(DataTypeCategory category) { - Validate.notNull(category); - this.category = category; - } - - /** - * {@inheritDoc} - */ - public void setTypeName(String typeName) { - this.typeName = typeName; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - ReflectionToStringBuilder toStringBuilder = - new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); - toStringBuilder.setExcludeFieldNames(new String[] { - "jiemamy" - }); - - return toStringBuilder.toString(); - } - -} Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataTypeImpl.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataTypeImpl.java (rev 0) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataTypeImpl.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -0,0 +1,95 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2008/12/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.model.datatype; + +import org.apache.commons.lang.Validate; +import org.apache.commons.lang.builder.ReflectionToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +import org.jiemamy.model.AbstractAdaptable; + +/** + * {@link BuiltinDataType}の実装クラス。 + * @author daisuke + */ +public class BuiltinDataTypeImpl extends AbstractAdaptable implements BuiltinDataType { + + private DataTypeCategory category; + + private String typeName; + + + /** + * インスタンスを生成する。 + * + * @param category + * @param typeName + */ + public BuiltinDataTypeImpl(DataTypeCategory category, String typeName) { + this.category = category; + this.typeName = typeName; + } + + /** + * {@inheritDoc} + */ + public DataTypeCategory getCategory() { + return category; + } + + /** + * {@inheritDoc} + */ + public String getTypeName() { + if (typeName == null) { + return category.toString(); + } + return typeName; + } + + /** + * {@inheritDoc} + */ + public void setCategory(DataTypeCategory category) { + Validate.notNull(category); + this.category = category; + } + + /** + * {@inheritDoc} + */ + public void setTypeName(String typeName) { + this.typeName = typeName; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + ReflectionToStringBuilder toStringBuilder = + new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); + toStringBuilder.setExcludeFieldNames(new String[] { + "jiemamy" + }); + + return toStringBuilder.toString(); + } + +} Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomParser.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomParser.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomParser.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -40,6 +40,8 @@ import org.jiemamy.Jiemamy; import org.jiemamy.JiemamyFactory; +import org.jiemamy.dialect.BuiltinDataTypeMoldImpl; +import org.jiemamy.dialect.Dialect.BuiltinDataTypeMold; import org.jiemamy.exception.UnexpectedConditionError; import org.jiemamy.model.RootModel; import org.jiemamy.model.attribute.ColumnModel; @@ -195,10 +197,21 @@ String typeName = (String) XpathUtil.XPATH.evaluate("core:typeName/text()", element, XPathConstants.STRING); - BuiltinDataType dataType = factory.newModel(BuiltinDataType.class); + BuiltinDataTypeMold mold; if (StringUtils.isEmpty(typeCategoryString) == false) { - dataType.setCategory(DataTypeCategory.valueOf(typeCategoryString)); + // FIXME ここでモールド生成していいんか + mold = new BuiltinDataTypeMoldImpl(DataTypeCategory.valueOf(typeCategoryString), typeName); + } else { + DataTypeCategory category; + try { + category = DataTypeCategory.valueOf(typeName); + } catch (IllegalArgumentException e) { + category = DataTypeCategory.INTEGER; + } + // FIXME ここでモールド生成していいんか + mold = new BuiltinDataTypeMoldImpl(category, typeName); } + BuiltinDataType dataType = factory.newBuiltinDataType(mold); dataType.setTypeName(typeName); readAdapter(element, dataType); Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/AttributeComparator.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/AttributeComparator.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/AttributeComparator.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -37,7 +37,7 @@ * * @author daisuke */ -class AttributeComparator implements Comparator<AttributeModel> { +public class AttributeComparator implements Comparator<AttributeModel> { static final List<Class<? extends AttributeModel>> ORDER; @@ -66,9 +66,13 @@ private final TableModel tableModel; - AttributeComparator(TableModel tableModel) { + /** + * インスタンスを生成する。 + * + * @param tableModel + */ + public AttributeComparator(TableModel tableModel) { this.tableModel = tableModel; - } /** Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DateUtil.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DateUtil.java (rev 0) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DateUtil.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -0,0 +1,50 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/02/19 + * + * 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.utils; + +import java.util.Calendar; + +/** + * 日付時間系ユーティリティ。 + * + * <p>cf. http://d.hatena.ne.jp/higayasuo/20090219/1235020303</p> + * + * @author daisuke + */ +public class DateUtil { + + public static java.sql.Date toSqlDate(java.util.Date d) { + Calendar cal = Calendar.getInstance(); + cal.setTime(d); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + return new java.sql.Date(cal.getTimeInMillis()); + } + + public static java.sql.Time toSqlTime(java.util.Date d) { + Calendar cal = Calendar.getInstance(); + cal.setTime(d); + cal.set(Calendar.YEAR, 1970); + cal.set(Calendar.MONTH, Calendar.JANUARY); + cal.set(Calendar.DATE, 1); + return new java.sql.Time(cal.getTimeInMillis()); + } +} Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DateUtil.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/builder/DataTypeBuilder.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/builder/DataTypeBuilder.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/builder/DataTypeBuilder.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -21,6 +21,8 @@ import org.apache.commons.lang.Validate; import org.jiemamy.JiemamyFactory; +import org.jiemamy.dialect.BuiltinDataTypeMoldImpl; +import org.jiemamy.dialect.Dialect.BuiltinDataTypeMold; import org.jiemamy.model.datatype.BuiltinDataType; import org.jiemamy.model.datatype.DataTypeCategory; import org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter; @@ -31,8 +33,19 @@ * {@link BuiltinDataType}を生成するビルダ。 * @author daisuke */ -public class DataTypeBuilder extends ModelBuilder<BuiltinDataType> { +public class DataTypeBuilder { + private BuiltinDataTypeMold mold; + + private BuiltinDataType dataType; + + + /** + * インスタンスを生成する。 + * + * @param factory + * @param typeCategory + */ public DataTypeBuilder(JiemamyFactory factory, DataTypeCategory typeCategory) { this(factory, typeCategory, typeCategory.name()); } @@ -44,19 +57,27 @@ * @param typeName */ public DataTypeBuilder(JiemamyFactory factory, DataTypeCategory typeCategory, String typeName) { - super(factory, BuiltinDataType.class); + // FIXME ここでモールド生成していいんか + mold = new BuiltinDataTypeMoldImpl(typeCategory, typeName); Validate.notNull(typeName); - model.setCategory(typeCategory); - model.setTypeName(typeName); + dataType = factory.newBuiltinDataType(mold); } /** + * モデルを構築する。 + * @return model 構築されたモデル + */ + public BuiltinDataType build() { + return dataType; + } + + /** * 精度を設定する。 * @param precision 精度 * @return this */ public DataTypeBuilder setPrecision(int precision) { - model.getAdapter(PrecisionedDataTypeAdapter.class).setPrecision(precision); + dataType.getAdapter(PrecisionedDataTypeAdapter.class).setPrecision(precision); return this; } @@ -66,7 +87,7 @@ * @return this */ public DataTypeBuilder setScale(int scale) { - model.getAdapter(PrecisionedDataTypeAdapter.class).setScale(scale); + dataType.getAdapter(PrecisionedDataTypeAdapter.class).setScale(scale); return this; } @@ -76,7 +97,7 @@ * @return this */ public DataTypeBuilder setSerial(boolean serial) { - model.getAdapter(SerialDataTypeAdapter.class).setSerial(serial); + dataType.getAdapter(SerialDataTypeAdapter.class).setSerial(serial); return this; } @@ -86,7 +107,7 @@ * @return this */ public DataTypeBuilder setSize(int size) { - model.getAdapter(SizedDataTypeAdapter.class).setSize(size); + dataType.getAdapter(SizedDataTypeAdapter.class).setSize(size); return this; } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/builder/ModelBuilder.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/builder/ModelBuilder.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/builder/ModelBuilder.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -21,6 +21,7 @@ import org.apache.commons.lang.Validate; import org.jiemamy.JiemamyFactory; +import org.jiemamy.model.JiemamyElement; import org.jiemamy.model.RootModel; /** @@ -28,7 +29,7 @@ * @param <T> 構築するモデルの型 * @author daisuke */ -public abstract class ModelBuilder<T> { +public abstract class ModelBuilder<T extends JiemamyElement> { /** 構築元となる{@link JiemamyFactory} */ JiemamyFactory factory; Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/ColumnUtil.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/ColumnUtil.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/ColumnUtil.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -63,7 +63,7 @@ PrimaryKeyModel primaryKey = TableUtil.getPrimaryKey(tableModel); List<ColumnRef> keyColumns = primaryKey.getKeyColumns(); for (ColumnRef columnRef : keyColumns) { - if (columnRef.getReferenceId() == columnModel.getId()) { + if (columnRef.getReferenceId().equals(columnModel.getId())) { return true; } } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/ForeignKeyUtil.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/ForeignKeyUtil.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/ForeignKeyUtil.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -113,7 +113,7 @@ */ public static KeyConstraintModel getReferenceKeyConstraint(ForeignKeyModel fkModel) { TableModel referenceTable = (TableModel) ForeignKeyUtil.getReferenceEntity(fkModel); - for (KeyConstraintModel keyConstraint : TableUtil.getAttributes(referenceTable, KeyConstraintModel.class)) { + for (KeyConstraintModel keyConstraint : TableUtil.getAttributes(referenceTable, KeyConstraintModel.class, true)) { // サイズ不一致であれば、そもそもこのキーを参照したものではない if (keyConstraint.getKeyColumns().size() != fkModel.getReferenceColumns().size()) { Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/KeyConstraintUtil.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/KeyConstraintUtil.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/KeyConstraintUtil.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -18,9 +18,12 @@ */ package org.jiemamy.utils.model; +import java.util.List; + import org.jiemamy.model.attribute.ColumnModel; import org.jiemamy.model.attribute.ColumnRef; import org.jiemamy.model.attribute.constraint.KeyConstraintModel; +import org.jiemamy.utils.CollectionsUtil; /** * {@link KeyConstraintModel}のユーティリティクラス。 @@ -36,10 +39,41 @@ * @param column 追加するカラム */ public static void addKeyColumn(KeyConstraintModel keyModel, ColumnModel column) { + if (containsKeyColumn(keyModel, column)) { + return; + } ColumnRef ref = column.getJiemamy().getFactory().newReference(column); keyModel.getKeyColumns().add(ref); } + /** + * TODO for daisuke + * + * @param keyModel + * @param column + * @return + */ + public static boolean containsKeyColumn(KeyConstraintModel keyModel, ColumnModel column) { + List<ColumnRef> keyColumns = keyModel.getKeyColumns(); + for (ColumnRef columnRef : keyColumns) { + if (column.getId() == columnRef.getReferenceId()) { + return true; + } + } + return false; + } + + public static void removeKeyColumn(KeyConstraintModel keyModel, ColumnModel column) { + List<ColumnRef> keyColumns = keyModel.getKeyColumns(); + List<ColumnRef> toRemove = CollectionsUtil.newArrayList(); + for (ColumnRef columnRef : keyColumns) { + if (column.getId() == columnRef.getReferenceId()) { + toRemove.add(columnRef); + } + } + keyColumns.removeAll(toRemove); + } + private KeyConstraintUtil() { } } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/RootModelUtil.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/RootModelUtil.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/RootModelUtil.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -19,12 +19,15 @@ package org.jiemamy.utils.model; import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.UUID; import org.apache.commons.lang.Validate; import org.jiemamy.Jiemamy; +import org.jiemamy.ReferenceResolver; import org.jiemamy.dialect.Dialect; import org.jiemamy.exception.ElementNotFoundException; import org.jiemamy.exception.TooManyElementsException; @@ -34,6 +37,7 @@ import org.jiemamy.model.RootModel; import org.jiemamy.model.attribute.AttributeModel; import org.jiemamy.model.attribute.ColumnModel; +import org.jiemamy.model.attribute.ColumnRef; import org.jiemamy.model.attribute.constraint.ColumnCheckModel; import org.jiemamy.model.attribute.constraint.Deferrability; import org.jiemamy.model.attribute.constraint.ForeignKeyModel; @@ -46,6 +50,7 @@ import org.jiemamy.model.entity.EntityModel; import org.jiemamy.model.entity.TableModel; import org.jiemamy.model.index.IndexModel; +import org.jiemamy.utils.AttributeComparator; import org.jiemamy.utils.CollectionsUtil; import org.jiemamy.utils.ProcessorUtil; @@ -197,6 +202,43 @@ } /** + * モデルの正規化を行う。 + * + * @param rootModel + */ + public static void normalize(RootModel rootModel) { + ReferenceResolver resolver = rootModel.getJiemamy().getReferenceResolver(); + for (TableModel tableModel : getEntities(rootModel, TableModel.class)) { + // PKの正規化 + try { + TableUtil.getAttribute(tableModel, PrimaryKeyModel.class, false); + } catch (ElementNotFoundException e) { + try { + PrimaryKeyModel primaryKey = TableUtil.getPrimaryKey(tableModel); + ColumnRef columnRef = primaryKey.getKeyColumns().get(0); + resolver.resolve(columnRef).setPrimaryKey(null); + tableModel.getAttributes().add(primaryKey); + } catch (ElementNotFoundException e2) { + // nothing to do + } + } + + // UKの正規化 + for (ColumnModel columnModel : TableUtil.getColumns(tableModel)) { + UniqueKeyModel uniqueKey = columnModel.getUniqueKey(); + if (uniqueKey != null) { + columnModel.setUniqueKey(null); + tableModel.getAttributes().add(uniqueKey); + } + } + + // 属性順序の正規化 + Comparator<AttributeModel> comparator = new AttributeComparator(tableModel); + Collections.sort(tableModel.getAttributes(), comparator); + } + } + + /** * SQL方言を設定する。 * @param rootModel * @param dialectClass SQL方言クラス Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/TableUtil.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/TableUtil.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/TableUtil.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -26,9 +26,7 @@ import org.jiemamy.internal.processor.GetColumnProcessor; import org.jiemamy.model.attribute.AttributeModel; import org.jiemamy.model.attribute.ColumnModel; -import org.jiemamy.model.attribute.constraint.ColumnCheckModel; import org.jiemamy.model.attribute.constraint.ForeignKeyModel; -import org.jiemamy.model.attribute.constraint.NotNullConstraintModel; import org.jiemamy.model.attribute.constraint.PrimaryKeyModel; import org.jiemamy.model.attribute.constraint.TableConstraint; import org.jiemamy.model.attribute.constraint.UniqueKeyModel; @@ -53,7 +51,11 @@ * @throws ElementNotFoundException */ public static <T extends AttributeModel>T getAttribute(TableModel tableModel, Class<T> clazz) { - List<T> attributes = getAttributes(tableModel, clazz); + return getAttribute(tableModel, clazz, false); + } + + public static <T extends AttributeModel>T getAttribute(TableModel tableModel, Class<T> clazz, boolean columnAttr) { + List<T> attributes = getAttributes(tableModel, clazz, columnAttr); if (attributes.size() == 0) { throw new ElementNotFoundException(tableModel, clazz); } else if (attributes.size() > 1) { @@ -69,13 +71,27 @@ * @param clazz * @return 属性のリスト */ - public static <T>List<T> getAttributes(TableModel tableModel, Class<T> clazz) { + public static <T extends AttributeModel>List<T> getAttributes(TableModel tableModel, Class<T> clazz) { + return getAttributes(tableModel, clazz, false); + } + + /** + * TODO for daisuke + * + * @param <T> + * @param tableModel + * @param clazz + * @param columnAttr + * @return + */ + public static <T extends AttributeModel>List<T> getAttributes(TableModel tableModel, Class<T> clazz, + boolean columnAttr) { List<T> result = CollectionsUtil.newArrayList(); for (AttributeModel attribute : tableModel.getAttributes()) { if (clazz.isAssignableFrom(attribute.getClass())) { result.add(clazz.cast(attribute)); } - if (attribute instanceof ColumnModel) { + if (columnAttr && attribute instanceof ColumnModel) { ColumnModel columnModel = (ColumnModel) attribute; UniqueKeyModel uniqueKey = columnModel.getUniqueKey(); if (uniqueKey != null && clazz.isAssignableFrom(uniqueKey.getClass())) { @@ -85,14 +101,7 @@ if (primaryKey != null && clazz.isAssignableFrom(primaryKey.getClass())) { result.add(clazz.cast(primaryKey)); } - ColumnCheckModel check = columnModel.getCheck(); - if (check != null && clazz.isAssignableFrom(check.getClass())) { - result.add(clazz.cast(check)); - } - NotNullConstraintModel notNull = columnModel.getNotNull(); - if (notNull != null && clazz.isAssignableFrom(notNull.getClass())) { - result.add(clazz.cast(notNull)); - } + // column chek と not null は attributeじゃないので処理しない } } return result; @@ -172,7 +181,7 @@ * @throws ElementNotFoundException */ public static PrimaryKeyModel getPrimaryKey(TableModel tableModel) { - return getAttribute(tableModel, PrimaryKeyModel.class); + return getAttribute(tableModel, PrimaryKeyModel.class, true); } private TableUtil() { Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/PrimaryKeyValidator.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/PrimaryKeyValidator.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/PrimaryKeyValidator.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -48,7 +48,7 @@ Collection<Problem> result = super.validate(rootModel); Collection<TableModel> tableModels = RootModelUtil.getEntities(rootModel, TableModel.class); for (TableModel tableModel : tableModels) { - int size = TableUtil.getAttributes(tableModel, PrimaryKeyModel.class).size(); + int size = TableUtil.getAttributes(tableModel, PrimaryKeyModel.class, true).size(); if (size == 0) { result.add(new NoPrimaryKeyProblem(tableModel)); } else if (size > 1) { Modified: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ArtemisJiemamyFactoryTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ArtemisJiemamyFactoryTest.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ArtemisJiemamyFactoryTest.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -26,7 +26,7 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import java.io.Serializable; +import java.util.List; import java.util.UUID; import org.junit.After; @@ -35,6 +35,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.jiemamy.model.JiemamyElement; import org.jiemamy.model.RootModel; import org.jiemamy.model.attribute.ColumnModel; import org.jiemamy.model.attribute.ColumnRef; @@ -46,7 +47,6 @@ import org.jiemamy.model.attribute.constraint.UniqueKeyModel; import org.jiemamy.model.dataset.DataSetModel; import org.jiemamy.model.dataset.RecordModel; -import org.jiemamy.model.datatype.BuiltinDataType; import org.jiemamy.model.datatype.DomainModel; import org.jiemamy.model.datatype.DomainRef; import org.jiemamy.model.entity.TableModel; @@ -100,18 +100,11 @@ assertThat(rootModel, is(notNullValue())); try { - factory.newModel(Object.class); + factory.newModel(JiemamyElementMock.class); fail(); } catch (IllegalArgumentException e) { // success } - - try { - factory.newModel(Serializable.class); - fail(); - } catch (IllegalArgumentException e) { - // success - } } /** @@ -133,7 +126,6 @@ assertThat(factory.newModel(DomainModel.class), is(notNullValue())); assertThat(factory.newModel(DataSetModel.class), is(notNullValue())); assertThat(factory.newModel(RecordModel.class), is(notNullValue())); - assertThat(factory.newModel(BuiltinDataType.class), is(notNullValue())); assertThat(factory.newModel(IndexModel.class), is(notNullValue())); assertThat(factory.newModel(IndexColumnModel.class), is(notNullValue())); @@ -255,4 +247,50 @@ assertThat(rootModel2, is(sameInstance(rootModel1))); assertThat(rootModel3, is(sameInstance(rootModel1))); } + + + private static class JiemamyElementMock implements JiemamyElement { + + /** + * {@inheritDoc} + */ + public <T>T getAdapter(Class<T> adapterClass) { + return null; + } + + /** + * {@inheritDoc} + */ + public List<Object> getAdapters() { + return null; + } + + /** + * {@inheritDoc} + */ + public UUID getId() { + return null; + } + + /** + * {@inheritDoc} + */ + public Jiemamy getJiemamy() { + return null; + } + + /** + * {@inheritDoc} + */ + public boolean hasAdapter(Class<?> adapterClass) { + return false; + } + + /** + * {@inheritDoc} + */ + public void registerAdapter(Object adapter) { + } + + } } Modified: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/datatype/BuiltinDataTypeImplTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/datatype/BuiltinDataTypeImplTest.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/datatype/BuiltinDataTypeImplTest.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -29,6 +29,8 @@ import org.jiemamy.Jiemamy; import org.jiemamy.JiemamyFactory; +import org.jiemamy.dialect.BuiltinDataTypeMoldImpl; +import org.jiemamy.dialect.Dialect.BuiltinDataTypeMold; import org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter; /** @@ -68,8 +70,9 @@ */ @Test public void test01_インスタンス毎にアダプタは異なったインスタンスが設定されている() throws Exception { - BuiltinDataType dataType1 = factory.newModel(BuiltinDataType.class); - BuiltinDataType dataType2 = factory.newModel(BuiltinDataType.class); + BuiltinDataTypeMold mold = new BuiltinDataTypeMoldImpl(DataTypeCategory.INTEGER); + BuiltinDataType dataType1 = factory.newBuiltinDataType(mold); + BuiltinDataType dataType2 = factory.newBuiltinDataType(mold); SizedDataTypeAdapter sized1 = dataType1.getAdapter(SizedDataTypeAdapter.class); SizedDataTypeAdapter sized2 = dataType2.getAdapter(SizedDataTypeAdapter.class); Deleted: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/builder/ModelBuilderTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/builder/ModelBuilderTest.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/builder/ModelBuilderTest.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -1,225 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2008/12/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.utils.builder; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.jiemamy.Artemis; -import org.jiemamy.Jiemamy; -import org.jiemamy.JiemamyFactory; -import org.jiemamy.model.RootModel; -import org.jiemamy.model.attribute.ColumnModel; -import org.jiemamy.model.attribute.constraint.ForeignKeyModel; -import org.jiemamy.model.attribute.constraint.PrimaryKeyModel; -import org.jiemamy.model.datatype.BuiltinDataType; -import org.jiemamy.model.datatype.DataTypeCategory; -import org.jiemamy.model.datatype.adapter.SerialDataTypeAdapter; -import org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter; -import org.jiemamy.model.entity.TableModel; -import org.jiemamy.test.ReflectionDialectProvider; -import org.jiemamy.utils.model.ForeignKeyUtil; -import org.jiemamy.utils.model.RootModelUtil; -import org.jiemamy.utils.model.TableUtil; - -/** - * {@link ModelBuilder}のテストクラス。 - * @author daisuke - */ -public class ModelBuilderTest { - - private static Logger logger = LoggerFactory.getLogger(ModelBuilderTest.class); - - private Jiemamy jiemamy; - - private RootModel rootModel; - - private JiemamyFactory factory; - - - /** - * setup - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - jiemamy = Jiemamy.newInstance(new Artemis(), new ReflectionDialectProvider()); - factory = jiemamy.getFactory(); - rootModel = factory.getRootModel(); - } - - /** - * teardown - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - rootModel = null; - factory = null; - jiemamy = null; - } - - /** - * べた書きモデル構築。 - * @throws Exception - */ - @Test - public void test01() throws Exception { - rootModel.setDialectClassName("org.jiemamy.dialect.mysql.MySqlDialect"); - - // EMPテーブルのビルド - TableModel emp = factory.newModel(TableModel.class); - emp.setName("T_EMP"); - ColumnModel empId = factory.newModel(ColumnModel.class); - empId.setName("ID"); - BuiltinDataType empIdDataType = factory.newModel(BuiltinDataType.class); - empIdDataType.setCategory(DataTypeCategory.INTEGER); - empIdDataType.setTypeName("INTEGER"); - empIdDataType.getAdapter(SerialDataTypeAdapter.class).setSerial(true); - empId.setDataType(empIdDataType); - ColumnModel empName = factory.newModel(ColumnModel.class); - empName.setName("NAME"); - BuiltinDataType empNameDataType = factory.newModel(BuiltinDataType.class); - empNameDataType.setCategory(DataTypeCategory.VARCHAR); - empNameDataType.setTypeName("VARCHAR"); - empNameDataType.getAdapter(SizedDataTypeAdapter.class).setSize(32); - empName.setDataType(empNameDataType); - ColumnModel empDeptId = factory.newModel(ColumnModel.class); - empDeptId.setName("DEPT_ID"); - BuiltinDataType empDeptIdDataType = factory.newModel(BuiltinDataType.class); - empDeptIdDataType.setCategory(DataTypeCategory.INTEGER); - empDeptIdDataType.setTypeName("INTEGER"); - empDeptId.setDataType(empDeptIdDataType); - ColumnModel empHiredate = factory.newModel(ColumnModel.class); - empHiredate.setName("HIREDATE"); - BuiltinDataType empHireDateDataType = factory.newModel(BuiltinDataType.class); - empHireDateDataType.setCategory(DataTypeCategory.TIMESTAMP); - empHireDateDataType.setTypeName("TIMESTAMP"); - empHiredate.setDataType(empHireDateDataType); - - PrimaryKeyModel empPk = factory.newModel(PrimaryKeyModel.class); - empPk.getKeyColumns().add(factory.newReference(empId)); - - emp.getAttributes().add(empId); - emp.getAttributes().add(empName); - emp.getAttributes().add(empDeptId); - emp.getAttributes().add(empHiredate); - emp.getAttributes().add(empPk); - - rootModel.getEntities().add(emp); - - // DEPTテーブルのビルド - TableModel dept = factory.newModel(TableModel.class); - dept.setName("T_DEPT"); - ColumnModel deptId = factory.newModel(ColumnModel.class); - deptId.setName("ID"); - BuiltinDataType deptIdDataType = factory.newModel(BuiltinDataType.class); - deptIdDataType.setCategory(DataTypeCategory.INTEGER); - deptIdDataType.setTypeName("INTEGER"); - deptIdDataType.getAdapter(SerialDataTypeAdapter.class).setSerial(true); - deptId.setDataType(deptIdDataType); - ColumnModel deptName = factory.newModel(ColumnModel.class); - deptName.setName("NAME"); - BuiltinDataType deptNameDataType = factory.newModel(BuiltinDataType.class); - deptNameDataType.setCategory(DataTypeCategory.VARCHAR); - deptNameDataType.setTypeName("VARCHAR"); - deptNameDataType.getAdapter(SizedDataTypeAdapter.class).setSize(32); - deptName.setDataType(deptNameDataType); - ColumnModel deptLocation = factory.newModel(ColumnModel.class); - deptLocation.setName("LOCATION"); - BuiltinDataType deptLocationDataType = factory.newModel(BuiltinDataType.class); - deptLocationDataType.setCategory(DataTypeCategory.VARCHAR); - deptLocationDataType.setTypeName("VARCHAR"); - deptLocationDataType.getAdapter(SizedDataTypeAdapter.class).setSize(16); - deptLocation.setDataType(deptLocationDataType); - - PrimaryKeyModel deptPk = factory.newModel(PrimaryKeyModel.class); - deptPk.getKeyColumns().add(factory.newReference(deptId)); - - dept.getAttributes().add(deptId); - dept.getAttributes().add(deptName); - dept.getAttributes().add(deptLocation); - dept.getAttributes().add(deptPk); - - rootModel.getEntities().add(dept); - - // 外部キーの設定 - ForeignKeyModel fk = factory.newModel(ForeignKeyModel.class); - ForeignKeyUtil.addMapping(fk, empDeptId, deptId); - emp.getAttributes().add(fk); - - // モデルをSQLに変換し、表示 - logger.info(rootModel.toString()); - // FIXME このテストが走る時点で、MySqlDialectがコンパイルされていない可能性がある -// List<SqlStatement> statements = jiemamy.toStatements(rootModel); -// for (SqlStatement statement : statements) { -// logger.info(statement.toString()); -// } - } - - /** - * ModelBuilderを使用したモデル構築。 - * @throws Exception - */ - @Test - public void test02() throws Exception { - rootModel.setDialectClassName("org.jiemamy.dialect.mysql.MySqlDialect"); - - // EMPテーブルのビルド - rootModel.getEntities().add( - new TableBuilder(factory, "T_EMP").column( - new ColumnBuilder(factory, "ID", new DataTypeBuilder(factory, DataTypeCategory.INTEGER) - .setSerial(true).build()).build()).column( - new ColumnBuilder(factory, "NAME", new DataTypeBuilder(factory, DataTypeCategory.VARCHAR) - .setSize(32).build()).build()).column( - new ColumnBuilder(factory, "DEPT_ID", new DataTypeBuilder(factory, DataTypeCategory.INTEGER) - .build()).build()).column( - new ColumnBuilder(factory, "HIREDATE", new DataTypeBuilder(factory, DataTypeCategory.TIMESTAMP) - .build()).build()).primaryKey(0).build()); - - // DEPTテーブルのビルド - rootModel.getEntities().add( - new TableBuilder(factory, "T_DEPT").column( - new ColumnBuilder(factory, "ID", new DataTypeBuilder(factory, DataTypeCategory.INTEGER) - .setSerial(true).build()).build()).column( - new ColumnBuilder(factory, "NAME", new DataTypeBuilder(factory, DataTypeCategory.VARCHAR) - .setSize(32).build()).build()).column( - new ColumnBuilder(factory, "LOCATION", new DataTypeBuilder(factory, DataTypeCategory.VARCHAR) - .setSize(16).build()).build()).primaryKey(0).build()); - - // 外部キーの設定 - TableModel emp = RootModelUtil.getEntity(rootModel, TableModel.class, "T_EMP"); - TableModel dept = RootModelUtil.getEntity(rootModel, TableModel.class, "T_DEPT"); - ColumnModel deptId = TableUtil.getColumn(dept, "ID"); - ColumnModel empDeptId = TableUtil.getColumn(emp, "DEPT_ID"); - - emp.getAttributes().add(new ForeignKeyBuilder(factory, emp, dept).mapping(empDeptId, deptId).build()); - - // モデルをSQLに変換し、表示 - logger.info(rootModel.toString()); - // FIXME このテストが走る時点で、MySqlDialectがコンパイルされていない可能性がある -// List<SqlStatement> statements = jiemamy.toStatements(rootModel); -// for (SqlStatement statement : statements) { -// logger.info(statement.toString()); -// } - } -} Modified: artemis/trunk/jiemamy-dialect-mysql/src/main/java/org/jiemamy/dialect/mysql/MySqlDialect.java =================================================================== --- artemis/trunk/jiemamy-dialect-mysql/src/main/java/org/jiemamy/dialect/mysql/MySqlDialect.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-dialect-mysql/src/main/java/org/jiemamy/dialect/mysql/MySqlDialect.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -23,7 +23,7 @@ import org.apache.commons.collections15.list.UnmodifiableList; import org.jiemamy.dialect.AbstractDialect; -import org.jiemamy.dialect.AvailableTypeInfoImpl; +import org.jiemamy.dialect.BuiltinDataTypeMoldImpl; import org.jiemamy.model.datatype.DataTypeCategory; import org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter; import org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter; @@ -38,28 +38,28 @@ */ public class MySqlDialect extends AbstractDialect { - private static final List<AvailableTypeInfo> allDataTypes; + private static final List<BuiltinDataTypeMold> allDataTypes; static { - List<AvailableTypeInfo> list = CollectionsUtil.newArrayList(); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.CHARACTER, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.VARCHAR, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.CLOB, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.BLOB, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.BIT, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.VARBIT, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.NUMERIC, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.DECIMAL, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.INTEGER)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.SMALLINT)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.FLOAT, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.REAL, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.DOUBLE, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.BOOLEAN)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.DATE)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.TIME, TimezonedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.TIMESTAMP, TimezonedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.INTERVAL)); + List<BuiltinDataTypeMold> list = CollectionsUtil.newArrayList(); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.CHARACTER, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.VARCHAR, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.CLOB, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BLOB, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BIT, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.VARBIT, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.NUMERIC, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DECIMAL, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.INTEGER)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.SMALLINT)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.FLOAT, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.REAL, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DOUBLE, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BOOLEAN)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DATE)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.TIME, TimezonedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.TIMESTAMP, TimezonedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.INTERVAL)); allDataTypes = UnmodifiableList.decorate(list); // FIXME 適当 } @@ -74,7 +74,7 @@ /** * {@inheritDoc} */ - public List<AvailableTypeInfo> getAllDataTypes() { + public List<BuiltinDataTypeMold> getAllDataTypes() { return allDataTypes; } Modified: artemis/trunk/jiemamy-dialect-postgresql/src/main/java/org/jiemamy/dialect/postgresql/PostgresqlDialect.java =================================================================== --- artemis/trunk/jiemamy-dialect-postgresql/src/main/java/org/jiemamy/dialect/postgresql/PostgresqlDialect.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-dialect-postgresql/src/main/java/org/jiemamy/dialect/postgresql/PostgresqlDialect.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -19,7 +19,7 @@ import org.apache.commons.collections15.list.UnmodifiableList; import org.jiemamy.dialect.AbstractDialect; -import org.jiemamy.dialect.AvailableTypeInfoImpl; +import org.jiemamy.dialect.BuiltinDataTypeMoldImpl; import org.jiemamy.model.datatype.DataTypeCategory; import org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter; import org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter; @@ -34,28 +34,28 @@ */ public class PostgresqlDialect extends AbstractDialect { - private static final List<AvailableTypeInfo> allDataTypes; + private static final List<BuiltinDataTypeMold> allDataTypes; static { - List<AvailableTypeInfo> list = CollectionsUtil.newArrayList(); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.CHARACTER, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.VARCHAR, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.CLOB, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.BLOB, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.BIT, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.VARBIT, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.NUMERIC, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.DECIMAL, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.INTEGER)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.SMALLINT)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.FLOAT, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.REAL, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.DOUBLE, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.BOOLEAN)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.DATE)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.TIME, TimezonedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.TIMESTAMP, TimezonedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.INTERVAL)); + List<BuiltinDataTypeMold> list = CollectionsUtil.newArrayList(); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.CHARACTER, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.VARCHAR, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.CLOB, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BLOB, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BIT, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.VARBIT, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.NUMERIC, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DECIMAL, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.INTEGER)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.SMALLINT)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.FLOAT, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.REAL, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DOUBLE, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BOOLEAN)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DATE)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.TIME, TimezonedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.TIMESTAMP, TimezonedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.INTERVAL)); allDataTypes = UnmodifiableList.decorate(list); // FIXME 適当 } @@ -71,7 +71,7 @@ /** * {@inheritDoc} */ - public List<AvailableTypeInfo> getAllDataTypes() { + public List<BuiltinDataTypeMold> getAllDataTypes() { return allDataTypes; } Modified: artemis/trunk/jiemamy-dialect-sql99/src/main/java/org/jiemamy/dialect/sql99/Sql99Dialect.java =================================================================== --- artemis/trunk/jiemamy-dialect-sql99/src/main/java/org/jiemamy/dialect/sql99/Sql99Dialect.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-dialect-sql99/src/main/java/org/jiemamy/dialect/sql99/Sql99Dialect.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -23,7 +23,7 @@ import org.apache.commons.collections15.list.UnmodifiableList; import org.jiemamy.dialect.AbstractDialect; -import org.jiemamy.dialect.AvailableTypeInfoImpl; +import org.jiemamy.dialect.BuiltinDataTypeMoldImpl; import org.jiemamy.model.datatype.DataTypeCategory; import org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter; import org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter; @@ -38,28 +38,28 @@ */ public class Sql99Dialect extends AbstractDialect { - private static final List<AvailableTypeInfo> allDataTypes; + private static final List<BuiltinDataTypeMold> allDataTypes; static { - List<AvailableTypeInfo> list = CollectionsUtil.newArrayList(); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.CHARACTER, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.VARCHAR, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.CLOB, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.BLOB, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.BIT, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.VARBIT, SizedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.NUMERIC, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.DECIMAL, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.INTEGER)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.SMALLINT)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.FLOAT, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.REAL, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.DOUBLE, PrecisionedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.BOOLEAN)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.DATE)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.TIME, TimezonedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.TIMESTAMP, TimezonedDataTypeAdapter.class)); - list.add(new AvailableTypeInfoImpl(DataTypeCategory.INTERVAL)); + List<BuiltinDataTypeMold> list = CollectionsUtil.newArrayList(); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.CHARACTER, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.VARCHAR, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.CLOB, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BLOB, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BIT, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.VARBIT, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.NUMERIC, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DECIMAL, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.INTEGER)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.SMALLINT)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.FLOAT, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.REAL, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DOUBLE, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BOOLEAN)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DATE)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.TIME, TimezonedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.TIMESTAMP, TimezonedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.INTERVAL)); allDataTypes = UnmodifiableList.decorate(list); // FIXME 適当 } @@ -74,7 +74,7 @@ /** * {@inheritDoc} */ - public List<AvailableTypeInfo> getAllDataTypes() { + public List<BuiltinDataTypeMold> getAllDataTypes() { return allDataTypes; } Modified: artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/ArtemisViewTest.java =================================================================== --- artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/ArtemisViewTest.java 2009-02-18 18:56:59 UTC (rev 2688) +++ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/ArtemisViewTest.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -44,7 +44,6 @@ import org.jiemamy.model.connection.ConnectionAdapter; import org.jiemamy.model.dataset.DataSetModel; import org.jiemamy.model.dataset.RecordModel; -import org.jiemamy.model.datatype.BuiltinDataType; import org.jiemamy.model.datatype.DomainModel; import org.jiemamy.model.datatype.DomainRef; import org.jiemamy.model.entity.TableModel; @@ -112,7 +111,6 @@ assertThat(factory.newModel(DomainModel.class), is(notNullValue())); assertThat(factory.newModel(DataSetModel.class), is(notNullValue())); assertThat(factory.newModel(RecordModel.class), is(notNullValue())); - assertThat(factory.newModel(BuiltinDataType.class), is(notNullValue())); assertThat(factory.newModel(IndexModel.class), is(notNullValue())); assertThat(factory.newModel(IndexColumnModel.class), is(notNullValue())); @@ -157,7 +155,6 @@ assertThat(factoryWithView.newModel(DomainModel.class), is(notNullValue())); assertThat(factoryWithView.newModel(DataSetModel.class), is(notNullValue())); assertThat(factoryWithView.newModel(RecordModel.class), is(notNullValue())); - assertThat(factoryWithView.newModel(BuiltinDataType.class), is(notNullValue())); assertThat(factoryWithView.newModel(IndexModel.class), is(notNullValue())); assertThat(factoryWithView.newModel(IndexColumnModel.class), is(notNullValue())); Modified: vesta/trunk/jiemamy-vesta/pull.bat =================================================================== --- vesta/trunk/jiemamy-vesta/pull.bat 2009-02-18 18:56:59 UTC (rev 2688) +++ vesta/trunk/jiemamy-vesta/pull.bat 2009-02-19 11:16:10 UTC (rev 2689) @@ -34,6 +34,6 @@ call mvn install -Dmaven.test.skip=true cd ..\jiemamy-vesta\ -call mvn package -Dmaven.test.skip=true +call mvn clean package -Dmaven.test.skip=true pause Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/JiemamyPlugin.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/JiemamyPlugin.java 2009-02-18 18:56:59 UTC (rev 2688) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/JiemamyPlugin.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -21,6 +21,7 @@ import java.net.URL; import java.util.ResourceBundle; +import org.apache.commons.lang.Validate; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -103,8 +104,10 @@ * * @param path the path * @return the image descriptor + * @throws IllegalArgumentException 引数に{@code null}を与えた場合 */ public static ImageDescriptor getImageDescriptor(String path) { + Validate.notNull(path); return imageDescriptorFromPlugin(PLUGIN_ID, path); } Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditor.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditor.java 2009-02-18 18:56:59 UTC (rev 2688) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditor.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -106,6 +106,7 @@ import org.jiemamy.model.DiagramPresentationModel; import org.jiemamy.model.DiagramPresentations; import org.jiemamy.model.RootModel; +import org.jiemamy.utils.model.RootModelUtil; /** * ERダイアグラムエディタ。 @@ -507,6 +508,7 @@ IFile file = ((IFileEditorInput) getEditorInput()).getFile(); try { rootModel = jiemamy.getSerializer().deserialize(file.getContents()); + RootModelUtil.normalize(rootModel); // rootModel.setDisplayMode(DatabaseModel.MODE_PHYSICAL_ATTRTYPE); } catch (SerializationException e) { ExceptionHandler.handleException(e, "Data file is broken."); Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditorPaletteFactory.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditorPaletteFactory.java 2009-02-18 18:56:59 UTC (rev 2688) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditorPaletteFactory.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -34,6 +34,7 @@ import org.jiemamy.eclipse.Images; import org.jiemamy.eclipse.JiemamyPlugin; import org.jiemamy.eclipse.utils.EditorUtil; +import org.jiemamy.model.JiemamyElement; import org.jiemamy.model.RootModel; import org.jiemamy.model.attribute.constraint.ForeignKeyModel; import org.jiemamy.model.entity.TableModel; @@ -186,14 +187,14 @@ */ private static class JiemamyModelCreationFactory implements CreationFactory { - private Class<?> type; + private Class<? extends JiemamyElement> type; /** * インスタンスを生成する。 * @param type */ - public JiemamyModelCreationFactory(Class<?> type) { + public JiemamyModelCreationFactory(Class<? extends JiemamyElement> type) { this.type = type; } Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/MultiDiagramEditor.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/MultiDiagramEditor.java 2009-02-18 18:56:59 UTC (rev 2688) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/MultiDiagramEditor.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -54,6 +54,7 @@ import org.jiemamy.model.DiagramPresentations; import org.jiemamy.model.RootModel; import org.jiemamy.utils.CollectionsUtil; +import org.jiemamy.utils.model.RootModelUtil; /** * マルチページ構成のダイアグラムエディタクラス。 @@ -187,6 +188,7 @@ IFile file = ((IFileEditorInput) input).getFile(); try { rootModel = jiemamy.getSerializer().deserialize(file.getContents()); + RootModelUtil.normalize(rootModel); // rootModel.setDisplayMode(DatabaseModel.MODE_PHYSICAL_ATTRTYPE); } catch (SerializationException e) { ExceptionHandler.handleException(e, "Data file is broken."); Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDomainTab.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDomainTab.java 2009-02-18 18:56:59 UTC (rev 2688) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDomainTab.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -54,7 +54,7 @@ import org.jiemamy.Jiemamy; import org.jiemamy.JiemamyFactory; import org.jiemamy.dialect.Dialect; -import org.jiemamy.dialect.Dialect.AvailableTypeInfo; +import org.jiemamy.dialect.Dialect.BuiltinDataTypeMold; import org.jiemamy.eclipse.Images; import org.jiemamy.eclipse.JiemamyPlugin; import org.jiemamy.eclipse.editor.DisplayPlace; @@ -72,9 +72,9 @@ import org.jiemamy.model.attribute.constraint.NotNullConstraintModel; import org.jiemamy.model.datatype.BuiltinDataType; import org.jiemamy.model.datatype.DataType; -import org.jiemamy.model.datatype.DataTypeCategory; import org.jiemamy.model.datatype.DomainModel; import org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter; +import org.jiemamy.utils.CollectionsUtil; import org.jiemamy.utils.ListUtils; import org.jiemamy.utils.model.RootModelUtil; @@ -89,6 +89,8 @@ private final RootModel rootModel; + private List<BuiltinDataTypeMold> allTypes; + private AbstractTableEditor domainEditor; private Text txtDomainName; @@ -116,6 +118,18 @@ this.rootModel = rootModel; + Dialect dialect; + try { + dialect = RootModelUtil.getDialect(rootModel); + } catch (ClassNotFoundException e) { + // TODO DefaultDialectをセットするように変更。 + dialect = JiemamyPlugin.getDialectResolver().getAllInstance().get(0); + } + + allTypes = CollectionsUtil.newArrayList(rootModel.getDomains().size() + dialect.getAllDataTypes().size()); + + allTypes.addAll(dialect.getAllDataTypes()); + Composite composite = new Composite(parentTabFolder, SWT.NULL); composite.setLayout(new GridLayout(1, false)); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); @@ -284,8 +298,7 @@ domainModel.setName("DOMAIN_" + (domains.size() + 1)); - BuiltinDataType builtinDataType = factory.newModel(BuiltinDataType.class); - builtinDataType.setCategory(DataTypeCategory.INTEGER); + BuiltinDataType builtinDataType = factory.newBuiltinDataType(allTypes.get(0)); domainModel.setDataType(builtinDataType); domains.add(domainModel); @@ -302,7 +315,7 @@ protected void configureEditorControls() { super.configureEditorControls(); - for (AvailableTypeInfo typeInfo : dialect.getAllDataTypes()) { + for (BuiltinDataTypeMold typeInfo : dialect.getAllDataTypes()) { cmbColumnType.add(typeInfo.getTypeName()); } Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogColumnTab.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogColumnTab.java 2009-02-18 18:56:59 UTC (rev 2688) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogColumnTab.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -51,7 +51,7 @@ import org.jiemamy.Jiemamy; import org.jiemamy.JiemamyFactory; import org.jiemamy.dialect.Dialect; -import org.jiemamy.dialect.Dialect.AvailableTypeInfo; +import org.jiemamy.dialect.Dialect.BuiltinDataTypeMold; import org.jiemamy.eclipse.Images; import org.jiemamy.eclipse.JiemamyPlugin; import org.jiemamy.eclipse.editor.DisplayPlace; @@ -63,14 +63,15 @@ import org.jiemamy.eclipse.ui.tab.AbstractTab; import org.jiemamy.editcommand.Command; import org.jiemamy.editcommand.CommandListener; +import org.jiemamy.exception.ElementNotFoundException; import org.jiemamy.model.JiemamyElement; import org.jiemamy.model.RootModel; import org.jiemamy.model.attribute.ColumnModel; import org.jiemamy.model.attribute.constraint.ColumnCheckModel; import org.jiemamy.model.attribute.constraint.NotNullConstraintModel; +import org.jiemamy.model.attribute.constraint.PrimaryKeyModel; import org.jiemamy.model.datatype.BuiltinDataType; import org.jiemamy.model.datatype.DataType; -import org.jiemamy.model.datatype.DataTypeCategory; import org.jiemamy.model.datatype.DomainModel; import org.jiemamy.model.datatype.DomainRef; import org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter; @@ -78,6 +79,7 @@ import org.jiemamy.utils.CollectionsUtil; import org.jiemamy.utils.ListUtils; import org.jiemamy.utils.model.ColumnUtil; +import org.jiemamy.utils.model.KeyConstraintUtil; import org.jiemamy.utils.model.RootModelUtil; import org.jiemamy.utils.model.TableUtil; @@ -94,7 +96,7 @@ private TableModel tableModel; - private List<AvailableTypeInfo> allTypes; + private List<BuiltinDataTypeMold> allTypes; private AbstractTableEditor columnEditor; @@ -118,7 +120,7 @@ try { dialect = RootModelUtil.getDialect(rootModel); } catch (ClassNotFoundException e) { - // FIXME なんとか…。 + // TODO DefaultDialectをセットするように変更。 dialect = JiemamyPlugin.getDialectResolver().getAllInstance().get(0); } @@ -345,8 +347,7 @@ ColumnModel columnModel = factory.newModel(ColumnModel.class); columnModel.setName("COLUMN_" + (columns.size() + 1)); - BuiltinDataType builtinDataType = factory.newModel(BuiltinDataType.class); - builtinDataType.setCategory(DataTypeCategory.INTEGER); + BuiltinDataType builtinDataType = factory.newBuiltinDataType(allTypes.get(0)); columnModel.setDataType(builtinDataType); columns.add(columnModel); @@ -364,7 +365,7 @@ protected void configureEditorControls() { super.configureEditorControls(); - for (AvailableTypeInfo typeInfo : dialect.getAllDataTypes()) { + for (BuiltinDataTypeMold typeInfo : dialect.getAllDataTypes()) { cmbColumnType.add(typeInfo.getTypeName()); } @@ -716,7 +717,7 @@ // 現在値の設定 txtColumnName.setText(column.getName()); - txtColumnLogicalName.setText(column.getLogicalName()); + txtColumnLogicalName.setText(StringUtils.defaultIfEmpty(column.getLogicalName(), "")); ColumnCheckModel columnCheckModel = column.getCheck(); if (columnCheckModel == null) { @@ -741,8 +742,8 @@ Integer size = builtinDataType.getAdapter(SizedDataTypeAdapter.class).getSize(); txtColumnSize.setText(StringUtils.defaultIfEmpty(ObjectUtils.toString(size), "")); } - txtDefaultValue.setText(column.getDefaultValue()); - txtDescription.setText(column.getDescription()); + txtDefaultValue.setText(StringUtils.defaultIfEmpty(column.getDefaultValue(), "")); + txtDescription.setText(StringUtils.defaultIfEmpty(column.getDescription(), "")); chkIsPK.setSelection(ColumnUtil.isPartOfPrimaryKeyColumns(column)); @@ -759,8 +760,7 @@ ColumnModel columnModel = factory.newModel(ColumnModel.class); columnModel.setName("COLUMN_" + (columns.size() + 1)); - BuiltinDataType builtinDataType = factory.newModel(BuiltinDataType.class); - builtinDataType.setCategory(DataTypeCategory.INTEGER); + BuiltinDataType builtinDataType = factory.newBuiltinDataType(allTypes.get(0)); columnModel.setDataType(builtinDataType); if (index < 0 || index > table.getItemCount()) { @@ -836,28 +836,43 @@ if (columnEditIndex != -1 && selectionInedx != -1) { ColumnModel column = columns.get(columnEditIndex); + + JiemamyFactory factory = column.getJiemamy().getFactory(); + column.setName(txtColumnName.getText()); column.setLogicalName(StringUtils.defaultIfEmpty(txtColumnLogicalName.getText(), null)); - AvailableTypeInfo availableTypeInfo = allTypes.get(selectionInedx); - // TODO dataType +// AvailableTypeInfo availableTypeInfo = allTypes.get(selectionInedx); // column.setDataType(selectedType); // column.setSize(txtColumnSize.getText()); column.setDefaultValue(StringUtils.defaultIfEmpty(txtDefaultValue.getText(), null)); column.setDescription(StringUtils.defaultIfEmpty(txtDescription.getText(), null)); - if (chkIsPK.getSelection() == false) { + if (chkIsNotNull.getSelection() == false) { column.setNotNull(null); } else if (column.getNotNull() == null) { - JiemamyFactory factory = column.getJiemamy().getFactory(); NotNullConstraintModel nnModel = factory.newModel(NotNullConstraintModel.class); column.setNotNull(nnModel); } - // TODO PK -// column.setConstraint(DefinitionModel.CONSTRAINT_PRIMARY_KEY, chkIsPK.getSelection()); + PrimaryKeyModel primaryKey = null; + try { + primaryKey = TableUtil.getPrimaryKey(tableModel); + } catch (ElementNotFoundException e) { + // ignore + } + if (chkIsPK.getSelection() == false && primaryKey != null) { + // FIXME BUG ここでremoveされない? + KeyConstraintUtil.removeKeyColumn(primaryKey, column); + } else { + if (primaryKey == null) { + primaryKey = factory.newModel(PrimaryKeyModel.class); + tableModel.getAttributes().add(primaryKey); + } + KeyConstraintUtil.addKeyColumn(primaryKey, column); + } // TODO unique // column.setConstraint(DefinitionModel.CONSTRAINT_UNIQUE, chkIsUnique.getSelection()); @@ -867,7 +882,6 @@ } else { ColumnCheckModel checkModel = column.getCheck(); if (checkModel == null) { - JiemamyFactory factory = column.getJiemamy().getFactory(); checkModel = factory.newModel(ColumnCheckModel.class); } checkModel.setName(txtCheckName.getText()); Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyFactory.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyFactory.java 2009-02-18 18:56:59 UTC (rev 2688) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyFactory.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -21,10 +21,12 @@ import java.util.Set; import java.util.UUID; +import org.jiemamy.dialect.Dialect.BuiltinDataTypeMold; import org.jiemamy.model.JiemamyElement; import org.jiemamy.model.RootModel; import org.jiemamy.model.attribute.ColumnModel; import org.jiemamy.model.attribute.ColumnRef; +import org.jiemamy.model.datatype.BuiltinDataType; import org.jiemamy.model.datatype.DomainModel; import org.jiemamy.model.datatype.DomainRef; import org.jiemamy.model.entity.TableModel; @@ -90,6 +92,8 @@ */ <M, B extends PrematureBuilder<M>>B newBuilder(Class<B> clazz); + BuiltinDataType newBuiltinDataType(BuiltinDataTypeMold mold); + /** * 新しいモデルを生成する。 * @@ -105,7 +109,7 @@ * @throws IllegalArgumentException 引数として{@code null}を与えた場合 */ // @Deprecated - <T>T newModel(Class<T> clazz); + <T extends JiemamyElement>T newModel(Class<T> clazz); /** * 指定したIDを持つ新しいモデルを生成する。 Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/dialect/Dialect.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/dialect/Dialect.java 2009-02-18 18:56:59 UTC (rev 2688) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/dialect/Dialect.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -82,7 +82,7 @@ * * @return データ型名のリスト */ - List<AvailableTypeInfo> getAllDataTypes(); + List<BuiltinDataTypeMold> getAllDataTypes(); /** * モデリング用DataType・一般型・型名間のマッピング情報を取得する。 @@ -135,21 +135,21 @@ * * @author daisuke */ - public interface AvailableTypeInfo { + public interface BuiltinDataTypeMold { /** * TODO for daisuke * * @return */ - Collection<Class<?>> getAdapterClasses(); + DataTypeCategory getCategory(); /** * TODO for daisuke * * @return */ - DataTypeCategory getCategory(); + Collection<Class<?>> getSupportedAdapterClasses(); /** * TODO for daisuke Deleted: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataType.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataType.java 2009-02-18 18:56:59 UTC (rev 2688) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataType.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -1,53 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2008/12/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.model.datatype; - -import org.jiemamy.utils.Adaptable; - -/** - * DBに本来組み込まれているデータ型を表すインターフェイス。つまり、Domain型ではないプリミティブなデータ型。 - * @author daisuke - */ -public interface BuiltinDataType extends DataType, Adaptable { - - /** - * 型カテゴリを取得する。 - * @return 型カテゴリ - */ - DataTypeCategory getCategory(); - - /** - * データ型名を取得する。 - * @return データ型名 - */ - String getTypeName(); - - /** - * 型カテゴリを設定する。 - * @param category 型カテゴリ - */ - void setCategory(DataTypeCategory category); - - /** - * データ型名を設定する。 - * @param typeName データ型名 - */ - void setTypeName(String typeName); - -} Added: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataType.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataType.java (rev 0) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataType.java 2009-02-19 11:16:10 UTC (rev 2689) @@ -0,0 +1,53 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2008/12/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.model.datatype; + +import org.jiemamy.utils.Adaptable; + +/** + * DBに本来組み込まれているデータ型を表すインターフェイス。つまり、Domain型ではないプリミティブなデータ型。 + * @author daisuke + */ +public interface BuiltinDataType extends DataType, Adaptable { + + /** + * 型カテゴリを取得する。 + * @return 型カテゴリ + */ + DataTypeCategory getCategory(); + + /** + * データ型名を取得する。 + * @return データ型名 + */ + String getTypeName(); + + /** + * 型カテゴリを設定する。 + * @param category 型カテゴリ + */ + void setCategory(DataTypeCategory category); + + /** + * データ型名を設定する。 + * @param typeName データ型名 + */ + void setTypeName(String typeName); + +}