| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.edl.impl.dao.impl; |
| 17 | |
|
| 18 | |
import java.util.ArrayList; |
| 19 | |
import java.util.List; |
| 20 | |
|
| 21 | |
import javax.persistence.EntityManager; |
| 22 | |
import javax.persistence.PersistenceContext; |
| 23 | |
|
| 24 | |
import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; |
| 25 | |
import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria; |
| 26 | |
import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria; |
| 27 | |
import org.kuali.rice.edl.impl.bo.EDocLiteAssociation; |
| 28 | |
import org.kuali.rice.edl.impl.bo.EDocLiteDefinition; |
| 29 | |
import org.kuali.rice.edl.impl.dao.EDocLiteDAO; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | 0 | public class EDocLiteDAOJpaImpl implements EDocLiteDAO { |
| 37 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(EDocLiteDAOJpaImpl.class); |
| 38 | |
|
| 39 | |
private static final String ACTIVE_IND_CRITERIA = "activeInd"; |
| 40 | |
private static final String NAME_CRITERIA = "name"; |
| 41 | |
|
| 42 | |
@PersistenceContext(unitName = "kew-unit") |
| 43 | |
private EntityManager entityManager; |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
public void saveEDocLiteDefinition(final EDocLiteDefinition edocLiteData) { |
| 51 | 0 | if (edocLiteData.getEDocLiteDefId() == null) { |
| 52 | 0 | entityManager.persist(edocLiteData); |
| 53 | |
} else { |
| 54 | 0 | OrmUtils.merge(entityManager, edocLiteData); |
| 55 | |
} |
| 56 | 0 | } |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
public void saveEDocLiteAssociation(final EDocLiteAssociation assoc) { |
| 64 | 0 | if (assoc.getEdocLiteAssocId() == null) { |
| 65 | 0 | entityManager.persist(assoc); |
| 66 | |
} else { |
| 67 | 0 | OrmUtils.merge(entityManager, assoc); |
| 68 | |
} |
| 69 | 0 | } |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
public EDocLiteDefinition getEDocLiteDefinition(final String defName) { |
| 77 | 0 | final Criteria crit = new Criteria(EDocLiteDefinition.class.getName()); |
| 78 | 0 | crit.eq(NAME_CRITERIA, defName); |
| 79 | 0 | crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE); |
| 80 | 0 | return (EDocLiteDefinition) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult(); |
| 81 | |
} |
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
public EDocLiteAssociation getEDocLiteAssociation(final String docTypeName) { |
| 89 | 0 | final Criteria crit = new Criteria(EDocLiteAssociation.class.getName()); |
| 90 | 0 | crit.eq("edlName", docTypeName); |
| 91 | 0 | crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE); |
| 92 | 0 | return (EDocLiteAssociation) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult(); |
| 93 | |
} |
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
@SuppressWarnings("unchecked") |
| 101 | |
public List<String> getEDocLiteDefinitions() { |
| 102 | 0 | final Criteria crit = new Criteria(EDocLiteDefinition.class.getName()); |
| 103 | 0 | crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE); |
| 104 | |
|
| 105 | 0 | final List<EDocLiteDefinition> defs = (List<EDocLiteDefinition>) new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
| 106 | 0 | final ArrayList<String> names = new ArrayList<String>(defs.size()); |
| 107 | 0 | for (EDocLiteDefinition def : defs) { |
| 108 | 0 | names.add(def.getName()); |
| 109 | |
} |
| 110 | 0 | return names; |
| 111 | |
} |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
@SuppressWarnings("unchecked") |
| 119 | |
public List<EDocLiteAssociation> getEDocLiteAssociations() { |
| 120 | 0 | final Criteria crit = new Criteria(EDocLiteAssociation.class.getName()); |
| 121 | 0 | crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE); |
| 122 | 0 | return (List<EDocLiteAssociation>) new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
| 123 | |
} |
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
@SuppressWarnings("unchecked") |
| 131 | |
public List<EDocLiteAssociation> search(final EDocLiteAssociation edocLite) { |
| 132 | 0 | final Criteria crit = new Criteria(EDocLiteAssociation.class.getName()); |
| 133 | 0 | if (edocLite.getActiveInd() != null) { |
| 134 | 0 | crit.eq(ACTIVE_IND_CRITERIA, edocLite.getActiveInd()); |
| 135 | |
} |
| 136 | 0 | if (edocLite.getDefinition() != null) { |
| 137 | 0 | crit.like("UPPER(definition)", "%" + edocLite.getDefinition().toUpperCase() + "%"); |
| 138 | |
} |
| 139 | 0 | if (edocLite.getEdlName() != null) { |
| 140 | 0 | crit.like("UPPER(edlName)", "%" + edocLite.getEdlName().toUpperCase() + "%"); |
| 141 | |
} |
| 142 | 0 | if (edocLite.getStyle() != null) { |
| 143 | 0 | crit.like("UPPER(style)", "%" + edocLite.getStyle().toUpperCase() + "%"); |
| 144 | |
} |
| 145 | 0 | return (List<EDocLiteAssociation>) new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
| 146 | |
} |
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
public EDocLiteAssociation getEDocLiteAssociation(final Long associationId) { |
| 154 | 0 | final Criteria crit = new Criteria(EDocLiteAssociation.class.getName()); |
| 155 | 0 | crit.eq("edocLiteAssocId", associationId); |
| 156 | 0 | return (EDocLiteAssociation) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult(); |
| 157 | |
} |
| 158 | |
|
| 159 | |
public EntityManager getEntityManager() { |
| 160 | 0 | return this.entityManager; |
| 161 | |
} |
| 162 | |
|
| 163 | |
public void setEntityManager(EntityManager entityManager) { |
| 164 | 0 | this.entityManager = entityManager; |
| 165 | 0 | } |
| 166 | |
} |