View Javadoc
1   package org.kuali.ole.olekrad.dao.impl;
2   
3   import org.kuali.rice.krad.bo.PersistableBusinessObject;
4   import org.kuali.rice.krad.dao.impl.BusinessObjectDaoOjb;
5   import org.kuali.rice.krad.service.PersistenceStructureService;
6   import org.kuali.rice.krad.util.ObjectUtils;
7   import org.springframework.dao.DataAccessException;
8   
9   import java.util.Iterator;
10  import java.util.List;
11  import java.util.Set;
12  
13  /**
14   * Created by sheiksalahudeenm on 9/5/2015.
15   */
16  public class OleBusinessObjectDaoOjb extends BusinessObjectDaoOjb {
17  
18      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BusinessObjectDaoOjb.class);
19  
20      public OleBusinessObjectDaoOjb(PersistenceStructureService persistenceStructureService) {
21          super(persistenceStructureService);
22      }
23  
24      @Override
25      public List<? extends PersistableBusinessObject> save(List businessObjects) throws DataAccessException {
26          if ( LOG.isDebugEnabled() ) {
27              LOG.debug( "About to persist the following BOs:" );
28              for ( Object bo : businessObjects ) {
29                  LOG.debug( "   --->" + bo );
30              }
31          }
32          for (Iterator i = businessObjects.iterator(); i.hasNext();) {
33              PersistableBusinessObject bo = (PersistableBusinessObject) i.next();
34              // refresh bo to get db copy of collections
35              Set<String> boCollections = getPersistenceStructureService().listCollectionObjectTypes(bo.getClass()).keySet();
36              PersistableBusinessObject savedBo = null;
37              if (!boCollections.isEmpty()) {
38                  // refresh bo to get db copy of collections
39                  savedBo = (PersistableBusinessObject) ObjectUtils.deepCopy(bo);
40                  for (String boCollection : boCollections) {
41                      if (getPersistenceStructureService().isCollectionUpdatable(savedBo.getClass(), boCollection)) {
42                          savedBo.refreshReferenceObject(boCollection);
43                      }
44                  }
45                  getOjbCollectionHelper().processCollections(this, bo, savedBo);
46              }
47              getPersistenceBrokerTemplate().store(bo);
48          }
49          return businessObjects;
50      }
51  }