[Jiemamy-notify] commit [1996] refactor

アーカイブの一覧に戻る

svnno****@sourc***** svnno****@sourc*****
2008年 10月 5日 (日) 13:42:31 JST


Revision: 1996
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=jiemamy&view=rev&rev=1996
Author:   daisuke_m
Date:     2008-10-05 13:42:31 +0900 (Sun, 05 Oct 2008)

Log Message:
-----------
refactor

Modified Paths:
--------------
    artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/DatabaseImporter.java
    artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/DomainModelImpl.java
    artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/connection/ForeignKeyModelImpl.java
    artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/utils/processor/connection/foreignkey/UpdateMappingsProcessor.java
    artemis/trunk/org.jiemamy.core/src/main/resources/jiemamy-core.dicon
    artemis/trunk/org.jiemamy.dialect/src/main/java/org/jiemamy/dialect/AbstractDialect.java
    artemis/trunk/org.jiemamy.dialect/src/main/java/org/jiemamy/dialect/general/GeneralDialect.java
    artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/model/typedef/SerializeDomainModel.java
    zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/creator/FactoryStrategy.java
    zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/spec/extension/dialect/Dialect.java


-------------- next part --------------
Modified: artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/DatabaseImporter.java
===================================================================
--- artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/DatabaseImporter.java	2008-10-05 00:44:59 UTC (rev 1995)
+++ artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/DatabaseImporter.java	2008-10-05 04:42:31 UTC (rev 1996)
@@ -2,6 +2,7 @@
 
 import java.net.URL;
 import java.sql.Connection;
+import java.sql.DatabaseMetaData;
 import java.sql.Driver;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -98,6 +99,7 @@
 			String className = ctx.getValue(DRIVER_CLASS_NAME);
 			Driver driver = DriverUtil.getDriverInstance(paths, className);
 			connection = driver.connect((String) ctx.getValue(URI), props);
+			DatabaseMetaData meta = connection.getMetaData();
 			
 			// 詰め替え
 			assert ctx.hasAdapter(DatabaseReadingContext.class);
@@ -105,8 +107,8 @@
 			
 			DatabaseReader reader = new DatabaseReader(dialect, readingCtx);
 			
-			reader.readEnities(connection, new EntityImportVisitor(connection, rootModel, ctx));
-			reader.readRelations(connection, new RelationImportVisitor(connection, rootModel, ctx));
+			reader.readEnities(connection, new EntityImportVisitor(meta, rootModel, ctx));
+			reader.readRelations(connection, new RelationImportVisitor(meta, rootModel, ctx));
 		} catch (RuntimeException e) {
 			// ランタイムは再スロー
 			throw e;
@@ -127,8 +129,8 @@
 	 */
 	class EntityImportVisitor extends AbstractResultSetVisitor<Void> {
 		
-		/** DB接続 */
-		private Connection connection;
+		/** DBメタデータ */
+		private DatabaseMetaData meta;
 		
 		/** 書き込み先モデル */
 		private RootModel rootModel;
@@ -150,13 +152,13 @@
 
 		/**
 		 * コンストラクタ。
-		 * @param connection DB接続
+		 * @param meta DBメタデータ
 		 * @param rootModel 書き込み先モデル
 		 * @param ctx インポートに関するコンテキスト情報
 		 * @category instance creation
 		 */
-		public EntityImportVisitor(Connection connection, RootModel rootModel, ImportContext ctx) {
-			this.connection = connection;
+		public EntityImportVisitor(DatabaseMetaData meta, RootModel rootModel, ImportContext ctx) {
+			this.meta = meta;
 			this.rootModel = rootModel;
 			String[] entityTypesValue = ctx.getValue(ENTITY_TYPES);
 			if (entityTypesValue == null) {
@@ -176,7 +178,7 @@
 		public Void visit(ResultSet entity) throws SQLException {
 			if ((entityTypes.contains(entity.getString("TABLE_TYPE")))
 					&& (selectedEntities == null || selectedEntities.contains(entity.getString("TABLE_NAME")))) {
-				AbstractEntityModel entityModel = dialect.createEntity(rootModel, entity, connection);
+				AbstractEntityModel entityModel = dialect.createEntity(rootModel, entity, meta);
 				if (entityModel != null) {
 					entityModel.setDescription(entity.getString("REMARKS"));
 					// UNDONE 制約などその他情報なども
@@ -194,10 +196,6 @@
 	 */
 	class RelationImportVisitor extends AbstractResultSetVisitor<Void> {
 		
-		/** DB接続 */
-		@SuppressWarnings("unused")
-		private Connection connection;
-		
 		/** 書き込み先モデル */
 		private RootModel rootModel;
 		
@@ -206,13 +204,12 @@
 
 		/**
 		 * コンストラクタ。
-		 * @param connection DB接続
+		 * @param meta DBメタデータ
 		 * @param rootModel 書き込み先モデル
 		 * @param ctx
 		 * @category instance creation
 		 */
-		public RelationImportVisitor(Connection connection, RootModel rootModel, ImportContext ctx) {
-			this.connection = connection;
+		public RelationImportVisitor(DatabaseMetaData meta, RootModel rootModel, ImportContext ctx) {
 			this.rootModel = rootModel;
 		}
 		

Modified: artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/DomainModelImpl.java
===================================================================
--- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/DomainModelImpl.java	2008-10-05 00:44:59 UTC (rev 1995)
+++ artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/DomainModelImpl.java	2008-10-05 04:42:31 UTC (rev 1996)
@@ -23,7 +23,6 @@
 import org.jiemamy.spec.model.constraint.Constraint;
 import org.jiemamy.spec.model.constraint.ConstraintSetModel;
 import org.jiemamy.spec.model.datatype.DataType;
-import org.jiemamy.spec.model.datatype.DataTypeAdapter;
 
 /**
  * ドメイン定義モデル
@@ -95,13 +94,6 @@
 	/**
 	 * {@inheritDoc}
 	 */
-	public <T extends DataTypeAdapter>T getAdapter(Class<T> adapter) {
-		throw new UnsupportedOperationException();
-	}
-	
-	/**
-	 * {@inheritDoc}
-	 */
 	public ConstraintSetModel getConstraint() {
 		return constraints;
 	}

Modified: artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/connection/ForeignKeyModelImpl.java
===================================================================
--- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/connection/ForeignKeyModelImpl.java	2008-10-05 00:44:59 UTC (rev 1995)
+++ artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/connection/ForeignKeyModelImpl.java	2008-10-05 04:42:31 UTC (rev 1996)
@@ -114,7 +114,7 @@
 		TableModel tableModel = (TableModel) getTarget();
 		List<ColumnModel> referencePkColumns = tableModel.getPrimaryKeyColumns();
 		for (ColumnModel referencePkColumn : referencePkColumns) {
-			ForeignKeyMapping mapping = new ForeignKeyMappingImpl();
+			ForeignKeyMapping mapping = rootModel.createJiemamyModel(ForeignKeyMapping.class).init();
 			mapping.setDefaultColumns(rootModel, (TableModel) getSource(), referencePkColumn, createColumn);
 			mappings.add(mapping);
 		}

Modified: artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/utils/processor/connection/foreignkey/UpdateMappingsProcessor.java
===================================================================
--- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/utils/processor/connection/foreignkey/UpdateMappingsProcessor.java	2008-10-05 00:44:59 UTC (rev 1995)
+++ artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/utils/processor/connection/foreignkey/UpdateMappingsProcessor.java	2008-10-05 04:42:31 UTC (rev 1996)
@@ -22,7 +22,6 @@
 import java.util.Collections;
 import java.util.List;
 
-import org.jiemamy.core.model.connection.ForeignKeyMappingImpl;
 import org.jiemamy.spec.Processor;
 import org.jiemamy.spec.exception.ElementNotFoundException;
 import org.jiemamy.spec.model.ColumnModel;
@@ -79,7 +78,7 @@
 			try {
 				fkModel.getMapping(referencePkColumn);
 			} catch (ElementNotFoundException e) {
-				ForeignKeyMapping mapping = new ForeignKeyMappingImpl();
+				ForeignKeyMapping mapping = rootModel.createJiemamyModel(ForeignKeyMapping.class).init();
 				mapping.setDefaultColumns(rootModel, sourceTable, referencePkColumn, createColumnWithFk);
 				additionalMappings.add(mapping);
 			}

Modified: artemis/trunk/org.jiemamy.core/src/main/resources/jiemamy-core.dicon
===================================================================
--- artemis/trunk/org.jiemamy.core/src/main/resources/jiemamy-core.dicon	2008-10-05 00:44:59 UTC (rev 1995)
+++ artemis/trunk/org.jiemamy.core/src/main/resources/jiemamy-core.dicon	2008-10-05 04:42:31 UTC (rev 1996)
@@ -23,6 +23,11 @@
 	<component class="org.jiemamy.core.model.dataset.InsertDataSetModelImpl" instance="prototype"/>
 	<component class="org.jiemamy.core.model.node.TableModelImpl" instance="prototype"/>
 	<component class="org.jiemamy.core.model.ColumnModelImpl" instance="prototype"/>
+	
+	<component class="org.jiemamy.core.model.constraint.NotNullConstraintModelImpl" instance="prototype" />
+	<component class="org.jiemamy.core.model.constraint.CheckConstraintModelImpl" instance="prototype" />
+	<component class="org.jiemamy.core.model.constraint.PrimaryKeyConstraintModelImpl" instance="prototype" />
+	<component class="org.jiemamy.core.model.constraint.UniqueConstraintModel" instance="prototype" />
 
 	<!-- Modelの自動登録 -->
 	<!--

Modified: artemis/trunk/org.jiemamy.dialect/src/main/java/org/jiemamy/dialect/AbstractDialect.java
===================================================================
--- artemis/trunk/org.jiemamy.dialect/src/main/java/org/jiemamy/dialect/AbstractDialect.java	2008-10-05 00:44:59 UTC (rev 1995)
+++ artemis/trunk/org.jiemamy.dialect/src/main/java/org/jiemamy/dialect/AbstractDialect.java	2008-10-05 04:42:31 UTC (rev 1996)
@@ -18,7 +18,6 @@
  */
 package org.jiemamy.dialect;
 
-import java.sql.Connection;
 import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -31,8 +30,6 @@
 import org.jiemamy.core.extension.dialect.mapping.SpecialDataTypeMapping;
 import org.jiemamy.core.extension.dialect.parser.DefaultModelParser;
 import org.jiemamy.core.extension.dialect.validator.DefaultIdentifierValidator;
-import org.jiemamy.core.model.constraint.NotNullConstraintModelImpl;
-import org.jiemamy.core.model.constraint.PrimaryKeyConstraintModelImpl;
 import org.jiemamy.core.model.datatype.adapter.SizedDataTypeAdapter;
 import org.jiemamy.core.utils.ForEachUtil;
 import org.jiemamy.core.utils.JmIOUtil;
@@ -47,6 +44,8 @@
 import org.jiemamy.spec.extension.dialect.mapping.DataTypeMapping;
 import org.jiemamy.spec.model.ColumnModel;
 import org.jiemamy.spec.model.RootModel;
+import org.jiemamy.spec.model.constraint.NotNullConstraintModel;
+import org.jiemamy.spec.model.constraint.PrimaryKeyConstraintModel;
 import org.jiemamy.spec.model.datatype.SpecialDataType;
 import org.jiemamy.spec.model.node.AbstractEntityModel;
 import org.jiemamy.spec.model.node.TableModel;
@@ -77,14 +76,14 @@
 	/**
 	 * {@inheritDoc}
 	 */
-	public AbstractEntityModel createEntity(RootModel rootModel, ResultSet entity, Connection connection)
+	public AbstractEntityModel createEntity(RootModel rootModel, ResultSet entity, DatabaseMetaData meta)
 			throws SQLException {
 		String type = entity.getString("TABLE_TYPE");
 		AbstractEntityModel result = null;
 		if ("TABLE".equals(type)) {
-			return createTable(rootModel, entity.getString("TABLE_NAME"), connection);
+			return createTable(rootModel, entity.getString("TABLE_NAME"), meta);
 		} else if ("VIEW".equals(type)) {
-			return createView(rootModel, entity.getString("TABLE_NAME"), connection);
+			return createView(rootModel, entity.getString("TABLE_NAME"), meta);
 		}
 		return result;
 	}
@@ -181,11 +180,11 @@
 	 * {@link DatabaseMetaData}から得られた結果を読み込み、{@link TableModel}を生成する。
 	 * @param rootModel 
 	 * @param tableName 読み込み対象テーブル名
-	 * @param connection コネクション
+	 * @param meta DBメタデータ
 	 * @return 読み込んだ結果生成された{@link TableModel}
 	 * @throws SQLException 
 	 */
-	private TableModel createTable(final RootModel rootModel, String tableName, Connection connection)
+	private TableModel createTable(final RootModel rootModel, String tableName, DatabaseMetaData meta)
 			throws SQLException {
 		final TableModel tableModel = rootModel.createJiemamyModel(TableModel.class).init(rootModel);
 		final List<ColumnModel> columns = new ArrayList<ColumnModel>();
@@ -195,8 +194,6 @@
 		ResultSet columnsResult = null;
 		ResultSet keysResult = null;
 		try {
-			DatabaseMetaData meta = connection.getMetaData();
-			
 			columnsResult = meta.getColumns("", null/* FIXME schema */, tableName, "%");
 			ForEachUtil.accept(columnsResult, new AbstractResultSetVisitor<List<ColumnModel>>() {
 				
@@ -211,7 +208,7 @@
 						String name = element.getString("COLUMN_NAME");
 						
 						ColumnModel column = rootModel.createJiemamyModel(ColumnModel.class).init(name, dataType);
-						tableModel.getColumns().add(column);
+						columns.add(column);
 						
 						if (dataType.hasAdapter(SizedDataTypeAdapter.class)) {
 							SizedDataTypeAdapter sized = dataType.getAdapter(SizedDataTypeAdapter.class);
@@ -226,7 +223,7 @@
 						column.setDefaultValue(element.getString("COLUMN_DEF"));
 						
 						if ("NO".equals(element.getString("IS_NULLABLE")) == false) {
-							column.addConstraint(new NotNullConstraintModelImpl());
+							column.addConstraint(rootModel.createJiemamyModel(NotNullConstraintModel.class).init());
 						}
 						
 						finalResult.add(column);
@@ -254,7 +251,8 @@
 						String columnName = element.getString("COLUMN_NAME");
 						for (ColumnModel column : columns) {
 							if (column.getName().equals(columnName)) {
-								column.addConstraint(new PrimaryKeyConstraintModelImpl());
+								column.addConstraint(rootModel.createJiemamyModel(PrimaryKeyConstraintModel.class)
+									.init());
 							}
 						}
 					} catch (SQLException ignore) {
@@ -269,10 +267,7 @@
 			JmIOUtil.closeQuietly(keysResult);
 		}
 		
-//		for (ColumnModel column : columns) {
-//			tableModel.getColumns().add(column);
-//		}
-		
+		tableModel.getColumns().addAll(columns);
 		return tableModel;
 	}
 	
@@ -280,16 +275,15 @@
 	 * {@link DatabaseMetaData}から得られた結果を読み込み、{@link ViewModel}を生成する。
 	 * @param rootModel 
 	 * @param viewName 読み込み対象ビュー名
-	 * @param connection コネクション
+	 * @param meta DBメタデータ
 	 * @return 読み込んだ結果生成された{@link ViewModel}
 	 * @throws SQLException 
 	 */
 	@SuppressWarnings("unused")
-	private ViewModel createView(RootModel rootModel, String viewName, Connection connection) throws SQLException {
+	private ViewModel createView(RootModel rootModel, String viewName, DatabaseMetaData meta) throws SQLException {
 		// UNDONE ビューの定義SQLを取得する一般的な手段が分からない。
 		// bacchusでは実は実装できなかった所。
 		String definition = null;
-		
 		ViewModel view = rootModel.createJiemamyModel(ViewModel.class).init(viewName, definition);
 		
 		return view;

Modified: artemis/trunk/org.jiemamy.dialect/src/main/java/org/jiemamy/dialect/general/GeneralDialect.java
===================================================================
--- artemis/trunk/org.jiemamy.dialect/src/main/java/org/jiemamy/dialect/general/GeneralDialect.java	2008-10-05 00:44:59 UTC (rev 1995)
+++ artemis/trunk/org.jiemamy.dialect/src/main/java/org/jiemamy/dialect/general/GeneralDialect.java	2008-10-05 04:42:31 UTC (rev 1996)
@@ -18,7 +18,7 @@
  */
 package org.jiemamy.dialect.general;
 
-import java.sql.Connection;
+import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 
 import org.jiemamy.core.extension.dialect.DefaultConnectionAdvisor;
@@ -94,7 +94,7 @@
 	/**
 	 * {@inheritDoc}
 	 */
-	public AbstractEntityModel createEntity(RootModel rootModel, ResultSet entity, Connection connection) {
+	public AbstractEntityModel createEntity(RootModel rootModel, ResultSet entity, DatabaseMetaData meta) {
 		throw new UnsupportedOperationException();
 	}
 	

Modified: artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/model/typedef/SerializeDomainModel.java
===================================================================
--- artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/model/typedef/SerializeDomainModel.java	2008-10-05 00:44:59 UTC (rev 1995)
+++ artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/model/typedef/SerializeDomainModel.java	2008-10-05 04:42:31 UTC (rev 1996)
@@ -25,7 +25,6 @@
 import org.jiemamy.spec.Processor;
 import org.jiemamy.spec.model.JiemamyModel;
 import org.jiemamy.spec.model.datatype.DataType;
-import org.jiemamy.spec.model.datatype.DataTypeAdapter;
 
 /**
  * DomainModelに対応するシリアライズ用のモデル。
@@ -55,14 +54,6 @@
 	/**
 	 * {@inheritDoc}
 	 */
-	public <T extends DataTypeAdapter>T getAdapter(Class<T> adapter) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-	
-	/**
-	 * {@inheritDoc}
-	 */
 	public List<Object> getAdapters() {
 		// TODO Auto-generated method stub
 		return null;
@@ -85,12 +76,4 @@
 		return null;
 	}
 	
-	/**
-	 * {@inheritDoc}
-	 */
-	public SerializeDomainModel removeAdapter() {
-		// TODO Auto-generated method stub
-		return null;
-	}
-	
 }

Modified: zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/creator/FactoryStrategy.java
===================================================================
--- zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/creator/FactoryStrategy.java	2008-10-05 00:44:59 UTC (rev 1995)
+++ zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/creator/FactoryStrategy.java	2008-10-05 04:42:31 UTC (rev 1996)
@@ -25,10 +25,10 @@
 public interface FactoryStrategy {
 	
 	/**
-	 * Jiemamy関連のインスタンスを生成する。
+	 * Jiemamy関連クラスのインスタンスを生成する。
 	 * @param <T> 
 	 * @param clazz 
-	 * @return Jiemamy関連のインスタンス
+	 * @return Jiemamy関連クラスのインスタンス
 	 */
 	<T>T create(Class<T> clazz);
 	

Modified: zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/spec/extension/dialect/Dialect.java
===================================================================
--- zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/spec/extension/dialect/Dialect.java	2008-10-05 00:44:59 UTC (rev 1995)
+++ zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/spec/extension/dialect/Dialect.java	2008-10-05 04:42:31 UTC (rev 1996)
@@ -18,7 +18,7 @@
  */
 package org.jiemamy.spec.extension.dialect;
 
-import java.sql.Connection;
+import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
@@ -39,11 +39,11 @@
 	 * 
 	 * @param rootModel 
 	 * @param entity エンティティ情報
-	 * @param connection DB接続
+	 * @param meta DBメタデータ
 	 * @return 生成された {@link AbstractEntityModel}
 	 * @throws SQLException 
 	 */
-	AbstractEntityModel createEntity(RootModel rootModel, ResultSet entity, Connection connection) throws SQLException;
+	AbstractEntityModel createEntity(RootModel rootModel, ResultSet entity, DatabaseMetaData meta) throws SQLException;
 	
 	/**
 	 * このSQL方言用の{@link ConnectionAdvisor}を取得する。


Jiemamy-notify メーリングリストの案内
アーカイブの一覧に戻る