[Jiemamy-notify:2043] commit [3163] IterableResult, ResultSetIteratorを諦め、TypeSafeResultSetを作成。 /

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 4月 7日 (火) 23:59:13 JST


Revision: 3163
          http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=3163
Author:   daisuke_m
Date:     2009-04-07 23:59:13 +0900 (Tue, 07 Apr 2009)

Log Message:
-----------
IterableResult, ResultSetIteratorを諦め、TypeSafeResultSetを作成。 /
schemaの取り扱いを一時中止。

Modified Paths:
--------------
    artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/DatabaseTest.java
    artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/TestDatabaseInstanceTest.java
    artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/JiemamySerializerTest.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/DatabaseReader.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/EntityImportVisitor.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/ForeignKeyImportVisitor.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/impl/DefaultEntityImportVisitor.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/impl/DefaultMoldManager.java
    hestia/trunk/org.jiemamy.eclipse.site/site.xml
    leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/ForEachUtil.java
    leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/JmIOUtil.java
    leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/metadata/TypeSafeDatabaseMetaData.java
    leto/jiemamy-test-helper/trunk/src/main/java/org/jiemamy/internal/test/CoreTestModelBuilder.java
    zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/dialect/MoldManager.java
    zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/DataTypeCategory.java

Added Paths:
-----------
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/visitor/AbstractTypeSafeResultSetVisitor.java


-------------- next part --------------
Modified: artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/DatabaseTest.java
===================================================================
--- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/DatabaseTest.java	2009-04-07 12:56:48 UTC (rev 3162)
+++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/DatabaseTest.java	2009-04-07 14:59:13 UTC (rev 3163)
@@ -22,6 +22,7 @@
 import static org.hamcrest.Matchers.notNullValue;
 import static org.junit.Assert.assertThat;
 
+import java.io.FileNotFoundException;
 import java.net.URL;
 import java.sql.Connection;
 import java.sql.Driver;
@@ -96,6 +97,8 @@
 						executer.execute(stmt.toString());
 					}
 				}
+			} catch (FileNotFoundException e) {
+				logger.warn(db.name() + " skip");
 			} finally {
 				JmIOUtil.closeQuietly(connection);
 			}

Modified: artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/TestDatabaseInstanceTest.java
===================================================================
--- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/TestDatabaseInstanceTest.java	2009-04-07 12:56:48 UTC (rev 3162)
+++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/TestDatabaseInstanceTest.java	2009-04-07 14:59:13 UTC (rev 3163)
@@ -64,7 +64,7 @@
 			URL[] paths = config.getDriverJarPaths();
 			if (existsAll(paths) == false) {
 				// driver jarファイルが見つからない場合、テストをスキップする
-				logger.info("skip");
+				logger.warn("skip");
 				continue;
 			}
 			String className = config.getDriverClassName();
@@ -76,7 +76,7 @@
 				assertThat(connection, is(notNullValue()));
 				logger.info("success");
 			} catch (Exception e) {
-				logger.info("failed");
+				logger.error("failed", e);
 				throw e;
 			} finally {
 				JmIOUtil.closeQuietly(connection);

Modified: artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/JiemamySerializerTest.java
===================================================================
--- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/JiemamySerializerTest.java	2009-04-07 12:56:48 UTC (rev 3162)
+++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/JiemamySerializerTest.java	2009-04-07 14:59:13 UTC (rev 3163)
@@ -108,8 +108,8 @@
 		// RootModel基本プロパティのチェック
 		assertThat(document, hasXPath("/jiemamy/dialect", is("org.jiemamy.dialect.mysql.MySqlDialect")));
 		assertThat(document, hasXPath("/jiemamy/schemaName", is("FOO")));
-		assertThat(document, hasXPath("/jiemamy/beginScript", is("BEGIN;")));
-		assertThat(document, hasXPath("/jiemamy/endScript", is("COMMIT;")));
+//		assertThat(document, hasXPath("/jiemamy/beginScript", is("BEGIN;")));
+//		assertThat(document, hasXPath("/jiemamy/endScript", is("COMMIT;")));
 		assertThat(document, hasXPath("/jiemamy/description", is("Jiemamyテストモデル1")));
 		
 		NodeList domainNodes =

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/DatabaseReader.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/DatabaseReader.java	2009-04-07 12:56:48 UTC (rev 3162)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/DatabaseReader.java	2009-04-07 14:59:13 UTC (rev 3163)
@@ -35,12 +35,12 @@
 import org.jiemamy.model.entity.EntityModel;
 import org.jiemamy.utils.CollectionsUtil;
 import org.jiemamy.utils.ForEachUtil;
-import org.jiemamy.utils.ForEachUtil.CollectionVisitor;
+import org.jiemamy.utils.ForEachUtil.TypeSafeResultSetVisitor;
 import org.jiemamy.utils.metadata.KeyMeta;
 import org.jiemamy.utils.metadata.TableMeta;
 import org.jiemamy.utils.metadata.TypeSafeDatabaseMetaData;
-import org.jiemamy.utils.metadata.TypeSafeDatabaseMetaData.IterableResult;
-import org.jiemamy.utils.visitor.AbstractCollectionVisitor;
+import org.jiemamy.utils.metadata.TypeSafeDatabaseMetaData.TypeSafeResultSet;
+import org.jiemamy.utils.visitor.AbstractTypeSafeResultSetVisitor;
 
 /**
  * データベースを読み込む。
@@ -91,7 +91,7 @@
 	 * @throws SQLException SQLの実行に失敗した場合
 	 * @throws IllegalArgumentException 引数に{@code null}を与えた場合
 	 */
-	public <T>T readEnities(CollectionVisitor<TableMeta, T, SQLException> visitor) throws SQLException {
+	public <T>T readEnities(TypeSafeResultSetVisitor<TableMeta, T, RuntimeException> visitor) throws SQLException {
 		assert dialect != null;
 		assert config != null;
 		assert metaData != null;
@@ -99,7 +99,7 @@
 		
 		String schema = config.getSchema();
 		
-		IterableResult<TableMeta> tables = metaData.getTables(null, schema, "%", null);
+		TypeSafeResultSet<TableMeta> tables = metaData.getTables(null, /*schema*/null, "%", null);
 		T result = ForEachUtil.accept(tables, visitor);
 		
 		return result;
@@ -114,18 +114,18 @@
 	 * @throws SQLException SQLの実行に失敗した場合
 	 * @throws IllegalArgumentException 引数に{@code null}を与えた場合
 	 */
-	public <T>Collection<T> readRelations(CollectionVisitor<KeyMeta, T, RuntimeException> visitor) throws SQLException {
+	public <T>Collection<T> readRelations(TypeSafeResultSetVisitor<KeyMeta, T, RuntimeException> visitor)
+			throws SQLException {
 		assert dialect != null;
 		assert config != null;
 		Validate.notNull(visitor);
 		
-		String schema = config.getSchema();
-		
 		Collection<String> entityNames = readEnities(new EntityNamesVisitor());
 		
 		List<T> result = CollectionsUtil.newArrayList();
 		for (String entityName : entityNames) {
-			IterableResult<KeyMeta> importedKeys = metaData.getImportedKeys(null, schema, entityName);
+			TypeSafeResultSet<KeyMeta> importedKeys =
+					metaData.getImportedKeys(null, /* TODO config.getSchema() */null, entityName);
 			result.add(ForEachUtil.accept(importedKeys, visitor));
 		}
 		return result;
@@ -143,7 +143,7 @@
 	 * @author daisuke
 	 */
 	private static class EntityNamesVisitor extends
-			AbstractCollectionVisitor<TableMeta, Collection<String>, SQLException> {
+			AbstractTypeSafeResultSetVisitor<TableMeta, Collection<String>, RuntimeException> {
 		
 		public void intialize(DatabaseMetaData meta, RootModel rootModel, ImportMetadataConfig config,
 				Map<String, EntityModel> importedEntities, DataTypeResolver dataTypeResolver) {

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/EntityImportVisitor.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/EntityImportVisitor.java	2009-04-07 12:56:48 UTC (rev 3162)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/EntityImportVisitor.java	2009-04-07 14:59:13 UTC (rev 3163)
@@ -18,14 +18,13 @@
  */
 package org.jiemamy.dialect.internal;
 
-import java.sql.SQLException;
 import java.util.Map;
 
 import org.jiemamy.dialect.DataTypeResolver;
 import org.jiemamy.dialect.ImportMetadataConfig;
 import org.jiemamy.model.RootModel;
 import org.jiemamy.model.entity.EntityModel;
-import org.jiemamy.utils.ForEachUtil.CollectionVisitor;
+import org.jiemamy.utils.ForEachUtil.TypeSafeResultSetVisitor;
 import org.jiemamy.utils.metadata.TableMeta;
 import org.jiemamy.utils.metadata.TypeSafeDatabaseMetaData;
 
@@ -34,7 +33,7 @@
  * 
  * @author daisuke
  */
-public interface EntityImportVisitor extends CollectionVisitor<TableMeta, Void, SQLException> {
+public interface EntityImportVisitor extends TypeSafeResultSetVisitor<TableMeta, Void, RuntimeException> {
 	
 	/**
 	 * ビジターを初期化する。

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/ForeignKeyImportVisitor.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/ForeignKeyImportVisitor.java	2009-04-07 12:56:48 UTC (rev 3162)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/ForeignKeyImportVisitor.java	2009-04-07 14:59:13 UTC (rev 3163)
@@ -22,7 +22,7 @@
 
 import org.jiemamy.model.RootModel;
 import org.jiemamy.model.attribute.constraint.ForeignKey;
-import org.jiemamy.utils.ForEachUtil.CollectionVisitor;
+import org.jiemamy.utils.ForEachUtil.TypeSafeResultSetVisitor;
 import org.jiemamy.utils.metadata.KeyMeta;
 
 /**
@@ -30,7 +30,7 @@
  * 
  * @author daisuke
  */
-public interface ForeignKeyImportVisitor extends CollectionVisitor<KeyMeta, Void, RuntimeException> {
+public interface ForeignKeyImportVisitor extends TypeSafeResultSetVisitor<KeyMeta, Void, RuntimeException> {
 	
 	/**
 	 * ビジターを初期化する。

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/impl/DefaultEntityImportVisitor.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/impl/DefaultEntityImportVisitor.java	2009-04-07 12:56:48 UTC (rev 3162)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/impl/DefaultEntityImportVisitor.java	2009-04-07 14:59:13 UTC (rev 3163)
@@ -53,8 +53,9 @@
 import org.jiemamy.utils.metadata.TableMeta;
 import org.jiemamy.utils.metadata.TypeSafeDatabaseMetaData;
 import org.jiemamy.utils.metadata.ColumnMeta.Nullable;
-import org.jiemamy.utils.metadata.TypeSafeDatabaseMetaData.IterableResult;
+import org.jiemamy.utils.metadata.TypeSafeDatabaseMetaData.TypeSafeResultSet;
 import org.jiemamy.utils.visitor.AbstractCollectionVisitor;
+import org.jiemamy.utils.visitor.AbstractTypeSafeResultSetVisitor;
 
 /**
  * {@link EntityImportVisitor}のデフォルト実装クラス。
@@ -169,12 +170,12 @@
 		
 		tableModel.setName(tableName);
 		
-		IterableResult<ColumnMeta> columnsResult = null;
-		IterableResult<PrimaryKeyMeta> keysResult = null;
+		TypeSafeResultSet<ColumnMeta> columnsResult = null;
+		TypeSafeResultSet<PrimaryKeyMeta> keysResult = null;
 		try {
-			columnsResult = meta.getColumns("", config.getSchema(), tableName, "%");
+			columnsResult = meta.getColumns("", /* TODO config.getSchema()*/null, tableName, "%");
 			ForEachUtil.accept(columnsResult,
-					new AbstractCollectionVisitor<ColumnMeta, List<ColumnModel>, SQLException>() {
+					new AbstractTypeSafeResultSetVisitor<ColumnMeta, List<ColumnModel>, SQLException>() {
 						
 						public List<ColumnModel> visit(ColumnMeta element) {
 							BuiltinDataType dataType =
@@ -211,22 +212,23 @@
 						
 					});
 			
-			keysResult = meta.getPrimaryKeys("", config.getSchema(), tableName);
-			ForEachUtil.accept(keysResult, new AbstractCollectionVisitor<PrimaryKeyMeta, Boolean, SQLException>() {
-				
-				public Boolean visit(PrimaryKeyMeta element) {
-					PrimaryKey primaryKey = factory.newModel(PrimaryKey.class);
-					for (ColumnModel columnModel : columns) {
-						if (columnModel.getName().equals(element.columnName)) {
-							ColumnRef columnRef = factory.newReference(columnModel);
-							primaryKey.getKeyColumns().add(columnRef);
+			keysResult = meta.getPrimaryKeys("", /* TODO config.getSchema()*/null, tableName);
+			ForEachUtil.accept(keysResult,
+					new AbstractTypeSafeResultSetVisitor<PrimaryKeyMeta, Boolean, SQLException>() {
+						
+						public Boolean visit(PrimaryKeyMeta element) {
+							PrimaryKey primaryKey = factory.newModel(PrimaryKey.class);
+							for (ColumnModel columnModel : columns) {
+								if (columnModel.getName().equals(element.columnName)) {
+									ColumnRef columnRef = factory.newReference(columnModel);
+									primaryKey.getKeyColumns().add(columnRef);
+								}
+							}
+							tableModel.getAttributes().add(primaryKey);
+							return null;
 						}
-					}
-					tableModel.getAttributes().add(primaryKey);
-					return null;
-				}
-				
-			});
+						
+					});
 		} finally {
 			JmIOUtil.closeQuietly(columnsResult);
 			JmIOUtil.closeQuietly(keysResult);

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/impl/DefaultMoldManager.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/impl/DefaultMoldManager.java	2009-04-07 12:56:48 UTC (rev 3162)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/internal/impl/DefaultMoldManager.java	2009-04-07 14:59:13 UTC (rev 3163)
@@ -51,7 +51,6 @@
 	}
 	
 	public BuiltinDataTypeMold findDataTypeMold(DataTypeCategory category, String typeName) {
-		Validate.notNull(category);
 		Validate.notNull(typeName);
 		for (BuiltinDataTypeMold mold : typeList) {
 			if (mold.getCategory() == category && mold.getName().equals(typeName)) {

Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/visitor/AbstractTypeSafeResultSetVisitor.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/visitor/AbstractTypeSafeResultSetVisitor.java	                        (rev 0)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/visitor/AbstractTypeSafeResultSetVisitor.java	2009-04-07 14:59:13 UTC (rev 3163)
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on 2008/06/24
+ *
+ * This file is part of Jiemamy.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.utils.visitor;
+
+import org.jiemamy.utils.ForEachUtil;
+import org.jiemamy.utils.metadata.TypeSafeDatabaseMetaData.TypeSafeResultSet;
+
+/**
+ * {@link TypeSafeResultSet}に対するビジターの抽象クラス。
+ * 
+ * @author daisuke
+ * @param <T> Collectionが保持する型
+ * @param <R> forEachが返すべき戻り値の型
+ * @param <X> スローする可能性のある例外
+ */
+public abstract class AbstractTypeSafeResultSetVisitor<T, R, X extends Exception> implements
+		ForEachUtil.TypeSafeResultSetVisitor<T, R, X> {
+	
+	/** ループが終了した後、forEachが返すべき戻り値 */
+	protected R finalResult;
+	
+
+	/**
+	 * インスタンスを生成する。
+	 */
+	public AbstractTypeSafeResultSetVisitor() {
+		init();
+	}
+	
+	public R getFinalResult() {
+		return finalResult;
+	}
+	
+	@Override
+	public String toString() {
+		return finalResult.toString();
+	}
+	
+	/**
+	 * 最終戻り値の初期化を行う。
+	 */
+	protected void init() {
+		finalResult = null;
+	}
+	
+}


Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/visitor/AbstractTypeSafeResultSetVisitor.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: hestia/trunk/org.jiemamy.eclipse.site/site.xml
===================================================================
--- hestia/trunk/org.jiemamy.eclipse.site/site.xml	2009-04-07 12:56:48 UTC (rev 3162)
+++ hestia/trunk/org.jiemamy.eclipse.site/site.xml	2009-04-07 14:59:13 UTC (rev 3163)
@@ -51,6 +51,10 @@
    <feature url="features/org.jiemamy.eclipse.dialect.sql99.feature_0.2.0.200903232213.jar" id="org.jiemamy.eclipse.dialect.sql99.feature" version="0.2.0.200903232213">
       <category name="jiemamy_eclipse_dialects"/>
    </feature>
+   <feature url="features/org.jiemamy.eclipse.importer.jpa.feature_0.2.0.qualifier.jar" id="org.jiemamy.eclipse.importer.jpa.feature" version="0.2.0.qualifier">
+      <category name="jiemamy_eclipse_importers"/>
+   </feature>
    <category-def name="jiemamy_eclipse_model_editor" label="Jiemamy Eclipse Model Editor"/>
    <category-def name="jiemamy_eclipse_dialects" label="Jiemamy Eclipse Dialects"/>
+   <category-def name="jiemamy_eclipse_importers" label="Jiemamy Eclipse Importers"/>
 </site>

Modified: leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/ForEachUtil.java
===================================================================
--- leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/ForEachUtil.java	2009-04-07 12:56:48 UTC (rev 3162)
+++ leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/ForEachUtil.java	2009-04-07 14:59:13 UTC (rev 3163)
@@ -26,6 +26,8 @@
 
 import org.apache.commons.lang.Validate;
 
+import org.jiemamy.utils.metadata.TypeSafeDatabaseMetaData.TypeSafeResultSet;
+
 /**
  * {@link Collection}や{@link Map}等、複数の要素を持つObjectに対して、全ての要素に処理を行うためのユーティリティ。
  * 
@@ -107,6 +109,28 @@
 	}
 	
 	/**
+	 * TODO for daisuke
+	 * 
+	 * @param <R>
+	 * @param <X>
+	 * @param target
+	 * @param visitor
+	 * @return
+	 * @throws SQLException
+	 * @throws X
+	 */
+	public static <T, R, X extends Exception>R accept(TypeSafeResultSet<T> target,
+			TypeSafeResultSetVisitor<T, R, X> visitor) throws SQLException, X {
+		Validate.notNull(target);
+		Validate.notNull(visitor);
+		
+		while (target.next()) {
+			visitor.visit(target.getResult());
+		}
+		return visitor.getFinalResult();
+	}
+	
+	/**
 	 * ユーティリティクラス。
 	 */
 	private ForEachUtil() {
@@ -197,4 +221,31 @@
 		R visit(T element) throws SQLException, X;
 	}
 	
+	/**
+	 * {@link TypeSafeResultSet}に対するビジター。
+	 * 
+	 * @param <T> ビジターが受け取る要素の型
+	 * @param <R> forEachが返すべき戻り値の型
+	 * @param <X> visitメソッドが投げる可能性のある例外
+	 * @author daisuke
+	 */
+	public static interface TypeSafeResultSetVisitor<T, R, X extends Exception> {
+		
+		/**
+		 * ループが終了した後、acceptが返すべき戻り値を取得する。
+		 * 
+		 * @return ループが終了した後、acceptが返すべき戻り値
+		 */
+		R getFinalResult();
+		
+		/**
+		 * 処理内容を記述するメソッド。
+		 * 
+		 * @param element 処理対象要素
+		 * @return 引き続きacceptを継続する場合null、ループを終了する場合acceptが返すべき戻り値を返す。
+		 * @throws X ビジタが指定した例外が発生した場合
+		 * @throws SQLException SQLの実行に失敗した場合
+		 */
+		R visit(T element) throws SQLException, X;
+	}
 }

Modified: leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/JmIOUtil.java
===================================================================
--- leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/JmIOUtil.java	2009-04-07 12:56:48 UTC (rev 3162)
+++ leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/JmIOUtil.java	2009-04-07 14:59:13 UTC (rev 3163)
@@ -25,7 +25,7 @@
 
 import org.apache.commons.io.IOUtils;
 
-import org.jiemamy.utils.metadata.TypeSafeDatabaseMetaData.IterableResult;
+import org.jiemamy.utils.metadata.TypeSafeDatabaseMetaData.TypeSafeResultSet;
 
 /**
  * 入出力ユーティリティクラス。
@@ -75,12 +75,12 @@
 	/**
 	 * 無条件にリソースを閉じる。
 	 * 
-	 * <p>{@link IterableResult#close()} と等価であるが、例外を無視する。
+	 * <p>{@link TypeSafeResultSet#close()} と等価であるが、例外を無視する。
 	 * 主に finally 句内で使われることを想定している。</p>
 	 * 
 	 * @param columnsResult 閉じる対象。nullでも、既にclose済みであっても構わない
 	 */
-	public static void closeQuietly(IterableResult<?> columnsResult) {
+	public static void closeQuietly(TypeSafeResultSet<?> columnsResult) {
 		if (columnsResult != null) {
 			try {
 				columnsResult.close();

Modified: leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/metadata/TypeSafeDatabaseMetaData.java
===================================================================
--- leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/metadata/TypeSafeDatabaseMetaData.java	2009-04-07 12:56:48 UTC (rev 3162)
+++ leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/metadata/TypeSafeDatabaseMetaData.java	2009-04-07 14:59:13 UTC (rev 3163)
@@ -25,7 +25,6 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Iterator;
-import java.util.NoSuchElementException;
 
 import org.apache.commons.lang.Validate;
 import org.slf4j.Logger;
@@ -85,10 +84,10 @@
 	 * @return 属性情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<AttributesMeta> getAttributes(String catalog, String schemaPattern, String typeNamePattern,
+	public TypeSafeResultSet<AttributesMeta> getAttributes(String catalog, String schemaPattern, String typeNamePattern,
 			String attributeNamePattern) throws SQLException {
 		ResultSet attributes = meta.getAttributes(catalog, schemaPattern, typeNamePattern, attributeNamePattern);
-		return new IterableResult<AttributesMeta>(attributes, AttributesMeta.class);
+		return new TypeSafeResultSet<AttributesMeta>(attributes, AttributesMeta.class);
 	}
 	
 	/**
@@ -102,10 +101,10 @@
 	 * @return 識別子情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<BestRowIdentifierMeta> getBestRowIdentifier(String catalog, String schema, String table,
+	public TypeSafeResultSet<BestRowIdentifierMeta> getBestRowIdentifier(String catalog, String schema, String table,
 			int scope, boolean nullable) throws SQLException {
 		ResultSet bestRowIdentifier = meta.getBestRowIdentifier(catalog, schema, table, scope, nullable);
-		return new IterableResult<BestRowIdentifierMeta>(bestRowIdentifier, BestRowIdentifierMeta.class);
+		return new TypeSafeResultSet<BestRowIdentifierMeta>(bestRowIdentifier, BestRowIdentifierMeta.class);
 	}
 	
 	/**
@@ -114,9 +113,9 @@
 	 * @return カタログ名情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<CatalogMeta> getCatalogs() throws SQLException {
+	public TypeSafeResultSet<CatalogMeta> getCatalogs() throws SQLException {
 		ResultSet catalogs = meta.getCatalogs();
-		return new IterableResult<CatalogMeta>(catalogs, CatalogMeta.class);
+		return new TypeSafeResultSet<CatalogMeta>(catalogs, CatalogMeta.class);
 	}
 	
 	/**
@@ -129,10 +128,10 @@
 	 * @return アクセス権情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<ColumnPrivilegeMeta> getColumnPrivileges(String catalog, String schema, String table,
+	public TypeSafeResultSet<ColumnPrivilegeMeta> getColumnPrivileges(String catalog, String schema, String table,
 			String columnNamePattern) throws SQLException {
 		ResultSet columnPrivileges = meta.getColumnPrivileges(catalog, schema, table, columnNamePattern);
-		return new IterableResult<ColumnPrivilegeMeta>(columnPrivileges, ColumnPrivilegeMeta.class);
+		return new TypeSafeResultSet<ColumnPrivilegeMeta>(columnPrivileges, ColumnPrivilegeMeta.class);
 	}
 	
 	/**
@@ -146,10 +145,10 @@
 	 * @throws SQLException SQLの実行に失敗した場合
 	 * @see DatabaseMetaData#getColumns(String, String, String, String)
 	 */
-	public IterableResult<ColumnMeta> getColumns(String catalog, String schemaPattern, String tableNamePattern,
+	public TypeSafeResultSet<ColumnMeta> getColumns(String catalog, String schemaPattern, String tableNamePattern,
 			String columnNamePattern) throws SQLException {
 		ResultSet tables = meta.getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern);
-		return new IterableResult<ColumnMeta>(tables, ColumnMeta.class);
+		return new TypeSafeResultSet<ColumnMeta>(tables, ColumnMeta.class);
 	}
 	
 	/**
@@ -165,12 +164,12 @@
 	 * @return キー情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<KeyMeta> getCrossReference(String primaryCatalog, String primarySchema, String primaryTable,
+	public TypeSafeResultSet<KeyMeta> getCrossReference(String primaryCatalog, String primarySchema, String primaryTable,
 			String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException {
 		ResultSet crossReference =
 				meta.getCrossReference(primaryCatalog, primarySchema, primaryTable, foreignCatalog, foreignSchema,
 						foreignTable);
-		return new IterableResult<KeyMeta>(crossReference, KeyMeta.class);
+		return new TypeSafeResultSet<KeyMeta>(crossReference, KeyMeta.class);
 	}
 	
 	/**
@@ -182,9 +181,9 @@
 	 * @return キー情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<KeyMeta> getExportedKeys(String catalog, String schema, String table) throws SQLException {
+	public TypeSafeResultSet<KeyMeta> getExportedKeys(String catalog, String schema, String table) throws SQLException {
 		ResultSet exportedKeys = meta.getExportedKeys(catalog, schema, table);
-		return new IterableResult<KeyMeta>(exportedKeys, KeyMeta.class);
+		return new TypeSafeResultSet<KeyMeta>(exportedKeys, KeyMeta.class);
 	}
 	
 	/**
@@ -196,9 +195,9 @@
 	 * @return キー情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<KeyMeta> getImportedKeys(String catalog, String schema, String table) throws SQLException {
+	public TypeSafeResultSet<KeyMeta> getImportedKeys(String catalog, String schema, String table) throws SQLException {
 		ResultSet importedKeys = meta.getImportedKeys(catalog, schema, table);
-		return new IterableResult<KeyMeta>(importedKeys, KeyMeta.class);
+		return new TypeSafeResultSet<KeyMeta>(importedKeys, KeyMeta.class);
 	}
 	
 	/**
@@ -212,10 +211,10 @@
 	 * @return インデックス情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<IndexInfoMeta> getIndexInfo(String catalog, String schema, String table, boolean unique,
+	public TypeSafeResultSet<IndexInfoMeta> getIndexInfo(String catalog, String schema, String table, boolean unique,
 			boolean approximate) throws SQLException {
 		ResultSet indexInfo = meta.getIndexInfo(catalog, schema, table, unique, approximate);
-		return new IterableResult<IndexInfoMeta>(indexInfo, IndexInfoMeta.class);
+		return new TypeSafeResultSet<IndexInfoMeta>(indexInfo, IndexInfoMeta.class);
 	}
 	
 	/**
@@ -227,10 +226,10 @@
 	 * @return キー情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<PrimaryKeyMeta> getPrimaryKeys(String catalog, String schema, String table)
+	public TypeSafeResultSet<PrimaryKeyMeta> getPrimaryKeys(String catalog, String schema, String table)
 			throws SQLException {
 		ResultSet primaryKeys = meta.getPrimaryKeys(catalog, schema, table);
-		return new IterableResult<PrimaryKeyMeta>(primaryKeys, PrimaryKeyMeta.class);
+		return new TypeSafeResultSet<PrimaryKeyMeta>(primaryKeys, PrimaryKeyMeta.class);
 	}
 	
 	/**
@@ -243,11 +242,11 @@
 	 * @return ストアドプロシージャ情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<ProcedureColumnsMeta> getProcedureColumns(String catalog, String schemaPattern,
+	public TypeSafeResultSet<ProcedureColumnsMeta> getProcedureColumns(String catalog, String schemaPattern,
 			String procedureNamePattern, String columnNamePattern) throws SQLException {
 		ResultSet procedureColumns =
 				meta.getProcedureColumns(catalog, schemaPattern, procedureNamePattern, columnNamePattern);
-		return new IterableResult<ProcedureColumnsMeta>(procedureColumns, ProcedureColumnsMeta.class);
+		return new TypeSafeResultSet<ProcedureColumnsMeta>(procedureColumns, ProcedureColumnsMeta.class);
 	}
 	
 	/**
@@ -259,10 +258,10 @@
 	 * @return ストアドプロシージャ情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<ProcedureMeta> getProcedures(String catalog, String schemaPattern, String procedureNamePattern)
+	public TypeSafeResultSet<ProcedureMeta> getProcedures(String catalog, String schemaPattern, String procedureNamePattern)
 			throws SQLException {
 		ResultSet procedures = meta.getProcedures(catalog, schemaPattern, procedureNamePattern);
-		return new IterableResult<ProcedureMeta>(procedures, ProcedureMeta.class);
+		return new TypeSafeResultSet<ProcedureMeta>(procedures, ProcedureMeta.class);
 	}
 	
 	/**
@@ -271,9 +270,9 @@
 	 * @return スキーマ名情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<SchemaMeta> getSchemas() throws SQLException {
+	public TypeSafeResultSet<SchemaMeta> getSchemas() throws SQLException {
 		ResultSet schemas = meta.getSchemas();
-		return new IterableResult<SchemaMeta>(schemas, SchemaMeta.class);
+		return new TypeSafeResultSet<SchemaMeta>(schemas, SchemaMeta.class);
 	}
 	
 	/**
@@ -285,10 +284,10 @@
 	 * @return テーブル階層情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<SuperTableMeta> getSuperTables(String catalog, String schemaPattern, String tableNamePattern)
+	public TypeSafeResultSet<SuperTableMeta> getSuperTables(String catalog, String schemaPattern, String tableNamePattern)
 			throws SQLException {
 		ResultSet superTables = meta.getSuperTables(catalog, schemaPattern, tableNamePattern);
-		return new IterableResult<SuperTableMeta>(superTables, SuperTableMeta.class);
+		return new TypeSafeResultSet<SuperTableMeta>(superTables, SuperTableMeta.class);
 	}
 	
 	/**
@@ -300,10 +299,10 @@
 	 * @return UDT階層情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<SuperTypeMeta> getSuperTypes(String catalog, String schemaPattern, String typeNamePattern)
+	public TypeSafeResultSet<SuperTypeMeta> getSuperTypes(String catalog, String schemaPattern, String typeNamePattern)
 			throws SQLException {
 		ResultSet superTypes = meta.getSuperTypes(catalog, schemaPattern, typeNamePattern);
-		return new IterableResult<SuperTypeMeta>(superTypes, SuperTypeMeta.class);
+		return new TypeSafeResultSet<SuperTypeMeta>(superTypes, SuperTypeMeta.class);
 	}
 	
 	/**
@@ -315,10 +314,10 @@
 	 * @return アクセス権情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<TablePrivilegeMeta> getTablePrivileges(String catalog, String schemaPattern,
+	public TypeSafeResultSet<TablePrivilegeMeta> getTablePrivileges(String catalog, String schemaPattern,
 			String tableNamePattern) throws SQLException {
 		ResultSet tablePrivileges = meta.getTablePrivileges(catalog, schemaPattern, tableNamePattern);
-		return new IterableResult<TablePrivilegeMeta>(tablePrivileges, TablePrivilegeMeta.class);
+		return new TypeSafeResultSet<TablePrivilegeMeta>(tablePrivileges, TablePrivilegeMeta.class);
 	}
 	
 	/**
@@ -332,10 +331,10 @@
 	 * @throws SQLException SQLの実行に失敗した場合
 	 * @see DatabaseMetaData#getTables(String, String, String, String[])
 	 */
-	public IterableResult<TableMeta> getTables(String catalog, String schemaPattern, String tableNamePattern,
+	public TypeSafeResultSet<TableMeta> getTables(String catalog, String schemaPattern, String tableNamePattern,
 			String[] types) throws SQLException {
 		ResultSet tables = meta.getTables(catalog, schemaPattern, tableNamePattern, types);
-		return new IterableResult<TableMeta>(tables, TableMeta.class);
+		return new TypeSafeResultSet<TableMeta>(tables, TableMeta.class);
 	}
 	
 	/**
@@ -344,9 +343,9 @@
 	 * @return テーブルタイプ情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<TableTypeMeta> getTableTypes() throws SQLException {
+	public TypeSafeResultSet<TableTypeMeta> getTableTypes() throws SQLException {
 		ResultSet tableTypes = meta.getTableTypes();
-		return new IterableResult<TableTypeMeta>(tableTypes, TableTypeMeta.class);
+		return new TypeSafeResultSet<TableTypeMeta>(tableTypes, TableTypeMeta.class);
 	}
 	
 	/**
@@ -356,9 +355,9 @@
 	 * @throws SQLException SQLの実行に失敗した場合
 	 * @see DatabaseMetaData#getTypeInfo()
 	 */
-	public IterableResult<TypeInfoMeta> getTypeInfo() throws SQLException {
+	public TypeSafeResultSet<TypeInfoMeta> getTypeInfo() throws SQLException {
 		ResultSet typeInfo = meta.getTypeInfo();
-		return new IterableResult<TypeInfoMeta>(typeInfo, TypeInfoMeta.class);
+		return new TypeSafeResultSet<TypeInfoMeta>(typeInfo, TypeInfoMeta.class);
 	}
 	
 	/**
@@ -371,10 +370,10 @@
 	 * @return ユーザ定義型情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<UDTMeta> getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types)
+	public TypeSafeResultSet<UDTMeta> getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types)
 			throws SQLException {
 		ResultSet udts = meta.getUDTs(catalog, schemaPattern, typeNamePattern, types);
-		return new IterableResult<UDTMeta>(udts, UDTMeta.class);
+		return new TypeSafeResultSet<UDTMeta>(udts, UDTMeta.class);
 	}
 	
 	/**
@@ -386,10 +385,10 @@
 	 * @return バージョンカラム情報
 	 * @throws SQLException SQLの実行に失敗した場合
 	 */
-	public IterableResult<VersionColumnMeta> getVersionColumns(String catalog, String schema, String table)
+	public TypeSafeResultSet<VersionColumnMeta> getVersionColumns(String catalog, String schema, String table)
 			throws SQLException {
 		ResultSet versionColumns = meta.getVersionColumns(catalog, schema, table);
-		return new IterableResult<VersionColumnMeta>(versionColumns, VersionColumnMeta.class);
+		return new TypeSafeResultSet<VersionColumnMeta>(versionColumns, VersionColumnMeta.class);
 	}
 	
 
@@ -399,14 +398,16 @@
 	 * @param <T> イテレートする型
 	 * @author daisuke
 	 */
-	public static class IterableResult<T> implements Iterable<T> {
+	public static class TypeSafeResultSet<T> {
 		
+		private static Logger logger = LoggerFactory.getLogger(TypeSafeResultSet.class);
+		
 		private ResultSet resultSet;
 		
 		private Class<T> resultClass;
 		
 
-		IterableResult(ResultSet resultSet, Class<T> resultClass) {
+		TypeSafeResultSet(ResultSet resultSet, Class<T> resultClass) {
 			Validate.notNull(resultSet);
 			Validate.notNull(resultClass);
 			this.resultSet = resultSet;
@@ -417,67 +418,15 @@
 		 * Releases this <code>ResultSet</code> object's database and
 		 * JDBC resources immediately instead of waiting for
 		 * this to happen when it is automatically closed.
+		 * 
 		 * @throws SQLException if a database access error occurs
 		 */
 		public void close() throws SQLException {
 			resultSet.close();
 		}
 		
-		public Iterator<T> iterator() {
-			return new ResultSetIterator<T>(resultSet, resultClass);
-		}
-	}
-	
-	/**
-	 * ResultSetをラップするイテレータ。
-	 * 
-	 * @param <T> イテレート要素の型
-	 * @author daisuke
-	 */
-	static class ResultSetIterator<T> implements Iterator<T> {
-		
-		private static Logger logger = LoggerFactory.getLogger(ResultSetIterator.class);
-		
-		private ResultSet resultSet;
-		
-		private Class<T> resultClass;
-		
-
-		/**
-		 * インスタンスを生成する。
-		 * 
-		 * <p>resultClassは、resultSetを引数に持つコンストラクタを持っていなければならない。</p>
-		 * 
-		 * @param resultSet イテレート対象の{@link ResultSet}
-		 * @param resultClass イテレート要素の型
-		 * @throws IllegalArgumentException 引数に{@code null}を与えた場合
-		 */
-		ResultSetIterator(ResultSet resultSet, Class<T> resultClass) {
-			Validate.notNull(resultSet);
-			Validate.notNull(resultClass);
-			this.resultSet = resultSet;
-			this.resultClass = resultClass;
-		}
-		
-		public boolean hasNext() {
-			boolean hasNext = false;
+		public T getResult() throws SQLException {
 			try {
-				// HACK nextしてpreviousするとか、イヤです。
-				hasNext = resultSet.next();
-				resultSet.previous();
-			} catch (SQLException e) {
-				logger.warn("SQLException", e);
-				// ignore
-			}
-			return hasNext;
-		}
-		
-		public T next() {
-			try {
-				boolean next = resultSet.next();
-				if (next == false) {
-					throw new NoSuchElementException();
-				}
 				Constructor<T> constructor = resultClass.getConstructor(ResultSet.class);
 				return constructor.newInstance(resultSet);
 			} catch (SecurityException e) {
@@ -491,21 +440,16 @@
 			} catch (IllegalAccessException e) {
 				throw new JiemamyError("resultClass must have public constructor.", e);
 			} catch (InvocationTargetException e) {
+				Throwable cause = e.getCause();
+				if (cause instanceof SQLException) {
+					throw (SQLException) cause;
+				}
 				throw new JiemamyError("resultClass construction failed.", e);
-			} catch (SQLException e) {
-				logger.warn("SQLException", e);
-				// ignore
 			}
-			return null;
 		}
 		
-		public void remove() {
-			try {
-				resultSet.deleteRow();
-			} catch (SQLException e) {
-				logger.warn("SQLException", e);
-				// ignore
-			}
+		public boolean next() throws SQLException {
+			return resultSet.next();
 		}
 	}
 }

Modified: leto/jiemamy-test-helper/trunk/src/main/java/org/jiemamy/internal/test/CoreTestModelBuilder.java
===================================================================
--- leto/jiemamy-test-helper/trunk/src/main/java/org/jiemamy/internal/test/CoreTestModelBuilder.java	2009-04-07 12:56:48 UTC (rev 3162)
+++ leto/jiemamy-test-helper/trunk/src/main/java/org/jiemamy/internal/test/CoreTestModelBuilder.java	2009-04-07 14:59:13 UTC (rev 3163)
@@ -257,8 +257,8 @@
 	
 	public Jiemamy build() {
 		rootModel.setDialectClassName(DIALECT_CLASS_NAME);
-		rootModel.setBeginScript("BEGIN;");
-		rootModel.setEndScript("COMMIT;");
+//		rootModel.setBeginScript("BEGIN;");
+//		rootModel.setEndScript("COMMIT;");
 		rootModel.setDescription("Jiemamyテストモデル1");
 		rootModel.setSchemaName("FOO");
 		

Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/dialect/MoldManager.java
===================================================================
--- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/dialect/MoldManager.java	2009-04-07 12:56:48 UTC (rev 3162)
+++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/dialect/MoldManager.java	2009-04-07 14:59:13 UTC (rev 3163)
@@ -59,7 +59,7 @@
 	 * @param category 型カテゴリ
 	 * @param typeName 型名
 	 * @return モールド
-	 * @throws IllegalArgumentException 引数に{@code null}を与えた場合
+	 * @throws IllegalArgumentException 引数typeNameに{@code null}を与えた場合
 	 * @since 0.2
 	 */
 	BuiltinDataTypeMold findDataTypeMold(DataTypeCategory category, String typeName);

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-04-07 12:56:48 UTC (rev 3162)
+++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/DataTypeCategory.java	2009-04-07 14:59:13 UTC (rev 3163)
@@ -88,7 +88,7 @@
 	 * {@link Types}の値から、カテゴリを取得する。
 	 * 
 	 * @param sqlType {@link Types}の値
-	 * @return カテゴリ
+	 * @return カテゴリ. 適切なカテゴリが見つからなかった場合は{@code null}
 	 * @since 0.2
 	 */
 	public static DataTypeCategory fromSqlType(int sqlType) {



Jiemamy-notify メーリングリストの案内
Back to archive index