[cvs] expresso commit by lhamel: addMaster() function is complement to

JCorporate Ltd jcorp at jcorporate.com
Fri Feb 18 19:43:04 UTC 2005


Log Message:
-----------
addMaster() function is complement to addDetail function, but allows a client application to add a detail record to a library DBObject even without the library source

Modified Files:
--------------
    expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj:
        DBObject.java

Revision Data
-------------
Index: DBObject.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObject.java,v
retrieving revision 1.240
retrieving revision 1.241
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObject.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObject.java -u -r1.240 -r1.241
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObject.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObject.java
@@ -587,19 +587,44 @@
 
     /**
      * Specify a new "detail" db object, and the fields in this object
-     * they specify the fields in the related object
+     * that form a foreign key with the fields in the related object.
+     *
+     * This method is typically used in setupFields() to indicate cascading delete
+     * of all detail records when the master record is deleted.
      *
      * @param objName          The class name of the related object. There is assumed to be
-     *                         a one to one or one to many relationship from this object to the specified object
-     * @param keyFieldsLocal   A pipe-delimited list of field names in this object
-     * @param keyFieldsForeign A pipe-delimieted list of field names in the other object
+     *                         a one to one or one to many relationship to this object to the specified object
+     * @param keyFieldsLocalMaster   A pipe-delimited list of field names in this object
+     * @param keyFieldsForeignDetail A pipe-delimieted list of field names in the other detail object
      * @throws DBException upon error.
      */
     protected synchronized void addDetail(String objName,
-                                          String keyFieldsLocal,
-                                          String keyFieldsForeign)
+                                          String keyFieldsLocalMaster,
+                                          String keyFieldsForeignDetail)
+            throws DBException {
+        getDef().addDetail(objName, keyFieldsLocalMaster, keyFieldsForeignDetail);
+    }
+
+    /**
+     * Specify a new "master" db object, and the fields in this object
+     * that are the foreign key to the fields in the related object.  This is typically
+     * done to enable cascading deletion of detail records.
+     * <p/>
+     * Note: this method is the complement of addDetail(). You need only
+     * call one of these two methods to establish the foreign key.  addMaster() is supplied
+     * for the use case where the master DBObject is in a library where you do not have source code,
+     * and you want to add a detail record that will be deleted if the master is deleted.
+     *
+     * @param masterObjName    The class name of the related object. There is assumed to be
+     *                         a one to one or one to many relationship from this object to the specified object
+     * @param keyFieldsMasterKey   A pipe-delimited list of field names in master object
+     * @param keyFieldsForeignDetail A pipe-delimieted list of field names in this object
+     */
+    synchronized protected void addMaster(String masterObjName, String keyFieldsMasterKey,
+                                       String keyFieldsForeignDetail)
             throws DBException {
-        getDef().addDetail(objName, keyFieldsLocal, keyFieldsForeign);
+        DBObjectDef masterDef = (DBObjectDef) sMetadataMap.get(masterObjName);
+        masterDef.addDetail(myClassName, keyFieldsMasterKey, keyFieldsForeignDetail);
     }
 
     /**


More information about the cvs mailing list