svnno****@sourc*****
svnno****@sourc*****
2009年 4月 6日 (月) 02:17:24 JST
Revision: 3128 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=3128 Author: j5ik2o Date: 2009-04-06 02:17:24 +0900 (Mon, 06 Apr 2009) Log Message: ----------- リファクタリング Modified Paths: -------------- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/JpaImporter.java charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMeta.java charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/PropertyMeta.java charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaFactoryImpl.java charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaReaderImpl.java Added Paths: ----------- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/ColumnMetaFactoryImpl.java charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/FieldDuplicatedException.java charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/PropertyMetaFactoryImpl.java charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/UnsupportedInheritanceException.java -------------- next part -------------- Modified: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/JpaImporter.java =================================================================== --- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/JpaImporter.java 2009-04-05 17:15:43 UTC (rev 3127) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/JpaImporter.java 2009-04-05 17:17:24 UTC (rev 3128) @@ -28,9 +28,11 @@ import org.jiemamy.composer.importer.meta.EntityMeta; import org.jiemamy.composer.importer.meta.EntityMetaReader; import org.jiemamy.composer.importer.meta.EntityMetaReaderContext; +import org.jiemamy.composer.importer.meta.impl.ColumnMetaFactoryImpl; import org.jiemamy.composer.importer.meta.impl.EntityClassNotFoundException; import org.jiemamy.composer.importer.meta.impl.EntityMetaFactoryImpl; import org.jiemamy.composer.importer.meta.impl.EntityMetaReaderImpl; +import org.jiemamy.composer.importer.meta.impl.PropertyMetaFactoryImpl; import org.jiemamy.composer.importer.meta.impl.TableMetaFactoryImpl; import org.jiemamy.composer.importer.utils.ClassUtil; import org.jiemamy.composer.importer.utils.CollectionsUtil; @@ -71,7 +73,9 @@ } context.setPackageName(ClassUtil.concatName(config.getRootPackageName(), config.getEntityPackageName())); context.setJavaFileEncoding(config.getJavaFileEncoding()); - context.setEntityMetaFactory(new EntityMetaFactoryImpl(new TableMetaFactoryImpl())); + + context.setEntityMetaFactory(new EntityMetaFactoryImpl(new TableMetaFactoryImpl(), new PropertyMetaFactoryImpl( + new ColumnMetaFactoryImpl()))); EntityMetaReader entityMetaReader = new EntityMetaReaderImpl(context); try { Modified: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMeta.java =================================================================== --- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMeta.java 2009-04-05 17:15:43 UTC (rev 3127) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMeta.java 2009-04-05 17:17:24 UTC (rev 3128) @@ -34,25 +34,65 @@ public class EntityMeta { /** エンティティクラス */ - protected Class<?> entityClass; + private Class<?> entityClass; /** エンティティ名 */ - protected String name; + private String name; /** テーブルメタデータ */ - protected TableMeta tableMeta; + private TableMeta tableMeta; /** IDプロパティメタデータのリスト */ - protected List<PropertyMeta> idPropertyMetas = CollectionsUtil.newArrayList(); + private List<PropertyMeta> idPropertyMetas = CollectionsUtil.newArrayList(); /** プロパティメタデータのマップ */ - protected Map<String, PropertyMeta> propertyMetas = CollectionsUtil.newHashMap(); + private Map<String, PropertyMeta> propertyMetas = CollectionsUtil.newHashMap(); /** バージョンのプロパティメタデータ */ - protected PropertyMeta versionPropertyMeta; + private PropertyMeta versionPropertyMeta; + private Map<String, PropertyMeta> columnPropertyMetas = CollectionsUtil.newHashMap(); + + private Map<String, Map<String, PropertyMeta>> mappedByPropertyMetas = CollectionsUtil.newHashMap(); + /** + * {@link PropertyMeta}を追加する。 + * + * @param propertyMeta {@link PropertyMeta} + * @throws ColumnDuplicatedException カラムがだぶって生成された場合 + * @throws PropertyDuplicatedException プロパティがだぶって生成された場合 + */ + public void addPropertyMeta(PropertyMeta propertyMeta) throws ColumnDuplicatedException, + PropertyDuplicatedException { + if (propertyMetas.put(propertyMeta.getName(), propertyMeta) != null) { + throw new PropertyDuplicatedException(name, propertyMeta.getName()); + } + if (propertyMeta.isId()) { + idPropertyMetas.add(propertyMeta); + } + if (propertyMeta.isVersion()) { + versionPropertyMeta = propertyMeta; + } + if (propertyMeta.getMappedBy() != null) { + Map<String, PropertyMeta> m = mappedByPropertyMetas.get(propertyMeta.getMappedBy()); + if (m == null) { + m = CollectionsUtil.newHashMap(); + mappedByPropertyMetas.put(propertyMeta.getMappedBy(), m); + } + m.put(propertyMeta.getRelationshipClass().getName(), propertyMeta); + } + if (propertyMeta.getColumnMeta() != null) { + String columnName = propertyMeta.getColumnMeta().getName(); + PropertyMeta pm2 = columnPropertyMetas.put(columnName, propertyMeta); + if (pm2 != null) { + throw new ColumnDuplicatedException(name, pm2.getName(), propertyMeta.getName(), columnName); + } + } + + } + + /** * エンンティクラスを取得する。 * * @return エンティティクラス Modified: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/PropertyMeta.java =================================================================== --- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/PropertyMeta.java 2009-04-05 17:15:43 UTC (rev 3127) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/PropertyMeta.java 2009-04-05 17:17:24 UTC (rev 3128) @@ -19,11 +19,16 @@ package org.jiemamy.composer.importer.meta; import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EnumType; +import javax.persistence.FetchType; +import javax.persistence.GenerationType; +import javax.persistence.TemporalType; + import org.apache.commons.lang.builder.ToStringBuilder; -import org.jiemamy.utils.metadata.ColumnMeta; - /** * JPA用のプロパティメタデータクラス。 * @@ -43,9 +48,64 @@ /** IDフラグ */ private boolean id; - /** カラムメタ */ + /** カラムメタデータ */ private ColumnMeta columnMeta; + /** + * IDを自動生成する方法です。 + */ + private GenerationType generationType; + + /** + * フェッチタイプです。 + */ + private FetchType fetchType; + + /** + * 時制の種別です。 + */ + private TemporalType temporalType; + + /** + * enumの種別です。 + */ + private EnumType enumType; + + /** + * バージョン用かどうかです。 + */ + private boolean version; + + /** + * 一時的かどうかです。 + */ + private boolean trnsient; + + /** + * <code>LOB</code>かどうかです。 + */ + private boolean lob; + + /** + * 結合カラムメタデータのリストです。 + */ + private List<JoinColumnMeta> joinColumnMetaList = new ArrayList<JoinColumnMeta>(); + + /** + * 関連タイプです。 + */ + private RelationshipType relationshipType; + + /** + * 関連の所有者側のプロパティ名です。 + */ + private String mappedBy; + + /** + * 関連クラスです。 + */ + private Class<?> relationshipClass; + /** * カラムメタを取得する。 @@ -57,6 +117,24 @@ } /** + * {@link EnumType}を取得する。 + * + * @return {@link EnumType} + */ + public EnumType getEnumType() { + return enumType; + } + + /** + * {@link FetchType}を取得する。 + * + * @return {@link FetchType} + */ + public FetchType getFetchType() { + return fetchType; + } + + /** * フィールドを取得する。 * * @return {@link Field} @@ -66,6 +144,33 @@ } /** + * {@link GenerationType}を取得する。 + * + * @return {@link GenerationType} + */ + public GenerationType getGenerationType() { + return generationType; + } + + /** + * {@JoinColumnMeta}のリストを取得する。 + * + * @return {@JoinColumnMeta}のリスト + */ + public List<JoinColumnMeta> getJoinColumnMetaList() { + return joinColumnMetaList; + } + + /** + * TODO for junichi + * + * @return + */ + public String getMappedBy() { + return mappedBy; + } + + /** * 名前を取得する。 * * @return 名前 @@ -84,6 +189,33 @@ } /** + * TODO for junichi + * + * @return + */ + public Class<?> getRelationshipClass() { + return relationshipClass; + } + + /** + * TODO for junichi + * + * @return + */ + public RelationshipType getRelationshipType() { + return relationshipType; + } + + /** + * TODO for junichi + * + * @return + */ + public TemporalType getTemporalType() { + return temporalType; + } + + /** * IDフラグを取得する。 * * @return trueの場合はID @@ -93,6 +225,33 @@ } /** + * TODO for junichi + * + * @return + */ + public boolean isLob() { + return lob; + } + + /** + * TODO for junichi + * + * @return + */ + public boolean isTransient() { + return trnsient; + } + + /** + * TODO for junichi + * + * @return + */ + public boolean isVersion() { + return version; + } + + /** * カラムメタを設定する。 * * @param columnMeta {@link ColumnMeta} @@ -102,6 +261,24 @@ } /** + * TODO for junichi + * + * @param enumType + */ + public void setEnumType(EnumType enumType) { + this.enumType = enumType; + } + + /** + * TODO for junichi + * + * @param fetchType + */ + public void setFetchType(FetchType fetchType) { + this.fetchType = fetchType; + } + + /** * フィールドを設定する。 * * @param field {@link Field} @@ -110,6 +287,10 @@ this.field = field; } + public void setGenerationType(GenerationType generationType) { + this.generationType = generationType; + } + /** * IDフラグを設定する。 * @@ -119,7 +300,29 @@ this.id = id; } + public void setJoinColumnMetaList(final List<JoinColumnMeta> joinColumnMetaList) { + this.joinColumnMetaList = joinColumnMetaList; + } + /** + * TODO for junichi + * + * @param lob + */ + public void setLob(boolean lob) { + this.lob = lob; + } + + /** + * TODO for junichi + * + * @param mappedBy + */ + public void setMappedBy(String mappedBy) { + this.mappedBy = mappedBy; + } + + /** * 名前を設定する。 * * @param name 名前 @@ -137,6 +340,46 @@ this.propertyClass = propertyClass; } + public void setRelationshipClass(Class<?> relationshipClass) { + this.relationshipClass = relationshipClass; + } + + /** + * TODO for junichi + * + * @param relationshipType + */ + public void setRelationshipType(RelationshipType relationshipType) { + this.relationshipType = relationshipType; + } + + /** + * TODO for junichi + * + * @param temporalType + */ + public void setTemporalType(TemporalType temporalType) { + this.temporalType = temporalType; + } + + /** + * TODO for junichi + * + * @param trnsient + */ + public void setTransient(boolean trnsient) { + this.trnsient = trnsient; + } + + /** + * TODO for junichi + * + * @param version + */ + public void setVersion(boolean version) { + this.version = version; + } + @Override public String toString() { return ToStringBuilder.reflectionToString(this); Added: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/ColumnMetaFactoryImpl.java =================================================================== --- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/ColumnMetaFactoryImpl.java (rev 0) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/ColumnMetaFactoryImpl.java 2009-04-05 17:17:24 UTC (rev 3128) @@ -0,0 +1,41 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on Apr 5, 2009 + * + * 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.meta.impl; + +import java.lang.reflect.Field; + +import org.jiemamy.composer.importer.meta.ColumnMeta; +import org.jiemamy.composer.importer.meta.ColumnMetaFactory; +import org.jiemamy.composer.importer.meta.EntityMeta; +import org.jiemamy.composer.importer.meta.PropertyMeta; + + +/** + * TODO for junichi + * + * @author junichi + */ +public class ColumnMetaFactoryImpl implements ColumnMetaFactory { + + public ColumnMeta createColumnMeta(Field field, EntityMeta entityMeta, PropertyMeta propertyMeta) { + // TODO Auto-generated method stub + return null; + } + +} Property changes on: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/ColumnMetaFactoryImpl.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaFactoryImpl.java =================================================================== --- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaFactoryImpl.java 2009-04-05 17:15:43 UTC (rev 3127) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaFactoryImpl.java 2009-04-05 17:17:24 UTC (rev 3128) @@ -18,18 +18,29 @@ */ package org.jiemamy.composer.importer.meta.impl; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.List; import java.util.concurrent.ConcurrentHashMap; +import javassist.NotFoundException; + import javax.persistence.Entity; +import javax.persistence.MappedSuperclass; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.Validate; +import org.jiemamy.composer.importer.meta.ColumnDuplicatedException; import org.jiemamy.composer.importer.meta.EntityMeta; import org.jiemamy.composer.importer.meta.EntityMetaFactory; +import org.jiemamy.composer.importer.meta.PropertyDuplicatedException; +import org.jiemamy.composer.importer.meta.PropertyMetaFactory; import org.jiemamy.composer.importer.meta.TableMeta; import org.jiemamy.composer.importer.meta.TableMetaFactory; +import org.jiemamy.composer.importer.utils.ClassUtil; import org.jiemamy.composer.importer.utils.CollectionsUtil; +import org.jiemamy.composer.importer.utils.ModifierUtil; /** * {@link EntityMetaFactory}の実装クラス。 @@ -38,19 +49,50 @@ */ public class EntityMetaFactoryImpl implements EntityMetaFactory { + @SuppressWarnings("serial") + private static class FieldMap extends HashMap<String, Field> { + + private List<Field> fieldList = CollectionsUtil.newArrayList(); + + + @Override + public Field put(String key, Field value) { + Field result = super.put(key, value); + fieldList.add(value); + return result; + } + + /** + * TODO for junichi + * + * @param fields + * @return + */ + public Field[] toArray(Field[] fields) { + return fieldList.toArray(fields); + } + + } + + private ConcurrentHashMap<String, EntityMeta> entityMetaCache = CollectionsUtil.newConcurrentHashMap(); private TableMetaFactory tableMetaFactory; + private PropertyMetaFactory propertyMetaFactory; + /** * インスタンスを生成する。 * * @param tableMetaFactory テーブルメタファクトリ + * @param propertyMetaFactory プロパティメタファクトリ */ - public EntityMetaFactoryImpl(TableMetaFactory tableMetaFactory) { + public EntityMetaFactoryImpl(TableMetaFactory tableMetaFactory, PropertyMetaFactory propertyMetaFactory) { Validate.notNull(tableMetaFactory); + Validate.notNull(propertyMetaFactory); this.tableMetaFactory = tableMetaFactory; + this.propertyMetaFactory = propertyMetaFactory; } private EntityMeta createEntityMeta(Class<?> entityClass) throws NonEntityException { @@ -63,9 +105,23 @@ doEntityClass(entityMeta, entityClass); doName(entityMeta, entityAnnotation); doTableMeta(entityMeta); - doPropertyMeta(entityMeta); + try { + doPropertyMeta(entityMeta); + } catch (ColumnDuplicatedException e) { + throw new NonEntityException(e); + } catch (PropertyDuplicatedException e) { + throw new NonEntityException(e); + } catch (NotFoundException e) { + throw new NonEntityException(e); + } catch (NoSuchFieldException e) { + throw new NonEntityException(e); + } catch (UnsupportedInheritanceException e) { + throw new NonEntityException(e); + } catch (FieldDuplicatedException e) { + throw new NonEntityException(e); + } + //doCustomize(entityMeta); - // TODO エンティティクラスからEntityMetaを作成する(残項目あり) return entityMeta; } @@ -85,8 +141,13 @@ entityMeta.setName(entityName); } - private void doPropertyMeta(EntityMeta entityMeta) { - + private void doPropertyMeta(EntityMeta entityMeta) throws ColumnDuplicatedException, PropertyDuplicatedException, + NotFoundException, NoSuchFieldException, UnsupportedInheritanceException, FieldDuplicatedException { + Field[] fields = getFields(entityMeta.getEntityClass()); + for (Field f : fields) { + f.setAccessible(true); + entityMeta.addPropertyMeta(propertyMetaFactory.createPropertyMeta(entityMeta, f)); + } } private void doTableMeta(EntityMeta entityMeta) { @@ -104,4 +165,34 @@ EntityMeta entityMeta2 = entityMetaCache.putIfAbsent(entityClass.getName(), entityMeta); return entityMeta2 != null ? entityMeta2 : entityMeta; } + + private Field[] getFields(Class<?> entityClass) throws NotFoundException, NoSuchFieldException, + UnsupportedInheritanceException, FieldDuplicatedException { + FieldMap fields = new FieldMap(); + for (Field f : ClassUtil.getDeclaredFields(entityClass)) { + if (!ModifierUtil.isInstanceField(f)) { + continue; + } + fields.put(f.getName(), f); + } + for (Class<?> clazz = entityClass.getSuperclass(); clazz != Object.class; clazz = clazz.getSuperclass()) { + if (clazz.isAnnotationPresent(Entity.class)) { + throw new UnsupportedInheritanceException(entityClass); + } + if (clazz.isAnnotationPresent(MappedSuperclass.class)) { + for (Field f : ClassUtil.getDeclaredFields(clazz)) { + if (ModifierUtil.isInstanceField(f) == false) { + continue; + } + String name = f.getName(); + if (fields.containsKey(name) == false) { + fields.put(name, f); + } else { + throw new FieldDuplicatedException(f); + } + } + } + } + return fields.toArray(new Field[fields.size()]); + } } Modified: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaReaderImpl.java =================================================================== --- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaReaderImpl.java 2009-04-05 17:15:43 UTC (rev 3127) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaReaderImpl.java 2009-04-05 17:17:24 UTC (rev 3128) @@ -122,12 +122,19 @@ if (entityMetas.isEmpty()) { throw new EntityClassNotFoundException(); } + if (entityMetaReaderContext.isReadComment()) { + readComment(entityMetas); + } return entityMetas; } finally { factory.dispose(); } } + private void readComment(List<EntityMeta> entityMetas) { + // TODO Auto-generated method stub + } + private List<URL> toURLs(List<File> files) throws MalformedURLException { List<URL> urlList = new ArrayList<URL>(); for (File classPathDir : entityMetaReaderContext.getClassPathDirs()) { Added: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/FieldDuplicatedException.java =================================================================== --- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/FieldDuplicatedException.java (rev 0) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/FieldDuplicatedException.java 2009-04-05 17:17:24 UTC (rev 3128) @@ -0,0 +1,39 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on Apr 6, 2009 + * + * 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.meta.impl; + +import java.lang.reflect.Field; + +/** + * TODO for junichi + * + * @author junichi + */ +public class FieldDuplicatedException extends Exception { + + /** + * インスタンスを生成する。 + * + * @param f + */ + public FieldDuplicatedException(Field f) { + // TODO Auto-generated constructor stub + } + +} Property changes on: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/FieldDuplicatedException.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/PropertyMetaFactoryImpl.java =================================================================== --- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/PropertyMetaFactoryImpl.java (rev 0) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/PropertyMetaFactoryImpl.java 2009-04-05 17:17:24 UTC (rev 3128) @@ -0,0 +1,251 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on Apr 5, 2009 + * + * 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.meta.impl; + +import java.lang.reflect.Field; + +import org.apache.commons.lang.Validate; + +import org.jiemamy.composer.importer.meta.ColumnMetaFactory; +import org.jiemamy.composer.importer.meta.EntityMeta; +import org.jiemamy.composer.importer.meta.PropertyMeta; +import org.jiemamy.composer.importer.meta.PropertyMetaFactory; + +/** + * TODO for junichi + * + * @author junichi + */ +public class PropertyMetaFactoryImpl implements PropertyMetaFactory { + + private ColumnMetaFactory columnMetaFactory; + + + /** + * インスタンスを生成する。 + * + * @param columnMetaFactory {@link ColumnMetaFactory} + */ + public PropertyMetaFactoryImpl(ColumnMetaFactory columnMetaFactory) { + Validate.notNull(columnMetaFactory); + this.columnMetaFactory = columnMetaFactory; + } + + public PropertyMeta createPropertyMeta(EntityMeta entityMeta, Field field) { + PropertyMeta propertyMeta = new PropertyMeta(); + doField(propertyMeta, field, entityMeta); + doName(propertyMeta, field, entityMeta); + doTransient(propertyMeta, field, entityMeta); + if (!propertyMeta.isTransient()) { + Object relationshipAnnotation = getRelationshipAnnotation(field); + if (relationshipAnnotation == null) { + doColumnMeta(propertyMeta, field, entityMeta); + doId(propertyMeta, field, entityMeta); + doFetchType(propertyMeta, field, entityMeta); + doTemporal(propertyMeta, field, entityMeta); + doEnum(propertyMeta, field, entityMeta); + doVersion(propertyMeta, field, entityMeta); + doLob(propertyMeta, field, entityMeta); + doValueType(propertyMeta, entityMeta); + } else { + doRelationship(propertyMeta, field, entityMeta, relationshipAnnotation); + } + } + doCustomize(propertyMeta, field, entityMeta); + return propertyMeta; + + } + + /** + * TODO for junichi + * + * @param propertyMeta + * @param field + * @param entityMeta + */ + private void doColumnMeta(PropertyMeta propertyMeta, Field field, EntityMeta entityMeta) { + propertyMeta.setColumnMeta(columnMetaFactory.createColumnMeta(field, entityMeta, propertyMeta)); + } + + /** + * TODO for junichi + * + * @param propertyMeta + * @param field + * @param entityMeta + */ + private void doCustomize(PropertyMeta propertyMeta, Field field, EntityMeta entityMeta) { + // TODO Auto-generated method stub + + } + + /** + * TODO for junichi + * + * @param propertyMeta + * @param field + * @param entityMeta + */ + private void doEnum(PropertyMeta propertyMeta, Field field, EntityMeta entityMeta) { + // TODO Auto-generated method stub + + } + + /** + * TODO for junichi + * + * @param propertyMeta + * @param field + * @param entityMeta + */ + private void doFetchType(PropertyMeta propertyMeta, Field field, EntityMeta entityMeta) { + // TODO Auto-generated method stub + + } + + /** + * TODO for junichi + * + * @param propertyMeta + * @param field + * @param entityMeta + */ + private void doField(PropertyMeta propertyMeta, Field field, EntityMeta entityMeta) { + propertyMeta.setField(field); + } + + /** + * TODO for junichi + * + * @param propertyMeta + * @param field + * @param entityMeta + */ + private void doId(PropertyMeta propertyMeta, Field field, EntityMeta entityMeta) { + // TODO Auto-generated method stub + + } + + /** + * TODO for junichi + * + * @param propertyMeta + * @param field + * @param entityMeta + */ + private void doLob(PropertyMeta propertyMeta, Field field, EntityMeta entityMeta) { + // TODO Auto-generated method stub + + } + + /** + * TODO for junichi + * + * @param propertyMeta + * @param field + * @param entityMeta + */ + private void doName(PropertyMeta propertyMeta, Field field, EntityMeta entityMeta) { + propertyMeta.setName(fromFieldNameToPropertyName(field.getName())); + } + + /** + * TODO for junichi + * + * @param propertyMeta + * @param field + * @param entityMeta + * @param relationshipAnnotation + */ + private void doRelationship(PropertyMeta propertyMeta, Field field, EntityMeta entityMeta, + Object relationshipAnnotation) { + // TODO Auto-generated method stub + + } + + /** + * TODO for junichi + * + * @param propertyMeta + * @param field + * @param entityMeta + */ + private void doTemporal(PropertyMeta propertyMeta, Field field, EntityMeta entityMeta) { + // TODO Auto-generated method stub + + } + + /** + * TODO for junichi + * + * @param propertyMeta + * @param field + * @param entityMeta + */ + private void doTransient(PropertyMeta propertyMeta, Field field, EntityMeta entityMeta) { + // TODO Auto-generated method stub + + } + + /** + * TODO for junichi + * + * @param propertyMeta + * @param entityMeta + */ + private void doValueType(PropertyMeta propertyMeta, EntityMeta entityMeta) { + // TODO Auto-generated method stub + + } + + /** + * TODO for junichi + * + * @param propertyMeta + * @param field + * @param entityMeta + */ + private void doVersion(PropertyMeta propertyMeta, Field field, EntityMeta entityMeta) { + // TODO Auto-generated method stub + + } + + /** + * TODO for junichi + * + * @param name + * @return + */ + private String fromFieldNameToPropertyName(String name) { + // TODO Auto-generated method stub + return name; + } + + /** + * TODO for junichi + * + * @param field + * @return + */ + private Object getRelationshipAnnotation(Field field) { + // TODO Auto-generated method stub + return null; + } + +} Property changes on: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/PropertyMetaFactoryImpl.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/UnsupportedInheritanceException.java =================================================================== --- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/UnsupportedInheritanceException.java (rev 0) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/UnsupportedInheritanceException.java 2009-04-05 17:17:24 UTC (rev 3128) @@ -0,0 +1,38 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on Apr 6, 2009 + * + * 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.meta.impl; + +/** + * TODO for junichi + * + * @author junichi + */ + @ SuppressWarnings("serial") +public class UnsupportedInheritanceException extends Exception { + + /** + * インスタンスを生成する。 + * + * @param entityClass + */ + public UnsupportedInheritanceException(Class<?> entityClass) { + // TODO Auto-generated constructor stub + } + +} Property changes on: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/UnsupportedInheritanceException.java ___________________________________________________________________ Added: svn:mime-type + text/plain