svnno****@sourc*****
svnno****@sourc*****
2009年 2月 12日 (木) 01:35:30 JST
Revision: 2651 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2651 Author: daisuke_m Date: 2009-02-12 01:35:30 +0900 (Thu, 12 Feb 2009) Log Message: ----------- SQL化ロジックを色々整備。 Modified Paths: -------------- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultSqlEmitter.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataTypeImpl.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/adapter/TimezonedDataTypeAdapter.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/SqlStatementImpl.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/test/TestModelBuilder2.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/dialect/DefaultSqlEmitterTest.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/dialect/DataTypeResolver.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/DataTypeCategory.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/sql/SqlStatement.java Added Paths: ----------- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefailtTokenResolver.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/TokenResolver.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/formatter/ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/formatter/DefaultSqlFormatter.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Identifier.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Keyword.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Literal.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Separator.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/formatter/ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/formatter/SqlFormatter.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/LiteralType.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/sql/Token.java -------------- next part -------------- Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefailtTokenResolver.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefailtTokenResolver.java (rev 0) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefailtTokenResolver.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -0,0 +1,87 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/02/12 + * + * This file is part of Jiemamy. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.jiemamy.dialect; + +import java.util.List; + +import org.jiemamy.model.attribute.constraint.Deferrability.InitiallyCheckTime; +import org.jiemamy.model.attribute.constraint.ForeignKeyModel.MatchType; +import org.jiemamy.model.attribute.constraint.ForeignKeyModel.ReferentialAction; +import org.jiemamy.model.sql.Keyword; +import org.jiemamy.model.sql.Token; +import org.jiemamy.utils.CollectionsUtil; + +/** + * TODO for daisuke + * + * @author daisuke + */ +public class DefailtTokenResolver implements TokenResolver { + + /** + * {@inheritDoc} + */ + public List<Token> resolve(InitiallyCheckTime initiallyCheckTime) { + List<Token> tokens = CollectionsUtil.newArrayList(1); + if (initiallyCheckTime == InitiallyCheckTime.IMMEDIATE) { + tokens.add(Keyword.IMMEDIATE); + } else if (initiallyCheckTime == InitiallyCheckTime.DEFERRED) { + tokens.add(Keyword.DEFERRED); + } + return tokens; + } + + /** + * {@inheritDoc} + */ + public List<Token> resolve(MatchType matchType) { + List<Token> tokens = CollectionsUtil.newArrayList(1); + if (matchType == MatchType.SIMPLE) { + tokens.add(Keyword.SIMPLE); + } else if (matchType == MatchType.FULL) { + tokens.add(Keyword.FULL); + } else if (matchType == MatchType.PARTIAL) { + tokens.add(Keyword.PARTIAL); + } + return tokens; + } + + /** + * {@inheritDoc} + */ + public List<Token> resolve(ReferentialAction referentialAction) { + List<Token> tokens = CollectionsUtil.newArrayList(1); + if (referentialAction == ReferentialAction.CASCADE) { + tokens.add(Keyword.CASCADE); + } else if (referentialAction == ReferentialAction.SET_NULL) { + tokens.add(Keyword.SET); + tokens.add(Keyword.NULL); + } else if (referentialAction == ReferentialAction.SET_DEFAULT) { + tokens.add(Keyword.SET); + tokens.add(Keyword.DEFAULT); + } else if (referentialAction == ReferentialAction.RESTRICT) { + tokens.add(Keyword.RESTRICT); + } else if (referentialAction == ReferentialAction.NO_ACTION) { + tokens.add(Keyword.NO); + tokens.add(Keyword.ACTION); + } + return tokens; + } + +} Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefailtTokenResolver.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java 2009-02-11 13:30:09 UTC (rev 2650) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -18,6 +18,11 @@ */ package org.jiemamy.dialect; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; +import java.util.Set; + import org.apache.commons.lang.Validate; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; @@ -27,6 +32,14 @@ import org.jiemamy.model.datatype.BuiltinDataType; import org.jiemamy.model.datatype.DataType; import org.jiemamy.model.datatype.DataTypeCategory; +import org.jiemamy.model.datatype.adapter.PrecisionedDataTypeAdapter; +import org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter; +import org.jiemamy.model.datatype.adapter.TimezonedDataTypeAdapter; +import org.jiemamy.model.sql.Keyword; +import org.jiemamy.model.sql.Literal; +import org.jiemamy.model.sql.Separator; +import org.jiemamy.model.sql.Token; +import org.jiemamy.utils.CollectionsUtil; import org.jiemamy.utils.model.DataTypeUtil; /** @@ -35,11 +48,63 @@ */ public class DefaultDataTypeResolver implements DataTypeResolver { + private final Set<DataTypeCategory> sizedDataType; + + /** + * インスタンスを生成する。 + */ + public DefaultDataTypeResolver() { + sizedDataType = + EnumSet.of(DataTypeCategory.CHARACTER, DataTypeCategory.BIT, DataTypeCategory.BIT, + DataTypeCategory.VARCHAR, DataTypeCategory.CLOB, DataTypeCategory.VARBIT); + } + + /** * {@inheritDoc} */ - public String resolveDataType(DataType dataType, ReferenceResolver resolver) { - return DataTypeUtil.getTypeName(dataType, resolver); + public List<Token> resolveDataType(DataType dataType, ReferenceResolver resolver) { + List<Token> tokens = CollectionsUtil.newArrayList(); + BuiltinDataType builtinDataType = DataTypeUtil.toBuiltinDataType(dataType, resolver); + tokens.add(Keyword.of(builtinDataType.getTypeName())); + if (sizedDataType.contains(builtinDataType.getCategory()) + && builtinDataType.hasAdapter(SizedDataTypeAdapter.class)) { + Integer size = builtinDataType.getAdapter(SizedDataTypeAdapter.class).getSize(); + if (size != null) { + tokens.add(Separator.LEFT_PAREN); + tokens.add(new Literal(size)); + tokens.add(Separator.RIGHT_PAREN); + } + } + if (Arrays.asList(DataTypeCategory.FLOAT, DataTypeCategory.NUMERIC, DataTypeCategory.DECIMAL).contains( + builtinDataType.getCategory()) + && builtinDataType.hasAdapter(PrecisionedDataTypeAdapter.class)) { + PrecisionedDataTypeAdapter adapter = builtinDataType.getAdapter(PrecisionedDataTypeAdapter.class); + Integer prec = adapter.getPrecision(); + Integer scale = adapter.getScale(); + if (prec != null) { + tokens.add(Separator.LEFT_PAREN); + tokens.add(new Literal(prec)); + if (scale != null) { + tokens.add(new Literal(scale)); + } + tokens.add(Separator.RIGHT_PAREN); + } + } + if (Arrays.asList(DataTypeCategory.TIME, DataTypeCategory.TIMESTAMP).contains(builtinDataType.getCategory()) + && builtinDataType.hasAdapter(TimezonedDataTypeAdapter.class)) { + TimezonedDataTypeAdapter adapter = builtinDataType.getAdapter(TimezonedDataTypeAdapter.class); + Boolean withTimezone = adapter.isWithTimezone(); + if (withTimezone != null) { + if (withTimezone) { + tokens.add(Keyword.WITH); + } else { + tokens.add(Keyword.WITHOUT); + } + tokens.add(Keyword.TIMEZONE); + } + } + return tokens; } /** 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-11 13:30:09 UTC (rev 2650) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultSqlEmitter.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -37,14 +37,21 @@ 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.attribute.constraint.Deferrability.InitiallyCheckTime; +import org.jiemamy.model.datatype.BuiltinDataType; +import org.jiemamy.model.datatype.LiteralType; import org.jiemamy.model.entity.EntityModel; import org.jiemamy.model.entity.TableModel; import org.jiemamy.model.entity.ViewModel; +import org.jiemamy.model.sql.Identifier; +import org.jiemamy.model.sql.Keyword; +import org.jiemamy.model.sql.Literal; +import org.jiemamy.model.sql.Separator; import org.jiemamy.model.sql.SqlStatement; import org.jiemamy.model.sql.SqlStatementImpl; +import org.jiemamy.model.sql.Token; import org.jiemamy.utils.CollectionsUtil; import org.jiemamy.utils.EntityDependencyCalculator; +import org.jiemamy.utils.model.DataTypeUtil; import org.jiemamy.utils.model.ForeignKeyUtil; /** @@ -64,6 +71,8 @@ private ReferenceResolver referenceResolver; + private TokenResolver tokenResolver = new DefailtTokenResolver(); + /** * インスタンスを生成する。 @@ -84,7 +93,7 @@ // THINK RootBeginScript と CreateSchemaStatement、どっちが先? if (StringUtils.isEmpty(rootModel.getBeginScript()) == false) { - result.add(new SqlStatementImpl(rootModel.getBeginScript())); + result.add(new SqlStatementImpl(new Literal(rootModel.getBeginScript(), LiteralType.FRAGMENT))); } if (StringUtils.isEmpty(rootModel.getSchemaName()) == false) { @@ -93,18 +102,18 @@ for (EntityModel entity : EntityDependencyCalculator.getSortedEntityList(rootModel)) { if (StringUtils.isEmpty(entity.getBeginScript()) == false) { - result.add(new SqlStatementImpl(entity.getBeginScript())); + result.add(new SqlStatementImpl(new Literal(entity.getBeginScript(), LiteralType.FRAGMENT))); } result.add(emitDdl(entity, config)); if (StringUtils.isEmpty(entity.getEndScript()) == false) { - result.add(new SqlStatementImpl(entity.getEndScript())); + result.add(new SqlStatementImpl(new Literal(entity.getEndScript(), LiteralType.FRAGMENT))); } } if (StringUtils.isEmpty(rootModel.getEndScript()) == false) { - result.add(new SqlStatementImpl(rootModel.getEndScript())); + result.add(new SqlStatementImpl(new Literal(rootModel.getEndScript(), LiteralType.FRAGMENT))); } return result; @@ -117,10 +126,11 @@ * @return */ private SqlStatement emitCreateSchemaStatement(String schemaName) { - List<String> tokens = CollectionsUtil.newArrayList(); - tokens.add("CREATE"); - tokens.add("SCHEMA"); - tokens.add(schemaName); + List<Token> tokens = CollectionsUtil.newArrayList(); + tokens.add(Keyword.CREATE); + tokens.add(Keyword.SCHEMA); + tokens.add(new Identifier(schemaName)); + tokens.add(Separator.SEMICOLON); return new SqlStatementImpl(tokens); } @@ -132,7 +142,7 @@ * @return */ private SqlStatement emitDdl(EntityModel entity, EmitConfig config) { - return EntityEmitStrategy.fromEntity(entity).emit(entity, dataTypeResolver, referenceResolver); + return EntityEmitStrategy.fromEntity(entity).emit(entity, dataTypeResolver, referenceResolver, tokenResolver); } @@ -141,15 +151,18 @@ COLUMN(ColumnModel.class) { @Override - public List<String> emit(AttributeModel attributeModel, DataTypeResolver dataTypeResolver, - ReferenceResolver referenceResolver) { + public List<Token> emit(AttributeModel attributeModel, DataTypeResolver dataTypeResolver, + ReferenceResolver referenceResolver, TokenResolver tokenResolver) { ColumnModel columnModel = (ColumnModel) attributeModel; - List<String> tokens = CollectionsUtil.newArrayList(); - tokens.add(columnModel.getName()); - tokens.add(dataTypeResolver.resolveDataType(columnModel.getDataType(), referenceResolver)); + List<Token> tokens = CollectionsUtil.newArrayList(); + tokens.add(new Identifier(columnModel.getName())); + tokens.addAll(dataTypeResolver.resolveDataType(columnModel.getDataType(), referenceResolver)); if (StringUtils.isEmpty(columnModel.getDefaultValue()) == false) { - tokens.add("DEFAULT"); - tokens.add(columnModel.getDefaultValue()); + BuiltinDataType builtinDataType = + DataTypeUtil.toBuiltinDataType(columnModel.getDataType(), referenceResolver); + tokens.add(Keyword.DEFAULT); + tokens.add(new Literal(columnModel.getDefaultValue(), builtinDataType.getCategory() + .getLiteralType())); } return tokens; } @@ -159,12 +172,13 @@ PK(PrimaryKeyModel.class) { @Override - public List<String> emit(AttributeModel attributeModel, DataTypeResolver dataTypeResolver, - ReferenceResolver referenceResolver) { + public List<Token> emit(AttributeModel attributeModel, DataTypeResolver dataTypeResolver, + ReferenceResolver referenceResolver, TokenResolver tokenResolver) { PrimaryKeyModel pkModel = (PrimaryKeyModel) attributeModel; - List<String> tokens = CollectionsUtil.newArrayList(); + List<Token> tokens = CollectionsUtil.newArrayList(); addConstraintNameDefinition(pkModel, tokens); - tokens.add("PRIMARY KEY"); + tokens.add(Keyword.PRIMARY); + tokens.add(Keyword.KEY); addColumnList(tokens, pkModel.getKeyColumns(), referenceResolver); return tokens; } @@ -175,12 +189,13 @@ UK(UniqueKeyModel.class) { @Override - public List<String> emit(AttributeModel attributeModel, DataTypeResolver dataTypeResolver, - ReferenceResolver referenceResolver) { + public List<Token> emit(AttributeModel attributeModel, DataTypeResolver dataTypeResolver, + ReferenceResolver referenceResolver, TokenResolver tokenResolver) { UniqueKeyModel ukModel = (UniqueKeyModel) attributeModel; - List<String> tokens = CollectionsUtil.newArrayList(); + List<Token> tokens = CollectionsUtil.newArrayList(); addConstraintNameDefinition(ukModel, tokens); - tokens.add("UNIQUE KEY"); + tokens.add(Keyword.UNIQUE); + tokens.add(Keyword.KEY); addColumnList(tokens, ukModel.getKeyColumns(), referenceResolver); return tokens; } @@ -190,37 +205,42 @@ FK(ForeignKeyModel.class) { @Override - public List<String> emit(AttributeModel attributeModel, DataTypeResolver dataTypeResolver, - ReferenceResolver referenceResolver) { + public List<Token> emit(AttributeModel attributeModel, DataTypeResolver dataTypeResolver, + ReferenceResolver referenceResolver, TokenResolver tokenResolver) { ForeignKeyModel fkModel = (ForeignKeyModel) attributeModel; - List<String> tokens = CollectionsUtil.newArrayList(); + List<Token> tokens = CollectionsUtil.newArrayList(); addConstraintNameDefinition(fkModel, tokens); - tokens.add("FOREIGN KEY"); + tokens.add(Keyword.FOREIGN); + tokens.add(Keyword.KEY); addColumnList(tokens, fkModel.getKeyColumns(), referenceResolver); - tokens.add("REFERENCES"); + tokens.add(Keyword.REFERENCES); EntityModel referenceEntity = ForeignKeyUtil.getReferenceEntity(fkModel); - tokens.add(referenceEntity.getName()); + tokens.add(new Identifier(referenceEntity.getName())); addColumnList(tokens, fkModel.getReferenceColumns(), referenceResolver); if (fkModel.getMatchType() != null) { - tokens.add("MATCH " + fkModel.getMatchType()); + tokens.add(Keyword.MATCH); + tokens.addAll(tokenResolver.resolve(fkModel.getMatchType())); } if (fkModel.getOnDelete() != null) { - tokens.add("ON DELETE " + fkModel.getOnDelete().toString().replace('_', ' ')); + tokens.add(Keyword.ON); + tokens.add(Keyword.DELETE); + tokens.addAll(tokenResolver.resolve(fkModel.getOnDelete())); } if (fkModel.getOnUpdate() != null) { - tokens.add("ON UPDATE " + fkModel.getOnUpdate().toString().replace('_', ' ')); + tokens.add(Keyword.ON); + tokens.add(Keyword.UPDATE); + tokens.addAll(tokenResolver.resolve(fkModel.getOnUpdate())); } if (fkModel.getDeferrability() != null) { Deferrability deferrability = fkModel.getDeferrability(); if (deferrability.isDeferrable() == false) { - tokens.add("NOT"); + tokens.add(Keyword.NOT); } - tokens.add("DEFERRABLE"); + tokens.add(Keyword.DEFERRABLE); if (deferrability.getInitiallyCheckTime() != null) { - InitiallyCheckTime initiallyCheckTime = deferrability.getInitiallyCheckTime(); - tokens.add("INITIALLY"); - tokens.add(initiallyCheckTime.toString()); + tokens.add(Keyword.INITIALLY); + tokens.addAll(tokenResolver.resolve(deferrability.getInitiallyCheckTime())); } } return tokens; @@ -231,19 +251,21 @@ NN(NotNullConstraintModel.class) { @Override - public List<String> emit(AttributeModel attributeModel, DataTypeResolver dataTypeResolver, - ReferenceResolver referenceResolver) { + public List<Token> emit(AttributeModel attributeModel, DataTypeResolver dataTypeResolver, + ReferenceResolver referenceResolver, TokenResolver tokenResolver) { NotNullConstraintModel nnModel = (NotNullConstraintModel) attributeModel; - List<String> tokens = CollectionsUtil.newArrayList(); + List<Token> tokens = CollectionsUtil.newArrayList(); addConstraintNameDefinition(nnModel, tokens); - tokens.add("CHECK"); - tokens.add("("); + tokens.add(Keyword.CHECK); + tokens.add(Separator.LEFT_PAREN); ColumnModel columnModel = referenceResolver.resolve(nnModel.getColumn()); - tokens.add(columnModel.getName()); + tokens.add(new Identifier(columnModel.getName())); - tokens.add("IS NOT NULL"); - tokens.add(")"); + tokens.add(Keyword.IS); + tokens.add(Keyword.NOT); + tokens.add(Keyword.NULL); + tokens.add(Separator.RIGHT_PAREN); return tokens; } }, @@ -252,15 +274,15 @@ CHECK(CheckConstraintModel.class) { @Override - public List<String> emit(AttributeModel attributeModel, DataTypeResolver dataTypeResolver, - ReferenceResolver referenceResolver) { + public List<Token> emit(AttributeModel attributeModel, DataTypeResolver dataTypeResolver, + ReferenceResolver referenceResolver, TokenResolver tokenResolver) { CheckConstraintModel checkModel = (CheckConstraintModel) attributeModel; - List<String> tokens = CollectionsUtil.newArrayList(); + List<Token> tokens = CollectionsUtil.newArrayList(); addConstraintNameDefinition(checkModel, tokens); - tokens.add("CHECK"); - tokens.add("("); - tokens.add(checkModel.getExpression()); - tokens.add(")"); + tokens.add(Keyword.CHECK); + tokens.add(Separator.LEFT_PAREN); + tokens.add(new Literal(checkModel.getExpression(), LiteralType.FRAGMENT)); + tokens.add(Separator.RIGHT_PAREN); return tokens; } }; @@ -285,22 +307,22 @@ return null; } - private static void addColumnList(List<String> tokens, List<ColumnRef> columnRefs, + private static void addColumnList(List<Token> tokens, List<ColumnRef> columnRefs, ReferenceResolver referenceResolver) { - tokens.add("("); + tokens.add(Separator.LEFT_PAREN); for (ColumnRef columnRef : columnRefs) { ColumnModel columnModel = referenceResolver.resolve(columnRef); - tokens.add(columnModel.getName()); - tokens.add(","); + tokens.add(new Identifier(columnModel.getName())); + tokens.add(Separator.COMMA); } tokens.remove(tokens.size() - 1); - tokens.add(")"); + tokens.add(Separator.RIGHT_PAREN); } - private static void addConstraintNameDefinition(ConstraintModel constraint, List<String> tokens) { + private static void addConstraintNameDefinition(ConstraintModel constraint, List<Token> tokens) { if (StringUtils.isEmpty(constraint.getName()) == false) { - tokens.add("CONSTRAINT"); - tokens.add(constraint.getName()); + tokens.add(Keyword.CONSTRAINT); + tokens.add(new Identifier(constraint.getName())); } } @@ -320,8 +342,8 @@ * @param referenceResolver * @return */ - public abstract List<String> emit(AttributeModel attributeModel, DataTypeResolver resolver, - ReferenceResolver referenceResolver); + public abstract List<Token> emit(AttributeModel attributeModel, DataTypeResolver resolver, + ReferenceResolver referenceResolver, TokenResolver tokenResolver); } @@ -331,23 +353,24 @@ TABLE(TableModel.class) { @Override - public SqlStatement emit(EntityModel entity, DataTypeResolver resolver, ReferenceResolver referenceResolver) { + public SqlStatement emit(EntityModel entity, DataTypeResolver resolver, + ReferenceResolver referenceResolver, TokenResolver tokenResolver) { TableModel tableModel = (TableModel) entity; - List<String> tokens = CollectionsUtil.newArrayList(); - tokens.add("CREATE"); - tokens.add("TABLE"); - tokens.add(tableModel.getName()); - tokens.add("("); + List<Token> tokens = CollectionsUtil.newArrayList(); + tokens.add(Keyword.CREATE); + tokens.add(Keyword.TABLE); + tokens.add(new Identifier(tableModel.getName())); + tokens.add(Separator.LEFT_PAREN); for (AttributeModel attributeModel : tableModel.getAttributes()) { - List<String> attributes = + List<Token> attributes = AttributeEmitStrategy.fromAttribute(attributeModel).emit(attributeModel, resolver, - referenceResolver); + referenceResolver, tokenResolver); tokens.addAll(attributes); - tokens.add(","); + tokens.add(Separator.COMMA); } tokens.remove(tokens.size() - 1); - tokens.add(")"); - + tokens.add(Separator.RIGHT_PAREN); + tokens.add(Separator.SEMICOLON); return new SqlStatementImpl(tokens); } }, @@ -356,15 +379,16 @@ VIEW(ViewModel.class) { @Override - public SqlStatement emit(EntityModel entity, DataTypeResolver resolver, ReferenceResolver referenceResolver) { + public SqlStatement emit(EntityModel entity, DataTypeResolver resolver, + ReferenceResolver referenceResolver, TokenResolver tokenResolver) { ViewModel viewModel = (ViewModel) entity; - List<String> tokens = CollectionsUtil.newArrayList(); - tokens.add("CREATE"); - tokens.add("VIEW"); - tokens.add(viewModel.getName()); - tokens.add("AS"); - tokens.add(viewModel.getDefinition()); - + List<Token> tokens = CollectionsUtil.newArrayList(); + tokens.add(Keyword.CREATE); + tokens.add(Keyword.VIEW); + tokens.add(new Identifier(viewModel.getName())); + tokens.add(Keyword.AS); + tokens.add(new Literal(viewModel.getDefinition(), LiteralType.FRAGMENT)); + tokens.add(Separator.SEMICOLON); return new SqlStatementImpl(tokens); } }; @@ -406,7 +430,7 @@ * @return */ public abstract SqlStatement emit(EntityModel entity, DataTypeResolver resolver, - ReferenceResolver referenceResolver); + ReferenceResolver referenceResolver, TokenResolver tokenResolver); } } Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/TokenResolver.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/TokenResolver.java (rev 0) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/TokenResolver.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -0,0 +1,59 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/02/12 + * + * This file is part of Jiemamy. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.jiemamy.dialect; + +import java.util.List; + +import org.jiemamy.model.attribute.constraint.Deferrability.InitiallyCheckTime; +import org.jiemamy.model.attribute.constraint.ForeignKeyModel.MatchType; +import org.jiemamy.model.attribute.constraint.ForeignKeyModel.ReferentialAction; +import org.jiemamy.model.sql.Token; + +/** + * TODO for daisuke + * + * @author daisuke + */ +public interface TokenResolver { + + /** + * TODO for daisuke + * + * @param initiallyCheckTime + * @return + */ + List<Token> resolve(InitiallyCheckTime initiallyCheckTime); + + /** + * TODO for daisuke + * + * @param matchType + * @return + */ + List<Token> resolve(MatchType matchType); + + /** + * TODO for daisuke + * + * @param onDelete + * @return + */ + List<Token> resolve(ReferentialAction onDelete); + +} Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/TokenResolver.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/formatter/DefaultSqlFormatter.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/formatter/DefaultSqlFormatter.java (rev 0) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/formatter/DefaultSqlFormatter.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -0,0 +1,52 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/02/11 + * + * This file is part of Jiemamy. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.jiemamy.formatter; + +import org.apache.commons.lang.ArrayUtils; + +import org.jiemamy.model.sql.Separator; +import org.jiemamy.model.sql.SqlStatement; +import org.jiemamy.model.sql.Token; + +/** + * TODO for daisuke + * + * @author daisuke + */ +public class DefaultSqlFormatter implements SqlFormatter { + + /** + * {@inheritDoc} + */ + public String format(SqlStatement stmt) { + StringBuilder sb = new StringBuilder(); + Token lastToken = Separator.SEMICOLON; + for (Token token : stmt.getTokens()) { + if (lastToken.equals(Separator.COMMA) + || (ArrayUtils.contains(Separator.values(), lastToken) == false && ArrayUtils.contains(Separator + .values(), token) == false)) { + sb.append(" "); + } + sb.append(token); + lastToken = token; + } + return sb.toString(); + } + +} Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/formatter/DefaultSqlFormatter.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataTypeImpl.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataTypeImpl.java 2009-02-11 13:30:09 UTC (rev 2650) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/BuiltinDataTypeImpl.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -46,6 +46,9 @@ * {@inheritDoc} */ public String getTypeName() { + if (typeName == null) { + return category.toString(); + } return typeName; } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/adapter/TimezonedDataTypeAdapter.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/adapter/TimezonedDataTypeAdapter.java 2009-02-11 13:30:09 UTC (rev 2650) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/datatype/adapter/TimezonedDataTypeAdapter.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -83,7 +83,7 @@ * タイムゾーンを管理するかどうかを取得する。 * @return 精度 */ - public boolean isWithTimezone() { + public Boolean isWithTimezone() { return withTimezone; } Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Identifier.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Identifier.java (rev 0) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Identifier.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -0,0 +1,47 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/02/12 + * + * This file is part of Jiemamy. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.jiemamy.model.sql; + +/** + * TODO for daisuke + * + * @author daisuke + */ +public class Identifier implements Token { + + private final String identifier; + + + /** + * インスタンスを生成する。 + * + * @param identifier + */ + public Identifier(String identifier) { + this.identifier = identifier; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return identifier; + } +} Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Identifier.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Keyword.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Keyword.java (rev 0) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Keyword.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -0,0 +1,159 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/02/11 + * + * This file is part of Jiemamy. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.jiemamy.model.sql; + +/** + * TODO for daisuke + * + * @author daisuke + */ +public class Keyword implements Token { + + /***/ + public static final Keyword CREATE = new Keyword("CREATE"); + + /***/ + public static final Keyword TABLE = new Keyword("TABLE"); + + /***/ + public static final Keyword VIEW = new Keyword("VIEW"); + + /***/ + public static final Keyword KEY = new Keyword("KEY"); + + /***/ + public static final Keyword PRIMARY = new Keyword("PRIMARY"); + + /***/ + public static final Keyword UNIQUE = new Keyword("UNIQUE"); + + /***/ + public static final Keyword FOREIGN = new Keyword("FOREIGN"); + + /***/ + public static final Keyword CHECK = new Keyword("CHECK"); + + /***/ + public static final Keyword NOT = new Keyword("NOT"); + + /***/ + public static final Keyword NULL = new Keyword("NULL"); + + /***/ + public static final Keyword SCHEMA = new Keyword("SCHEMA"); + + /***/ + public static final Keyword AS = new Keyword("AS"); + + /***/ + public static final Keyword CONSTRAINT = new Keyword("CONSTRAINT"); + + /***/ + public static final Keyword DEFAULT = new Keyword("DEFAULT"); + + /***/ + public static final Keyword IS = new Keyword("IS"); + + /***/ + public static final Keyword REFERENCES = new Keyword("REFERENCES"); + + /***/ + public static final Keyword MATCH = new Keyword("MATCH"); + + /***/ + public static final Keyword ON = new Keyword("ON"); + + /***/ + public static final Keyword DELETE = new Keyword("DELETE"); + + /***/ + public static final Keyword UPDATE = new Keyword("UPDATE"); + + /***/ + public static final Keyword DEFERRABLE = new Keyword("DEFERRABLE"); + + /***/ + public static final Keyword INITIALLY = new Keyword("INITIALLY"); + + /***/ + public static final Keyword WITH = new Keyword("WITH"); + + /***/ + public static final Keyword WITHOUT = new Keyword("WITHOUT"); + + /***/ + public static final Keyword TIMEZONE = new Keyword("TIMEZONE"); + + /***/ + public static final Keyword SET = new Keyword("SET"); + + /***/ + public static final Keyword CASCADE = new Keyword("CASCADE"); + + /***/ + public static final Keyword RESTRICT = new Keyword("RESTRICT"); + + /***/ + public static final Keyword NO = new Keyword("NO"); + + /***/ + public static final Keyword ACTION = new Keyword("ACTION"); + + /***/ + public static final Keyword SIMPLE = new Keyword("SIMPLE"); + + /***/ + public static final Keyword FULL = new Keyword("FULL"); + + /***/ + public static final Keyword PARTIAL = new Keyword("PARTIAL"); + + /***/ + public static final Keyword IMMEDIATE = new Keyword("IMMEDIATE"); + + /***/ + public static final Keyword DEFERRED = new Keyword("DEFERRED"); + + + /** + * TODO for daisuke + * + * @param typeName + * @return + */ + public static Keyword of(String typeName) { + return new Keyword(typeName); + } + + + private final String string; + + + Keyword(String string) { + this.string = string; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string; + } +} Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Keyword.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Literal.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Literal.java (rev 0) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Literal.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -0,0 +1,61 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/02/12 + * + * This file is part of Jiemamy. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.jiemamy.model.sql; + +import org.apache.commons.lang.Validate; + +import org.jiemamy.model.datatype.LiteralType; + +/** + * TODO for daisuke + * + * @author daisuke + */ +public class Literal implements Token { + + private final String string; + + + /** + * インスタンスを生成する。 + * + * @param number + */ + public Literal(Number number) { + this(number.toString(), LiteralType.NUMERIC); + } + + /** + * インスタンスを生成する。 + * + * @param string + */ + public Literal(String string, LiteralType type) { + Validate.notNull(string); + this.string = type.convert(string); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string; + } +} Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Literal.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Separator.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Separator.java (rev 0) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Separator.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -0,0 +1,54 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/02/12 + * + * This file is part of Jiemamy. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.jiemamy.model.sql; + +/** + * TODO for daisuke + * + * @author daisuke + */ +public enum Separator implements Token { + + /** セミコロン */ + SEMICOLON(";"), + + /** カンマ */ + COMMA(","), + + /** 左括弧 */ + LEFT_PAREN("("), + + /** 右括弧 */ + RIGHT_PAREN(")"); + + private final String string; + + + Separator(String string) { + this.string = string; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string; + } +} Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Separator.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/SqlStatementImpl.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/SqlStatementImpl.java 2009-02-11 13:30:09 UTC (rev 2650) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/SqlStatementImpl.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -20,8 +20,8 @@ import java.util.List; -import org.apache.commons.lang.StringUtils; - +import org.jiemamy.formatter.DefaultSqlFormatter; +import org.jiemamy.formatter.SqlFormatter; import org.jiemamy.utils.CollectionsUtil; /** @@ -32,7 +32,7 @@ // FIXME とりあえずStringでの意味無し実装。SQLを上手くモデル化できれば、という希望…。 - private List<String> tokens = CollectionsUtil.newArrayList(); + private List<Token> tokens = CollectionsUtil.newArrayList(); /** @@ -45,26 +45,34 @@ /** * インスタンスを生成する。 * - * @param strings + * @param tokens */ - public SqlStatementImpl(List<String> strings) { - tokens.addAll(strings); + public SqlStatementImpl(List<Token> tokens) { + this.tokens.addAll(tokens); } /** * インスタンスを生成する。 * - * @param string + * @param token */ - public SqlStatementImpl(String string) { - tokens.add(string); + public SqlStatementImpl(Token token) { + tokens.add(token); } + public List<Token> getTokens() { + return CollectionsUtil.newArrayList(tokens); + } + /** * {@inheritDoc} */ @Override public String toString() { - return StringUtils.join(tokens, " ") + ";"; + return toString(new DefaultSqlFormatter()); } + + public String toString(SqlFormatter formatter) { + return formatter.format(this); + } } 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-11 13:30:09 UTC (rev 2650) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/test/TestModelBuilder2.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -707,7 +707,8 @@ private void createTableItem() { tableItem = factory.newModel(TableModel.class, uuid.get("7ecf5ba1-e80c-472c-b19b-bef2649d7974")); tableItem.setName("T_ITEM"); - tableItem.setBeginScript("/* test begin script */"); + tableItem.setBeginScript("/* test begin script of T_ITEM */"); + tableItem.setEndScript("/* test end script of T_ITEM */"); tableItem.setDescription("商品マスタです。"); itemId = factory.newModel(ColumnModel.class, uuid.get("5a9585be-4b0d-4675-99aa-97b0417c816c")); Modified: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/dialect/DefaultSqlEmitterTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/dialect/DefaultSqlEmitterTest.java 2009-02-11 13:30:09 UTC (rev 2650) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/dialect/DefaultSqlEmitterTest.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -28,7 +28,7 @@ import org.jiemamy.Jiemamy; import org.jiemamy.model.sql.SqlStatement; -import org.jiemamy.test.TestModelBuilder; +import org.jiemamy.test.TestModelBuilder2; /** * TODO for daisuke @@ -41,7 +41,7 @@ private Jiemamy jiemamy; - private DefaultSqlEmitter defaultSqlEmitter; + private SqlEmitter sqlEmitter; /** @@ -51,10 +51,10 @@ */ @Before public void setUp() throws Exception { - TestModelBuilder testModelBuilder = new TestModelBuilder(); + TestModelBuilder2 testModelBuilder = new TestModelBuilder2(); testModelBuilder.build(); jiemamy = testModelBuilder.getJiemamy(); - defaultSqlEmitter = new DefaultSqlEmitter(new DefaultDataTypeResolver()); + sqlEmitter = new DefaultSqlEmitter(new DefaultDataTypeResolver()); } /** @@ -65,12 +65,12 @@ @After public void tearDown() throws Exception { jiemamy = null; - defaultSqlEmitter = null; + sqlEmitter = null; } @Test public void test01_() throws Exception { - List<SqlStatement> statements = defaultSqlEmitter.emit(jiemamy.getFactory().getRootModel(), null); + List<SqlStatement> statements = sqlEmitter.emit(jiemamy.getFactory().getRootModel(), null); for (SqlStatement sqlStatement : statements) { logger.info(sqlStatement.toString()); } Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/dialect/DataTypeResolver.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/dialect/DataTypeResolver.java 2009-02-11 13:30:09 UTC (rev 2650) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/dialect/DataTypeResolver.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -18,10 +18,13 @@ */ package org.jiemamy.dialect; +import java.util.List; + import org.jiemamy.JiemamyFactory; import org.jiemamy.ReferenceResolver; import org.jiemamy.model.datatype.BuiltinDataType; import org.jiemamy.model.datatype.DataType; +import org.jiemamy.model.sql.Token; /** * データ型同士の対応関係(マッピング)を表現するクラス。 @@ -36,7 +39,7 @@ * @return 型名 * @throws IllegalArgumentException 引数に{@code null}を与えた場合 */ - String resolveDataType(DataType dataType, ReferenceResolver resolver); + List<Token> resolveDataType(DataType dataType, ReferenceResolver resolver); /** * 型名から型記述子を解決する。 Added: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/formatter/SqlFormatter.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/formatter/SqlFormatter.java (rev 0) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/formatter/SqlFormatter.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -0,0 +1,38 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/02/11 + * + * This file is part of Jiemamy. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.jiemamy.formatter; + +import org.jiemamy.model.sql.SqlStatement; + +/** + * TODO for daisuke + * + * @author daisuke + */ +public interface SqlFormatter { + + /** + * TODO for daisuke + * + * @param tokens + * @return + */ + String format(SqlStatement stmt); + +} Property changes on: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/formatter/SqlFormatter.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/DataTypeCategory.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/DataTypeCategory.java 2009-02-11 13:30:09 UTC (rev 2650) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/DataTypeCategory.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -28,62 +28,65 @@ public enum DataTypeCategory { /** CHARACTER型 */ - CHARACTER(Types.CHAR), + CHARACTER(Types.CHAR, LiteralType.CHARACTER), /** VARCHAR型 */ - VARCHAR(Types.VARCHAR), + VARCHAR(Types.VARCHAR, LiteralType.CHARACTER), /** CLOB型 */ - CLOB(Types.CLOB), + CLOB(Types.CLOB, LiteralType.CHARACTER), /** BLOB型 */ - BLOB(Types.BLOB), + BLOB(Types.BLOB, LiteralType.CHARACTER), /** BIT型 */ - BIT(Types.BIT), + BIT(Types.BIT, LiteralType.CHARACTER), /** VARBIT型 */ - VARBIT(Types.OTHER), + VARBIT(Types.OTHER, LiteralType.CHARACTER), /** NUMERIC型 */ - NUMERIC(Types.NUMERIC), + NUMERIC(Types.NUMERIC, LiteralType.NUMERIC), /** DECIMAL型 */ - DECIMAL(Types.DECIMAL), + DECIMAL(Types.DECIMAL, LiteralType.NUMERIC), /** INTEGER型 */ - INTEGER(Types.INTEGER), + INTEGER(Types.INTEGER, LiteralType.NUMERIC), /** SMALLINT型 */ - SMALLINT(Types.SMALLINT), + SMALLINT(Types.SMALLINT, LiteralType.NUMERIC), /** FLOAT型 */ - FLOAT(Types.FLOAT), + FLOAT(Types.FLOAT, LiteralType.NUMERIC), /** REAL型 */ - REAL(Types.REAL), + REAL(Types.REAL, LiteralType.NUMERIC), /** DOUBLE型 */ - DOUBLE(Types.DOUBLE), + DOUBLE(Types.DOUBLE, LiteralType.NUMERIC), /** BOOLEAN型 */ - BOOLEAN(Types.BOOLEAN), + BOOLEAN(Types.BOOLEAN, LiteralType.BOOLEAN), /** DATE型 */ - DATE(Types.DATE), + DATE(Types.DATE, LiteralType.DATE), /** TIME型 */ - TIME(Types.TIME), + TIME(Types.TIME, LiteralType.TIME), /** TIMESTAMP型 */ - TIMESTAMP(Types.TIMESTAMP), + TIMESTAMP(Types.TIMESTAMP, LiteralType.TIMESTAMP), /** INTERVAL型 */ - INTERVAL(Types.OTHER), + INTERVAL(Types.OTHER, LiteralType.INTERVAL), /** その他型 */ - OTHER(Types.OTHER); + OTHER(Types.OTHER, LiteralType.CHARACTER); + private static LiteralType literalType; + + /** * TODO for daisuke * @@ -103,11 +106,21 @@ private final int sqlType; - DataTypeCategory(int sqlType) { + DataTypeCategory(int sqlType, LiteralType literalType) { this.sqlType = sqlType; + this.literalType = literalType; } + /** + * TODO for daisuke + * + * @return + */ + public LiteralType getLiteralType() { + return literalType; + } + public int getSqlType() { return sqlType; } Added: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/LiteralType.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/LiteralType.java (rev 0) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/LiteralType.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -0,0 +1,76 @@ +package org.jiemamy.model.datatype; + +/** + * TODO for daisuke + * + * @author daisuke + */ +public enum LiteralType { + /***/ + CHARACTER { + + @Override + public String convert(String string) { + return "'" + string + "'"; + } + }, + /***/ + NUMERIC { + + @Override + public String convert(String string) { + return string; + } + }, + /***/ + BOOLEAN { + + @Override + public String convert(String string) { + return string; + } + }, + /***/ + DATE { + + @Override + public String convert(String string) { + return "DATE '" + string + "'"; + } + }, + /***/ + TIME { + + @Override + public String convert(String string) { + return "TIME '" + string + "'"; + } + }, + /***/ + TIMESTAMP { + + @Override + public String convert(String string) { + return "TIMESTAMP '" + string + "'"; + } + }, + /***/ + INTERVAL { + + @Override + public String convert(String string) { + return "INTERVAL " + string; + } + }, + + /***/ + FRAGMENT { + + @Override + public String convert(String string) { + return string; + } + }; + + public abstract String convert(String string); +} Property changes on: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/LiteralType.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/sql/SqlStatement.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/sql/SqlStatement.java 2009-02-11 13:30:09 UTC (rev 2650) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/sql/SqlStatement.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -18,6 +18,10 @@ */ package org.jiemamy.model.sql; +import java.util.List; + +import org.jiemamy.formatter.SqlFormatter; + /** * SQL文をあらわすインターフェイス。 * @@ -27,9 +31,13 @@ */ public interface SqlStatement { + List<Token> getTokens(); + /** * SQL文に変換する。 * @return SQL文 */ String toString(); + + String toString(SqlFormatter formatter); } Added: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/sql/Token.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/sql/Token.java (rev 0) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/sql/Token.java 2009-02-11 16:35:30 UTC (rev 2651) @@ -0,0 +1,29 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/02/11 + * + * This file is part of Jiemamy. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.jiemamy.model.sql; + +/** + * TODO for daisuke + * + * @author daisuke + */ +public interface Token { + + String toString(); +} Property changes on: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/sql/Token.java ___________________________________________________________________ Added: svn:mime-type + text/plain