db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r378672 - in /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata: CollectionDescriptor.java ObjectReferenceDescriptor.java
Date Sat, 18 Feb 2006 01:14:36 GMT
Author: arminw
Date: Fri Feb 17 17:14:34 2006
New Revision: 378672

URL: http://svn.apache.org/viewcvs?rev=378672&view=rev
Log:
fix for test-suite errors caused by new ForeignKey class

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/CollectionDescriptor.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ObjectReferenceDescriptor.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/CollectionDescriptor.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/CollectionDescriptor.java?rev=378672&r1=378671&r2=378672&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/CollectionDescriptor.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/CollectionDescriptor.java
Fri Feb 17 17:14:34 2006
@@ -19,6 +19,7 @@
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Vector;
+import java.util.List;
 
 import org.apache.commons.lang.SystemUtils;
 import org.apache.ojb.broker.PersistenceBrokerException;
@@ -64,6 +65,17 @@
         super(descriptor);
     }
 
+    /**
+     * Override method from base class to declare foreign key
+     * field as inverse.
+     * @param fkField
+     * @param targetField
+     */
+    public void addForeignKeyField(Object fkField, String targetField)
+    {
+        addForeignKeyField(fkField, targetField, true);
+    }
+
     public String[] getFksToThisClass()
     {
         if (fksToThisClassAry == null)
@@ -259,23 +271,12 @@
         // close opening tag
         result       += "      >" + eol;
 
-        // write elements
-         // inverse fk elements
-        for (int i=0;i<getForeignKeyFields().size();i++)
-        {
-        Object obj = getForeignKeyFields().get(i);
-        if (obj instanceof Integer)
-        {
-                String fkId = obj.toString();
-            result += "        " + tags.getOpeningTagNonClosingById(INVERSE_FK) + " ";
-                result += tags.getAttribute(FIELD_ID_REF, fkId) + "/>" + eol;
-        }
-        else
-        {
-                String fk = (String) obj;
-            result += "        " + tags.getOpeningTagNonClosingById(INVERSE_FK) + " ";
-                result += tags.getAttribute(FIELD_REF, fk) + "/>" + eol;
-        }
+        // write foreignkey elements
+        List fkf = getForeignKeyFields();
+        for(int i = 0; i < fkf.size(); i++)
+        {
+            ForeignKey fk =  (ForeignKey) fkf.get(i);
+            result += (fk.toXML());
         }
 
         // write optional M:N elements

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ObjectReferenceDescriptor.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ObjectReferenceDescriptor.java?rev=378672&r1=378671&r2=378672&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ObjectReferenceDescriptor.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ObjectReferenceDescriptor.java
Fri Feb 17 17:14:34 2006
@@ -350,11 +350,22 @@
      */
     public void addForeignKeyField(Object fkField, String targetField)
     {
+        addForeignKeyField(fkField, targetField, false);
+    }
+
+    /**
+     * Add a foreign key field.
+     * @param fkField the id or name of the foreign key field
+     * @param targetField the name of the target field
+     * @param inverse Flag to mark inverse foreign key fields.
+     */
+    protected void addForeignKeyField(Object fkField, String targetField, boolean inverse)
+    {
         if (m_ForeignKeyFields == null)
         {
             m_ForeignKeyFields = new Vector();
         }
-        m_ForeignKeyFields.add(new ForeignKey(fkField, targetField));
+        m_ForeignKeyFields.add(new ForeignKey(fkField, targetField, inverse));
     }
 
 
@@ -733,29 +744,11 @@
 
         // elements
         // write foreignkey elements
-        for( int i = 0; i < getForeignKeyFields().size(); i++ )
+        List fkf = getForeignKeyFields();
+        for(int i = 0; i < fkf.size(); i++)
         {
-            Object obj = getForeignKeyFields().get( i );
-            if( obj instanceof Integer )
-            {
-                String fkId = obj.toString();
-                result.append( "        " );
-                result.append( tags.getOpeningTagNonClosingById( FOREIGN_KEY ) );
-                result.append( " " );
-                result.append( tags.getAttribute( FIELD_ID_REF, fkId ) );
-                result.append( "/>" );
-                result.append( eol );
-            }
-            else
-            {
-                String fk = ( String ) obj;
-                result.append( "        " );
-                result.append( tags.getOpeningTagNonClosingById( FOREIGN_KEY ) );
-                result.append( " " );
-                result.append( tags.getAttribute( FIELD_REF, fk ) );
-                result.append( "/>" );
-                result.append( eol );
-            }
+            ForeignKey fk =  (ForeignKey) fkf.get(i);
+            result.append(fk.toXML());
         }
 
         // closing tag
@@ -768,17 +761,50 @@
     /**
      * Helper to store the fkField and the field it's referencing.
      */
-    static class ForeignKey implements Serializable
+    static class ForeignKey implements Serializable, XmlCapable
     {
         private static final long serialVersionUID = 3256718468362482741L;
-
+        boolean inverse;
         Object fkField;
         String targetField;
 
-        ForeignKey(Object fkField, String targetField)
+        public ForeignKey(Object fkField, String targetField, boolean inverse)
         {
             this.fkField = fkField;
             this.targetField = targetField;
+            this.inverse = inverse;
+        }
+
+        public String toXML()
+        {
+            RepositoryTags tags = RepositoryTags.getInstance();
+            String eol = System.getProperty( "line.separator" );
+            // opening tag
+            StringBuffer result = new StringBuffer();
+            result.append( "        " );
+            if(inverse) result.append( tags.getOpeningTagNonClosingById( INVERSE_FK ) );
+            else result.append( tags.getOpeningTagNonClosingById( FOREIGN_KEY ) );
+            result.append( " " );
+            String fk;
+            if(fkField instanceof String)
+            {
+                fk = ( String ) fkField;
+                result.append( tags.getAttribute( FIELD_REF, fk ) );
+            }
+            else
+            {
+                fk = fkField.toString();
+                result.append( tags.getAttribute( FIELD_ID_REF, fk ) );
+            }
+            result.append( " " );
+            if(targetField != null)
+            {
+                result.append( tags.getAttribute(TARGET_FIELD_REF, targetField));
+            }
+            result.append( "/>" );
+            result.append( eol );
+
+            return result.toString();
         }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message