Clover Coverage Report - KS Common 1.2-M2-SNAPSHOT (Aggregated)
Coverage timestamp: Fri Apr 22 2011 04:34:25 EST
../../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
19   85   10   2.38
4   53   0.53   8
8     1.25  
1    
 
  AbstractCrudDaoImpl       Line # 26 19 0% 10 0 100% 1.0
 
  (407)
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15   
16    package org.kuali.student.common.dao.impl;
17   
18    import java.util.List;
19   
20    import javax.persistence.EntityManager;
21    import javax.persistence.Query;
22   
23    import org.kuali.student.common.dao.CrudDao;
24    import org.kuali.student.common.exceptions.DoesNotExistException;
25   
 
26    public abstract class AbstractCrudDaoImpl implements CrudDao {
27   
28    protected EntityManager em;
29   
 
30  5 toggle public EntityManager getEm() {
31  5 return em;
32    }
33   
 
34  221 toggle public void setEm(EntityManager em) {
35  221 this.em = em;
36    }
37   
38   
 
39  12002 toggle @Override
40    public <T> T fetch(Class<T> clazz, String key) throws DoesNotExistException {
41  12002 T entity = em.find(clazz, key);
42  12002 if (entity == null) {
43  115 throw new DoesNotExistException("No entity for key '" + key + "' found for " + clazz);
44    }
45  11887 return entity;
46    }
47   
 
48  42 toggle @SuppressWarnings("unchecked")
49    @Override
50    public <T> List<T> find(Class<T> clazz){
51   
52  42 String className = clazz.getSimpleName();
53   
54  42 Query q = em.createQuery("SELECT x FROM "+className+" x");
55  42 return (List<T>) q.getResultList();
56    }
57   
 
58  3454 toggle @Override
59    public <T> T create(T entity) {
60  3454 em.persist(entity);
61  3453 return entity;
62    }
63   
 
64  129 toggle @Override
65    public <T> void delete(Class<T> clazz, String key) throws DoesNotExistException {
66  129 T entity = em.find(clazz, key);
67  129 if (entity == null) {
68  9 throw new DoesNotExistException("No such key '" + key + "' for " + clazz);
69    }
70  120 em.remove(entity);
71    }
72   
 
73  677 toggle @Override
74    public void delete(Object entity) {
75  677 em.remove(entity);
76    }
77   
 
78  294 toggle @Override
79    public <T> T update(T entity) {
80  294 T updated = em.merge(entity);
81    //We need to flush here to make sure the version number is updated before we populate any messages that return the version
82  294 em.flush();
83  294 return updated;
84    }
85    }