1 package org.kuali.student.enrollment.class2.courseoffering.dao;
2
3 import org.kuali.student.enrollment.class2.courseoffering.model.CodeGeneratorLocksEntity;
4 import org.kuali.student.r2.common.dao.GenericEntityDao;
5 import org.springframework.transaction.annotation.Propagation;
6 import org.springframework.transaction.annotation.Transactional;
7
8
9
10
11
12
13
14
15 public class CodeGeneratorLocksDao extends GenericEntityDao<CodeGeneratorLocksEntity> implements CodeGeneratorLocksDaoApi {
16
17 @Transactional(propagation= Propagation.REQUIRES_NEW)
18 public void createLock (String code, String key, String namespace){
19 CodeGeneratorLocksEntity entity = new CodeGeneratorLocksEntity();
20 entity.setCode(code);
21 entity.setUniqueKey(key);
22 entity.setNamespace(namespace);
23 em.persist(entity);
24 }
25 @Transactional
26 public void removeLock (String code, String key, String namespace){
27 em.createQuery("delete from CodeGeneratorLocksEntity a where a.code=:code and a.uniqueKey=:uniqueKey and a.namespace=:namespace")
28 .setParameter("code", code).setParameter("uniqueKey", key).setParameter("namespace", namespace).executeUpdate();
29 }
30 @Transactional
31 public void cleanLocks (String key, String pendingKey, String namespace){
32
33 em.createQuery("delete from CodeGeneratorLocksEntity a where a.uniqueKey=:key and a.namespace=:namespace and 0 = (Select count(*) from CodeGeneratorLocksEntity b where b.uniqueKey=:pendingKey and b.namespace=:namespace) ")
34 .setParameter("key", key).setParameter("namespace", namespace).setParameter("pendingKey", pendingKey).executeUpdate();
35 }
36 }