protected Object buildOrRefreshObject(Map row, ClassDescriptor targetClassDescriptor, Object targetObject) { Object result = targetObject; FieldDescriptor fmd = null; if(targetObject == null) { // 1. create new object instance if needed // result = ClassHelper.buildNewObjectInstance(targetClassDescriptor); try { result = Class.forName((String) row.get(OJB_CONCRETE_CLASS_KEY)).newInstance(); } catch (Exception e) { throw new PersistenceBrokerException("Unexpected error while try to instantiate concrete PersistentJetspeedPrincipal instance of class: [" +row.get(OJB_CONCRETE_CLASS_KEY), e); } } // 2. fill all scalar attributes of the new object FieldDescriptor[] fields = targetClassDescriptor.getFieldDescriptions(); for (int i = 0; i < fields.length; i++) { fmd = fields[i]; fmd.getPersistentField().set(result, row.get(fmd.getColumnName())); } return result; }
@Override public void retrieveReference(Object obj, String pAttributeName) throws PersistenceBrokerException { // In the new version of the fenix-framework, where we use OIDs allover as foreign keys // this method is no longer called for retrieving references to single objects // (those described by an ObjectReferenceDescriptor). // Now, this method should be used only for retrieving collections. // // So, the code here is the merging of the original // PersistenceBrokerImpl.retrieveReference with the // QueryReferenceBroker.retrieveCollection method, changed to // use OIDs rather the primary keys (which remain to be, // still, the idInternal, to create the SQL queries. ClassDescriptor cld = getClassDescriptor(obj.getClass()); CollectionDescriptor cds = cld.getCollectionDescriptorByName(pAttributeName); if (cds == null) { throw new PersistenceBrokerException("In the Fenix Framework retrieveReference should be called only for collections"); } // this collection type will be used: Class collectionClass = cds.getCollectionClass(); Query fkQuery = getFKQuery((AbstractDomainObject) obj, cld, cds); ManageableCollection result = referencesBroker.getCollectionByQuery(collectionClass, fkQuery, false); cds.getPersistentField().set(obj, result); }