001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kew.engine.node.dao.impl; 017 018import java.util.List; 019 020import javax.persistence.EntityManager; 021import javax.persistence.PersistenceContext; 022 023import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; 024import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria; 025import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria; 026import org.kuali.rice.kew.engine.node.Branch; 027import org.kuali.rice.kew.engine.node.BranchState; 028import org.kuali.rice.kew.engine.node.dao.BranchDAO; 029 030/** 031 * This is a description of what this class does - Garey don't forget to fill this in. 032 * 033 * @author Kuali Rice Team (rice.collab@kuali.org) 034 * 035 */ 036public class BranchDAOJpaImpl implements BranchDAO { 037 038 @PersistenceContext(unitName="kew-unit") 039 private EntityManager entityManager; 040 041 /** 042 * This overridden method ... 043 * 044 * @see org.kuali.rice.kew.engine.node.dao.BranchDAO#deleteBranchStates(java.util.List) 045 */ 046 public void deleteBranchStates(List<Long> statesToBeDeleted) { 047 for(Long stateId : statesToBeDeleted){ 048 this.deleteBranchStatesById(stateId); 049 } 050 051 } 052 053 /** 054 * This overridden method ... 055 * 056 * @see org.kuali.rice.kew.engine.node.dao.BranchDAO#save(org.kuali.rice.kew.engine.node.Branch) 057 */ 058 public void save(Branch branch) { 059 if (branch.getBranchId() == null) { 060 entityManager.persist(branch); 061 } else { 062 OrmUtils.merge(entityManager, branch); 063 } 064 065 } 066 067 protected void deleteBranchStatesById(Long stateId){ 068 Criteria criteria = new Criteria("BranchState", "branchState"); 069 criteria.eq("stateId", stateId); 070 BranchState branchState = (BranchState)new QueryByCriteria(entityManager, criteria).toQuery().getSingleResult(); 071 entityManager.remove(branchState); 072 } 073 074 public EntityManager getEntityManager() { 075 return this.entityManager; 076 } 077 078 public void setEntityManager(EntityManager entityManager) { 079 this.entityManager = entityManager; 080 } 081 082}