svnno****@sourc*****
svnno****@sourc*****
2009年 2月 19日 (木) 03:56:59 JST
Revision: 2688 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2688 Author: daisuke_m Date: 2009-02-19 03:56:59 +0900 (Thu, 19 Feb 2009) Log Message: ----------- Domain, Columnの制約を、コレクションではなく単一フィールドで保持するように変更。 / vestaのテーブル編集ダイアログ・カラムタブの表示追加。 Modified Paths: -------------- artemis/trunk/jiemamy-artemis-test/.project artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/SerializationTest.java artemis/trunk/jiemamy-composer/.project artemis/trunk/jiemamy-composer/src/main/java/org/jiemamy/composer/importer/DatabaseImporter.java artemis/trunk/jiemamy-composer/src/main/java/org/jiemamy/composer/importer/DatabaseReader.java artemis/trunk/jiemamy-core/.project artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/FactoryExtension.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/AbstractDialect.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultSqlEmitter.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/processor/GetColumnProcessor.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/processor/GetEntityProcessor.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/attribute/ColumnModelImpl.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/DomainModelImpl.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomBuilder.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomParser.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/test/TestModelBuilder.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/test/TestModelBuilder2.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/XpathUtil.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/DomainUtil.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/AbstractTraversalValidator.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/ColumnValidator.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/InstanceCollisionValidator.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/XpathUtilTest.java artemis/trunk/jiemamy-dialect-mysql/.project artemis/trunk/jiemamy-dialect-postgresql/.project artemis/trunk/jiemamy-dialect-sql99/.project 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/TableEditDialog.java 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/editpart/diagram/TableEditPart.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/ViewEditPart.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyProperty.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/exception/TooManyElementsException.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/attribute/ColumnModel.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/DomainModel.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/xml/CoreQName.java zeus/trunk/jiemamy-spec-core/src/main/resources/jiemamy-core.xsd zeus/trunk/jiemamy-spec-core/src/main/resources/sample.xml zeus/trunk/jiemamy-spec-diff/.project zeus/trunk/jiemamy-spec-view/.project -------------- next part -------------- Modified: artemis/trunk/jiemamy-artemis-test/.project =================================================================== --- artemis/trunk/jiemamy-artemis-test/.project 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-artemis-test/.project 2009-02-18 18:56:59 UTC (rev 2688) @@ -34,6 +34,11 @@ </natures> <linkedResources> <link> + <name>.checkstyle</name> + <type>1</type> + <locationURI>DOCUMENTS/jiemamy-artemis/.checkstyle</locationURI> + </link> + <link> <name>.fbprefs</name> <type>1</type> <locationURI>DOCUMENTS/jiemamy-artemis/.fbprefs</locationURI> @@ -43,10 +48,5 @@ <type>1</type> <locationURI>DOCUMENTS/jiemamy-artemis/findbugs.xml</locationURI> </link> - <link> - <name>.checkstyle</name> - <type>1</type> - <locationURI>DOCUMENTS/jiemamy-artemis/.checkstyle</locationURI> - </link> </linkedResources> </projectDescription> 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 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/SerializationTest.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -221,6 +221,9 @@ new ViewTestModelBuilder(jiemamy1).build(); RootModel rootModel1 = jiemamy1.getFactory().getRootModel(); Collection<Problem> problems1 = validator.validate(rootModel1); + for (Problem problem : problems1) { + logger.error(problem.getMessage()); + } assertThat(problems1.size(), is(0)); // 一応バリデーションを行っておく // rootModel1 -> xml1 @@ -274,14 +277,19 @@ // xml1 -> rootModel1 RootModel rootModel1 = convertXmlToRootModel(xml1, serializer1); - assertThat(validator.validate(rootModel1).size(), is(0)); // 一応バリデーションを行っておく + Collection<Problem> problem1 = validator.validate(rootModel1); + for (Problem problem : problem1) { + logger.error(problem.getMessage()); + } + assertThat(problem1.size(), is(0)); // 一応バリデーションを行っておく // rootModel1 -> xml2 String xml2 = convertRootModelToXml(serializer2, rootModel1); // xml1 -> rootModel2 RootModel rootModel2 = convertXmlToRootModel(xml2, serializer2); - assertThat(validator.validate(rootModel2).size(), is(0)); // 一応バリデーションを行っておく + Collection<Problem> problem2 = validator.validate(rootModel2); + assertThat(problem2.toString(), problem2.size(), is(0)); // 一応バリデーションを行っておく // 参考のため、targetディレクトリに出力XMLを記録 FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) Modified: artemis/trunk/jiemamy-composer/.project =================================================================== --- artemis/trunk/jiemamy-composer/.project 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-composer/.project 2009-02-18 18:56:59 UTC (rev 2688) @@ -34,6 +34,11 @@ </natures> <linkedResources> <link> + <name>.checkstyle</name> + <type>1</type> + <locationURI>DOCUMENTS/jiemamy-artemis/.checkstyle</locationURI> + </link> + <link> <name>.fbprefs</name> <type>1</type> <locationURI>DOCUMENTS/jiemamy-artemis/.fbprefs</locationURI> @@ -43,10 +48,5 @@ <type>1</type> <locationURI>DOCUMENTS/jiemamy-artemis/findbugs.xml</locationURI> </link> - <link> - <name>.checkstyle</name> - <type>1</type> - <locationURI>DOCUMENTS/jiemamy-artemis/.checkstyle</locationURI> - </link> </linkedResources> </projectDescription> Modified: artemis/trunk/jiemamy-composer/src/main/java/org/jiemamy/composer/importer/DatabaseImporter.java =================================================================== --- artemis/trunk/jiemamy-composer/src/main/java/org/jiemamy/composer/importer/DatabaseImporter.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-composer/src/main/java/org/jiemamy/composer/importer/DatabaseImporter.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -41,7 +41,6 @@ import org.jiemamy.dialect.Dialect; import org.jiemamy.dialect.generic.GenericDialect; import org.jiemamy.exception.GenericModelingModeException; -import org.jiemamy.exception.TooManyElementsException; import org.jiemamy.model.RootModel; import org.jiemamy.model.attribute.ColumnModel; import org.jiemamy.model.attribute.constraint.ForeignKeyModel; @@ -230,7 +229,7 @@ * {@link DatabaseReader}に対するストラテジとも言える。 * @author daisuke */ - class RelationImportVisitor extends AbstractResultSetVisitor<Void, TooManyElementsException> { + class RelationImportVisitor extends AbstractResultSetVisitor<Void, RuntimeException> { /** 書き込み先モデル */ private RootModel rootModel; @@ -252,7 +251,7 @@ /** * {@inheritDoc} */ - public Void visit(ResultSet keys) throws SQLException, TooManyElementsException { + public Void visit(ResultSet keys) throws SQLException { String fkName = keys.getString("FK_NAME"); String fkTableName = keys.getString("FKTABLE_NAME"); String fkColumnName = keys.getString("FKCOLUMN_NAME"); Modified: artemis/trunk/jiemamy-composer/src/main/java/org/jiemamy/composer/importer/DatabaseReader.java =================================================================== --- artemis/trunk/jiemamy-composer/src/main/java/org/jiemamy/composer/importer/DatabaseReader.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-composer/src/main/java/org/jiemamy/composer/importer/DatabaseReader.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -30,7 +30,6 @@ import org.slf4j.LoggerFactory; import org.jiemamy.dialect.Dialect; -import org.jiemamy.exception.TooManyElementsException; import org.jiemamy.utils.CollectionsUtil; import org.jiemamy.utils.ForEachUtil; import org.jiemamy.utils.visitor.AbstractResultSetVisitor; @@ -106,7 +105,7 @@ * @throws SQLException * @throws IllegalArgumentException 引数に{@code null}を与えた場合 */ - public <T>List<T> readRelations(AbstractResultSetVisitor<T, TooManyElementsException> visitor) throws SQLException { + public <T>List<T> readRelations(AbstractResultSetVisitor<T, RuntimeException> visitor) throws SQLException { assert dialect != null; assert ctx != null; assert meta != null; @@ -119,11 +118,7 @@ List<T> result = CollectionsUtil.newArrayList(); for (String entityName : entityNames) { ResultSet relations = meta.getImportedKeys(null, schema, entityName); - try { - result.add(ForEachUtil.accept(relations, visitor)); - } catch (TooManyElementsException e) { - logger.warn("", e); - } + result.add(ForEachUtil.accept(relations, visitor)); } return result; } Modified: artemis/trunk/jiemamy-core/.project =================================================================== --- artemis/trunk/jiemamy-core/.project 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/.project 2009-02-18 18:56:59 UTC (rev 2688) @@ -34,6 +34,11 @@ </natures> <linkedResources> <link> + <name>.checkstyle</name> + <type>1</type> + <locationURI>DOCUMENTS/jiemamy-artemis/.checkstyle</locationURI> + </link> + <link> <name>.fbprefs</name> <type>1</type> <locationURI>DOCUMENTS/jiemamy-artemis/.fbprefs</locationURI> @@ -43,10 +48,5 @@ <type>1</type> <locationURI>DOCUMENTS/jiemamy-artemis/findbugs.xml</locationURI> </link> - <link> - <name>.checkstyle</name> - <type>1</type> - <locationURI>DOCUMENTS/jiemamy-artemis/.checkstyle</locationURI> - </link> </linkedResources> </projectDescription> 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 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/FactoryExtension.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -38,8 +38,8 @@ import org.jiemamy.model.attribute.ColumnRef; import org.jiemamy.model.attribute.ColumnRefImpl; import org.jiemamy.model.attribute.RepresentationAdapter; -import org.jiemamy.model.attribute.constraint.ColumnCheckModelImpl; import org.jiemamy.model.attribute.constraint.ColumnCheckModel; +import org.jiemamy.model.attribute.constraint.ColumnCheckModelImpl; import org.jiemamy.model.attribute.constraint.ColumnConstraint; import org.jiemamy.model.attribute.constraint.Deferrability; import org.jiemamy.model.attribute.constraint.DeferrabilityImpl; @@ -49,8 +49,8 @@ import org.jiemamy.model.attribute.constraint.NotNullConstraintModelImpl; import org.jiemamy.model.attribute.constraint.PrimaryKeyModel; import org.jiemamy.model.attribute.constraint.PrimaryKeyModelImpl; -import org.jiemamy.model.attribute.constraint.TableCheckModelImpl; import org.jiemamy.model.attribute.constraint.TableCheckModel; +import org.jiemamy.model.attribute.constraint.TableCheckModelImpl; import org.jiemamy.model.attribute.constraint.UniqueKeyModel; import org.jiemamy.model.attribute.constraint.UniqueKeyModelImpl; import org.jiemamy.model.dataset.DataSetModel; @@ -331,7 +331,6 @@ @Override public <T>T newInstance(Jiemamy jiemamy, UUID id) { DomainModelImpl domainModel = new DomainModelImpl(jiemamy, id); - domainModel.setConstraints(new ArrayList<ColumnConstraint>()); return (T) domainModel; } }, Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/AbstractDialect.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/AbstractDialect.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/AbstractDialect.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -199,7 +199,7 @@ if ("NO".equals(isNullable) == false) { NotNullConstraintModel notNullConstraintModel = factory.newModel(NotNullConstraintModel.class); - column.getConstraints().add(notNullConstraintModel); + column.setNotNull(notNullConstraintModel); } finalResult.add(column); Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultSqlEmitter.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultSqlEmitter.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultSqlEmitter.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -28,7 +28,7 @@ import org.jiemamy.model.attribute.ColumnModel; import org.jiemamy.model.attribute.ColumnRef; import org.jiemamy.model.attribute.constraint.CheckConstraintModel; -import org.jiemamy.model.attribute.constraint.ColumnConstraint; +import org.jiemamy.model.attribute.constraint.ColumnCheckModel; import org.jiemamy.model.attribute.constraint.ConstraintModel; import org.jiemamy.model.attribute.constraint.Deferrability; import org.jiemamy.model.attribute.constraint.ForeignKeyModel; @@ -156,17 +156,6 @@ tokens.add(new Identifier(columnModel.getName())); tokens.addAll(dataTypeResolver.resolveDataType(columnModel.getDataType(), referenceResolver)); - for (ColumnConstraint columnConstraint : columnModel.getConstraints()) { - if (columnConstraint instanceof NotNullConstraintModel) { - if (StringUtils.isEmpty(columnConstraint.getName()) == false) { - tokens.add(Keyword.CONSTRAINT); - tokens.add(new Identifier(columnConstraint.getName())); - tokens.add(Keyword.NOT); - tokens.add(Keyword.NULL); - } - } - } - if (StringUtils.isEmpty(columnModel.getDefaultValue()) == false) { BuiltinDataType builtinDataType = DataTypeUtil.toBuiltinDataType(columnModel.getDataType(), referenceResolver); @@ -174,6 +163,46 @@ tokens.add(new Literal(columnModel.getDefaultValue(), builtinDataType.getCategory() .getLiteralType())); } + + NotNullConstraintModel nnModel = columnModel.getNotNull(); + if (nnModel != null) { + if (StringUtils.isEmpty(nnModel.getName()) == false) { + tokens.add(Keyword.CONSTRAINT); + tokens.add(new Identifier(nnModel.getName())); + } + tokens.add(Keyword.NOT); + tokens.add(Keyword.NULL); + } + + UniqueKeyModel ukModel = columnModel.getUniqueKey(); + if (ukModel != null) { + if (StringUtils.isEmpty(ukModel.getName()) == false) { + tokens.add(Keyword.CONSTRAINT); + tokens.add(new Identifier(ukModel.getName())); + } + tokens.add(Keyword.UNIQUE); + } + + PrimaryKeyModel pkModel = columnModel.getPrimaryKey(); + if (pkModel != null) { + if (StringUtils.isEmpty(pkModel.getName()) == false) { + tokens.add(Keyword.CONSTRAINT); + tokens.add(new Identifier(pkModel.getName())); + } + tokens.add(Keyword.PRIMARY); + tokens.add(Keyword.KEY); + } + + ColumnCheckModel checkModel = columnModel.getCheck(); + if (checkModel != null) { + if (StringUtils.isEmpty(checkModel.getName()) == false) { + tokens.add(Keyword.CONSTRAINT); + tokens.add(new Identifier(checkModel.getName())); + } + tokens.add(Keyword.CHECK); + tokens.add(new Literal(checkModel.getExpression(), LiteralType.FRAGMENT)); + } + return tokens; } }, Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/processor/GetColumnProcessor.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/processor/GetColumnProcessor.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/processor/GetColumnProcessor.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -33,7 +33,7 @@ * 指定した名称を持つカラムを取得するプロセッサ。 * @author daisuke */ -public class GetColumnProcessor extends AbstractProcessor<TableModel, ColumnModel, TooManyElementsException> { +public class GetColumnProcessor extends AbstractProcessor<TableModel, ColumnModel, RuntimeException> { private String columnName; @@ -52,7 +52,7 @@ * {@inheritDoc} * @throws TooManyElementsException 複数のカラムが見つかった時 */ - public ColumnModel process(TableModel tableModel) throws TooManyElementsException { + public ColumnModel process(TableModel tableModel) { Validate.notNull(tableModel); List<ColumnModel> columns = CollectionsUtil.newArrayList(); for (ColumnModel column : TableUtil.getAttributes(tableModel, ColumnModel.class)) { Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/processor/GetEntityProcessor.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/processor/GetEntityProcessor.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/processor/GetEntityProcessor.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -34,7 +34,7 @@ * @author daisuke */ public class GetEntityProcessor<T extends EntityModel> extends - AbstractProcessor<RootModel, EntityModel, TooManyElementsException> { + AbstractProcessor<RootModel, EntityModel, RuntimeException> { /** エンティティの種類を表すクラス */ private Class<?> clazz; @@ -70,7 +70,7 @@ * {@inheritDoc} * @throws TooManyElementsException */ - public EntityModel process(RootModel rootModel) throws TooManyElementsException { + public EntityModel process(RootModel rootModel) { Validate.notNull(rootModel); List<EntityModel> entities = CollectionsUtil.newArrayList(); for (EntityModel entity : rootModel.getEntities()) { Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/attribute/ColumnModelImpl.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/attribute/ColumnModelImpl.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/attribute/ColumnModelImpl.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -25,7 +25,11 @@ import org.apache.commons.lang.builder.ToStringStyle; import org.jiemamy.Jiemamy; +import org.jiemamy.model.attribute.constraint.ColumnCheckModel; import org.jiemamy.model.attribute.constraint.ColumnConstraint; +import org.jiemamy.model.attribute.constraint.NotNullConstraintModel; +import org.jiemamy.model.attribute.constraint.PrimaryKeyModel; +import org.jiemamy.model.attribute.constraint.UniqueKeyModel; import org.jiemamy.model.datatype.DataType; import org.jiemamy.utils.ValidateUtil; @@ -45,6 +49,14 @@ /** カラム制約の集合 */ private Collection<ColumnConstraint> constraints; + private ColumnCheckModel check; + + private NotNullConstraintModel notNull; + + private PrimaryKeyModel primaryKey; + + private UniqueKeyModel uniqueKey; + /** * インスタンスを生成する。 @@ -59,6 +71,13 @@ /** * {@inheritDoc} */ + public ColumnCheckModel getCheck() { + return check; + } + + /** + * {@inheritDoc} + */ public Collection<ColumnConstraint> getConstraints() { return constraints; } @@ -78,12 +97,40 @@ } /** + * {@inheritDoc} + */ + public NotNullConstraintModel getNotNull() { + return notNull; + } + + /** + * {@inheritDoc} + */ + public PrimaryKeyModel getPrimaryKey() { + return primaryKey; + } + + /** + * {@inheritDoc} + */ + public UniqueKeyModel getUniqueKey() { + return uniqueKey; + } + + /** + * {@inheritDoc} + */ + public void setCheck(ColumnCheckModel check) { + this.check = check; + } + + /** * TODO for daisuke * @param columnConstraints the columnConstraints to set */ public void setColumnConstraints(Collection<ColumnConstraint> columnConstraints) { - ValidateUtil.injectionSetter(this.constraints); - this.constraints = columnConstraints; + ValidateUtil.injectionSetter(constraints); + constraints = columnConstraints; } /** @@ -103,6 +150,27 @@ /** * {@inheritDoc} */ + public void setNotNull(NotNullConstraintModel notNull) { + this.notNull = notNull; + } + + /** + * {@inheritDoc} + */ + public void setPrimaryKey(PrimaryKeyModel primaryKey) { + this.primaryKey = primaryKey; + } + + /** + * {@inheritDoc} + */ + public void setUniqueKey(UniqueKeyModel uniqueKey) { + this.uniqueKey = uniqueKey; + } + + /** + * {@inheritDoc} + */ @Override public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/DomainModelImpl.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/DomainModelImpl.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/DomainModelImpl.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -25,7 +25,8 @@ import org.jiemamy.Jiemamy; import org.jiemamy.model.AbstractJiemamyElement; -import org.jiemamy.model.attribute.constraint.ColumnConstraint; +import org.jiemamy.model.attribute.constraint.ColumnCheckModel; +import org.jiemamy.model.attribute.constraint.NotNullConstraintModel; /** * ドメイン定義モデル。 @@ -43,12 +44,13 @@ /** ドメインとして定義された型記述子 */ private BuiltinDataType dataType; - /** 制約のリスト */ - private List<ColumnConstraint> constraints; - /** 説明文 */ private String description; + private ColumnCheckModel check; + + private NotNullConstraintModel notNull; + /** * インスタンスを生成する。 @@ -86,8 +88,8 @@ /** * {@inheritDoc} */ - public List<ColumnConstraint> getConstraints() { - return constraints; + public ColumnCheckModel getCheck() { + return check; } /** @@ -121,6 +123,13 @@ /** * {@inheritDoc} */ + public NotNullConstraintModel getNotNull() { + return notNull; + } + + /** + * {@inheritDoc} + */ @Override public boolean hasAdapter(Class<?> adapterClass) { if (dataType == null) { @@ -141,12 +150,10 @@ } /** - * 制約のリストを設定する。 - * - * @param constraints 制約のリスト + * {@inheritDoc} */ - public void setConstraints(List<ColumnConstraint> constraints) { - this.constraints = constraints; + public void setCheck(ColumnCheckModel check) { + this.check = check; } /** @@ -177,4 +184,11 @@ this.name = name; } + /** + * {@inheritDoc} + */ + public void setNotNull(NotNullConstraintModel notNull) { + this.notNull = notNull; + } + } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomBuilder.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomBuilder.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomBuilder.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -22,9 +22,10 @@ import static org.jiemamy.xml.CoreQName.ATTRIBUTES; import static org.jiemamy.xml.CoreQName.BEGIN_SCRIPT; import static org.jiemamy.xml.CoreQName.COLUMN_CHECK_CONSTRAINT; +import static org.jiemamy.xml.CoreQName.COLUMN_PRIMARY_KEY; import static org.jiemamy.xml.CoreQName.COLUMN_REF; import static org.jiemamy.xml.CoreQName.COLUMN_REFS; -import static org.jiemamy.xml.CoreQName.CONSTRAINTS; +import static org.jiemamy.xml.CoreQName.COLUMN_UNIQUE_KEY; import static org.jiemamy.xml.CoreQName.DATASET; import static org.jiemamy.xml.CoreQName.DATASETS; import static org.jiemamy.xml.CoreQName.DATA_TYPE; @@ -57,7 +58,6 @@ import static org.jiemamy.xml.CoreQName.VIEW; import java.lang.reflect.Field; -import java.util.Collection; import java.util.Comparator; import java.util.List; import java.util.Map; @@ -124,26 +124,34 @@ private static Logger logger = LoggerFactory.getLogger(DomBuilder.class); - private static Element newColumnConstraintsElement(Element parentElement, Collection<ColumnConstraint> constraints) { - if (constraints.size() == 0) { + private static Element newColumnConstraintsElement(Element parentElement, ColumnConstraint columnConstraint) { + if (columnConstraint == null) { return null; } - Element constraintsElement = DomUtil.newChild(parentElement, CONSTRAINTS); - for (ColumnConstraint columnConstraint : constraints) { - if (columnConstraint instanceof NotNullConstraintModel) { - NotNullConstraintModel notNullConstraintModel = (NotNullConstraintModel) columnConstraint; - Element nnElement = DomUtil.newChild(constraintsElement, NOT_NULL); - nnElement.setAttribute(CoreQName.ID.getQNameString(), notNullConstraintModel.getId().toString()); - writeAdapters(nnElement, notNullConstraintModel.getAdapters()); - } else if (columnConstraint instanceof ColumnCheckModel) { - ColumnCheckModel columnCheckModel = (ColumnCheckModel) columnConstraint; - writeColumnCheckConstrait(constraintsElement, columnCheckModel); - } else { - // 処理しない。 - logger.info("column keyConstraint convert to table keyConstraint"); - } + Element element = null; + if (columnConstraint instanceof NotNullConstraintModel) { + NotNullConstraintModel nnModel = (NotNullConstraintModel) columnConstraint; + element = DomUtil.newChild(parentElement, NOT_NULL); + element.setAttribute(CoreQName.ID.getQNameString(), nnModel.getId().toString()); + DomUtil.newChild(element, NAME, nnModel.getName()); + writeAdapters(element, nnModel.getAdapters()); + } else if (columnConstraint instanceof ColumnCheckModel) { + ColumnCheckModel columnCheckModel = (ColumnCheckModel) columnConstraint; + writeColumnCheckConstrait(parentElement, columnCheckModel); + } else if (columnConstraint instanceof UniqueKeyModel) { + UniqueKeyModel ukModel = (UniqueKeyModel) columnConstraint; + element = DomUtil.newChild(parentElement, COLUMN_UNIQUE_KEY); + element.setAttribute(CoreQName.ID.getQNameString(), ukModel.getId().toString()); + DomUtil.newChild(element, NAME, ukModel.getName()); + writeAdapters(element, ukModel.getAdapters()); + } else if (columnConstraint instanceof PrimaryKeyModel) { + PrimaryKeyModel pkModel = (PrimaryKeyModel) columnConstraint; + element = DomUtil.newChild(parentElement, COLUMN_PRIMARY_KEY); + element.setAttribute(CoreQName.ID.getQNameString(), pkModel.getId().toString()); + DomUtil.newChild(element, NAME, pkModel.getName()); + writeAdapters(element, pkModel.getAdapters()); } - return constraintsElement; + return element; } private static Element newDataTypeElement(Element parentElement, DataType dataType) { @@ -306,24 +314,18 @@ DomUtil.newChild(domainElement, DESCRIPTION, domainModel.getDescription()); newDataTypeElement(domainElement, domainModel.getDataType()); - if (domainModel.getConstraints().size() > 0) { - Element constraintsElement = DomUtil.newChild(domainElement, CONSTRAINTS); - for (ColumnConstraint constraint : domainModel.getConstraints()) { - if (constraint instanceof NotNullConstraintModel) { - NotNullConstraintModel notNullConstraintModel = (NotNullConstraintModel) constraint; - Element notNullElement = DomUtil.newChild(constraintsElement, NOT_NULL); - notNullElement.setAttribute(CoreQName.ID.getQNameString(), notNullConstraintModel.getId() - .toString()); - DomUtil.newChild(notNullElement, NAME, notNullConstraintModel.getName()); - writeAdapters(notNullElement, notNullConstraintModel.getAdapters()); - } else if (constraint instanceof ColumnCheckModel) { - writeColumnCheckConstrait(constraintsElement, (ColumnCheckModel) constraint); - } else { - logger.warn("unknown domain constraint: " + constraint.getClass().getName()); - } - } + NotNullConstraintModel notNull = domainModel.getNotNull(); + if (notNull != null) { + Element notNullElement = DomUtil.newChild(domainElement, NOT_NULL); + notNullElement.setAttribute(CoreQName.ID.getQNameString(), notNull.getId().toString()); + DomUtil.newChild(notNullElement, NAME, notNull.getName()); + writeAdapters(notNullElement, notNull.getAdapters()); } - // dataType要素で既にadapterは処理済みの為、ここではアダプタ出力をしない。 + + ColumnCheckModel check = domainModel.getCheck(); + if (check != null) { + writeColumnCheckConstrait(domainElement, check); + } } } @@ -360,7 +362,10 @@ ColumnModel columnModel = (ColumnModel) attributeModel; newDataTypeElement(attributeElement, columnModel.getDataType()); DomUtil.newChild(attributeElement, DEFAULT_VALUE, columnModel.getDefaultValue()); - newColumnConstraintsElement(attributeElement, columnModel.getConstraints()); + newColumnConstraintsElement(attributeElement, columnModel.getNotNull()); + newColumnConstraintsElement(attributeElement, columnModel.getUniqueKey()); + newColumnConstraintsElement(attributeElement, columnModel.getPrimaryKey()); + newColumnConstraintsElement(attributeElement, columnModel.getCheck()); } else if (attributeModel instanceof KeyConstraintModel) { KeyConstraintModel keyeyModel = (KeyConstraintModel) attributeModel; Element columnRefsElement = DomUtil.newChild(attributeElement, COLUMN_REFS); 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 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomParser.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -18,8 +18,6 @@ */ package org.jiemamy.serializer; -import static org.jiemamy.xml.CoreQName.COLUMN_CHECK_CONSTRAINT; -import static org.jiemamy.xml.CoreQName.NOT_NULL; import static org.jiemamy.xml.CoreQName.TABLE; import static org.jiemamy.xml.CoreQName.VIEW; @@ -48,7 +46,6 @@ import org.jiemamy.model.attribute.ColumnRef; import org.jiemamy.model.attribute.ColumnRefImpl; import org.jiemamy.model.attribute.constraint.ColumnCheckModel; -import org.jiemamy.model.attribute.constraint.ColumnConstraint; import org.jiemamy.model.attribute.constraint.Deferrability; import org.jiemamy.model.attribute.constraint.ForeignKeyModel; import org.jiemamy.model.attribute.constraint.KeyConstraintModel; @@ -250,34 +247,43 @@ columnModel.setDataType(getDataType((Element) XpathUtil.getNode(columnElement, "core:dataType"))); columnModel.setDefaultValue(XpathUtil.getTextContent(columnElement, "core:defaultValue")); - if (XpathUtil.getNode(columnElement, "core:constraints") != null) { - NodeList constraintNodeList = XpathUtil.getNodes(columnElement, "core:constraints/*"); - Iterable<Node> constraintIterableNodeList = new IterableNodeList(constraintNodeList); - for (Node constraintNode : constraintIterableNodeList) { - if ((constraintNode instanceof Element) == false) { - continue; - } - Element constraintElement = (Element) constraintNode; - if (DomUtil.equalsElement(constraintElement, CoreQName.NOT_NULL)) { - NotNullConstraintModel nnModel = - factory.newModel(NotNullConstraintModel.class, DomUtil.getUUID(constraintElement, - CoreQName.ID)); - nnModel.setName(XpathUtil.getText(constraintElement, "core:name/text()")); - readAdapter(constraintElement, nnModel); - columnModel.getConstraints().add(nnModel); - } else if (DomUtil.equalsElement(constraintElement, CoreQName.COLUMN_CHECK_CONSTRAINT)) { - ColumnCheckModel checkModel = - factory.newModel(ColumnCheckModel.class, DomUtil.getUUID(constraintElement, CoreQName.ID)); - checkModel.setName(XpathUtil.getText(constraintElement, "core:name/text()")); - checkModel.setExpression(XpathUtil.getText(constraintElement, "core:expression/text()")); - readAdapter(constraintElement, checkModel); - columnModel.getConstraints().add(checkModel); - } else { - logger.warn("unknown attribute"); - } - } + Element nnElement = (Element) XpathUtil.getNode(columnElement, "core:notNull"); + if (nnElement != null) { + NotNullConstraintModel nnModel = + factory.newModel(NotNullConstraintModel.class, DomUtil.getUUID(nnElement, CoreQName.ID)); + nnModel.setName(XpathUtil.getText(nnElement, "core:name/text()")); + readAdapter(nnElement, nnModel); + columnModel.setNotNull(nnModel); } + Element ukElement = (Element) XpathUtil.getNode(columnElement, "core:columnUniqueKey"); + if (ukElement != null) { + UniqueKeyModel ukModel = factory.newModel(UniqueKeyModel.class, DomUtil.getUUID(ukElement, CoreQName.ID)); + ukModel.setName(XpathUtil.getText(ukElement, "core:name/text()")); + ukModel.getKeyColumns().add(factory.newReference(columnModel)); + readAdapter(ukElement, ukModel); + columnModel.setUniqueKey(ukModel); + } + + Element pkElement = (Element) XpathUtil.getNode(columnElement, "core:columnPrimaryKey"); + if (pkElement != null) { + PrimaryKeyModel pkModel = factory.newModel(PrimaryKeyModel.class, DomUtil.getUUID(pkElement, CoreQName.ID)); + pkModel.setName(XpathUtil.getText(pkElement, "core:name/text()")); + pkModel.getKeyColumns().add(factory.newReference(columnModel)); + readAdapter(pkElement, pkModel); + columnModel.setPrimaryKey(pkModel); + } + + Element checkElement = (Element) XpathUtil.getNode(columnElement, "core:columnCheck"); + if (checkElement != null) { + ColumnCheckModel checkModel = + factory.newModel(ColumnCheckModel.class, DomUtil.getUUID(checkElement, CoreQName.ID)); + checkModel.setName(XpathUtil.getText(checkElement, "core:name/text()")); + checkModel.setExpression(XpathUtil.getText(checkElement, "core:expression/text()")); + readAdapter(checkElement, checkModel); + columnModel.setCheck(checkModel); + } + columnModel.setDescription(XpathUtil.getTextContent(columnElement, "core:description")); readAdapter(columnElement, columnModel); tableModel.getAttributes().add(columnModel); @@ -352,38 +358,27 @@ domainModel.setDataType((BuiltinDataType) getDataType((Element) XpathUtil.getNode(domainNode, "core:dataType"))); - NodeList constraintNodeList = XpathUtil.getNodes(domainNode, "core:constraints/*"); - Iterable<Node> constraintIterableNodeList = new IterableNodeList(constraintNodeList); - for (Node constraintNode : constraintIterableNodeList) { - if ((constraintNode instanceof Element) == false) { - logger.warn("unexpected constraint: " + constraintNode.getNodeType()); - continue; - } - ColumnConstraint constraint; - Element constraintElement = (Element) constraintNode; - - if (constraintElement.getNodeName().equals(NOT_NULL.getQName().getLocalPart())) { - NotNullConstraintModel notNullConstraintModel = - factory.newModel(NotNullConstraintModel.class, DomUtil - .getUUID(constraintNode, CoreQName.ID)); - readAdapter(constraintElement, notNullConstraintModel); - constraint = notNullConstraintModel; - } else if (constraintElement.getNodeName().equals(COLUMN_CHECK_CONSTRAINT.getQName().getLocalPart())) { - ColumnCheckModel checkConstraintModel = - factory.newModel(ColumnCheckModel.class, DomUtil.getUUID(constraintNode, CoreQName.ID)); - checkConstraintModel.setExpression(XpathUtil.getText(constraintElement, "core:expression/text()")); - readAdapter(constraintElement, checkConstraintModel); - constraint = checkConstraintModel; - } else { - logger.warn("unknown constraint: " + constraintElement.getNodeName()); - continue; - } - - constraint.setName(XpathUtil.getTextContent(constraintElement, "core:name")); - - domainModel.getConstraints().add(constraint); + Node nnNode = XpathUtil.getNode(domainNode, "core:notNull"); + if (nnNode != null) { + Element nnElement = (Element) nnNode; + NotNullConstraintModel nnModel = + factory.newModel(NotNullConstraintModel.class, DomUtil.getUUID(nnNode, CoreQName.ID)); + nnModel.setName(XpathUtil.getTextContent(nnElement, "core:name")); + readAdapter(nnElement, nnModel); + domainModel.setNotNull(nnModel); } + Node checkNode = XpathUtil.getNode(domainNode, "core:columnCheck"); + if (checkNode != null) { + Element checkElement = (Element) checkNode; + ColumnCheckModel checkModel = + factory.newModel(ColumnCheckModel.class, DomUtil.getUUID(checkNode, CoreQName.ID)); + checkModel.setExpression(XpathUtil.getText(checkElement, "core:expression/text()")); + readAdapter(checkElement, checkModel); + checkModel.setName(XpathUtil.getTextContent(checkElement, "core:name")); + domainModel.setCheck(checkModel); + } + domainModel.setDescription(XpathUtil.getTextContent(domainNode, "core:description")); readAdapter((Element) domainNode, domainModel); @@ -449,15 +444,6 @@ tableModel.getAttributes().add(fkModel); } - private void parseNotNullConstraint(Element nnElement, ColumnModel columnModel) { - NotNullConstraintModel nnModel = - factory.newModel(NotNullConstraintModel.class, DomUtil.getUUID(nnElement, CoreQName.ID)); - nnModel.setName(XpathUtil.getTextContent(nnElement, "core:name")); - - readAdapter(nnElement, nnModel); - columnModel.getConstraints().add(nnModel); - } - private void parsePrimaryKey(Element pkElement, TableModel tableModel) { PrimaryKeyModel pkModel = factory.newModel(PrimaryKeyModel.class, DomUtil.getUUID(pkElement, CoreQName.ID)); pkModel.setName(XpathUtil.getTextContent(pkElement, "core:name")); @@ -510,7 +496,6 @@ } private void parseTableCheckConstraint(Element checkElement, TableModel tableModel) { - ; TableCheckModel checkModel = factory.newModel(TableCheckModel.class, DomUtil.getUUID(checkElement, CoreQName.ID)); checkModel.setName(XpathUtil.getTextContent(checkElement, "core:name")); Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/test/TestModelBuilder.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/test/TestModelBuilder.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/test/TestModelBuilder.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -294,12 +294,12 @@ domainId.setDataType(new DataTypeBuilder(factory, DataTypeCategory.INTEGER).build()); NotNullConstraintModel notNull = factory.newModel(NotNullConstraintModel.class, uuid.get("af4845dc-7f3a-434d-b5ac-2f25b74d7e76")); - domainId.getConstraints().add(notNull); + domainId.setNotNull(notNull); ColumnCheckModel check = factory.newModel(ColumnCheckModel.class, uuid.get("48b76d76-b288-480a-afa4-111247379f8d")); check.setName("hoge"); check.setExpression("VALUE > 0"); - domainId.getConstraints().add(check); + domainId.setCheck(check); domainId.getAdapter(SerialDataTypeAdapter.class).setSerial(true); rootModel.getDomains().add(domainId); @@ -605,6 +605,10 @@ ColumnUtil.setDataType(deptId, domainId); } deptId.setLogicalName("部署ID"); + deptPk = factory.newModel(PrimaryKeyModel.class, uuid.get("8de55e65-ec48-467a-bac5-8eee2d71d41c")); + deptPk.setName("dept_pkey"); + deptPk.getKeyColumns().add(factory.newReference(deptId)); + deptId.setPrimaryKey(deptPk); tableDept.getAttributes().add(deptId); deptDeptNo = factory.newModel(ColumnModel.class, uuid.get("2d951389-6bc7-49d7-8631-1d26fe17047e")); @@ -627,11 +631,6 @@ deptLoc.setDefaultValue("secret"); tableDept.getAttributes().add(deptLoc); - deptPk = factory.newModel(PrimaryKeyModel.class, uuid.get("8de55e65-ec48-467a-bac5-8eee2d71d41c")); - deptPk.setName("dept_pkey"); - deptPk.getKeyColumns().add(factory.newReference(deptId)); - tableDept.getAttributes().add(deptPk); - Map<UUID, UUID> columnNotNullMap = CollectionsUtil.newHashMap(); columnNotNullMap.put(deptDeptNo.getId(), uuid.get("cc709f63-a886-4207-a316-58ad7f279e10")); columnNotNullMap.put(deptDeptName.getId(), uuid.get("fab2f883-0489-4661-bd57-f04286188eef")); @@ -639,7 +638,7 @@ for (ColumnModel column : Arrays.asList(deptDeptNo, deptDeptName)) { NotNullConstraintModel notNull = factory.newModel(NotNullConstraintModel.class, columnNotNullMap.get(column.getId())); - column.getConstraints().add(notNull); + column.setNotNull(notNull); } } @@ -667,7 +666,7 @@ NotNullConstraintModel notNullEmpEmpNo = factory.newModel(NotNullConstraintModel.class, uuid.get("05ee4c06-d8b5-4599-a7e9-1cda036ea2c7")); notNullEmpEmpNo.getAdapter(Disablable.class).setDisabled(true); - empEmpNo.getConstraints().add(notNullEmpEmpNo); + empEmpNo.setNotNull(notNullEmpEmpNo); tableEmp.getAttributes().add(empEmpNo); empEmpName = factory.newModel(ColumnModel.class, uuid.get("0e51b6df-43ab-408c-90ef-de13c6aab881")); @@ -717,7 +716,7 @@ for (ColumnModel column : Arrays.asList(empEmpName, empHiredate, empSal, empDeptId)) { NotNullConstraintModel notNull = factory.newModel(NotNullConstraintModel.class, columnNotNullMap.get(column.getId())); - column.getConstraints().add(notNull); + column.setNotNull(notNull); } } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/test/TestModelBuilder2.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/test/TestModelBuilder2.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/test/TestModelBuilder2.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -306,7 +306,7 @@ idDomain = factory.newModel(DomainModel.class, uuid.get("9a3ba23c-b328-4c70-a32d-3e4be3ee3f08")); idDomain.setName("ID"); idDomain.setDataType(new DataTypeBuilder(factory, DataTypeCategory.INTEGER).build()); - idDomain.getConstraints().add(factory.newModel(NotNullConstraintModel.class)); + idDomain.setNotNull(factory.newModel(NotNullConstraintModel.class)); idDomain.getAdapter(SerialDataTypeAdapter.class).setSerial(true); rootModel.getDomains().add(idDomain); @@ -699,7 +699,7 @@ for (ColumnModel column : Arrays.asList(detailOrderId, detailItemId, detailQuantity)) { NotNullConstraintModel notNull = factory.newModel(NotNullConstraintModel.class); - column.getConstraints().add(notNull); + column.setNotNull(notNull); } } @@ -739,7 +739,7 @@ for (ColumnModel column : Arrays.asList(itemName, itemPrice)) { NotNullConstraintModel notNull = factory.newModel(NotNullConstraintModel.class); - column.getConstraints().add(notNull); + column.setNotNull(notNull); } } @@ -776,7 +776,7 @@ for (ColumnModel column : Arrays.asList(orderUserId, orderDate)) { NotNullConstraintModel notNull = factory.newModel(NotNullConstraintModel.class); - column.getConstraints().add(notNull); + column.setNotNull(notNull); } } @@ -813,6 +813,6 @@ tableUser.getAttributes().add(userPk); NotNullConstraintModel notNull = factory.newModel(NotNullConstraintModel.class); - userName.getConstraints().add(notNull); + userName.setNotNull(notNull); } } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/XpathUtil.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/XpathUtil.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/XpathUtil.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -23,6 +23,7 @@ import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; +import org.apache.commons.lang.StringUtils; import org.w3c.dom.Attr; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -100,7 +101,7 @@ public static String getText(Node root, String strExpr) { try { String str = (String) XPATH.evaluate(strExpr, root, XPathConstants.STRING); - return str; //StringUtils.defaultIfEmpty(str, null); + return StringUtils.defaultIfEmpty(str, null); } catch (XPathExpressionException e) { throw new UnexpectedConditionError("XPath expression error: " + strExpr, e); } 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 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/ColumnUtil.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -24,7 +24,6 @@ import org.slf4j.LoggerFactory; import org.jiemamy.JiemamyFactory; -import org.jiemamy.exception.TooManyElementsException; import org.jiemamy.model.RootModel; import org.jiemamy.model.attribute.ColumnModel; import org.jiemamy.model.attribute.ColumnRef; @@ -61,17 +60,12 @@ public static boolean isPartOfPrimaryKeyColumns(ColumnModel columnModel) { TableModel tableModel = getDefinedTable(columnModel); - try { - PrimaryKeyModel primaryKey = TableUtil.getPrimaryKey(tableModel); - List<ColumnRef> keyColumns = primaryKey.getKeyColumns(); - for (ColumnRef columnRef : keyColumns) { - if (columnRef.getReferenceId() == columnModel.getId()) { - return true; - } + PrimaryKeyModel primaryKey = TableUtil.getPrimaryKey(tableModel); + List<ColumnRef> keyColumns = primaryKey.getKeyColumns(); + for (ColumnRef columnRef : keyColumns) { + if (columnRef.getReferenceId() == columnModel.getId()) { + return true; } - } catch (TooManyElementsException e) { - // FIXME 適切に処理せよ - logger.warn("複数PKテーブルでisPartOfPrimaryKeyColumnsが呼ばれた"); } return false; } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/DomainUtil.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/DomainUtil.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/DomainUtil.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -18,12 +18,7 @@ */ package org.jiemamy.utils.model; -import java.util.List; -import org.jiemamy.model.attribute.constraint.ColumnConstraint; -import org.jiemamy.model.attribute.constraint.ConstraintModel; -import org.jiemamy.model.datatype.DomainModel; - /** * TODO for daisuke * @@ -31,23 +26,6 @@ */ public class DomainUtil { - /** - * TODO for daisuke - * @param domainModel - * - * @param clazz - * @return - */ - public static boolean hasConstraint(DomainModel domainModel, Class<? extends ConstraintModel> clazz) { - List<ColumnConstraint> constraints = domainModel.getConstraints(); - for (ColumnConstraint constraint : constraints) { - if (clazz.isAssignableFrom(constraint.getClass())) { - return true; - } - } - return false; - } - private DomainUtil() { } } 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 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/RootModelUtil.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -33,9 +33,13 @@ import org.jiemamy.model.JiemamyElement; import org.jiemamy.model.RootModel; import org.jiemamy.model.attribute.AttributeModel; -import org.jiemamy.model.attribute.constraint.ColumnConstraint; +import org.jiemamy.model.attribute.ColumnModel; +import org.jiemamy.model.attribute.constraint.ColumnCheckModel; import org.jiemamy.model.attribute.constraint.Deferrability; 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.UniqueKeyModel; import org.jiemamy.model.dataset.DataSetModel; import org.jiemamy.model.dataset.RecordModel; import org.jiemamy.model.datatype.DomainModel; @@ -64,11 +68,14 @@ if (domainModel.getId().equals(refId)) { return domainModel; } - for (ColumnConstraint valueConstraintModel : domainModel.getConstraints()) { - if (valueConstraintModel.getId().equals(refId)) { - return valueConstraintModel; - } + NotNullConstraintModel notNull = domainModel.getNotNull(); + if (notNull != null && refId.equals(notNull.getId())) { + return notNull; } + ColumnCheckModel check = domainModel.getCheck(); + if (check != null && refId.equals(check.getId())) { + return check; + } } for (EntityModel entityModel : rootModel.getEntities()) { @@ -81,6 +88,25 @@ if (refId.equals(attributeModel.getId())) { return attributeModel; } + if (attributeModel instanceof ColumnModel) { + ColumnModel columnModel = (ColumnModel) attributeModel; + NotNullConstraintModel notNull = columnModel.getNotNull(); + if (notNull != null && refId.equals(notNull.getId())) { + return notNull; + } + UniqueKeyModel uniqueKey = columnModel.getUniqueKey(); + if (uniqueKey != null && refId.equals(uniqueKey.getId())) { + return uniqueKey; + } + PrimaryKeyModel primaryKey = columnModel.getPrimaryKey(); + if (primaryKey != null && refId.equals(primaryKey.getId())) { + return primaryKey; + } + ColumnCheckModel check = columnModel.getCheck(); + if (check != null && refId.equals(check.getId())) { + return check; + } + } if (attributeModel instanceof ForeignKeyModel) { ForeignKeyModel foreignKeyModel = (ForeignKeyModel) attributeModel; Deferrability deferrability = foreignKeyModel.getDeferrability(); @@ -163,8 +189,7 @@ * @throws TooManyElementsException 同名のエンティティが複数見つかった場合 * @throws ElementNotFoundException エンティティが見つからなかった場合 */ - public static <T extends EntityModel>T getEntity(RootModel rootModel, Class<T> clazz, String entityName) - throws TooManyElementsException { + public static <T extends EntityModel>T getEntity(RootModel rootModel, Class<T> clazz, String entityName) { // T型を返すことが保証されているため、キャスト安全である。 @SuppressWarnings("unchecked") T entity = (T) ProcessorUtil.process(rootModel, new GetEntityProcessor<T>(clazz, entityName)); 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 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/TableUtil.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -18,6 +18,7 @@ */ package org.jiemamy.utils.model; +import java.util.Collection; import java.util.List; import org.jiemamy.exception.ElementNotFoundException; @@ -25,9 +26,12 @@ 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; import org.jiemamy.model.entity.TableModel; import org.jiemamy.utils.CollectionsUtil; import org.jiemamy.utils.ProcessorUtil; @@ -46,9 +50,9 @@ * @param clazz 属性の型 * @return 属性 * @throws TooManyElementsException + * @throws ElementNotFoundException */ - public static <T extends AttributeModel>T getAttribute(TableModel tableModel, Class<T> clazz) - throws TooManyElementsException { + public static <T extends AttributeModel>T getAttribute(TableModel tableModel, Class<T> clazz) { List<T> attributes = getAttributes(tableModel, clazz); if (attributes.size() == 0) { throw new ElementNotFoundException(tableModel, clazz); @@ -65,12 +69,31 @@ * @param clazz * @return 属性のリスト */ - public static <T extends AttributeModel>List<T> getAttributes(TableModel tableModel, Class<T> clazz) { + public static <T>List<T> getAttributes(TableModel tableModel, Class<T> clazz) { List<T> result = CollectionsUtil.newArrayList(); for (AttributeModel attribute : tableModel.getAttributes()) { if (clazz.isAssignableFrom(attribute.getClass())) { result.add(clazz.cast(attribute)); } + if (attribute instanceof ColumnModel) { + ColumnModel columnModel = (ColumnModel) attribute; + UniqueKeyModel uniqueKey = columnModel.getUniqueKey(); + if (uniqueKey != null && clazz.isAssignableFrom(uniqueKey.getClass())) { + result.add(clazz.cast(uniqueKey)); + } + PrimaryKeyModel primaryKey = columnModel.getPrimaryKey(); + 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)); + } + } } return result; } @@ -84,14 +107,35 @@ * @throws TooManyElementsException 同名のカラムが複数見つかった場合 * @throws ElementNotFoundException カラムが見つからなかった場合 */ - public static ColumnModel getColumn(TableModel tableModel, String columnName) throws TooManyElementsException { - // T型を返すことが保証されているため、キャスト安全である。 - @SuppressWarnings("unchecked") + public static ColumnModel getColumn(TableModel tableModel, String columnName) { ColumnModel column = ProcessorUtil.process(tableModel, new GetColumnProcessor(columnName)); return column; } /** + * TODO for daisuke + * + * @param tableModel + * @return + */ + public static PrimaryKeyModel getColumnPrimaryKey(TableModel tableModel) { + Collection<PrimaryKeyModel> pks = CollectionsUtil.newArrayList(); + for (ColumnModel columnModel : getColumns(tableModel)) { + PrimaryKeyModel primaryKey = columnModel.getPrimaryKey(); + if (primaryKey != null) { + pks.add(primaryKey); + } + } + if (pks.size() > 1) { + throw new TooManyElementsException(tableModel, "column primaryKey", pks); + } + if (pks.size() == 0) { + return null; + } + return pks.iterator().next(); + } + + /** * カラムのリストを取得する。 * @param tableModel 対象のテーブル * @return カラムのリスト @@ -125,8 +169,9 @@ * @param tableModel 対象のテーブル * @return 主キー * @throws TooManyElementsException + * @throws ElementNotFoundException */ - public static PrimaryKeyModel getPrimaryKey(TableModel tableModel) throws TooManyElementsException { + public static PrimaryKeyModel getPrimaryKey(TableModel tableModel) { return getAttribute(tableModel, PrimaryKeyModel.class); } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/AbstractTraversalValidator.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/AbstractTraversalValidator.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/AbstractTraversalValidator.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -27,7 +27,6 @@ import org.jiemamy.model.attribute.ColumnModel; import org.jiemamy.model.attribute.ColumnRef; import org.jiemamy.model.attribute.constraint.CheckConstraintModel; -import org.jiemamy.model.attribute.constraint.ColumnConstraint; import org.jiemamy.model.attribute.constraint.ConstraintModel; import org.jiemamy.model.attribute.constraint.ForeignKeyModel; import org.jiemamy.model.attribute.constraint.KeyConstraintModel; @@ -91,20 +90,32 @@ if (attributeModel instanceof ColumnModel) { ColumnModel columnModel = (ColumnModel) attributeModel; check(columnModel.getDataType(), TABLE + index(i) + "/column" + index(j) + "/dataType"); - int k = 0; - for (ColumnConstraint columnConstraint : columnModel.getConstraints()) { - check(columnConstraint, TABLE + index(i) + "/column" + index(j) + "/constraint" + index(k)); - if (columnConstraint instanceof KeyConstraintModel) { - KeyConstraintModel keyConstraintModel = (KeyConstraintModel) columnConstraint; - int l = 0; - for (ColumnRef columnRef : keyConstraintModel.getKeyColumns()) { - check(columnRef, TABLE + index(i) + "/column" + index(j) + "/constraint" + index(k) - + "/columnRef" + index(l)); - l++; - } + + check(columnModel.getNotNull(), TABLE + index(i) + "/column" + index(j) + "/notNull"); + + UniqueKeyModel ukModel = columnModel.getUniqueKey(); + check(ukModel, TABLE + index(i) + "/column" + index(j) + "/uniqueKey"); + if (ukModel != null) { + int k = 0; + for (ColumnRef columnRef : ukModel.getKeyColumns()) { + check(columnRef, TABLE + index(i) + "/column" + index(j) + "/uniqueKey/columnRef" + + index(k)); + k++; } - k++; } + + PrimaryKeyModel pkModel = columnModel.getPrimaryKey(); + check(pkModel, TABLE + index(i) + "/column" + index(j) + "/primaryKey"); + if (pkModel != null) { + int k = 0; + for (ColumnRef columnRef : pkModel.getKeyColumns()) { + check(columnRef, TABLE + index(i) + "/column" + index(j) + "/primaryKey/columnRef" + + index(k)); + k++; + } + } + + check(columnModel.getCheck(), TABLE + index(i) + "/column" + index(j) + "/check"); } else if (attributeModel instanceof ConstraintModel) { checkConstraintModel(i, j, (ConstraintModel) attributeModel); } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/ColumnValidator.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/ColumnValidator.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/ColumnValidator.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -25,9 +25,8 @@ import org.jiemamy.model.RootModel; import org.jiemamy.model.attribute.ColumnModel; -import org.jiemamy.model.attribute.ColumnRef; -import org.jiemamy.model.attribute.constraint.ColumnConstraint; -import org.jiemamy.model.attribute.constraint.LocalKeyModel; +import org.jiemamy.model.attribute.constraint.PrimaryKeyModel; +import org.jiemamy.model.attribute.constraint.UniqueKeyModel; import org.jiemamy.model.entity.TableModel; import org.jiemamy.utils.model.RootModelUtil; import org.jiemamy.utils.model.TableUtil; @@ -60,18 +59,15 @@ if (column.getDataType() == null) { result.add(new EmptyDataTypeProblem(tableModel, column)); } - for (ColumnConstraint columnConstraint : column.getConstraints()) { - if (columnConstraint instanceof LocalKeyModel) { - LocalKeyModel localKeyModel = (LocalKeyModel) columnConstraint; - if (localKeyModel.getKeyColumns().size() != 1) { - // UNDONE - } - ColumnRef columnRef = localKeyModel.getKeyColumns().get(0); - if (columnRef.getReferenceId() != column.getId()) { - // UNDONE - } - } + + UniqueKeyModel uniqueKey = column.getUniqueKey(); + if (uniqueKey != null && uniqueKey.getKeyColumns().size() != 1) { + // UNDONE } + PrimaryKeyModel primaryKey = column.getPrimaryKey(); + if (primaryKey != null && primaryKey.getKeyColumns().size() != 1) { + // UNDONE + } index++; } } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/InstanceCollisionValidator.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/InstanceCollisionValidator.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/InstanceCollisionValidator.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -39,6 +39,9 @@ @Override void check(Object element, String pos) { + if (element == null) { + return; + } int identityHashCode = System.identityHashCode(element); if (ids.containsKey(identityHashCode)) { result.add(new InstanceCollisionProblem(identityHashCode, ids.get(identityHashCode), pos)); Modified: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/XpathUtilTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/XpathUtilTest.java 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/XpathUtilTest.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -122,8 +122,8 @@ @Test public void test04() throws Exception { assertThat(XpathUtil.getText(document, "/core:root/core:content/text()"), is("unba")); - assertThat(XpathUtil.getText(document, "/core:root/core:empty/text()"), is("")); - assertThat(XpathUtil.getText(document, "/core:root/core:nul/text()"), is("")); + assertThat(XpathUtil.getText(document, "/core:root/core:empty/text()"), is(nullValue())); + assertThat(XpathUtil.getText(document, "/core:root/core:nul/text()"), is(nullValue())); assertThat(XpathUtil.getTextContent(document, "/core:root/core:content"), is("unba")); assertThat(XpathUtil.getTextContent(document, "/core:root/core:empty1"), is("")); Modified: artemis/trunk/jiemamy-dialect-mysql/.project =================================================================== --- artemis/trunk/jiemamy-dialect-mysql/.project 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-dialect-mysql/.project 2009-02-18 18:56:59 UTC (rev 2688) @@ -34,6 +34,11 @@ </natures> <linkedResources> <link> + <name>.checkstyle</name> + <type>1</type> + <locationURI>DOCUMENTS/jiemamy-artemis/.checkstyle</locationURI> + </link> + <link> <name>.fbprefs</name> <type>1</type> <locationURI>DOCUMENTS/jiemamy-artemis/.fbprefs</locationURI> @@ -43,10 +48,5 @@ <type>1</type> <locationURI>DOCUMENTS/jiemamy-artemis/findbugs.xml</locationURI> </link> - <link> - <name>.checkstyle</name> - <type>1</type> - <locationURI>DOCUMENTS/jiemamy-artemis/.checkstyle</locationURI> - </link> </linkedResources> </projectDescription> Modified: artemis/trunk/jiemamy-dialect-postgresql/.project =================================================================== --- artemis/trunk/jiemamy-dialect-postgresql/.project 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-dialect-postgresql/.project 2009-02-18 18:56:59 UTC (rev 2688) @@ -34,6 +34,11 @@ </natures> <linkedResources> <link> + <name>.checkstyle</name> + <type>1</type> + <locationURI>DOCUMENTS/jiemamy-artemis/.checkstyle</locationURI> + </link> + <link> <name>.fbprefs</name> <type>1</type> <locationURI>DOCUMENTS/jiemamy-artemis/.fbprefs</locationURI> @@ -43,10 +48,5 @@ <type>1</type> <locationURI>DOCUMENTS/jiemamy-artemis/findbugs.xml</locationURI> </link> - <link> - <name>.checkstyle</name> - <type>1</type> - <locationURI>DOCUMENTS/jiemamy-artemis/.checkstyle</locationURI> - </link> </linkedResources> </projectDescription> Modified: artemis/trunk/jiemamy-dialect-sql99/.project =================================================================== --- artemis/trunk/jiemamy-dialect-sql99/.project 2009-02-18 15:39:26 UTC (rev 2687) +++ artemis/trunk/jiemamy-dialect-sql99/.project 2009-02-18 18:56:59 UTC (rev 2688) @@ -34,6 +34,11 @@ </natures> <linkedResources> <link> + <name>.checkstyle</name> + <type>1</type> + <locationURI>DOCUMENTS/jiemamy-artemis/.checkstyle</locationURI> + </link> + <link> <name>.fbprefs</name> <type>1</type> <locationURI>DOCUMENTS/jiemamy-artemis/.fbprefs</locationURI> @@ -43,10 +48,5 @@ <type>1</type> <locationURI>DOCUMENTS/jiemamy-artemis/findbugs.xml</locationURI> </link> - <link> - <name>.checkstyle</name> - <type>1</type> - <locationURI>DOCUMENTS/jiemamy-artemis/.checkstyle</locationURI> - </link> </linkedResources> </projectDescription> 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 15:39:26 UTC (rev 2687) +++ 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) @@ -18,7 +18,6 @@ */ package org.jiemamy.eclipse.editor.dialog.root; -import java.util.Collection; import java.util.List; import org.apache.commons.lang.ObjectUtils; @@ -69,17 +68,14 @@ import org.jiemamy.editcommand.CommandListener; import org.jiemamy.model.JiemamyElement; import org.jiemamy.model.RootModel; -import org.jiemamy.model.attribute.constraint.ColumnCheckModel; -import org.jiemamy.model.attribute.constraint.ColumnConstraint; +import org.jiemamy.model.attribute.constraint.CheckConstraintModel; 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.DomainUtil; import org.jiemamy.utils.model.RootModelUtil; /** @@ -210,8 +206,7 @@ DomainModel domain = (DomainModel) element; if (columnIndex == 2) { - boolean notNull = DomainUtil.hasConstraint(domain, NotNullConstraintModel.class); - return ir.get(notNull ? Images.CHECK_ON : Images.CHECK_OFF); + return ir.get(domain.getNotNull() != null ? Images.CHECK_ON : Images.CHECK_OFF); } return null; } @@ -554,15 +549,9 @@ txtColumnSize.setText(ObjectUtils.toString(domain.getDataType().getAdapter(SizedDataTypeAdapter.class) .getSize(), "")); txtDescription.setText(StringUtils.defaultIfEmpty(domain.getDescription(), "")); - chkIsNotNull.setSelection(DomainUtil.hasConstraint(domain, NotNullConstraintModel.class)); - List<ColumnConstraint> constraints = domain.getConstraints(); - for (ColumnConstraint valueConstraintModel : constraints) { - if (valueConstraintModel instanceof ColumnCheckModel) { - ColumnCheckModel checkConstraintModel = (ColumnCheckModel) valueConstraintModel; - txtCheck.setText(checkConstraintModel.getExpression()); - break; - } - } + chkIsNotNull.setSelection(domain.getNotNull() != null); + CheckConstraintModel checkConstraintModel = domain.getCheck(); + txtCheck.setText(checkConstraintModel.getExpression()); txtDomainName.setEnabled(true); cmbColumnType.setEnabled(true); @@ -659,19 +648,12 @@ // } domain.setDescription(txtDescription.getText()); - if (chkIsNotNull.getSelection()) { - Collection<ColumnConstraint> toRemove = CollectionsUtil.newArrayList(); - List<ColumnConstraint> constraints = domain.getConstraints(); - for (ColumnConstraint valueConstraintModel : constraints) { - if (valueConstraintModel instanceof NotNullConstraintModel) { - toRemove.add(valueConstraintModel); - } - } - constraints.removeAll(toRemove); - } else if (DomainUtil.hasConstraint(domain, NotNullConstraintModel.class) == false) { + if (chkIsNotNull.getSelection() && domain.getNotNull() == null) { JiemamyFactory factory = rootModel.getJiemamy().getFactory(); - NotNullConstraintModel nnConstraint = factory.newModel(NotNullConstraintModel.class); - domain.getConstraints().add(nnConstraint); + NotNullConstraintModel nnModel = factory.newModel(NotNullConstraintModel.class); + domain.setNotNull(nnModel); + } else if (chkIsNotNull.getSelection() == false && domain.getNotNull() != null) { + domain.setNotNull(null); } } } Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialog.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialog.java 2009-02-18 15:39:26 UTC (rev 2687) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialog.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -68,7 +68,9 @@ private Text txtLogicalName; -// private TableEditDialogColumnTab tabColumns; + private TableEditDialogColumnTab tabColumns; + +// private TableEditDialogKeyTab tabKeys; // // private TableEditDialogIndexTab tabIndexes; // @@ -169,7 +171,9 @@ gd.horizontalSpan = 6; tabFolder.setLayoutData(gd); -// tabColumns = new TableEditDialogColumnTab(tabFolder, SWT.NULL, tableModel); + tabColumns = new TableEditDialogColumnTab(tabFolder, SWT.NULL, tableModel); + +// tabKeys = new TableEditDialogKeyTab(tabFolder, SWT.NULL, tableModel); // // tabIndexes = new TableEditDialogIndexTab(tabFolder, SWT.NULL, tableModel); // 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 15:39:26 UTC (rev 2687) +++ 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) @@ -18,847 +18,868 @@ */ package org.jiemamy.eclipse.editor.dialog.table; -// -//import java.util.List; -// -//import org.eclipse.jface.resource.ImageRegistry; -//import org.eclipse.jface.viewers.ArrayContentProvider; -//import org.eclipse.jface.viewers.BaseLabelProvider; -//import org.eclipse.jface.viewers.ITableLabelProvider; -//import org.eclipse.jface.viewers.TableViewer; -//import org.eclipse.jface.viewers.Viewer; -//import org.eclipse.swt.SWT; -//import org.eclipse.swt.events.KeyAdapter; -//import org.eclipse.swt.events.KeyEvent; -//import org.eclipse.swt.events.SelectionAdapter; -//import org.eclipse.swt.events.SelectionEvent; -//import org.eclipse.swt.graphics.Image; -//import org.eclipse.swt.layout.GridData; -//import org.eclipse.swt.layout.GridLayout; -//import org.eclipse.swt.layout.RowLayout; -//import org.eclipse.swt.widgets.Button; -//import org.eclipse.swt.widgets.Combo; -//import org.eclipse.swt.widgets.Composite; -//import org.eclipse.swt.widgets.Label; -//import org.eclipse.swt.widgets.TabFolder; -//import org.eclipse.swt.widgets.Table; -//import org.eclipse.swt.widgets.TableColumn; -//import org.eclipse.swt.widgets.Text; -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -// -//import org.jiemamy.Jiemamy; -//import org.jiemamy.JiemamyFactory; -//import org.jiemamy.dialect.Dialect; -//import org.jiemamy.dialect.Dialect.AvailableTypeInfo; -//import org.jiemamy.eclipse.Images; -//import org.jiemamy.eclipse.JiemamyPlugin; -//import org.jiemamy.eclipse.editor.DisplayPlace; -//import org.jiemamy.eclipse.editor.DisplayTarget; -//import org.jiemamy.eclipse.editor.utils.LabelStringUtil; -//import org.jiemamy.eclipse.ui.AbstractTableEditor; -//import org.jiemamy.eclipse.ui.TableEditorConfigurator; -//import org.jiemamy.eclipse.ui.helper.TextSelectionAdapter; -//import org.jiemamy.eclipse.ui.tab.AbstractTab; -//import org.jiemamy.editcommand.Command; -//import org.jiemamy.editcommand.CommandListener; -//import org.jiemamy.model.JiemamyElement; -//import org.jiemamy.model.RootModel; -//import org.jiemamy.model.attribute.ColumnModel; -//import org.jiemamy.model.datatype.BuiltinDataType; -//import org.jiemamy.model.datatype.DataType; -//import org.jiemamy.model.datatype.DataTypeCategory; -//import org.jiemamy.model.entity.TableModel; -//import org.jiemamy.utils.CollectionsUtil; -//import org.jiemamy.utils.ListUtils; -//import org.jiemamy.utils.model.RootModelUtil; -//import org.jiemamy.utils.model.TableUtil; -// -///** -// * テーブル編集ダイアログの「カラム」タブ -// * -// * @author daisuke -// */ -//public class TableEditDialogColumnTab extends AbstractTab { -// -// private static Logger logger = LoggerFactory.getLogger(TableEditDialogColumnTab.class); -// -// private RootModel rootModel; -// -// private TableModel tableModel; -// -// private List<AvailableTypeInfo> allTypes; -// -// private AbstractTableEditor columnEditor; -// -// private ColumnContentProvider contentProvider; -// -// -// /** -// * インスタンスを生成する。 -// * -// * @param parentTabFolder -// * @param style -// * @param tableModel -// */ -// public TableEditDialogColumnTab(TabFolder parentTabFolder, int style, TableModel tableModel) { -// super(parentTabFolder, style, "カラム"); // RESOURCE -// -// this.tableModel = tableModel; -// rootModel = tableModel.getJiemamy().getFactory().getRootModel(); -// -// Dialect dialect; -// try { -// dialect = RootModelUtil.getDialect(rootModel); -// } catch (ClassNotFoundException e) { -// // FIXME なんとか…。 -// dialect = JiemamyPlugin.getDialectResolver().getAllInstance().get(0); -// } -// -// allTypes = CollectionsUtil.newArrayList(rootModel.getDomains().size() + dialect.getAllDataTypes().size()); -// -// allTypes.addAll(dialect.getAllDataTypes()); -//// allTypes.addAll(/* domain */); -// -// Composite composite = new Composite(parentTabFolder, SWT.NULL); -// composite.setLayout(new GridLayout(1, false)); -// composite.setLayoutData(new GridData(GridData.FILL_BOTH)); -// -// columnEditor = new ColumnTableEditor(composite, SWT.NULL, tableModel); -// columnEditor.configure(); -// columnEditor.disableEditControls(); -// -// getTabItem().setControl(composite); -// } -// -// -// /** -// * Column用ContentProvider -// * -// * @author daisuke -// */ -// private class ColumnContentProvider extends ArrayContentProvider implements CommandListener { -// -// private Viewer viewer; -// -// -// /** -// * {@inheritDoc} -// */ -// public void commandExecuted(Command command) { -//// if (evt.getPropertyName().equals(TableModel.P_ENTITY_TABLE_COLUMNS)) { -// columnEditor.refreshTable(); // レコードの変更を反映させる。 -//// } else if (evt.getSource() instanceof DefinitionModel) { -//// columnEditor.refreshTable(); // レコードの変更を反映させる。 -//// if (evt.getPropertyName().equals(DefinitionModel.P_CREATE)) { -//// // nothing to do -//// } else if (evt.getPropertyName().equals(DefinitionModel.P_DELETE)) { -//// ((AbstractModel) evt.getSource()).removePropertyChangeListener(this); -//// } else if (evt.getPropertyName().equals(DefinitionModel.P_REVERT)) { -//// ((AbstractModel) evt.getSource()).addPropertyChangeListener(this); -//// } -//// } -// } -// -// @Override -// public void dispose() { -// logger.debug("ColumnContentProvider: disposed"); -//// tableModel.removePropertyChangeListener(this); -//// for (ColumnModel column : tableModel.getColumns()) { -//// ((AbstractModel) column).removePropertyChangeListener(this); -//// } -// super.dispose(); -// } -// -// /** -// * {@inheritDoc} -// */ -// public JiemamyElement getTargetModel() { -// return (JiemamyElement) viewer.getInput(); -// } -// -// @Override -// public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { -// logger.debug("ColumnContentProvider: input changed"); -// logger.trace("oldInput: " + oldInput); -// logger.trace("newInput: " + newInput); -// -// this.viewer = viewer; -// -//// if (oldInput != null) { -//// tableModel.removePropertyChangeListener(this); -//// for (ColumnModel column : tableModel.getColumns()) { -//// ((AbstractModel) column).removePropertyChangeListener(this); -//// } -//// } -//// if (newInput != null) { -//// tableModel.addPropertyChangeListener(this); -//// for (ColumnModel column : tableModel.getColumns()) { -//// ((AbstractModel) column).addPropertyChangeListener(this); -//// } -//// } -// -// super.inputChanged(viewer, oldInput, newInput); -// } -// -// } -// -// /** -// * Column用LabelProvider -// * -// * @author daisuke -// */ -// private class ColumnLabelProvider extends BaseLabelProvider implements ITableLabelProvider { -// -// public Image getColumnImage(Object element, int columnIndex) { -// ImageRegistry ir = JiemamyPlugin.getDefault().getImageRegistry(); -// ColumnModel column = (ColumnModel) element; -// -// switch (columnIndex) { -// case 0: -// return null; -// -// case 1: -// // FIXME false固定 -// return /*ColumnUtil.isPartOfPrimaryKeyColumns(column)*/false ? ir.get(Images.ICON_PK) : null; -// -// case 4: -// // FIXME ここ、何を表示するんだっけ PKだっけ? ↑にあるじゃん。。 -// return null; -// -// case 5: -// // FIXME false固定 -// return ir.get(/* uniqueかどうか */false ? Images.CHECK_ON : Images.CHECK_OFF); -// -// case 6: -// // FIXME false固定 -// return ir.get(/* NNかどうか */false ? Images.CHECK_ON : Images.CHECK_OFF); -// -// default: -// return null; +import java.util.List; + +import org.apache.commons.lang.ObjectUtils; +import org.apache.commons.lang.StringUtils; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.BaseLabelProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.Text; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.jiemamy.Jiemamy; +import org.jiemamy.JiemamyFactory; +import org.jiemamy.dialect.Dialect; +import org.jiemamy.dialect.Dialect.AvailableTypeInfo; +import org.jiemamy.eclipse.Images; +import org.jiemamy.eclipse.JiemamyPlugin; +import org.jiemamy.eclipse.editor.DisplayPlace; +import org.jiemamy.eclipse.editor.DisplayTarget; +import org.jiemamy.eclipse.editor.utils.LabelStringUtil; +import org.jiemamy.eclipse.ui.AbstractTableEditor; +import org.jiemamy.eclipse.ui.TableEditorConfigurator; +import org.jiemamy.eclipse.ui.helper.TextSelectionAdapter; +import org.jiemamy.eclipse.ui.tab.AbstractTab; +import org.jiemamy.editcommand.Command; +import org.jiemamy.editcommand.CommandListener; +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.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; +import org.jiemamy.model.entity.TableModel; +import org.jiemamy.utils.CollectionsUtil; +import org.jiemamy.utils.ListUtils; +import org.jiemamy.utils.model.ColumnUtil; +import org.jiemamy.utils.model.RootModelUtil; +import org.jiemamy.utils.model.TableUtil; + +/** + * テーブル編集ダイアログの「カラム」タブ + * + * @author daisuke + */ +public class TableEditDialogColumnTab extends AbstractTab { + + private static Logger logger = LoggerFactory.getLogger(TableEditDialogColumnTab.class); + + private RootModel rootModel; + + private TableModel tableModel; + + private List<AvailableTypeInfo> allTypes; + + private AbstractTableEditor columnEditor; + + private ColumnContentProvider contentProvider; + + + /** + * インスタンスを生成する。 + * + * @param parentTabFolder + * @param style + * @param tableModel + */ + public TableEditDialogColumnTab(TabFolder parentTabFolder, int style, TableModel tableModel) { + super(parentTabFolder, style, "カラム"); // RESOURCE + + this.tableModel = tableModel; + rootModel = tableModel.getJiemamy().getFactory().getRootModel(); + + Dialect dialect; + try { + dialect = RootModelUtil.getDialect(rootModel); + } catch (ClassNotFoundException e) { + // FIXME なんとか…。 + dialect = JiemamyPlugin.getDialectResolver().getAllInstance().get(0); + } + + allTypes = CollectionsUtil.newArrayList(rootModel.getDomains().size() + dialect.getAllDataTypes().size()); + + allTypes.addAll(dialect.getAllDataTypes()); +// allTypes.addAll(/* domain */); + + Composite composite = new Composite(parentTabFolder, SWT.NULL); + composite.setLayout(new GridLayout(1, false)); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + columnEditor = new ColumnTableEditor(composite, SWT.NULL, tableModel); + columnEditor.configure(); + columnEditor.disableEditControls(); + + getTabItem().setControl(composite); + } + + + /** + * Column用ContentProvider + * + * @author daisuke + */ + private class ColumnContentProvider extends ArrayContentProvider implements CommandListener { + + private Viewer viewer; + + + /** + * {@inheritDoc} + */ + public void commandExecuted(Command command) { +// if (evt.getPropertyName().equals(TableModel.P_ENTITY_TABLE_COLUMNS)) { + columnEditor.refreshTable(); // レコードの変更を反映させる。 +// } else if (evt.getSource() instanceof DefinitionModel) { +// columnEditor.refreshTable(); // レコードの変更を反映させる。 +// if (evt.getPropertyName().equals(DefinitionModel.P_CREATE)) { +// // nothing to do +// } else if (evt.getPropertyName().equals(DefinitionModel.P_DELETE)) { +// ((AbstractModel) evt.getSource()).removePropertyChangeListener(this); +// } else if (evt.getPropertyName().equals(DefinitionModel.P_REVERT)) { +// ((AbstractModel) evt.getSource()).addPropertyChangeListener(this); +// } // } -// } -// -// public String getColumnText(Object element, int columnIndex) { -// ColumnModel column = (ColumnModel) element; -// switch (columnIndex) { -// case 1: -// return LabelStringUtil.getString(rootModel, column, DisplayTarget.NAME, DisplayPlace.TABLE); -// -// case 2: -// return LabelStringUtil.getString(rootModel, column, DisplayTarget.TYPE, DisplayPlace.TABLE); -// -// case 3: -// return column.getDefaultValue(); -// -// default: -// return ""; + } + + @Override + public void dispose() { + logger.debug("ColumnContentProvider: disposed"); +// tableModel.removePropertyChangeListener(this); +// for (ColumnModel column : tableModel.getColumns()) { +// ((AbstractModel) column).removePropertyChangeListener(this); // } -// } -// } -// -// private class ColumnTableEditor extends AbstractTableEditor { -// -// private Jiemamy jiemamy; -// -// private final List<ColumnModel> columns; -// -// private Dialect dialect; -// -// private Text txtColumnName; -// -// private Text txtColumnLogicalName; -// -// private Text txtCheckDefinition; -// -// private Text txtCheckName; -// -// private Combo cmbColumnType; -// -// private Text txtColumnSize; -// -// private Text txtDefaultValue; -// -// private Text txtDescription; -// -// private Button chkIsPK; -// -// private Button chkIsUnique; -// -// private Button chkIsNotNull; -// -// private Button chkIsTypical; -// -// -// /** -// * インスタンスを生成する。 -// * -// * @param parent -// * @param style -// * @param tableModel -// */ -// public ColumnTableEditor(Composite parent, int style, TableModel tableModel) { -// super(parent, style, new TableEditorConfigurator() { -// -// public String getAddLabel() { -// return "追加"; // RESOURCE + super.dispose(); + } + + /** + * {@inheritDoc} + */ + public JiemamyElement getTargetModel() { + return (JiemamyElement) viewer.getInput(); + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + logger.debug("ColumnContentProvider: input changed"); + logger.trace("oldInput: " + oldInput); + logger.trace("newInput: " + newInput); + + this.viewer = viewer; + +// if (oldInput != null) { +// tableModel.removePropertyChangeListener(this); +// for (ColumnModel column : tableModel.getColumns()) { +// ((AbstractModel) column).removePropertyChangeListener(this); // } -// -// public String getEditorTitle() { -// return "カラム情報"; // RESOURCE +// } +// if (newInput != null) { +// tableModel.addPropertyChangeListener(this); +// for (ColumnModel column : tableModel.getColumns()) { +// ((AbstractModel) column).addPropertyChangeListener(this); // } -// -// public String getInsertLabel() { -// return "挿入"; // RESOURCE -// } -// -// public String getRemoveLabel() { -// return "削除"; // RESOURCE -// } -// }); -// -// jiemamy = tableModel.getJiemamy(); -// columns = TableUtil.getColumns(tableModel); -// -// try { -// dialect = RootModelUtil.getDialect(rootModel.getJiemamy().getFactory().getRootModel()); -// } catch (ClassNotFoundException e) { -// // THINK どうにか。。。w -// dialect = JiemamyPlugin.getDialectResolver().getAllInstance().get(0); // } -// -// assert jiemamy != null; -// assert columns != null; -// assert dialect != null; -// } -// -// @Override -// protected JiemamyElement addItem() { -// Table table = getTableViewer().getTable(); -// JiemamyFactory factory = jiemamy.getFactory(); -// ColumnModel columnModel = factory.newModel(ColumnModel.class); -// columnModel.setName("COLUMN_" + (columns.size() + 1)); -// -// BuiltinDataType builtinDataType = factory.newModel(BuiltinDataType.class); -// builtinDataType.setCategory(DataTypeCategory.INTEGER); -// columnModel.setDataType(builtinDataType); -// -// columns.add(columnModel); -// tableModel.getAttributes().add(columnModel); -// -// int addedIndex = columns.indexOf(columnModel); -// table.setSelection(addedIndex); -// enableEditControls(addedIndex); -// txtColumnName.setFocus(); -// -// return columnModel; -// } -// -// @Override -// protected void configureEditorControls() { -// super.configureEditorControls(); -// -// for (AvailableTypeInfo typeInfo : dialect.getAllDataTypes()) { -// cmbColumnType.add(typeInfo.getTypeName()); -// } -// -// txtColumnName.addFocusListener(new TextSelectionAdapter(txtColumnName)); -// txtColumnName.addKeyListener(new KeyAdapter() { + + super.inputChanged(viewer, oldInput, newInput); + } + + } + + /** + * Column用LabelProvider + * + * @author daisuke + */ + private class ColumnLabelProvider extends BaseLabelProvider implements ITableLabelProvider { + + public Image getColumnImage(Object element, int columnIndex) { + ImageRegistry ir = JiemamyPlugin.getDefault().getImageRegistry(); + ColumnModel column = (ColumnModel) element; + + switch (columnIndex) { + case 0: + return null; + + case 1: + // FIXME false固定 + return /*ColumnUtil.isPartOfPrimaryKeyColumns(column)*/false ? ir.get(Images.ICON_PK) : null; + + case 4: + // FIXME ここ、何を表示するんだっけ PKだっけ? ↑にあるじゃん。。 + return null; + + case 5: + // FIXME false固定 + return ir.get(/* uniqueかどうか */false ? Images.CHECK_ON : Images.CHECK_OFF); + + case 6: + return ir.get(column.getNotNull() != null ? Images.CHECK_ON : Images.CHECK_OFF); + + default: + return null; + } + } + + public String getColumnText(Object element, int columnIndex) { + ColumnModel column = (ColumnModel) element; + switch (columnIndex) { + case 1: + return LabelStringUtil.getString(rootModel, column, DisplayTarget.NAME, DisplayPlace.TABLE); + + case 2: + return LabelStringUtil.getString(rootModel, column, DisplayTarget.TYPE, DisplayPlace.TABLE); + + case 3: + return column.getDefaultValue(); + + default: + return StringUtils.EMPTY; + } + } + } + + private class ColumnTableEditor extends AbstractTableEditor { + + private Jiemamy jiemamy; + + private final List<ColumnModel> columns; + + private Dialect dialect; + + private Text txtColumnName; + + private Text txtColumnLogicalName; + + private Text txtCheckExpression; + + private Text txtCheckName; + + private Combo cmbColumnType; + + private Text txtColumnSize; + + private Text txtDefaultValue; + + private Text txtDescription; + + private Button chkIsPK; + + private Button chkIsUnique; + + private Button chkIsNotNull; + + private Button chkIsTypical; + + + /** + * インスタンスを生成する。 + * + * @param parent + * @param style + * @param tableModel + */ + public ColumnTableEditor(Composite parent, int style, TableModel tableModel) { + super(parent, style, new TableEditorConfigurator() { + + public String getAddLabel() { + return "追加"; // RESOURCE + } + + public String getEditorTitle() { + return "カラム情報"; // RESOURCE + } + + public String getInsertLabel() { + return "挿入"; // RESOURCE + } + + public String getRemoveLabel() { + return "削除"; // RESOURCE + } + }); + + jiemamy = tableModel.getJiemamy(); + columns = TableUtil.getColumns(tableModel); + + try { + dialect = RootModelUtil.getDialect(rootModel.getJiemamy().getFactory().getRootModel()); + } catch (ClassNotFoundException e) { + // THINK どうにか。。。w + dialect = JiemamyPlugin.getDialectResolver().getAllInstance().get(0); + } + + assert jiemamy != null; + assert columns != null; + assert dialect != null; + } + + @Override + protected JiemamyElement addItem() { + Table table = getTableViewer().getTable(); + JiemamyFactory factory = jiemamy.getFactory(); + ColumnModel columnModel = factory.newModel(ColumnModel.class); + columnModel.setName("COLUMN_" + (columns.size() + 1)); + + BuiltinDataType builtinDataType = factory.newModel(BuiltinDataType.class); + builtinDataType.setCategory(DataTypeCategory.INTEGER); + columnModel.setDataType(builtinDataType); + + columns.add(columnModel); + tableModel.getAttributes().add(columnModel); + + int addedIndex = columns.indexOf(columnModel); + table.setSelection(addedIndex); + enableEditControls(addedIndex); + txtColumnName.setFocus(); + + return columnModel; + } + + @Override + protected void configureEditorControls() { + super.configureEditorControls(); + + for (AvailableTypeInfo typeInfo : dialect.getAllDataTypes()) { + cmbColumnType.add(typeInfo.getTypeName()); + } + + txtColumnName.addFocusListener(new TextSelectionAdapter(txtColumnName)); + txtColumnName.addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + updateModel(); + columnEditor.refreshTable(); + } + }); + txtColumnLogicalName.addFocusListener(new TextSelectionAdapter(txtColumnLogicalName)); + txtColumnLogicalName.addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + updateModel(); + columnEditor.refreshTable(); + } + }); + txtCheckName.addFocusListener(new TextSelectionAdapter(txtCheckName)); + txtCheckName.addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + updateModel(); + columnEditor.refreshTable(); + } + }); + txtCheckExpression.addFocusListener(new TextSelectionAdapter(txtCheckExpression)); + txtCheckExpression.addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + updateModel(); + columnEditor.refreshTable(); + } + }); + cmbColumnType.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + int columnEditIndex = getTableViewer().getTable().getSelectionIndex(); + updateModel(); + enableEditDetailControls(columnEditIndex); + columnEditor.refreshTable(); + } + }); + txtColumnSize.addFocusListener(new TextSelectionAdapter(txtColumnSize)); + txtColumnSize.addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + updateModel(); + columnEditor.refreshTable(); + } + }); + txtDefaultValue.addFocusListener(new TextSelectionAdapter(txtDefaultValue)); + txtDefaultValue.addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + updateModel(); + columnEditor.refreshTable(); + } + }); + txtDescription.addFocusListener(new TextSelectionAdapter(txtDefaultValue)); + txtDescription.addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + updateModel(); + } + }); + chkIsPK.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + int columnEditIndex = getTableViewer().getTable().getSelectionIndex(); + updateModel(); + enableEditDetailControls(columnEditIndex); + columnEditor.refreshTable(); + } + }); + chkIsUnique.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + int columnEditIndex = getTableViewer().getTable().getSelectionIndex(); + updateModel(); + enableEditDetailControls(columnEditIndex); + columnEditor.refreshTable(); + } + }); + chkIsNotNull.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + int columnEditIndex = getTableViewer().getTable().getSelectionIndex(); + updateModel(); + enableEditDetailControls(columnEditIndex); + columnEditor.refreshTable(); + } + }); + chkIsTypical.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + int columnEditIndex = getTableViewer().getTable().getSelectionIndex(); + updateModel(); + enableEditDetailControls(columnEditIndex); + columnEditor.refreshTable(); + } + }); + } + + @Override + protected void configureTable(final Table table) { + super.configureTable(table); + + table.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + int index = table.getSelectionIndex(); + if (index >= 0) { + enableEditDetailControls(index); + } else { + disableEditDetailControls(); + } + } + }); + + // THINK ↓要る? +// final Menu menu = new Menu(table); +// table.setMenu(menu); +// menu.addMenuListener(new MenuAdapter() { // // @Override -// public void keyReleased(KeyEvent e) { -// updateModel(); -// columnEditor.refreshTable(); -// } -// }); -// txtColumnLogicalName.addFocusListener(new TextSelectionAdapter(txtColumnLogicalName)); -// txtColumnLogicalName.addKeyListener(new KeyAdapter() { -// -// @Override -// public void keyReleased(KeyEvent e) { -// updateModel(); -// columnEditor.refreshTable(); -// } -// }); -// txtCheckName.addFocusListener(new TextSelectionAdapter(txtCheckName)); -// txtCheckName.addKeyListener(new KeyAdapter() { -// -// @Override -// public void keyReleased(KeyEvent e) { -// updateModel(); -// columnEditor.refreshTable(); -// } -// }); -// txtCheckDefinition.addFocusListener(new TextSelectionAdapter(txtCheckDefinition)); -// txtCheckDefinition.addKeyListener(new KeyAdapter() { -// -// @Override -// public void keyReleased(KeyEvent e) { -// updateModel(); -// columnEditor.refreshTable(); -// } -// }); -// cmbColumnType.addSelectionListener(new SelectionAdapter() { -// -// @Override -// public void widgetSelected(SelectionEvent e) { -// int columnEditIndex = getTableViewer().getTable().getSelectionIndex(); -// updateModel(); -// enableEditDetailControls(columnEditIndex); -// columnEditor.refreshTable(); -// } -// }); -// txtColumnSize.addFocusListener(new TextSelectionAdapter(txtColumnSize)); -// txtColumnSize.addKeyListener(new KeyAdapter() { -// -// @Override -// public void keyReleased(KeyEvent e) { -// updateModel(); -// columnEditor.refreshTable(); -// } -// }); -// txtDefaultValue.addFocusListener(new TextSelectionAdapter(txtDefaultValue)); -// txtDefaultValue.addKeyListener(new KeyAdapter() { -// -// @Override -// public void keyReleased(KeyEvent e) { -// updateModel(); -// columnEditor.refreshTable(); -// } -// }); -// txtDescription.addFocusListener(new TextSelectionAdapter(txtDefaultValue)); -// txtDescription.addKeyListener(new KeyAdapter() { -// -// @Override -// public void keyReleased(KeyEvent e) { -// updateModel(); -// } -// }); -// chkIsPK.addSelectionListener(new SelectionAdapter() { -// -// @Override -// public void widgetSelected(SelectionEvent e) { -// int columnEditIndex = getTableViewer().getTable().getSelectionIndex(); -// updateModel(); -// enableEditDetailControls(columnEditIndex); -// columnEditor.refreshTable(); -// } -// }); -// chkIsUnique.addSelectionListener(new SelectionAdapter() { -// -// @Override -// public void widgetSelected(SelectionEvent e) { -// int columnEditIndex = getTableViewer().getTable().getSelectionIndex(); -// updateModel(); -// enableEditDetailControls(columnEditIndex); -// columnEditor.refreshTable(); -// } -// }); -// chkIsNotNull.addSelectionListener(new SelectionAdapter() { -// -// @Override -// public void widgetSelected(SelectionEvent e) { -// int columnEditIndex = getTableViewer().getTable().getSelectionIndex(); -// updateModel(); -// enableEditDetailControls(columnEditIndex); -// columnEditor.refreshTable(); -// } -// }); -// chkIsTypical.addSelectionListener(new SelectionAdapter() { -// -// @Override -// public void widgetSelected(SelectionEvent e) { -// int columnEditIndex = getTableViewer().getTable().getSelectionIndex(); -// updateModel(); -// enableEditDetailControls(columnEditIndex); -// columnEditor.refreshTable(); -// } -// }); -// } -// -// @Override -// protected void configureTable(final Table table) { -// super.configureTable(table); -// -// table.addSelectionListener(new SelectionAdapter() { -// -// @Override -// public void widgetSelected(SelectionEvent e) { +// public void menuShown(MenuEvent evt) { +// for (MenuItem item : menu.getItems()) { +// item.dispose(); +// } // int index = table.getSelectionIndex(); -// if (index >= 0) { -// enableEditDetailControls(index); -// } else { -// disableEditDetailControls(); +// if (index == -1) { +// return; // } +// +// MenuItem removeItem = new MenuItem(menu, SWT.PUSH); +// removeItem.setText("&Remove"); // TODO 外部化せよ。 +// removeItem.addSelectionListener(new SelectionAdapter() { +// +// @Override +// public void widgetSelected(SelectionEvent evt) { +// removeTableSelectionItem(); +// } +// }); // } // }); -// -// // THINK ↓要る? -//// final Menu menu = new Menu(table); -//// table.setMenu(menu); -//// menu.addMenuListener(new MenuAdapter() { -//// -//// @Override -//// public void menuShown(MenuEvent evt) { -//// for (MenuItem item : menu.getItems()) { -//// item.dispose(); -//// } -//// int index = table.getSelectionIndex(); -//// if (index == -1) { -//// return; -//// } -//// -//// MenuItem removeItem = new MenuItem(menu, SWT.PUSH); -//// removeItem.setText("&Remove"); // TODO 外部化せよ。 -//// removeItem.addSelectionListener(new SelectionAdapter() { -//// -//// @Override -//// public void widgetSelected(SelectionEvent evt) { -//// removeTableSelectionItem(); -//// } -//// }); -//// } -//// }); -// } -// -// @Override -// protected void configureTableViewer(TableViewer tableViewer) { -// tableViewer.setLabelProvider(new ColumnLabelProvider()); -// contentProvider = new ColumnContentProvider(); -// tableViewer.setContentProvider(contentProvider); -// tableViewer.setInput(columns); -// } -// -// @Override -// protected void createEditorControls(Composite parent) { -// GridData gd; -// Label label; -// -// Composite cmpNames = new Composite(parent, SWT.NULL); -// cmpNames.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); -// GridLayout layout = new GridLayout(4, false); -// layout.marginHeight = 0; -// layout.marginWidth = 0; -// cmpNames.setLayout(layout); -// -// label = new Label(cmpNames, SWT.NULL); -// label.setText("カラム名"); // RESOURCE -// -// txtColumnName = new Text(cmpNames, SWT.BORDER); -// txtColumnName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); -// -// label = new Label(cmpNames, SWT.NULL); -// label.setText("論理名"); // RESOURCE -// -// txtColumnLogicalName = new Text(cmpNames, SWT.BORDER); -// txtColumnLogicalName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); -// -// Composite cmpCheckConstraint = new Composite(parent, SWT.NULL); -// cmpCheckConstraint.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); -// layout = new GridLayout(4, false); -// layout.marginHeight = 0; -// layout.marginWidth = 0; -// cmpCheckConstraint.setLayout(layout); -// -// label = new Label(cmpCheckConstraint, SWT.NULL); -// label.setText("チェック制約名"); // RESOURCE -// -// txtCheckName = new Text(cmpCheckConstraint, SWT.BORDER); -// txtCheckName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); -// -// label = new Label(cmpCheckConstraint, SWT.NULL); -// label.setText("チェック制約式"); // RESOURCE -// -// txtCheckDefinition = new Text(cmpCheckConstraint, SWT.BORDER); -// txtCheckDefinition.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); -// -// Composite cmpTypes = new Composite(parent, SWT.NULL); -// cmpTypes.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); -// layout = new GridLayout(6, false); -// layout.marginHeight = 0; -// layout.marginWidth = 0; -// cmpTypes.setLayout(layout); -// -// label = new Label(cmpTypes, SWT.NULL); -// label.setText("型"); // RESOURCE -// -// cmbColumnType = new Combo(cmpTypes, SWT.READ_ONLY); -// cmbColumnType.setVisibleItemCount(20); -// -// label = new Label(cmpTypes, SWT.NULL); -// label.setText("サイズ"); // RESOURCE -// -// txtColumnSize = new Text(cmpTypes, SWT.BORDER); -// gd = new GridData(); -// gd.widthHint = 60; -// txtColumnSize.setLayoutData(gd); -// -// label = new Label(cmpTypes, SWT.NULL); -// label.setText("デフォルト値"); // RESOURCE -// -// txtDefaultValue = new Text(cmpTypes, SWT.BORDER); -// txtDefaultValue.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); -// -// Composite cmpDesc = new Composite(parent, SWT.NULL); -// cmpDesc.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); -// layout = new GridLayout(2, false); -// layout.marginHeight = 0; -// layout.marginWidth = 0; -// cmpDesc.setLayout(layout); -// -// label = new Label(cmpDesc, SWT.NULL); -// label.setText("説明"); // RESOURCE -// txtDescription = new Text(cmpDesc, SWT.MULTI | SWT.BORDER); -// txtDescription.setLayoutData(new GridData(GridData.FILL_BOTH)); -// -// Composite cmpChecks = new Composite(parent, SWT.NULL); -// cmpChecks.setLayoutData(new GridData()); -// RowLayout rowLayout = new RowLayout(); -// layout.marginHeight = 0; -// layout.marginWidth = 0; -// cmpChecks.setLayout(rowLayout); -// -// chkIsPK = new Button(cmpChecks, SWT.CHECK); -// chkIsPK.setText("主キー"); // RESOURCE -// -// chkIsUnique = new Button(cmpChecks, SWT.CHECK); -// chkIsUnique.setText("単独一意"); // RESOURCE -// -// chkIsNotNull = new Button(cmpChecks, SWT.CHECK); -// chkIsNotNull.setText("非NULL"); // RESOURCE -// -// chkIsTypical = new Button(cmpChecks, SWT.CHECK); -// chkIsTypical.setText("代表"); // RESOURCE -// } -// -// @Override -// protected void createTableColumns(Table table) { -// TableColumn col = new TableColumn(table, SWT.LEFT); -// col.setText(""); -// col.setWidth(20); -// -// col = new TableColumn(table, SWT.LEFT); -// col.setText("カラム名"); // RESOURCE -// col.setWidth(200); -// -// col = new TableColumn(table, SWT.LEFT); -// col.setText("データ型"); // RESOURCE -// col.setWidth(150); -// -// col = new TableColumn(table, SWT.LEFT); -// col.setText("デフォルト値"); // RESOURCE -// col.setWidth(150); -// -// col = new TableColumn(table, SWT.LEFT); -// col.setText("PK"); // RESOURCE -// col.setWidth(30); -// -// col = new TableColumn(table, SWT.LEFT); -// col.setText("一意"); // RESOURCE -// col.setWidth(30); -// -// col = new TableColumn(table, SWT.LEFT); -// col.setText("NN"); -// col.setWidth(30); -// } -// -// @Override -// protected void disableEditDetailControls() { -// txtColumnName.setText(""); -// txtColumnLogicalName.setText(""); -// txtCheckName.setText(""); -// txtCheckDefinition.setText(""); -// cmbColumnType.setText(""); -// txtColumnSize.setText(""); -// chkIsPK.setSelection(false); -// chkIsUnique.setSelection(false); -// chkIsNotNull.setSelection(false); -// chkIsTypical.setSelection(false); -// txtDefaultValue.setText(""); -// txtDescription.setText(""); -// -// txtColumnName.setEnabled(false); -// txtColumnLogicalName.setEnabled(false); -// txtCheckName.setEnabled(false); -// txtCheckDefinition.setEnabled(false); -// cmbColumnType.setEnabled(false); -// txtColumnSize.setEnabled(false); -// chkIsPK.setEnabled(false); -// chkIsUnique.setEnabled(false); -// chkIsNotNull.setEnabled(false); -// chkIsTypical.setEnabled(false); -// txtDefaultValue.setEnabled(false); -// txtDescription.setEnabled(false); -// } -// -// @Override -// protected void enableEditDetailControls(int index) { -// ColumnModel column = columns.get(index); -// -// // 現在値の設定 -// txtColumnName.setText(column.getName()); -// txtColumnLogicalName.setText(column.getLogicalName()); -// txtCheckName.setText(column.getCheck().getName()); -// txtCheckDefinition.setText(column.getCheck().getDefinition()); -// if (column.getDataType().isDomain()) { -// cmbColumnType.setText(((DefinitionModel) column.getDataType()).getName()); -// } else { -// cmbColumnType.setText(rootModel.getDialect().convertToPrimitiveType(column.getDataType()).getName()); -// } -// txtDescription.setText(column.getDescription()); -// -// if (column.getDataType().isDomain()) { -// DefinitionModel definition = (DefinitionModel) column.getDataType(); -// -// txtColumnSize.setText(String.valueOf(definition.getSize())); -// txtDefaultValue.setText(definition.getDefaultValue()); -// } else { -// txtColumnSize.setText(String.valueOf(column.getSize())); -// txtDefaultValue.setText(column.getDefaultValue()); -// } -// -// chkIsPK.setSelection(column.getConstraint(DefinitionModel.CONSTRAINT_PRIMARY_KEY)); -// if (column.getDataType().isDomain()) { -// DefinitionModel definition = (DefinitionModel) column.getDataType(); -// chkIsUnique.setSelection(definition.getConstraint(DefinitionModel.CONSTRAINT_UNIQUE)); -// chkIsNotNull.setSelection(definition.getConstraint(DefinitionModel.CONSTRAINT_NOT_NULL)); -// } else { -// chkIsUnique.setSelection(column.getConstraint(DefinitionModel.CONSTRAINT_UNIQUE)); -// chkIsNotNull.setSelection(column.getConstraint(DefinitionModel.CONSTRAINT_NOT_NULL)); -// } + } + + @Override + protected void configureTableViewer(TableViewer tableViewer) { + tableViewer.setLabelProvider(new ColumnLabelProvider()); + contentProvider = new ColumnContentProvider(); + tableViewer.setContentProvider(contentProvider); + tableViewer.setInput(columns); + } + + @Override + protected void createEditorControls(Composite parent) { + GridData gd; + Label label; + + Composite cmpNames = new Composite(parent, SWT.NULL); + cmpNames.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + GridLayout layout = new GridLayout(4, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + cmpNames.setLayout(layout); + + label = new Label(cmpNames, SWT.NULL); + label.setText("カラム名"); // RESOURCE + + txtColumnName = new Text(cmpNames, SWT.BORDER); + txtColumnName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + label = new Label(cmpNames, SWT.NULL); + label.setText("論理名"); // RESOURCE + + txtColumnLogicalName = new Text(cmpNames, SWT.BORDER); + txtColumnLogicalName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Composite cmpCheckConstraint = new Composite(parent, SWT.NULL); + cmpCheckConstraint.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + layout = new GridLayout(4, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + cmpCheckConstraint.setLayout(layout); + + label = new Label(cmpCheckConstraint, SWT.NULL); + label.setText("チェック制約名"); // RESOURCE + + txtCheckName = new Text(cmpCheckConstraint, SWT.BORDER); + txtCheckName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + label = new Label(cmpCheckConstraint, SWT.NULL); + label.setText("チェック制約式"); // RESOURCE + + txtCheckExpression = new Text(cmpCheckConstraint, SWT.BORDER); + txtCheckExpression.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Composite cmpTypes = new Composite(parent, SWT.NULL); + cmpTypes.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + layout = new GridLayout(6, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + cmpTypes.setLayout(layout); + + label = new Label(cmpTypes, SWT.NULL); + label.setText("型"); // RESOURCE + + cmbColumnType = new Combo(cmpTypes, SWT.READ_ONLY); + cmbColumnType.setVisibleItemCount(20); + + label = new Label(cmpTypes, SWT.NULL); + label.setText("サイズ"); // RESOURCE + + txtColumnSize = new Text(cmpTypes, SWT.BORDER); + gd = new GridData(); + gd.widthHint = 60; + txtColumnSize.setLayoutData(gd); + + label = new Label(cmpTypes, SWT.NULL); + label.setText("デフォルト値"); // RESOURCE + + txtDefaultValue = new Text(cmpTypes, SWT.BORDER); + txtDefaultValue.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Composite cmpDesc = new Composite(parent, SWT.NULL); + cmpDesc.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + layout = new GridLayout(2, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + cmpDesc.setLayout(layout); + + label = new Label(cmpDesc, SWT.NULL); + label.setText("説明"); // RESOURCE + txtDescription = new Text(cmpDesc, SWT.MULTI | SWT.BORDER); + txtDescription.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Composite cmpChecks = new Composite(parent, SWT.NULL); + cmpChecks.setLayoutData(new GridData()); + RowLayout rowLayout = new RowLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + cmpChecks.setLayout(rowLayout); + + chkIsPK = new Button(cmpChecks, SWT.CHECK); + chkIsPK.setText("主キー"); // RESOURCE + + chkIsUnique = new Button(cmpChecks, SWT.CHECK); + chkIsUnique.setText("単独一意"); // RESOURCE + + chkIsNotNull = new Button(cmpChecks, SWT.CHECK); + chkIsNotNull.setText("非NULL"); // RESOURCE + + chkIsTypical = new Button(cmpChecks, SWT.CHECK); + chkIsTypical.setText("代表"); // RESOURCE + } + + @Override + protected void createTableColumns(Table table) { + TableColumn col = new TableColumn(table, SWT.LEFT); + col.setText(StringUtils.EMPTY); + col.setWidth(20); + + col = new TableColumn(table, SWT.LEFT); + col.setText("カラム名"); // RESOURCE + col.setWidth(200); + + col = new TableColumn(table, SWT.LEFT); + col.setText("データ型"); // RESOURCE + col.setWidth(150); + + col = new TableColumn(table, SWT.LEFT); + col.setText("デフォルト値"); // RESOURCE + col.setWidth(150); + + col = new TableColumn(table, SWT.LEFT); + col.setText("PK"); // RESOURCE + col.setWidth(30); + + col = new TableColumn(table, SWT.LEFT); + col.setText("一意"); // RESOURCE + col.setWidth(30); + + col = new TableColumn(table, SWT.LEFT); + col.setText("NN"); + col.setWidth(30); + } + + @Override + protected void disableEditDetailControls() { + txtColumnName.setText(StringUtils.EMPTY); + txtColumnLogicalName.setText(StringUtils.EMPTY); + txtCheckName.setText(StringUtils.EMPTY); + txtCheckExpression.setText(StringUtils.EMPTY); + cmbColumnType.setText(StringUtils.EMPTY); + txtColumnSize.setText(StringUtils.EMPTY); + chkIsPK.setSelection(false); + chkIsUnique.setSelection(false); + chkIsNotNull.setSelection(false); + chkIsTypical.setSelection(false); + txtDefaultValue.setText(StringUtils.EMPTY); + txtDescription.setText(StringUtils.EMPTY); + + txtColumnName.setEnabled(false); + txtColumnLogicalName.setEnabled(false); + txtCheckName.setEnabled(false); + txtCheckExpression.setEnabled(false); + cmbColumnType.setEnabled(false); + txtColumnSize.setEnabled(false); + chkIsPK.setEnabled(false); + chkIsUnique.setEnabled(false); + chkIsNotNull.setEnabled(false); + chkIsTypical.setEnabled(false); + txtDefaultValue.setEnabled(false); + txtDescription.setEnabled(false); + } + + @Override + protected void enableEditDetailControls(int index) { + ColumnModel column = columns.get(index); + + txtColumnName.setEnabled(true); + txtColumnLogicalName.setEnabled(true); + txtCheckName.setEnabled(true); + txtCheckExpression.setEnabled(true); + cmbColumnType.setEnabled(true); + txtColumnSize.setEnabled(true); + txtDefaultValue.setEnabled(true); + txtDescription.setEnabled(true); + chkIsPK.setEnabled(true); + chkIsUnique.setEnabled(true); + chkIsNotNull.setEnabled(true); + chkIsTypical.setEnabled(true); + + // 現在値の設定 + txtColumnName.setText(column.getName()); + txtColumnLogicalName.setText(column.getLogicalName()); + + ColumnCheckModel columnCheckModel = column.getCheck(); + if (columnCheckModel == null) { + txtCheckName.setText(StringUtils.EMPTY); + txtCheckExpression.setText(StringUtils.EMPTY); + } else { + txtCheckName.setText(StringUtils.defaultIfEmpty(columnCheckModel.getName(), "")); + txtCheckExpression.setText(StringUtils.defaultIfEmpty(columnCheckModel.getExpression(), "")); + } + + chkIsNotNull.setSelection(column.getNotNull() != null); + + DataType dataType = column.getDataType(); + if (dataType instanceof DomainRef) { + DomainRef domainRef = (DomainRef) dataType; + DomainModel domainModel = jiemamy.getReferenceResolver().resolve(domainRef); + cmbColumnType.setText(domainModel.getName()); + txtColumnSize.setEnabled(false); + } else if (dataType instanceof BuiltinDataType) { + BuiltinDataType builtinDataType = (BuiltinDataType) dataType; + cmbColumnType.setText(builtinDataType.getTypeName()); + Integer size = builtinDataType.getAdapter(SizedDataTypeAdapter.class).getSize(); + txtColumnSize.setText(StringUtils.defaultIfEmpty(ObjectUtils.toString(size), "")); + } + txtDefaultValue.setText(column.getDefaultValue()); + txtDescription.setText(column.getDescription()); + + chkIsPK.setSelection(ColumnUtil.isPartOfPrimaryKeyColumns(column)); + +// chkIsUnique.setSelection(definition.getConstraint(DefinitionModel.CONSTRAINT_UNIQUE)); // chkIsTypical.setSelection(column.getConstraint(DefinitionModel.CONSTRAINT_TYPICAL)); -// -// txtColumnName.setEnabled(true); -// txtColumnLogicalName.setEnabled(true); -// txtCheckName.setEnabled(true); -// txtCheckDefinition.setEnabled(true); -// cmbColumnType.setEnabled(true); -// txtColumnSize.setEnabled(true); -// txtDefaultValue.setEnabled(true); -// txtDescription.setEnabled(true); -// chkIsPK.setEnabled(true); -// chkIsUnique.setEnabled(true); -// chkIsNotNull.setEnabled(true); -// chkIsTypical.setEnabled(true); -// } -// -// @Override -// protected JiemamyElement insertTableSelectionItem() { -// Table table = getTableViewer().getTable(); -// int index = table.getSelectionIndex(); -// -// JiemamyFactory factory = jiemamy.getFactory(); -// ColumnModel columnModel = factory.newModel(ColumnModel.class); -// columnModel.setName("COLUMN_" + (columns.size() + 1)); -// -// BuiltinDataType builtinDataType = factory.newModel(BuiltinDataType.class); -// builtinDataType.setCategory(DataTypeCategory.INTEGER); -// columnModel.setDataType(builtinDataType); -// -// if (index < 0 || index > table.getItemCount()) { -// tableModel.getAttributes().add(columnModel); -// columns.add(columnModel); -// } else { -// // FIXME attributesに対しては、indexを調整しないと。 -// tableModel.getAttributes().add(index, columnModel); -// columns.add(index, columnModel); -// } -// -// int addedIndex = columns.indexOf(columnModel); -// table.setSelection(addedIndex); -// enableEditControls(addedIndex); -// txtColumnName.setFocus(); -// -// return columnModel; -// } -// -// @Override -// protected void moveDownTableSelectionItem() { -// Table table = getTableViewer().getTable(); -// int index = table.getSelectionIndex(); -// if (index < 0 || index >= table.getItemCount()) { -// return; -// } -// -// // FIXME attributesに対しては、indexを調整しないと。 -// ListUtils.moveDown(tableModel.getAttributes(), index); -// ListUtils.moveDown(columns, index); -// -// table.setSelection(index + 1); -// enableEditControls(index + 1); -// } -// -// @Override -// protected void moveUpTableSelectionItem() { -// Table table = getTableViewer().getTable(); -// int index = table.getSelectionIndex(); -// if (index <= 0 || index > table.getItemCount()) { -// return; -// } -// -// // FIXME attributesに対しては、indexを調整しないと。 -// ListUtils.moveUp(tableModel.getAttributes(), index); -// ListUtils.moveUp(columns, index); -// -// table.setSelection(index - 1); -// enableEditControls(index - 1); -// } -// -// @Override -// protected JiemamyElement removeTableSelectionItem() { -// TableViewer tableViewer = getTableViewer(); -// Table table = tableViewer.getTable(); -// int index = table.getSelectionIndex(); -// if (index < 0 || index > table.getItemCount()) { -// return null; -// } -// ColumnModel columnToRemove = columns.remove(index); -// tableModel.getAttributes().remove(columnToRemove); -// tableViewer.remove(columnToRemove); -// table.setSelection(index); -// -// disableEditControls(); -// -// return columnToRemove; -// } -// -// private void updateModel() { -// int columnEditIndex = getTableViewer().getTable().getSelectionIndex(); -// int selectionInedx = cmbColumnType.getSelectionIndex(); -// -// if (columnEditIndex != -1 && selectionInedx != -1) { -// ColumnModel column = columns.get(columnEditIndex); -// column.setName(txtColumnName.getText()); -// column.setLogicalName(txtColumnLogicalName.getText()); -// column.getCheck().setName(txtCheckName.getText()); -// column.getCheck().setDefinition(txtCheckDefinition.getText()); -// -// DataType selectedType = allTypes.get(selectionInedx); -// + } + + @Override + protected JiemamyElement insertTableSelectionItem() { + Table table = getTableViewer().getTable(); + int index = table.getSelectionIndex(); + + JiemamyFactory factory = jiemamy.getFactory(); + ColumnModel columnModel = factory.newModel(ColumnModel.class); + columnModel.setName("COLUMN_" + (columns.size() + 1)); + + BuiltinDataType builtinDataType = factory.newModel(BuiltinDataType.class); + builtinDataType.setCategory(DataTypeCategory.INTEGER); + columnModel.setDataType(builtinDataType); + + if (index < 0 || index > table.getItemCount()) { + tableModel.getAttributes().add(columnModel); + columns.add(columnModel); + } else { + // FIXME attributesに対しては、indexを調整しないと。 + tableModel.getAttributes().add(index, columnModel); + columns.add(index, columnModel); + } + + int addedIndex = columns.indexOf(columnModel); + table.setSelection(addedIndex); + enableEditControls(addedIndex); + txtColumnName.setFocus(); + + return columnModel; + } + + @Override + protected void moveDownTableSelectionItem() { + Table table = getTableViewer().getTable(); + int index = table.getSelectionIndex(); + if (index < 0 || index >= table.getItemCount()) { + return; + } + + // FIXME attributesに対しては、indexを調整しないと。 + ListUtils.moveDown(tableModel.getAttributes(), index); + ListUtils.moveDown(columns, index); + + table.setSelection(index + 1); + enableEditControls(index + 1); + } + + @Override + protected void moveUpTableSelectionItem() { + Table table = getTableViewer().getTable(); + int index = table.getSelectionIndex(); + if (index <= 0 || index > table.getItemCount()) { + return; + } + + // FIXME attributesに対しては、indexを調整しないと。 + ListUtils.moveUp(tableModel.getAttributes(), index); + ListUtils.moveUp(columns, index); + + table.setSelection(index - 1); + enableEditControls(index - 1); + } + + @Override + protected JiemamyElement removeTableSelectionItem() { + TableViewer tableViewer = getTableViewer(); + Table table = tableViewer.getTable(); + int index = table.getSelectionIndex(); + if (index < 0 || index > table.getItemCount()) { + return null; + } + ColumnModel columnToRemove = columns.remove(index); + tableModel.getAttributes().remove(columnToRemove); + tableViewer.remove(columnToRemove); + table.setSelection(index); + + disableEditControls(); + + return columnToRemove; + } + + private void updateModel() { + int columnEditIndex = getTableViewer().getTable().getSelectionIndex(); + int selectionInedx = cmbColumnType.getSelectionIndex(); + + if (columnEditIndex != -1 && selectionInedx != -1) { + ColumnModel column = columns.get(columnEditIndex); + column.setName(txtColumnName.getText()); + column.setLogicalName(StringUtils.defaultIfEmpty(txtColumnLogicalName.getText(), null)); + + AvailableTypeInfo availableTypeInfo = allTypes.get(selectionInedx); + + // TODO dataType // column.setDataType(selectedType); -// -// if (!column.getDataType().isDomain()) { -// if (rootModel.getDialect().convertToPrimitiveType(column.getDataType()).getSizeSupportLevel() == DataType.SIZE.NOT_SUPPORTED) { -// column.setSize(""); -// } else { -// column.setSize(txtColumnSize.getText()); -// } -// } -// column.setDefaultValue(txtDefaultValue.getText()); -// column.setDescription(txtDescription.getText()); -// +// column.setSize(txtColumnSize.getText()); + + column.setDefaultValue(StringUtils.defaultIfEmpty(txtDefaultValue.getText(), null)); + column.setDescription(StringUtils.defaultIfEmpty(txtDescription.getText(), null)); + + if (chkIsPK.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()); -// -// if (!column.getDataType().isDomain()) { -// column.setConstraint(DefinitionModel.CONSTRAINT_UNIQUE, chkIsUnique.getSelection()); -// column.setConstraint(DefinitionModel.CONSTRAINT_NOT_NULL, chkIsNotNull.getSelection()); -// } -// + + // TODO unique +// column.setConstraint(DefinitionModel.CONSTRAINT_UNIQUE, chkIsUnique.getSelection()); + + if (StringUtils.isEmpty(txtCheckName.getText()) && StringUtils.isEmpty(txtCheckExpression.getText())) { + column.setCheck(null); + } else { + ColumnCheckModel checkModel = column.getCheck(); + if (checkModel == null) { + JiemamyFactory factory = column.getJiemamy().getFactory(); + checkModel = factory.newModel(ColumnCheckModel.class); + } + checkModel.setName(txtCheckName.getText()); + checkModel.setExpression(txtCheckExpression.getText()); + } + + // TODO typical adapter // if (chkIsTypical.getSelection()) { // tableModel.clearTypical(); // } // column.setConstraint(DefinitionModel.CONSTRAINT_TYPICAL, chkIsTypical.getSelection()); -// } -// } -// } -//} + } + } + } +} Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/TableEditPart.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/TableEditPart.java 2009-02-18 15:39:26 UTC (rev 2687) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/TableEditPart.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -40,6 +40,7 @@ import org.jiemamy.eclipse.editor.figure.TableFigure; import org.jiemamy.eclipse.editor.utils.LabelStringUtil; import org.jiemamy.eclipse.utils.ConvertUtil; +import org.jiemamy.exception.ElementNotFoundException; import org.jiemamy.exception.TooManyElementsException; import org.jiemamy.model.DiagramPresentationModel; import org.jiemamy.model.DiagramPresentations; @@ -47,6 +48,7 @@ import org.jiemamy.model.RootModel; import org.jiemamy.model.DiagramPresentationModel.DisplayItem; import org.jiemamy.model.attribute.ColumnModel; +import org.jiemamy.model.attribute.constraint.PrimaryKeyModel; import org.jiemamy.model.entity.TableModel; import org.jiemamy.model.geometory.JmColor; import org.jiemamy.model.geometory.JmRectangle; @@ -186,9 +188,12 @@ boolean pkColumn = false; try { - pkColumn = TableUtil.getPrimaryKey(tableModel).getKeyColumns().contains(column); + PrimaryKeyModel primaryKey = TableUtil.getPrimaryKey(tableModel); + pkColumn = primaryKey.getKeyColumns().contains(column); } catch (TooManyElementsException e) { LogUtil.log(JiemamyPlugin.getDefault(), "too many primary key"); + } catch (ElementNotFoundException e) { + // ignore } if (pkColumn Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/ViewEditPart.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/ViewEditPart.java 2009-02-18 15:39:26 UTC (rev 2687) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/ViewEditPart.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -18,6 +18,7 @@ */ package org.jiemamy.eclipse.editor.editpart.diagram; +import org.apache.commons.lang.StringUtils; import org.eclipse.draw2d.ColorConstants; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.Label; @@ -101,7 +102,7 @@ ViewModel viewModel = (ViewModel) node.unwrap(); String definition = viewModel.getDefinition(); - if (definition.length() > 0) { + if (StringUtils.isEmpty(definition) == false) { Panel tooltip = new Panel(); tooltip.setLayoutManager(new StackLayout()); tooltip.setBackgroundColor(ColorConstants.tooltipBackground); Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyProperty.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyProperty.java 2009-02-18 15:39:26 UTC (rev 2687) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyProperty.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -99,8 +99,17 @@ /** {@link ColumnModel#getDefaultValue()}で取得できるプロパティ */ defaultValue, - /** {@link ColumnModel#getConstraints()}で取得できるプロパティ */ - constraints + /** {@link ColumnModel#getNotNull()}で取得できるプロパティ */ + notNull, + + /** {@link ColumnModel#getUniqueKey()}で取得できるプロパティ */ + uniqueKey, + + /** {@link ColumnModel#getPrimaryKey()}で取得できるプロパティ */ + primaryKey, + + /** {@link ColumnModel#getCheck()}で取得できるプロパティ */ + check } /** Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/exception/TooManyElementsException.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/exception/TooManyElementsException.java 2009-02-18 15:39:26 UTC (rev 2687) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/exception/TooManyElementsException.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -29,7 +29,7 @@ * @author daisuke */ @SuppressWarnings("serial") -public class TooManyElementsException extends JiemamyException { +public class TooManyElementsException extends JiemamyRuntimeException { /** 見つかった同名要素のリスト */ private Collection<?> elements; Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/attribute/ColumnModel.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/attribute/ColumnModel.java 2009-02-18 15:39:26 UTC (rev 2687) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/attribute/ColumnModel.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -18,9 +18,10 @@ */ package org.jiemamy.model.attribute; -import java.util.Collection; - -import org.jiemamy.model.attribute.constraint.ColumnConstraint; +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.attribute.constraint.UniqueKeyModel; import org.jiemamy.model.datatype.DataType; /** @@ -29,12 +30,7 @@ */ public interface ColumnModel extends AttributeModel { - /** - * カラム制約の集合を取得する。 - * - * @return カラム制約の集合 - */ - Collection<ColumnConstraint> getConstraints(); + ColumnCheckModel getCheck(); /** * 型記述子を取得する。 @@ -48,6 +44,14 @@ */ String getDefaultValue(); + NotNullConstraintModel getNotNull(); + + PrimaryKeyModel getPrimaryKey(); + + UniqueKeyModel getUniqueKey(); + + void setCheck(ColumnCheckModel check); + /** * 型記述子を設定する。 * @param dataType 型記述子 @@ -60,4 +64,10 @@ */ void setDefaultValue(String defaultValue); + void setNotNull(NotNullConstraintModel notNull); + + void setPrimaryKey(PrimaryKeyModel primaryKey); + + void setUniqueKey(UniqueKeyModel uniqueKey); + } Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/DomainModel.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/DomainModel.java 2009-02-18 15:39:26 UTC (rev 2687) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/DomainModel.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -21,7 +21,8 @@ import java.util.List; import org.jiemamy.model.JiemamyElement; -import org.jiemamy.model.attribute.constraint.ColumnConstraint; +import org.jiemamy.model.attribute.constraint.ColumnCheckModel; +import org.jiemamy.model.attribute.constraint.NotNullConstraintModel; /** * ドメインを表すモデルインターフェイス。 @@ -41,12 +42,7 @@ */ List<Object> getAdapters(); - /** - * 制約のリストを取得する。 - * - * @return 制約のリスト - */ - List<ColumnConstraint> getConstraints(); + ColumnCheckModel getCheck(); /** * ドメインとして定義された型記述子を取得する。 @@ -72,6 +68,8 @@ */ String getName(); + NotNullConstraintModel getNotNull(); + /** * {@inheritDoc} * @throws IllegalStateException dataTypeを設定する前にこのメソッドをコールした場合 @@ -84,6 +82,8 @@ */ void registerAdapter(Object adapter); + void setCheck(ColumnCheckModel check); + /** * ドメインとして定義された型記述子を設定する。 * @param dataType ドメインとして定義された型記述子 @@ -108,4 +108,6 @@ */ void setName(String name); + void setNotNull(NotNullConstraintModel notNull); + } Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/xml/CoreQName.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/xml/CoreQName.java 2009-02-18 15:39:26 UTC (rev 2687) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/xml/CoreQName.java 2009-02-18 18:56:59 UTC (rev 2688) @@ -79,9 +79,6 @@ ATTRIBUTES(CoreNamespace.NS_CORE, "attributes"), /***/ - CONSTRAINTS(CoreNamespace.NS_CORE, "constraints"), - - /***/ PRIMARY_KEY(CoreNamespace.NS_CORE, "primaryKey"), /***/ @@ -126,6 +123,12 @@ NOT_NULL(CoreNamespace.NS_CORE, "notNull"), /***/ + COLUMN_UNIQUE_KEY(CoreNamespace.NS_CORE, "columnUniqueKey"), + + /***/ + COLUMN_PRIMARY_KEY(CoreNamespace.NS_CORE, "columnPrimaryKey"), + + /***/ EXPRESSION(CoreNamespace.NS_CORE, "expression"), /***/ Modified: zeus/trunk/jiemamy-spec-core/src/main/resources/jiemamy-core.xsd =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/resources/jiemamy-core.xsd 2009-02-18 15:39:26 UTC (rev 2687) +++ zeus/trunk/jiemamy-spec-core/src/main/resources/jiemamy-core.xsd 2009-02-18 18:56:59 UTC (rev 2688) @@ -58,7 +58,8 @@ <xsd:element ref="logicalName" minOccurs="0" /> <xsd:element ref="description" minOccurs="0" /> <xsd:element ref="dataType" /> - <xsd:element ref="constraints" minOccurs="0" /> + <xsd:element ref="notNull" minOccurs="0"/> + <xsd:element ref="columnCheck" minOccurs="0"/> <xsd:element ref="adapter" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> <xsd:attribute name="id" type="uuidType" use="required" /> @@ -82,7 +83,7 @@ <xsd:complexType> <xsd:sequence minOccurs="0" maxOccurs="unbounded"> <xsd:element ref="column" maxOccurs="unbounded"/> - <xsd:element ref="primaryKey" minOccurs="1" /> + <xsd:element ref="primaryKey" minOccurs="0" /> <xsd:element ref="uniqueKey" minOccurs="0" maxOccurs="unbounded" /> <xsd:element ref="foreignKey" minOccurs="0" maxOccurs="unbounded" /> <xsd:element ref="tableCheck" minOccurs="0" maxOccurs="unbounded" /> @@ -127,7 +128,10 @@ <xsd:element ref="description" minOccurs="0" /> <xsd:element ref="dataType" /> <xsd:element ref="defaultValue" minOccurs="0" /> - <xsd:element ref="constraints" minOccurs="0" maxOccurs="unbounded" /> + <xsd:element ref="notNull" minOccurs="0"/> + <xsd:element ref="columnPrimaryKey" minOccurs="0"/> + <xsd:element ref="columnUniqueKey" minOccurs="0"/> + <xsd:element ref="columnCheck" minOccurs="0"/> <xsd:element ref="adapter" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> <xsd:attribute name="id" type="uuidType" use="required" /> @@ -135,6 +139,37 @@ </xsd:element> + <xsd:element name="columnPrimaryKey"> + <xsd:complexType> + <xsd:sequence> + <xsd:element ref="name" minOccurs="0"> + <xsd:annotation> + <xsd:documentation source="description" xml:lang="en">primary key physical name.</xsd:documentation> + <xsd:documentation source="description" xml:lang="ja-JP">主キー名を表す。</xsd:documentation> + </xsd:annotation> + </xsd:element> + <xsd:element ref="adapter" minOccurs="0" maxOccurs="unbounded"/> + </xsd:sequence> + <xsd:attribute name="id" type="uuidType" use="required" /> + </xsd:complexType> + </xsd:element> + + <xsd:element name="columnUniqueKey"> + <xsd:complexType> + <xsd:sequence> + <xsd:element ref="name" minOccurs="0"> + <xsd:annotation> + <xsd:documentation source="description" xml:lang="en">unique key physical name.</xsd:documentation> + <xsd:documentation source="description" xml:lang="ja-JP">一意キー名を表す。</xsd:documentation> + </xsd:annotation> + </xsd:element> + <xsd:element ref="adapter" minOccurs="0" maxOccurs="unbounded"/> + </xsd:sequence> + <xsd:attribute name="id" type="uuidType" use="required" /> + </xsd:complexType> + </xsd:element> + + <xsd:element name="primaryKey"> <xsd:complexType> <xsd:sequence> @@ -280,19 +315,6 @@ </xsd:complexType> </xsd:element> - <xsd:element name="constraints"> - <xsd:annotation> - <xsd:documentation source="description" xml:lang="en">column constraint</xsd:documentation> - <xsd:documentation source="description" xml:lang="ja-JP">制約の集合を表す。</xsd:documentation> - </xsd:annotation> - <xsd:complexType> - <xsd:sequence> - <xsd:element ref="notNull" minOccurs="0"/> - <xsd:element ref="columnCheck" minOccurs="0"/> - </xsd:sequence> - </xsd:complexType> - </xsd:element> - <xsd:element name="notNull"> <xsd:complexType> <xsd:sequence> Modified: zeus/trunk/jiemamy-spec-core/src/main/resources/sample.xml =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/resources/sample.xml 2009-02-18 15:39:26 UTC (rev 2687) +++ zeus/trunk/jiemamy-spec-core/src/main/resources/sample.xml 2009-02-18 18:56:59 UTC (rev 2688) @@ -15,13 +15,11 @@ <serial>true</serial> </adapter> </dataType> - <constraints> - <notNull id="af4845dc-7f3a-434d-b5ac-2f25b74d7e76"/> - <columnCheck id="48b76d76-b288-480a-afa4-111247379f8d"> - <name>hoge</name> - <expression>VALUE > 0</expression> - </columnCheck> - </constraints> + <notNull id="af4845dc-7f3a-434d-b5ac-2f25b74d7e76"/> + <columnCheck id="48b76d76-b288-480a-afa4-111247379f8d"> + <name>hoge</name> + <expression>VALUE > 0</expression> + </columnCheck> </domain> <domain id="62f1e6ec-e6aa-4d52-a6c3-27dac086f2d7"> <name>NAME</name> @@ -54,22 +52,18 @@ <typeCategory>INTEGER</typeCategory> <typeName>INTEGER</typeName> </dataType> - <constraints> - <notNull id="05ee4c06-d8b5-4599-a7e9-1cda036ea2c7"> - <adapter class="org.jiemamy.utils.DisablableImpl"> - <disabled>true</disabled> - </adapter> - </notNull> - </constraints> + <notNull id="05ee4c06-d8b5-4599-a7e9-1cda036ea2c7"> + <adapter class="org.jiemamy.utils.DisablableImpl"> + <disabled>true</disabled> + </adapter> + </notNull> </column> <column id="0e51b6df-43ab-408c-90ef-de13c6aab881"> <name>EMP_NAME</name> <logicalName>従業員名</logicalName> <dataType ref="62f1e6ec-e6aa-4d52-a6c3-27dac086f2d7"/> <defaultValue>no name</defaultValue> - <constraints> - <notNull id="41f178b9-2cb5-4dad-a6c0-48df2d5b1300"/> - </constraints> + <notNull id="41f178b9-2cb5-4dad-a6c0-48df2d5b1300"/> <adapter class="org.jiemamy.model.attribute.RepresentationAdapter"> <representation>true</representation> </adapter> @@ -88,9 +82,7 @@ <typeCategory>DATE</typeCategory> <typeName>DATE</typeName> </dataType> - <constraints> - <notNull id="2d66fd73-8d6b-41d8-b6b8-daec7d6c0c53"/> - </constraints> + <notNull id="2d66fd73-8d6b-41d8-b6b8-daec7d6c0c53"/> </column> <column id="80786549-dc2c-4c1c-bcbd-9f6fdec911d2"> <name>SAL</name> @@ -102,9 +94,7 @@ <scale>2</scale> </adapter> </dataType> - <constraints> - <notNull id="a446779a-4fb6-4a0f-8262-22daae856e85"/> - </constraints> + <notNull id="a446779a-4fb6-4a0f-8262-22daae856e85"/> </column> <column id="4ae69b7a-7a0e-422a-89dc-0f0cff77565b"> <name>DEPT_ID</name> @@ -112,9 +102,7 @@ <typeCategory>INTEGER</typeCategory> <typeName>INTEGER</typeName> </dataType> - <constraints> - <notNull id="b9a0fdce-a965-4118-ae71-5dc7150f6d4e"/> - </constraints> + <notNull id="b9a0fdce-a965-4118-ae71-5dc7150f6d4e"/> </column> <primaryKey id="6145e6a0-9ff7-4033-999d-99d80392a48f"> <name>emp_pkey</name> @@ -156,6 +144,9 @@ <name>ID</name> <logicalName>部署ID</logicalName> <dataType ref="2eec0aa0-5122-4eb7-833d-9f5a43e7abe9"/> + <columnPrimaryKey id="8de55e65-ec48-467a-bac5-8eee2d71d41c"> + <name>dept_pkey</name> + </columnPrimaryKey> </column> <column id="2d951389-6bc7-49d7-8631-1d26fe17047e"> <name>DEPT_NO</name> @@ -164,9 +155,7 @@ <typeCategory>INTEGER</typeCategory> <typeName>INTEGER</typeName> </dataType> - <constraints> - <notNull id="cc709f63-a886-4207-a316-58ad7f279e10"/> - </constraints> + <notNull id="cc709f63-a886-4207-a316-58ad7f279e10"/> </column> <column id="1fcd63d3-974e-4d2e-a0d8-3b9c233104d9"> <name>DEPT_NAME</name> @@ -178,9 +167,7 @@ <size>20</size> </adapter> </dataType> - <constraints> - <notNull id="fab2f883-0489-4661-bd57-f04286188eef"/> - </constraints> + <notNull id="fab2f883-0489-4661-bd57-f04286188eef"/> <adapter class="org.jiemamy.model.attribute.RepresentationAdapter"> <representation>true</representation> </adapter> @@ -197,12 +184,6 @@ </dataType> <defaultValue>secret</defaultValue> </column> - <primaryKey id="8de55e65-ec48-467a-bac5-8eee2d71d41c"> - <name>dept_pkey</name> - <columnRefs> - <columnRef ref="c7ed225d-92a6-4cc2-90de-60531804464e"/> - </columnRefs> - </primaryKey> </attributes> </table> <view id="516f7961-cb7b-48e2-990b-7fb0c750c3a4"> Modified: zeus/trunk/jiemamy-spec-diff/.project =================================================================== --- zeus/trunk/jiemamy-spec-diff/.project 2009-02-18 15:39:26 UTC (rev 2687) +++ zeus/trunk/jiemamy-spec-diff/.project 2009-02-18 18:56:59 UTC (rev 2688) @@ -34,6 +34,11 @@ </natures> <linkedResources> <link> + <name>.checkstyle</name> + <type>1</type> + <locationURI>DOCUMENTS/jiemamy-specs/.checkstyle</locationURI> + </link> + <link> <name>.fbprefs</name> <type>1</type> <locationURI>DOCUMENTS/jiemamy-specs/.fbprefs</locationURI> @@ -43,10 +48,5 @@ <type>1</type> <locationURI>DOCUMENTS/jiemamy-specs/findbugs.xml</locationURI> </link> - <link> - <name>.checkstyle</name> - <type>1</type> - <locationURI>DOCUMENTS/jiemamy-specs/.checkstyle</locationURI> - </link> </linkedResources> </projectDescription> Modified: zeus/trunk/jiemamy-spec-view/.project =================================================================== --- zeus/trunk/jiemamy-spec-view/.project 2009-02-18 15:39:26 UTC (rev 2687) +++ zeus/trunk/jiemamy-spec-view/.project 2009-02-18 18:56:59 UTC (rev 2688) @@ -34,6 +34,11 @@ </natures> <linkedResources> <link> + <name>.checkstyle</name> + <type>1</type> + <locationURI>DOCUMENTS/jiemamy-specs/.checkstyle</locationURI> + </link> + <link> <name>.fbprefs</name> <type>1</type> <locationURI>DOCUMENTS/jiemamy-specs/.fbprefs</locationURI> @@ -43,10 +48,5 @@ <type>1</type> <locationURI>DOCUMENTS/jiemamy-specs/findbugs.xml</locationURI> </link> - <link> - <name>.checkstyle</name> - <type>1</type> - <locationURI>DOCUMENTS/jiemamy-specs/.checkstyle</locationURI> - </link> </linkedResources> </projectDescription>