db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/core PersistenceBrokerImpl.java
Date Wed, 01 Oct 2003 18:56:36 GMT
brj         2003/10/01 11:56:36

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
  Log:
  changed sequence of store, rerences are stored before assigning reference fk
  
  Revision  Changes    Path
  1.37      +21 -33    db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- PersistenceBrokerImpl.java	17 Sep 2003 19:49:34 -0000	1.36
  +++ PersistenceBrokerImpl.java	1 Oct 2003 18:56:36 -0000	1.37
  @@ -728,20 +728,15 @@
               Class refClass = ProxyHelper.getRealClass(ref);
               ClassDescriptor refCld = descriptorRepository.getDescriptorFor(refClass);
   
  -            // by C.Worley: assignFK on referenced obj, traverse the references
  -            // this needs further investigation
  -            // assignReferenceFKs(ref, refCld.getObjectReferenceDescriptors()); 
  -            
  -            refPkValues = brokerHelper.getKeyValues(refCld, ref, false);
  +            refPkValues = brokerHelper.getKeyValues(refCld, ref, false);           
           }
   
           for (int i = 0; i < objFkFields.length; i++)
           {
               objFkFields[i].getPersistentField().set(realObj, refPkValues[i]);
           }
  -
       }
  -
  +    
       /**
        * Store collections of objects poiting to <b>obj</b>.
        * All object which have a FK poiting to this object (Via CollectionDescriptors)
  @@ -1974,45 +1969,38 @@
        * can recurse this function
        * @param obj
        * @param cld
  -     * @param oid
  +     * @param oid   BRJ: what is it good for ???
        * @param insert
        */
   	private void storeToDb(Object obj, ClassDescriptor cld, Identity oid, boolean insert)
   	{
  +        Vector ords = cld.getObjectReferenceDescriptors();
  +        
  +        if (ords.size() > 0)
  +        {    
  +            // 1. store references
  +            storeReferences(obj, ords);
  +            
  +            // 2. assign fk of references
  +            assignReferenceFKs(obj, ords);
  +        }
  +        
   		Object[] pkValues = oid.getPrimaryKeyValues();
   
  -		// only do the update/insert if all PK values are either defined as
  -		// autoincrement or locking, or do hold valid values.
  -        // BRJ: if the first check fails, assign foreign keys and check again
   		if (!assertValidPkFields(cld.getPkFields(), pkValues))
   		{
  -            // BRJ: assign fk values, they may be part of pk
  -			// 1. assign foreign key values so that they can be stored in step 2
  -			assignReferenceFKs(obj, cld.getObjectReferenceDescriptors());
  -
  +            // BRJ: fk values may be part of pk, but the are not known during 
  +            // creation of Identity. so we have to get them here
   			pkValues = serviceBrokerHelper().getKeyValues(cld, obj);
  +            
   			if (!assertValidPkFields(cld.getPkFields(), pkValues))
   			{
  -				String append = " on insert";
  -				if (insert)
  -					append = " on insert";
  -				else
  -					append = " on update";
  +				String append = insert ? " on insert" : " on update" ;
   				throw new PersistenceBrokerException("assertValidPkFields failed for Object of type:
" + cld.getClassNameOfObject() + append);
   			}
   		}
  -		else
  -		{
  -			// 1. assign foreign key values so that they can be stored in step 2
  -			// todo: this should be done through sequenceManager so that it can be handled (ignored?)
  -			// if using db auto_increment (ex: SequenceManagerMySQLImpl)
  -			assignReferenceFKs(obj, cld.getObjectReferenceDescriptors());
  -		}
  -
  -		// 2. store references (1:1) associations to avoid FK violations
  -		storeReferences(obj, cld.getObjectReferenceDescriptors());
   
  -		// setreferenceFKs for auto_inc dbs - this can be ignored by hi low or any that do pre
assignment
  +        // setreferenceFKs for auto_inc dbs - this can be ignored by hi low or any that
do pre assignment
   		try
   		{
   			sequenceManager.setReferenceFKs(obj, cld);
  @@ -2028,7 +2016,7 @@
   		 * 1. store super classes, topmost parent first
   		 * 2. go down through heirarchy until current class
   		 * 3. todo: store to full extent?
  -		  */
  +		 */
   		storeSuperClasses(obj, cld, oid, insert);
   
   		// 3. store primitive typed attributes (Or is THIS step 3 ?)
  
  
  

---------------------------------------------------------------------
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