View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.engine.node.dao.impl;
17  
18  import java.util.List;
19  
20  import javax.persistence.EntityManager;
21  import javax.persistence.PersistenceContext;
22  
23  import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
24  import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria;
25  import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria;
26  import org.kuali.rice.kew.engine.node.Branch;
27  import org.kuali.rice.kew.engine.node.BranchState;
28  import org.kuali.rice.kew.engine.node.dao.BranchDAO;
29  
30  /**
31   * This is a description of what this class does - Garey don't forget to fill this in. 
32   * 
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   *
35   */
36  public class BranchDAOJpaImpl implements BranchDAO {
37  
38  	 @PersistenceContext(unitName="kew-unit")
39  	 private EntityManager entityManager;
40  	
41  	/**
42  	 * This overridden method ...
43  	 * 
44  	 * @see org.kuali.rice.kew.engine.node.dao.BranchDAO#deleteBranchStates(java.util.List)
45  	 */
46  	public void deleteBranchStates(List<Long> statesToBeDeleted) {
47  		for(Long stateId : statesToBeDeleted){
48  			this.deleteBranchStatesById(stateId);
49  		}
50  
51  	}
52  
53  	/**
54  	 * This overridden method ...
55  	 * 
56  	 * @see org.kuali.rice.kew.engine.node.dao.BranchDAO#save(org.kuali.rice.kew.engine.node.Branch)
57  	 */
58  	public void save(Branch branch) {
59  		  if (branch.getBranchId() == null) {
60  	            entityManager.persist(branch);
61  	        } else {
62  	            OrmUtils.merge(entityManager, branch);
63  	        }
64  
65  	}
66  	
67  	 protected void deleteBranchStatesById(Long stateId){
68  	    	Criteria criteria = new Criteria("BranchState", "branchState");
69  	    	criteria.eq("branchStateId", stateId);	        	        
70  	        BranchState branchState = (BranchState)new QueryByCriteria(entityManager, criteria).toQuery().getSingleResult();
71  	        entityManager.remove(branchState);
72  	    }
73  
74      public EntityManager getEntityManager() {
75          return this.entityManager;
76      }
77  
78      public void setEntityManager(EntityManager entityManager) {
79          this.entityManager = entityManager;
80      }
81  
82  }