svnno****@sourc*****
svnno****@sourc*****
2009年 4月 13日 (月) 02:21:06 JST
Revision: 3232 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=3232 Author: daisuke_m Date: 2009-04-13 02:21:06 +0900 (Mon, 13 Apr 2009) Log Message: ----------- tutorial整備 Modified Paths: -------------- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/composer/exporter/SqlExporter.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/composer/importer/DatabaseImporter.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/generic/GenericDialect.java eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/CleanDatabaseMojo.java eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/JiemamyMojo.java metis/jiemamy-tutorial/trunk/pom.xml metis/jiemamy-tutorial/trunk/src/main/java/org/jiemamy/tutorial/JiemamyServlet.java Removed Paths: ------------- metis/jiemamy-tutorial/trunk/src/main/webapp/WEB-INF/classes/ -------------- next part -------------- Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/composer/exporter/SqlExporter.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/composer/exporter/SqlExporter.java 2009-04-12 16:15:01 UTC (rev 3231) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/composer/exporter/SqlExporter.java 2009-04-12 17:21:06 UTC (rev 3232) @@ -55,6 +55,12 @@ /** ConfigKey: 出力データセット番号 (Integer) */ public static final String DATA_SET_INDEX = "dataSetIndex"; + /** COnfigKey: DROP文を出力するかどうか (Boolean) */ + public static final String DROP = "drop"; + + /** COnfigKey: DROP文を出力するかどうか (Boolean) */ + public static final String SCHEMA = "schema"; + public boolean exportModel(RootModel rootModel, SqlExportConfig config) throws ExportException { Validate.notNull(rootModel); Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/composer/importer/DatabaseImporter.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/composer/importer/DatabaseImporter.java 2009-04-12 16:15:01 UTC (rev 3231) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/composer/importer/DatabaseImporter.java 2009-04-12 17:21:06 UTC (rev 3232) @@ -35,9 +35,7 @@ import org.jiemamy.composer.ImportException; import org.jiemamy.composer.Importer; import org.jiemamy.dialect.Dialect; -import org.jiemamy.dialect.generic.GenericDialect; import org.jiemamy.exception.DriverNotFoundException; -import org.jiemamy.exception.GenericModelingModeException; import org.jiemamy.model.RootModel; import org.jiemamy.model.attribute.constraint.ForeignKey; import org.jiemamy.model.entity.EntityModel; @@ -101,9 +99,6 @@ Connection connection = null; try { dialect = config.getDialect(); - if (dialect instanceof GenericDialect) { - throw new GenericModelingModeException(); - } Properties props = new Properties(); props.setProperty("user", config.getUsername()); @@ -116,8 +111,6 @@ DatabaseMetaData meta = connection.getMetaData(); dialect.importMetadata(rootModel, meta, config, importedEntities, importedForeignKeys); - } catch (GenericModelingModeException e) { - throw new ImportException(e); } catch (DriverNotFoundException e) { throw new ImportException(e); } catch (InstantiationException e) { Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/generic/GenericDialect.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/generic/GenericDialect.java 2009-04-12 16:15:01 UTC (rev 3231) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/generic/GenericDialect.java 2009-04-12 17:21:06 UTC (rev 3232) @@ -18,38 +18,32 @@ */ package org.jiemamy.dialect.generic; -import java.sql.DatabaseMetaData; import java.util.List; -import java.util.Map; import org.apache.commons.collections15.list.UnmodifiableList; import org.jiemamy.dialect.BuiltinDataTypeMold; import org.jiemamy.dialect.DataTypeResolver; -import org.jiemamy.dialect.Dialect; import org.jiemamy.dialect.EmitConfig; -import org.jiemamy.dialect.ImportMetadataConfig; -import org.jiemamy.dialect.MoldManager; +import org.jiemamy.dialect.internal.AbstractDialect; import org.jiemamy.dialect.internal.BuiltinDataTypeMoldImpl; import org.jiemamy.dialect.internal.impl.DefaultDataTypeResolver; +import org.jiemamy.dialect.internal.impl.DefaultDialectInitializer; import org.jiemamy.dialect.internal.impl.DefaultMoldManager; import org.jiemamy.model.RootModel; -import org.jiemamy.model.attribute.constraint.ForeignKey; 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.entity.EntityModel; import org.jiemamy.model.sql.SqlStatement; import org.jiemamy.utils.CollectionsUtil; -import org.jiemamy.validator.AllValidator; -import org.jiemamy.validator.Validator; /** * 全てのSQL方言に対応し得る、最大公約数的なSQL方言実装クラス。 - * @author daisuke + * + * @author daisuke */ -public final class GenericDialect implements Dialect { +public final class GenericDialect extends AbstractDialect { private static List<BuiltinDataTypeMold> typeList; @@ -77,80 +71,35 @@ typeList = UnmodifiableList.decorate(list); } - private final MoldManager moldManager; - - private final DataTypeResolver dataTypeResolver; - /** * インスタンスを生成する。 */ public GenericDialect() { - moldManager = new DefaultMoldManager(typeList); - dataTypeResolver = new DefaultDataTypeResolver(moldManager); + super(new DefaultDialectInitializer(new DefaultMoldManager(typeList)) { + + private DefaultDataTypeResolver defaultDataTypeResolver; + + + @Override + public DataTypeResolver getDataTypeResolver() { + if (defaultDataTypeResolver == null) { + defaultDataTypeResolver = new DefaultDataTypeResolver(getMoldManager()); + } + return defaultDataTypeResolver; + } + }); } + @Override public List<SqlStatement> emitStatements(RootModel rootModel, EmitConfig config) { throw new UnsupportedOperationException(); } - public BuiltinDataTypeMold findDataTypeMold(DataTypeCategory category) { - return findDataTypeMold(category, category.name()); - } - - public BuiltinDataTypeMold findDataTypeMold(DataTypeCategory category, String typeName) { - for (BuiltinDataTypeMold mold : typeList) { - if (mold.getCategory() == category && mold.getName().equals(typeName)) { - return mold; - } - } - for (BuiltinDataTypeMold mold : typeList) { - if (mold.getName().equals(typeName)) { - return mold; - } - } - for (BuiltinDataTypeMold mold : typeList) { - if (mold.getCategory() == category) { - return mold; - } - } - return BuiltinDataTypeMold.UNKNOWN; - } - - public List<BuiltinDataTypeMold> getAllDataTypes() { - return typeList; - } - - public String getConnectionUriTemplate() { - return null; - } - - public DataTypeResolver getDataTypeResolver() { - assert dataTypeResolver != null; - return dataTypeResolver; - } - - public MoldManager getMoldManager() { - return moldManager; - } - public String getName() { return "Generic Database"; } - public Validator getValidator() { - return new AllValidator(); - } - - public void importMetadata(RootModel rootModel, DatabaseMetaData meta, ImportMetadataConfig config, - Map<String, EntityModel> importedEntities, Map<String, ForeignKey> importedForeignKeys) { - throw new UnsupportedOperationException(); - } - - public RootModel parseStatements(List<SqlStatement> statements) { - throw new UnsupportedOperationException(); - } - @Override public String toString() { return this.getClass().getName(); Modified: eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/CleanDatabaseMojo.java =================================================================== --- eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/CleanDatabaseMojo.java 2009-04-12 16:15:01 UTC (rev 3231) +++ eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/CleanDatabaseMojo.java 2009-04-12 17:21:06 UTC (rev 3232) @@ -41,13 +41,12 @@ * TODO for daisuke * * @goal cleanDatabase - * @phase pre-integration-test + * @phase process-resources * @author daisuke */ public class CleanDatabaseMojo extends AbstractMojo { - /** TODO for daisuke */ - private static final String DIALECT = "org.jiemamy.dialect.postgresql.PostgresqlDialect"; + private static final String DIALECT = "org.jiemamy.dialect.generic.GenericDialect"; /** * @parameter Modified: eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/JiemamyMojo.java =================================================================== --- eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/JiemamyMojo.java 2009-04-12 16:15:01 UTC (rev 3231) +++ eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/JiemamyMojo.java 2009-04-12 17:21:06 UTC (rev 3232) @@ -37,7 +37,7 @@ * Goal which execute Exporter. * * @goal jiemamy - * @phase pre-integration-test + * @phase process-resources * @author daisuke */ public class JiemamyMojo extends AbstractMojo { @@ -94,6 +94,8 @@ DefaultSqlExportConfig config = new DefaultSqlExportConfig(); config.setOutputFile(new File((String) parameter.get(SqlExporter.OUTPUT_FILE))); config.setOverwrite(Boolean.valueOf((String) parameter.get(SqlExporter.OVERWRITE))); + config.setEmitDropStatements(Boolean.valueOf((String) parameter.get(SqlExporter.DROP))); + config.setEmitCreateSchema(Boolean.valueOf((String) parameter.get(SqlExporter.SCHEMA))); String indexObject = (String) parameter.get(SqlExporter.DATA_SET_INDEX); config.setDataSetIndex(indexObject == null ? -1 : Integer.valueOf(indexObject)); Modified: metis/jiemamy-tutorial/trunk/pom.xml =================================================================== --- metis/jiemamy-tutorial/trunk/pom.xml 2009-04-12 16:15:01 UTC (rev 3231) +++ metis/jiemamy-tutorial/trunk/pom.xml 2009-04-12 17:21:06 UTC (rev 3232) @@ -11,6 +11,20 @@ <defaultGoal>validate</defaultGoal> <plugins> <plugin> + <artifactId>maven-resources-plugin</artifactId> + <configuration> + <encoding>UTF-8</encoding> + </configuration> + </plugin> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + <target>1.5</target> + <encoding>UTF-8</encoding> + </configuration> + </plugin> + <plugin> <groupId>org.jiemamy</groupId> <artifactId>maven-jiemamy-plugin</artifactId> <executions> @@ -28,11 +42,10 @@ <goal>jiemamy</goal> </goals> <configuration> - <inputFile>src/database/jiemamy.jer</inputFile> + <inputFile>./src/database/jiemamy.jer</inputFile> <parameter> - <outputFile>target/jiemamy.sql</outputFile> + <outputFile>./target/jiemamy.sql</outputFile> <drop>false</drop> - <DML>true</DML> <schema>false</schema> <overwrite>true</overwrite> <dataSetIndex>0</dataSetIndex> @@ -55,8 +68,8 @@ <configuration> <username>${database.username}</username> <password>${database.password}</password> - <driver>org.postgresql.Driver</driver> - <uri>jdbc:postgresql://localhost:5432/jiemamy</uri> + <driver>${database.driver}</driver> + <uri>${database.uri}</uri> </configuration> </plugin> <plugin> @@ -73,7 +86,7 @@ <configuration> <autocommit>true</autocommit> <srcFiles> - <srcFile>target/jiemamy.sql</srcFile> + <srcFile>./target/jiemamy.sql</srcFile> </srcFiles> </configuration> </execution> @@ -89,8 +102,8 @@ <username>${database.username}</username> <password>${database.password}</password> <settingsKeys>sensibleKey</settingsKeys> - <driver>org.postgresql.Driver</driver> - <url>jdbc:postgresql://localhost:5432/jiemamy</url> + <driver>${database.driver}</driver> + <url>${database.uri}</url> <skip>${maven.test.skip}</skip> </configuration> </plugin> @@ -165,5 +178,7 @@ <jetty.version>6.1.4</jetty.version> <database.username>postgres</database.username> <database.password>postgres</database.password> + <database.driver>org.postgresql.Driver</database.driver> + <database.uri>jdbc:postgresql://localhost:5432/jiemamy</database.uri> </properties> </project> Modified: metis/jiemamy-tutorial/trunk/src/main/java/org/jiemamy/tutorial/JiemamyServlet.java =================================================================== --- metis/jiemamy-tutorial/trunk/src/main/java/org/jiemamy/tutorial/JiemamyServlet.java 2009-04-12 16:15:01 UTC (rev 3231) +++ metis/jiemamy-tutorial/trunk/src/main/java/org/jiemamy/tutorial/JiemamyServlet.java 2009-04-12 17:21:06 UTC (rev 3232) @@ -23,9 +23,12 @@ private static final String NL = System.getProperty("line.separator"); private static final String PASSWORD = "postgres"; + private static final String USERNAME = "postgres"; + private static final String URI = "jdbc:postgresql://localhost:5432/jiemamy"; + @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -56,7 +59,7 @@ sb.append("<table border=\"1\">").append(NL); sb.append("<caption>商品一覧</caption>").append(NL); - sb.append("<tr><th>商品名</th><th>価格</th></tr>").append(NL); + sb.append("<tr><th>ID</th><th>商品名</th><th>価格</th></tr>").append(NL); try { Class.forName("org.postgresql.Driver"); @@ -66,12 +69,15 @@ rs = st.executeQuery("SELECT * FROM T_ITEM"); if (rs != null) { while (rs.next()) { + int id = rs.getInt("ID"); String item = rs.getString("ITEM_NAME"); int price = rs.getInt("PRICE"); sb.append("<tr><th>"); + sb.append(id); + sb.append("</th><td>"); sb.append(item); - sb.append("</th><td>"); + sb.append("</td><td style='text-align:right'>"); sb.append(price); sb.append("</td></tr>").append(NL); } @@ -99,6 +105,7 @@ try { db.close(); } catch (SQLException e) { + // ignore } } } @@ -108,6 +115,7 @@ try { st.close(); } catch (SQLException e) { + // ignore } } } @@ -117,6 +125,7 @@ try { rs.close(); } catch (SQLException e) { + // ignore } } }