svnno****@sourc*****
svnno****@sourc*****
2009年 4月 8日 (水) 15:51:33 JST
Revision: 3184 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=3184 Author: j5ik2o Date: 2009-04-08 15:51:33 +0900 (Wed, 08 Apr 2009) Log Message: ----------- リファクタリング Modified Paths: -------------- 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/impl/ColumnMetaFactoryImpl.java charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDoclet.java charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDocletContext.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 charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/TableMetaFactoryImpl.java -------------- next part -------------- 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-08 06:46:31 UTC (rev 3183) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMeta.java 2009-04-08 06:51:33 UTC (rev 3184) @@ -24,6 +24,7 @@ import org.apache.commons.lang.builder.ToStringBuilder; +import org.jiemamy.utils.ArrayMap; import org.jiemamy.utils.CollectionsUtil; import org.jiemamy.utils.PropertyNotFoundException; @@ -46,20 +47,19 @@ /** IDプロパティメタデータのリスト */ private List<PropertyMeta> idPropertyMetas = CollectionsUtil.newArrayList(); - /** プロパティメタデータのマップ */ - private Map<String, PropertyMeta> propertyMetaMap = CollectionsUtil.newHashMap(); + /** プロパティ名に関連するプロパティメタデータのマップ */ + private ArrayMap<String, PropertyMeta> propertyMetas = new ArrayMap<String, PropertyMeta>(); - private List<PropertyMeta> propertyMetaList = CollectionsUtil.newArrayList(); - /** バージョンのプロパティメタデータ */ private PropertyMeta versionPropertyMeta; - private Map<String, PropertyMeta> columnPropertyMetaMap = CollectionsUtil.newHashMap(); + /** カラム名に関連するプロパティメタデータのマップ */ + private ArrayMap<String, PropertyMeta> columnPropertyMetas = new ArrayMap<String, PropertyMeta>(); - private List<PropertyMeta> columnPropertyMetaList = CollectionsUtil.newArrayList(); - + /** mappedBy属性に関連するプロパティメタデータのマップ */ private Map<String, Map<String, PropertyMeta>> mappedByPropertyMetas = CollectionsUtil.newHashMap(); + /** 追加情報 */ private Map<String, Object> additionalInfo = CollectionsUtil.newHashMap(); @@ -83,10 +83,9 @@ */ public void addPropertyMeta(PropertyMeta propertyMeta) throws ColumnDuplicatedException, PropertyDuplicatedException { - if (propertyMetaMap.put(propertyMeta.getName(), propertyMeta) != null) { + if (propertyMetas.put(propertyMeta.getName(), propertyMeta) != null) { throw new PropertyDuplicatedException(name, propertyMeta.getName()); } - propertyMetaList.add(propertyMeta); if (propertyMeta.isId()) { idPropertyMetas.add(propertyMeta); } @@ -103,7 +102,7 @@ } if (propertyMeta.getColumnMeta() != null) { String columnName = propertyMeta.getColumnMeta().getName(); - PropertyMeta pm2 = columnPropertyMetaMap.put(columnName, propertyMeta); + PropertyMeta pm2 = columnPropertyMetas.put(columnName, propertyMeta); if (pm2 != null) { throw new ColumnDuplicatedException(name, pm2.getName(), propertyMeta.getName(), columnName); } @@ -138,11 +137,11 @@ public boolean hasNext() { - return i < columnPropertyMetaMap.size(); + return i < columnPropertyMetas.size(); } public PropertyMeta next() { - return columnPropertyMetaList.get(i++); + return columnPropertyMetas.get(i++); } public void remove() { @@ -168,11 +167,11 @@ public boolean hasNext() { - return i < propertyMetaMap.size(); + return i < propertyMetas.size(); } public PropertyMeta next() { - return propertyMetaList.get(i++); + return propertyMetas.get(i++); } public void remove() { @@ -190,7 +189,7 @@ * @return プロパティメタデータ */ public PropertyMeta getColumnPropertyMeta(int index) { - return columnPropertyMetaList.get(index); + return columnPropertyMetas.get(index); } /** @@ -202,7 +201,7 @@ * */ public PropertyMeta getColumnPropertyMeta(String columnName) throws EntityColumnNotFoundException { - PropertyMeta meta = columnPropertyMetaMap.get(columnName); + PropertyMeta meta = columnPropertyMetas.get(columnName); if (meta == null) { throw new EntityColumnNotFoundException(name, columnName); } @@ -258,7 +257,7 @@ * @return プロパティメタデータ */ public PropertyMeta getPropertyMeta(int index) { - return propertyMetaList.get(index); + return propertyMetas.get(index); } /** @@ -269,7 +268,7 @@ * @throws PropertyNotFoundException プロパティがみつからなかった場合 */ public PropertyMeta getPropertyMeta(String propertyName) throws PropertyNotFoundException { - PropertyMeta meta = propertyMetaMap.get(propertyName); + PropertyMeta meta = propertyMetas.get(propertyName); if (meta == null) { throw new PropertyNotFoundException(name, propertyName); } @@ -282,7 +281,7 @@ * @return プロパティメタデータの数 */ public int getPropertyMetaSize() { - return propertyMetaMap.size(); + return propertyMetas.size(); } /** @@ -310,7 +309,7 @@ * @return プロパティメタデータがあるかどうか */ public boolean hasColumnPropertyMeta(String columnName) { - return columnPropertyMetaMap.containsKey(columnName); + return columnPropertyMetas.containsKey(columnName); } /** @@ -320,7 +319,7 @@ * @return trueの場合は存在する */ public boolean hasPropertyMeta(String propertyName) { - return propertyMetaMap.containsKey(propertyName); + return propertyMetas.containsKey(propertyName); } /** @@ -364,8 +363,8 @@ * * @param propertyMetas プロパティメタ */ - public void setPropertyMetaMap(Map<String, PropertyMeta> propertyMetas) { - propertyMetaMap = propertyMetas; + public void setPropertyMetaMap(ArrayMap<String, PropertyMeta> propertyMetas) { + this.propertyMetas = propertyMetas; } /** Modified: 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 2009-04-08 06:46:31 UTC (rev 3183) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/ColumnMetaFactoryImpl.java 2009-04-08 06:51:33 UTC (rev 3184) @@ -23,6 +23,7 @@ import javax.persistence.Column; import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.Validate; import org.jiemamy.composer.importer.meta.ColumnMeta; import org.jiemamy.composer.importer.meta.ColumnMetaFactory; @@ -38,6 +39,9 @@ public class ColumnMetaFactoryImpl implements ColumnMetaFactory { public ColumnMeta createColumnMeta(Field field, EntityMeta entityMeta, PropertyMeta propertyMeta) { + Validate.notNull(field); + Validate.notNull(entityMeta); + Validate.notNull(propertyMeta); ColumnMeta columnMeta = new ColumnMeta(); String defaultName = fromPropertyNameToColumnName(propertyMeta.getName()); Column column = field.getAnnotation(Column.class); Modified: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDoclet.java =================================================================== --- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDoclet.java 2009-04-08 06:46:31 UTC (rev 3183) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDoclet.java 2009-04-08 06:51:33 UTC (rev 3184) @@ -62,7 +62,7 @@ } /** - * プロパティのコメントを処理します。 + * プロパティのコメントを処理する。 * * @param fieldDoc {@link FieldDoc} * @param propertyMeta プロパティメタデータ @@ -72,7 +72,7 @@ } /** - * フィールド名をキー、 {@link FieldDoc}を値とするマップを返します。 + * フィールド名をキー、 {@link FieldDoc}を値とするマップを取得する。 * * @param classDoc {@link ClassDoc} * @return フィールド名をキー、 {@link FieldDoc}を値とするマップ @@ -96,7 +96,7 @@ } /** - * {@link MappedSuperclass}を表す場合{@code true}を返します。 + * {@link MappedSuperclass}を表す場合{@code true}を取得する。 * * @param classDoc {@link ClassDoc} * @return {@link MappedSuperclass}を表す場合{@code true} Modified: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDocletContext.java =================================================================== --- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDocletContext.java 2009-04-08 06:46:31 UTC (rev 3183) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDocletContext.java 2009-04-08 06:51:33 UTC (rev 3184) @@ -44,7 +44,7 @@ } /** - * エンティティメタデータのリストを設定します。 + * エンティティメタデータのリストを設定する。 * * @param entityMetaList エンティティメタデータのリスト */ 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-08 06:46:31 UTC (rev 3183) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaFactoryImpl.java 2009-04-08 06:51:33 UTC (rev 3184) @@ -19,8 +19,6 @@ 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; @@ -42,6 +40,7 @@ import org.jiemamy.composer.importer.meta.TableMetaFactory; import org.jiemamy.composer.importer.meta.exception.FieldDuplicatedException; import org.jiemamy.composer.importer.meta.exception.UnsupportedInheritanceException; +import org.jiemamy.utils.ArrayMap; import org.jiemamy.utils.ClassUtil; import org.jiemamy.utils.CollectionsUtil; import org.jiemamy.utils.JmStringUtil; @@ -54,32 +53,6 @@ */ 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; - } - - /** - * Mapの要素を配列に変換する。 - * - * @param fields 要素を格納する配列 - * @return 変換後の配列 - */ - public Field[] toArray(Field[] fields) { - return fieldList.toArray(fields); - } - - } - - private ConcurrentHashMap<String, EntityMeta> entityMetaCache = CollectionsUtil.newConcurrentHashMap(); private TableMetaFactory tableMetaFactory; @@ -124,10 +97,14 @@ } private void doEntityClass(EntityMeta entityMeta, Class<?> entityClass) { + Validate.notNull(entityMeta); + Validate.notNull(entityClass); entityMeta.setEntityClass(entityClass); } private void doName(EntityMeta entityMeta, Entity entityAnnotation) { + Validate.notNull(entityMeta); + Validate.notNull(entityAnnotation); String entityName = entityAnnotation.name(); if (StringUtils.isEmpty(entityName)) { entityName = JmStringUtil.toUnCapital(entityMeta.getEntityClass().getSimpleName()); @@ -138,6 +115,7 @@ private void doPropertyMeta(EntityMeta entityMeta) throws ColumnDuplicatedException, PropertyDuplicatedException, NotFoundException, NoSuchFieldException, UnsupportedInheritanceException, FieldDuplicatedException, CannotCreatePropertyException { + Validate.notNull(entityMeta); Field[] fields = getFields(entityMeta.getEntityClass()); for (Field f : fields) { f.setAccessible(true); @@ -146,6 +124,7 @@ } private void doTableMeta(EntityMeta entityMeta) { + Validate.notNull(entityMeta); TableMeta tableMeta = tableMetaFactory.createTableMeta(entityMeta); entityMeta.setTableMeta(tableMeta); } @@ -163,7 +142,8 @@ private Field[] getFields(Class<?> entityClass) throws NotFoundException, NoSuchFieldException, UnsupportedInheritanceException, FieldDuplicatedException { - FieldMap fields = new FieldMap(); + Validate.notNull(entityClass); + ArrayMap<String, Field> fields = new ArrayMap<String, Field>(); for (Field f : ClassUtil.getDeclaredFields(entityClass)) { if (!ModifierUtil.isInstanceField(f)) { continue; 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-08 06:46:31 UTC (rev 3183) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaReaderImpl.java 2009-04-08 06:51:33 UTC (rev 3184) @@ -132,6 +132,7 @@ } private boolean isIgnoreShortClassName(String shortClassName) { + Validate.notNull(shortClassName); if (entityMetaReaderContext.getIgnoreShortClassNamePatterns().isEmpty()) { return false; } @@ -144,6 +145,7 @@ } private boolean isShortClassName(String shortClassName) { + Validate.notNull(shortClassName); if (entityMetaReaderContext.getShortClassNamePatterns().isEmpty()) { return true; } Modified: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/TableMetaFactoryImpl.java =================================================================== --- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/TableMetaFactoryImpl.java 2009-04-08 06:46:31 UTC (rev 3183) +++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/TableMetaFactoryImpl.java 2009-04-08 06:51:33 UTC (rev 3184) @@ -21,6 +21,7 @@ import javax.persistence.Table; import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.Validate; import org.jiemamy.composer.importer.meta.EntityMeta; import org.jiemamy.composer.importer.meta.TableMeta; @@ -35,6 +36,7 @@ public class TableMetaFactoryImpl implements TableMetaFactory { public TableMeta createTableMeta(EntityMeta entityMeta) { + Validate.notNull(entityMeta); TableMeta tableMeta = new TableMeta(); String defaultName = fromEntityNameToTableName(entityMeta.getName()); Table table = entityMeta.getEntityClass().getAnnotation(Table.class); @@ -59,6 +61,7 @@ } private String fromEntityNameToTableName(String entityName) { + Validate.notNull(entityName); return JmStringUtil.toSQLName(entityName); } }