svnno****@sourc*****
svnno****@sourc*****
2008年 12月 12日 (金) 02:19:19 JST
Revision: 2251 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2251 Author: daisuke_m Date: 2008-12-12 02:19:19 +0900 (Fri, 12 Dec 2008) Log Message: ----------- DatabaseReaderをJ-composerに移動。 Modified Paths: -------------- artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/exporter/ExportContextImpl.java 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/ImportContextImpl.java artemis/trunk/org.jiemamy.core/META-INF/MANIFEST.MF Added Paths: ----------- artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/DatabaseReader.java artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/DatabaseReadingContext.java artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/utils/AbstractContext.java Removed Paths: ------------- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/internal/interpreter/AbstractContext.java artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/internal/interpreter/DatabaseReader.java artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/internal/interpreter/DatabaseReadingContext.java -------------- next part -------------- Modified: artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/exporter/ExportContextImpl.java =================================================================== --- artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/exporter/ExportContextImpl.java 2008-12-11 16:49:04 UTC (rev 2250) +++ artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/exporter/ExportContextImpl.java 2008-12-11 17:19:19 UTC (rev 2251) @@ -19,7 +19,7 @@ package org.jiemamy.composer.exporter; import org.jiemamy.composer.ExportContext; -import org.jiemamy.internal.interpreter.AbstractContext; +import org.jiemamy.utils.AbstractContext; /** * エクスポートに関するコンテキスト情報。 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-12-11 16:49:04 UTC (rev 2250) +++ artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/DatabaseImporter.java 2008-12-11 17:19:19 UTC (rev 2251) @@ -22,8 +22,6 @@ import org.jiemamy.exception.GenericModelingModeException; import org.jiemamy.exception.ImportException; import org.jiemamy.exception.TooManyElementsException; -import org.jiemamy.internal.interpreter.DatabaseReader; -import org.jiemamy.internal.interpreter.DatabaseReadingContext; import org.jiemamy.model.RootModel; import org.jiemamy.model.connection.ForeignKeyMapping; import org.jiemamy.model.connection.ForeignKeyModel; Added: artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/DatabaseReader.java =================================================================== --- artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/DatabaseReader.java (rev 0) +++ artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/DatabaseReader.java 2008-12-11 17:19:19 UTC (rev 2251) @@ -0,0 +1,127 @@ +/* + * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. + * Created on 2008/07/18 + * + * 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.composer.importer; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import org.apache.commons.lang.Validate; +import org.seasar.framework.util.tiger.CollectionsUtil; + +import org.jiemamy.dialect.Dialect; +import org.jiemamy.utils.ForEachUtil; +import org.jiemamy.utils.visitor.AbstractResultSetVisitor; +import org.jiemamy.utils.visitor.impl.EntityNamesVisitor; + +/** + * データベースを読み込む。 + * + * model, dialect, reader, database の関係を人間のメタファで説明しようとすると、 + * 方言というのは、リソース(読み出し対象)の性質である為、読み手が知っていれば読めるもの。 + * 方言を知っている読み手に対して、リソースを与えると、方言に応じて様々な情報を読み取る。 + * readerはこの「読み手」であり、databaseは「リソース」、modelは「様々な情報」である。 + * + * @author daisuke + */ +class DatabaseReader { + + // THINK DBを読み込んだ結果、modelを「出力する」主体はReaderである為、現在の実装のようにDialectに丸投げ委譲、 + // というのは責務の重心がおかしい。Dialectは必要な部分のみReaderから問い合わせられるだけの立場であり、 + // 基本的にモデルを組み立てる責務はReader側にあるものではないか? + + private final Dialect dialect; + + private final DatabaseReadingContext ctx; + + + /** + * コンストラクタ。 + * @param dialect SQL方言 + * @param ctx コンテキスト情報 + * @category instance creation + */ + public DatabaseReader(Dialect dialect, DatabaseReadingContext ctx) { + Validate.notNull(dialect); + Validate.notNull(ctx); + this.dialect = dialect; + this.ctx = ctx; + } + + /** + * DB接続からエンティティを読み込む。 + * @param <T> 読み込んだ結果、戻り値型 + * @param connection DB接続 + * @param visitor 各エンティティに情報に対するビジター。 + * @return ビジターに依存した、実行結果 + * @throws SQLException + * @throws IllegalArgumentException 引数に{@code null}を与えた場合 + */ + public <T>T readEnities(Connection connection, AbstractResultSetVisitor<T> visitor) throws SQLException { + assert dialect != null; + assert ctx != null; + Validate.notNull(connection); + Validate.notNull(visitor); + + dialect.getAdvisor().setUpRead(connection); + + String schema = ctx.getValue("schema"); // DatabaseImporter.SCHEMA + DatabaseMetaData meta = connection.getMetaData(); + + ResultSet entities = meta.getTables(null, schema, "%", null); + T result = ForEachUtil.accept(entities, visitor); + + dialect.getAdvisor().tearDownRead(connection); + return result; + } + + /** + * DB接続からリレーションを読み込む。 + * @param <T> 読み込んだ結果、戻り値型 + * @param connection DB接続 + * @param visitor 各エンティティに情報に対するビジター。 + * @return ビジターに依存した、実行結果 + * @throws SQLException + * @throws IllegalArgumentException 引数に{@code null}を与えた場合 + */ + public <T>List<T> readRelations(Connection connection, AbstractResultSetVisitor<T> visitor) throws SQLException { + assert dialect != null; + assert ctx != null; + Validate.notNull(connection); + Validate.notNull(visitor); + + dialect.getAdvisor().setUpRead(connection); + + String schema = ctx.getValue("schema"); // DatabaseImporter.SCHEMA + DatabaseMetaData meta = connection.getMetaData(); + + List<String> entityNames = readEnities(connection, new EntityNamesVisitor()); + + List<T> result = CollectionsUtil.newArrayList(); + for (String entityName : entityNames) { + ResultSet relations = meta.getImportedKeys(null, schema, entityName); + result.add(ForEachUtil.accept(relations, visitor)); + } + + dialect.getAdvisor().tearDownRead(connection); + return result; + } +} Added: artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/DatabaseReadingContext.java =================================================================== --- artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/DatabaseReadingContext.java (rev 0) +++ artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/DatabaseReadingContext.java 2008-12-11 17:19:19 UTC (rev 2251) @@ -0,0 +1,29 @@ +/* + * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. + * Created on 2008/07/04 + * + * 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.composer.importer; + +import org.jiemamy.utils.AbstractContext; + +/** + * データベースからモデルにインポートを行う際のコンテキスト情報。 + * @author daisuke + */ +class DatabaseReadingContext extends AbstractContext { + +} Modified: artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/ImportContextImpl.java =================================================================== --- artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/ImportContextImpl.java 2008-12-11 16:49:04 UTC (rev 2250) +++ artemis/trunk/org.jiemamy.composer/src/main/java/org/jiemamy/composer/importer/ImportContextImpl.java 2008-12-11 17:19:19 UTC (rev 2251) @@ -19,7 +19,7 @@ package org.jiemamy.composer.importer; import org.jiemamy.composer.ImportContext; -import org.jiemamy.internal.interpreter.AbstractContext; +import org.jiemamy.utils.AbstractContext; /** * インポートに関するコンテキスト情報。 Modified: artemis/trunk/org.jiemamy.core/META-INF/MANIFEST.MF =================================================================== --- artemis/trunk/org.jiemamy.core/META-INF/MANIFEST.MF 2008-12-11 16:49:04 UTC (rev 2250) +++ artemis/trunk/org.jiemamy.core/META-INF/MANIFEST.MF 2008-12-11 17:19:19 UTC (rev 2251) @@ -172,7 +172,6 @@ org.jiemamy.internal.accessor.dataset, org.jiemamy.internal.accessor.index, org.jiemamy.internal.accessor.node, - org.jiemamy.internal.interpreter, org.jiemamy.internal.processor, org.jiemamy.model, org.jiemamy.model.attribute, Deleted: artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/internal/interpreter/AbstractContext.java =================================================================== --- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/internal/interpreter/AbstractContext.java 2008-12-11 16:49:04 UTC (rev 2250) +++ artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/internal/interpreter/AbstractContext.java 2008-12-11 17:19:19 UTC (rev 2251) @@ -1,78 +0,0 @@ -/* - * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. - * Created on 2008/07/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.internal.interpreter; - -import java.util.Map; - -import org.seasar.framework.util.tiger.CollectionsUtil; - -import org.jiemamy.Context; - -/** - * コンテキスト情報。 - * - * @author daisuke - */ -public abstract class AbstractContext implements Context { - - /** コンテキスト値のマップ */ - private Map<String, Object> properties = CollectionsUtil.newHashMap(); - - - /** - * コンテキスト値のマップを取得する。 - * @return コンテキスト値のマップ - */ - public Map<String, Object> getProperties() { - assert properties != null; - return properties; - } - - /** - * コンテキスト値を取得する。 - * @param <T> コンテキスト値の型 - * @param key キー - * @return コンテキスト値 - */ - @SuppressWarnings("unchecked") - public <T>T getValue(String key) { - assert properties != null; - return (T) properties.get(key); - } - - /** - * コンテキスト値のマップを設定する。 - * @param properties コンテキスト値のマップ - */ - public void setProperties(Map<String, Object> properties) { - assert properties != null; - this.properties = properties; - } - - /** - * コンテキスト値を設定する。 - * @param <T> コンテキスト値の型 - * @param key キー - * @param value コンテキスト値 - */ - public <T>void setValue(String key, T value) { - assert properties != null; - properties.put(key, value); - } -} Deleted: artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/internal/interpreter/DatabaseReader.java =================================================================== --- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/internal/interpreter/DatabaseReader.java 2008-12-11 16:49:04 UTC (rev 2250) +++ artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/internal/interpreter/DatabaseReader.java 2008-12-11 17:19:19 UTC (rev 2251) @@ -1,127 +0,0 @@ -/* - * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. - * Created on 2008/07/18 - * - * 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.internal.interpreter; - -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; - -import org.apache.commons.lang.Validate; -import org.seasar.framework.util.tiger.CollectionsUtil; - -import org.jiemamy.dialect.Dialect; -import org.jiemamy.utils.ForEachUtil; -import org.jiemamy.utils.visitor.AbstractResultSetVisitor; -import org.jiemamy.utils.visitor.impl.EntityNamesVisitor; - -/** - * データベースを読み込む。 - * - * model, dialect, reader, database の関係を人間のメタファで説明しようとすると、 - * 方言というのは、リソース(読み出し対象)の性質である為、読み手が知っていれば読めるもの。 - * 方言を知っている読み手に対して、リソースを与えると、方言に応じて様々な情報を読み取る。 - * readerはこの「読み手」であり、databaseは「リソース」、modelは「様々な情報」である。 - * - * @author daisuke - */ -public class DatabaseReader { - - // THINK DBを読み込んだ結果、modelを「出力する」主体はReaderである為、現在の実装のようにDialectに丸投げ委譲、 - // というのは責務の重心がおかしい。Dialectは必要な部分のみReaderから問い合わせられるだけの立場であり、 - // 基本的にモデルを組み立てる責務はReader側にあるものではないか? - - private final Dialect dialect; - - private final DatabaseReadingContext ctx; - - - /** - * コンストラクタ。 - * @param dialect SQL方言 - * @param ctx コンテキスト情報 - * @category instance creation - */ - public DatabaseReader(Dialect dialect, DatabaseReadingContext ctx) { - Validate.notNull(dialect); - Validate.notNull(ctx); - this.dialect = dialect; - this.ctx = ctx; - } - - /** - * DB接続からエンティティを読み込む。 - * @param <T> 読み込んだ結果、戻り値型 - * @param connection DB接続 - * @param visitor 各エンティティに情報に対するビジター。 - * @return ビジターに依存した、実行結果 - * @throws SQLException - * @throws IllegalArgumentException 引数に{@code null}を与えた場合 - */ - public <T>T readEnities(Connection connection, AbstractResultSetVisitor<T> visitor) throws SQLException { - assert dialect != null; - assert ctx != null; - Validate.notNull(connection); - Validate.notNull(visitor); - - dialect.getAdvisor().setUpRead(connection); - - String schema = ctx.getValue("schema"); // DatabaseImporter.SCHEMA - DatabaseMetaData meta = connection.getMetaData(); - - ResultSet entities = meta.getTables(null, schema, "%", null); - T result = ForEachUtil.accept(entities, visitor); - - dialect.getAdvisor().tearDownRead(connection); - return result; - } - - /** - * DB接続からリレーションを読み込む。 - * @param <T> 読み込んだ結果、戻り値型 - * @param connection DB接続 - * @param visitor 各エンティティに情報に対するビジター。 - * @return ビジターに依存した、実行結果 - * @throws SQLException - * @throws IllegalArgumentException 引数に{@code null}を与えた場合 - */ - public <T>List<T> readRelations(Connection connection, AbstractResultSetVisitor<T> visitor) throws SQLException { - assert dialect != null; - assert ctx != null; - Validate.notNull(connection); - Validate.notNull(visitor); - - dialect.getAdvisor().setUpRead(connection); - - String schema = ctx.getValue("schema"); // DatabaseImporter.SCHEMA - DatabaseMetaData meta = connection.getMetaData(); - - List<String> entityNames = readEnities(connection, new EntityNamesVisitor()); - - List<T> result = CollectionsUtil.newArrayList(); - for (String entityName : entityNames) { - ResultSet relations = meta.getImportedKeys(null, schema, entityName); - result.add(ForEachUtil.accept(relations, visitor)); - } - - dialect.getAdvisor().tearDownRead(connection); - return result; - } -} Deleted: artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/internal/interpreter/DatabaseReadingContext.java =================================================================== --- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/internal/interpreter/DatabaseReadingContext.java 2008-12-11 16:49:04 UTC (rev 2250) +++ artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/internal/interpreter/DatabaseReadingContext.java 2008-12-11 17:19:19 UTC (rev 2251) @@ -1,28 +0,0 @@ -/* - * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. - * Created on 2008/07/04 - * - * 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.internal.interpreter; - - -/** - * データベースからモデルにインポートを行う際のコンテキスト情報。 - * @author daisuke - */ -public class DatabaseReadingContext extends AbstractContext { - -} Copied: artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/utils/AbstractContext.java (from rev 2249, artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/internal/interpreter/AbstractContext.java) =================================================================== --- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/utils/AbstractContext.java (rev 0) +++ artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/utils/AbstractContext.java 2008-12-11 17:19:19 UTC (rev 2251) @@ -0,0 +1,78 @@ +/* + * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. + * Created on 2008/07/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.utils; + +import java.util.Map; + +import org.seasar.framework.util.tiger.CollectionsUtil; + +import org.jiemamy.Context; + +/** + * コンテキスト情報。 + * + * @author daisuke + */ +public abstract class AbstractContext implements Context { + + /** コンテキスト値のマップ */ + private Map<String, Object> properties = CollectionsUtil.newHashMap(); + + + /** + * コンテキスト値のマップを取得する。 + * @return コンテキスト値のマップ + */ + public Map<String, Object> getProperties() { + assert properties != null; + return properties; + } + + /** + * コンテキスト値を取得する。 + * @param <T> コンテキスト値の型 + * @param key キー + * @return コンテキスト値 + */ + @SuppressWarnings("unchecked") + public <T>T getValue(String key) { + assert properties != null; + return (T) properties.get(key); + } + + /** + * コンテキスト値のマップを設定する。 + * @param properties コンテキスト値のマップ + */ + public void setProperties(Map<String, Object> properties) { + assert properties != null; + this.properties = properties; + } + + /** + * コンテキスト値を設定する。 + * @param <T> コンテキスト値の型 + * @param key キー + * @param value コンテキスト値 + */ + public <T>void setValue(String key, T value) { + assert properties != null; + properties.put(key, value); + } +} Property changes on: artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/utils/AbstractContext.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:mergeinfo +