Coverage Report - org.kuali.mobility.user.dao.UserDaoImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
UserDaoImpl
0%
0/45
0%
0/8
2.455
 
 1  
 /**
 2  
  * Copyright 2011 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.mobility.user.dao;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import javax.persistence.EntityManager;
 21  
 import javax.persistence.PersistenceContext;
 22  
 import javax.persistence.Query;
 23  
 
 24  
 import org.kuali.mobility.user.entity.User;
 25  
 import org.kuali.mobility.user.entity.UserPreference;
 26  
 import org.springframework.stereotype.Repository;
 27  
 
 28  
 @Repository
 29  
 public class UserDaoImpl implements UserDao {
 30  
 
 31  
     @PersistenceContext
 32  
     private EntityManager entityManager;
 33  
 
 34  0
     public UserDaoImpl() {}
 35  
     
 36  
     public User findUserByDeviceId(String deviceId) {
 37  0
         Query query = entityManager.createQuery("select u from User u where u.deviceId = :deviceId");
 38  0
         query.setParameter("deviceId", deviceId);
 39  
         try {
 40  0
             return (User) query.getSingleResult();
 41  0
         } catch (Exception e) {
 42  0
             return null;
 43  
         }
 44  
     }
 45  
     
 46  
     public User findUserByPrincipalName(String principalName) {
 47  0
         Query query = entityManager.createQuery("select u from User u where u.principalName = :principalName");
 48  0
         query.setParameter("principalName", principalName);
 49  
         try {
 50  0
             return (User) query.getSingleResult();
 51  0
         } catch (Exception e) {
 52  0
             return null;
 53  
         }
 54  
     }
 55  
     
 56  
     public User findUserByPrincipalId(Long principalId) {
 57  0
         Query query = entityManager.createQuery("select u from User u where u.principalId = :principalId");
 58  0
         query.setParameter("principalId", principalId);
 59  
         try {
 60  0
             return (User) query.getSingleResult();
 61  0
         } catch (Exception e) {
 62  0
             return null;
 63  
         }
 64  
     }
 65  
 
 66  
     public void saveUser(User user) {
 67  0
         if (user == null) {
 68  0
             return;
 69  
         }
 70  0
         if (user.getPrincipalId() == null) {
 71  0
             entityManager.persist(user);
 72  
         } else {
 73  0
             entityManager.merge(user);
 74  
         }
 75  0
     }
 76  
     
 77  
         public void saveUserPreference(UserPreference userPreference) {
 78  0
         if (userPreference == null) {
 79  0
             return;
 80  
         }
 81  0
         if (userPreference.getPreferenceId() == null) {
 82  0
             entityManager.persist(userPreference);
 83  
         } else {
 84  0
             entityManager.merge(userPreference);
 85  
         }                
 86  0
         }
 87  
 
 88  
         public void deleteUserPreferenceById(Long preferenceId) {
 89  0
         Query query = entityManager.createQuery("delete from UserPreference up where up.preferenceId = :preferenceId");
 90  0
         query.setParameter("preferenceId", preferenceId);
 91  0
         query.executeUpdate();
 92  0
         }
 93  
 
 94  
         @SuppressWarnings("unchecked")
 95  
         public List<UserPreference> findAllUserPreferencesByPrincipalId(Long principalId) {
 96  0
         Query query = entityManager.createQuery("select up from UserPreference up where up.principalId = :principalId");
 97  0
         query.setParameter("principalId", principalId);
 98  
         try {
 99  0
             return (List<UserPreference>) query.getResultList();
 100  0
         } catch (Exception e) {
 101  0
             return null;
 102  
         }
 103  
         }
 104  
 
 105  
         public UserPreference findUserPreferenceByPreferenceId(Long preferenceId) {
 106  0
         Query query = entityManager.createQuery("select up from UserPreference up where up.preferenceId = :preferenceId");
 107  0
         query.setParameter("preferenceId", preferenceId);
 108  
         try {
 109  0
             return (UserPreference) query.getSingleResult();
 110  0
         } catch (Exception e) {
 111  0
             return null;
 112  
         }
 113  
         }
 114  
 
 115  
     public EntityManager getEntityManager() {
 116  0
         return entityManager;
 117  
     }
 118  
 
 119  
     public void setEntityManager(EntityManager entityManager) {
 120  0
         this.entityManager = entityManager;
 121  0
     }
 122  
     
 123  
 }