[Jiemamy-notify:1377] commit [2621] empテーブルのattribute順をsample . xmlと一致させた。 /

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 2月 6日 (金) 02:16:38 JST


Revision: 2621
          http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2621
Author:   daisuke_m
Date:     2009-02-06 02:16:38 +0900 (Fri, 06 Feb 2009)

Log Message:
-----------
empテーブルのattribute順をsample.xmlと一致させた。 /
XML出力時に、attributesをソートしてしまっていたのをナシに。 /

これでテスト通ったーー。

Modified Paths:
--------------
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomBuilder.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/test/TestModelBuilder.java

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


-------------- next part --------------
Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomBuilder.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomBuilder.java	2009-02-05 17:13:03 UTC (rev 2620)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomBuilder.java	2009-02-05 17:16:38 UTC (rev 2621)
@@ -72,7 +72,6 @@
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.commons.collections15.list.UnmodifiableList;
-import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.lang.ObjectUtils;
 import org.slf4j.Logger;
@@ -93,8 +92,6 @@
 import org.jiemamy.model.attribute.constraint.ForeignKeyModel;
 import org.jiemamy.model.attribute.constraint.KeyConstraintModel;
 import org.jiemamy.model.attribute.constraint.NotNullConstraintModel;
-import org.jiemamy.model.attribute.constraint.PrimaryKeyModel;
-import org.jiemamy.model.attribute.constraint.UniqueKeyModel;
 import org.jiemamy.model.attribute.constraint.ValueConstraintModel;
 import org.jiemamy.model.dataset.DataSetModel;
 import org.jiemamy.model.dataset.RecordModel;
@@ -141,14 +138,6 @@
 		return dataTypeElement;
 	}
 	
-	private static SortedSet<AttributeModel> sortAttributes(TableModel tableModel) {
-		SortedSet<AttributeModel> treeSet = new TreeSet<AttributeModel>(new AttributeComparator(tableModel));
-		for (AttributeModel attribute : tableModel.getAttributes()) {
-			treeSet.add(attribute);
-		}
-		return treeSet;
-	}
-	
 	private static SortedSet<Entry<ColumnRef, String>> sortDataEntry(EntityModel entity, RecordModel recordModel) {
 		SortedSet<Entry<ColumnRef, String>> treeSet =
 				new TreeSet<Map.Entry<ColumnRef, String>>(new RecordSetComparator(TableUtil
@@ -338,7 +327,7 @@
 				DomUtil.newChild(entityElement, END_SCRIPT, tableModel.getEndScript());
 				
 				Element attributesElement = DomUtil.newChild(entityElement, ATTRIBUTES);
-				for (AttributeModel attributeModel : sortAttributes(tableModel)) {
+				for (AttributeModel attributeModel : tableModel.getAttributes()) {
 					Element attributeElement = DomUtil.newChild(attributesElement, getQName(attributeModel));
 					attributeElement.setAttribute(CoreQName.ID.getQNameString(), attributeModel.getId().toString());
 					DomUtil.newChild(attributeElement, NAME, attributeModel.getName());
@@ -420,61 +409,6 @@
 	
 
 	/**
-	 * 属性の出力順を
-	 * 
-	 * @author daisuke
-	 */
-	private static class AttributeComparator implements Comparator<AttributeModel> {
-		
-		static final List<Class<? extends AttributeModel>> ORDER;
-		
-		static {
-			List<Class<? extends AttributeModel>> order = CollectionsUtil.newArrayList();
-			order.add(ColumnModel.class);
-			order.add(PrimaryKeyModel.class);
-			order.add(UniqueKeyModel.class);
-			order.add(ForeignKeyModel.class);
-			order.add(NotNullConstraintModel.class);
-			order.add(CheckConstraintModel.class);
-			ORDER = UnmodifiableList.decorate(order);
-		}
-		
-
-		private static int getOrder(Class<?>[] interfaces) {
-			for (Class<?> interf : interfaces) {
-				int index = ORDER.indexOf(interf);
-				if (index != ArrayUtils.INDEX_NOT_FOUND) {
-					return index;
-				}
-			}
-			return -1;
-		}
-		
-
-		private final TableModel tableModel;
-		
-
-		AttributeComparator(TableModel tableModel) {
-			this.tableModel = tableModel;
-			
-		}
-		
-		/**
-		 * {@inheritDoc}
-		 */
-		public int compare(AttributeModel o1, AttributeModel o2) {
-			int i1 = getOrder(o1.getClass().getInterfaces());
-			int i2 = getOrder(o2.getClass().getInterfaces());
-			if (i1 != i2) {
-				return i1 - i2;
-			}
-			
-			List<AttributeModel> attributes = tableModel.getAttributes();
-			return attributes.indexOf(o1) - attributes.indexOf(o2);
-		}
-	}
-	
-	/**
 	 * 出力レコードの並び順を、カラム定義順に合わせるコンパレータ。
 	 * 
 	 * @author daisuke

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/test/TestModelBuilder.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/test/TestModelBuilder.java	2009-02-05 17:13:03 UTC (rev 2620)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/test/TestModelBuilder.java	2009-02-05 17:16:38 UTC (rev 2621)
@@ -329,6 +329,8 @@
 			return;
 		}
 		
+		int pkIndex = tableEmp.getAttributes().indexOf(empPk);
+		
 		fkEmpEmp = factory.newModel(ForeignKeyModel.class, uuid.get("e43d3c43-33c8-4b02-aa42-83f2d868cfe6"));
 		fkEmpEmp.setName("emp_mgr_id_fkey");
 		KeyConstraintUtil.addKeyColumn(fkEmpEmp, empMgrId);
@@ -339,13 +341,13 @@
 		deferrability.setDeferrable(true);
 		deferrability.setInitiallyCheckTime(InitiallyCheckTime.DEFERRED);
 		fkEmpEmp.setDeferrability(deferrability);
-		tableEmp.getAttributes().add(fkEmpEmp);
+		tableEmp.getAttributes().add(pkIndex + 1, fkEmpEmp);
 		
 		fkEmpDept = factory.newModel(ForeignKeyModel.class, uuid.get("e7dd92b4-1d97-4be6-bab6-fa9fe26eb6ed"));
 		fkEmpDept.setName("emp_dept_id_fkey");
 		KeyConstraintUtil.addKeyColumn(fkEmpDept, empDeptId);
 		ForeignKeyUtil.addReferenceColumn(fkEmpDept, deptId);
-		tableEmp.getAttributes().add(fkEmpDept);
+		tableEmp.getAttributes().add(pkIndex + 2, fkEmpDept);
 	}
 	
 	private List<RecordModel> createDataSetEnDept() {

Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/AttributeComparator.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/AttributeComparator.java	                        (rev 0)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/AttributeComparator.java	2009-02-05 17:16:38 UTC (rev 2621)
@@ -0,0 +1,71 @@
+package org.jiemamy.utils;
+
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.commons.collections15.list.UnmodifiableList;
+import org.apache.commons.lang.ArrayUtils;
+
+import org.jiemamy.model.attribute.AttributeModel;
+import org.jiemamy.model.attribute.ColumnModel;
+import org.jiemamy.model.attribute.constraint.CheckConstraintModel;
+import org.jiemamy.model.attribute.constraint.ForeignKeyModel;
+import org.jiemamy.model.attribute.constraint.NotNullConstraintModel;
+import org.jiemamy.model.attribute.constraint.PrimaryKeyModel;
+import org.jiemamy.model.attribute.constraint.UniqueKeyModel;
+import org.jiemamy.model.entity.TableModel;
+
+/**
+ * 属性の出力順を整列させるコンパレータ。
+ * 
+ * @author daisuke
+ */
+class AttributeComparator implements Comparator<AttributeModel> {
+	
+	static final List<Class<? extends AttributeModel>> ORDER;
+	
+	static {
+		List<Class<? extends AttributeModel>> order = CollectionsUtil.newArrayList();
+		order.add(ColumnModel.class);
+		order.add(PrimaryKeyModel.class);
+		order.add(UniqueKeyModel.class);
+		order.add(ForeignKeyModel.class);
+		order.add(NotNullConstraintModel.class);
+		order.add(CheckConstraintModel.class);
+		ORDER = UnmodifiableList.decorate(order);
+	}
+	
+
+	private static int getOrder(Class<?>[] interfaces) {
+		for (Class<?> interf : interfaces) {
+			int index = ORDER.indexOf(interf);
+			if (index != ArrayUtils.INDEX_NOT_FOUND) {
+				return index;
+			}
+		}
+		return -1;
+	}
+	
+
+	private final TableModel tableModel;
+	
+
+	AttributeComparator(TableModel tableModel) {
+		this.tableModel = tableModel;
+		
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public int compare(AttributeModel o1, AttributeModel o2) {
+		int i1 = getOrder(o1.getClass().getInterfaces());
+		int i2 = getOrder(o2.getClass().getInterfaces());
+		if (i1 != i2) {
+			return i1 - i2;
+		}
+		
+		List<AttributeModel> attributes = tableModel.getAttributes();
+		return attributes.indexOf(o1) - attributes.indexOf(o2);
+	}
+}


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



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