| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kew.useroptions.dao.impl; |
| 17 | |
|
| 18 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
| 19 | |
import org.kuali.rice.core.api.util.RiceConstants; |
| 20 | |
import org.kuali.rice.core.framework.persistence.platform.DatabasePlatform; |
| 21 | |
import org.kuali.rice.kew.useroptions.UserOptions; |
| 22 | |
import org.kuali.rice.kew.useroptions.dao.UserOptionsDAO; |
| 23 | |
|
| 24 | |
import javax.persistence.EntityManager; |
| 25 | |
import javax.persistence.PersistenceContext; |
| 26 | |
import java.util.ArrayList; |
| 27 | |
import java.util.Collection; |
| 28 | |
import java.util.List; |
| 29 | |
|
| 30 | |
|
| 31 | 0 | public class UserOptionsDaoJpaImpl implements UserOptionsDAO { |
| 32 | |
|
| 33 | |
@PersistenceContext |
| 34 | |
private EntityManager entityManager; |
| 35 | |
|
| 36 | |
public Long getNewOptionIdForActionList() { |
| 37 | 0 | return getPlatform().getNextValSQL("KREW_ACTN_LIST_OPTN_S", entityManager); |
| 38 | |
} |
| 39 | |
|
| 40 | |
protected DatabasePlatform getPlatform() { |
| 41 | 0 | return (DatabasePlatform) GlobalResourceLoader.getService(RiceConstants.DB_PLATFORM); |
| 42 | |
} |
| 43 | |
|
| 44 | |
public List findByUserQualified(String principalId, String likeString) { |
| 45 | 0 | return new ArrayList(entityManager.createNamedQuery("UserOptions.FindByUserQualified").setParameter("workflowId", principalId).setParameter("optionId", likeString).getResultList()); |
| 46 | |
} |
| 47 | |
|
| 48 | |
public void deleteByUserQualified(String principalId, String likeString) { |
| 49 | 0 | List<UserOptions> userOptions = (List<UserOptions>) entityManager.createNamedQuery("UserOptions.FindByUserQualified").setParameter("workflowId", principalId).setParameter("optionId", likeString).getResultList(); |
| 50 | 0 | for (UserOptions uo : userOptions) { |
| 51 | 0 | entityManager.remove(uo); |
| 52 | |
} |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
public Collection findByWorkflowUser(String principalId) { |
| 56 | 0 | return entityManager.createNamedQuery("UserOptions.FindByWorkflowId").setParameter("workflowId", principalId).getResultList(); |
| 57 | |
} |
| 58 | |
|
| 59 | |
public void save(UserOptions userOptions) { |
| 60 | 0 | if (userOptions.getOptionId() == null) { |
| 61 | 0 | entityManager.persist(userOptions); |
| 62 | |
} else { |
| 63 | 0 | entityManager.merge(userOptions); |
| 64 | |
} |
| 65 | 0 | } |
| 66 | |
|
| 67 | |
public void save(Collection<UserOptions> userOptions) { |
| 68 | 0 | if (userOptions != null) for (UserOptions option : userOptions) { |
| 69 | 0 | save(option); |
| 70 | |
} |
| 71 | 0 | } |
| 72 | |
|
| 73 | |
public void deleteUserOptions(UserOptions userOptions) { |
| 74 | 0 | UserOptions reattatched = entityManager.merge(userOptions); |
| 75 | 0 | entityManager.remove(reattatched); |
| 76 | 0 | } |
| 77 | |
|
| 78 | |
public UserOptions findByOptionId(String optionId, String principalId) { |
| 79 | 0 | return (UserOptions) entityManager.createNamedQuery("UserOptions.FindByOptionId").setParameter("optionId", optionId).setParameter("workflowId", principalId).getSingleResult(); |
| 80 | |
} |
| 81 | |
|
| 82 | |
public Collection findByOptionValue(String optionId, String optionValue) { |
| 83 | 0 | return entityManager.createNamedQuery("UserOptions.FindByOptionValue").setParameter("optionId", optionId).setParameter("optionValue", optionValue).getResultList(); |
| 84 | |
} |
| 85 | |
|
| 86 | |
public EntityManager getEntityManager() { |
| 87 | 0 | return this.entityManager; |
| 88 | |
} |
| 89 | |
|
| 90 | |
public void setEntityManager(EntityManager entityManager) { |
| 91 | 0 | this.entityManager = entityManager; |
| 92 | 0 | } |
| 93 | |
} |