1 19 20 package org.efs.openreports.providers.persistence; 21 22 import java.util.List ; 23 24 import org.apache.log4j.Logger; 25 import org.efs.openreports.objects.Report; 26 import org.efs.openreports.objects.ReportGroup; 27 import org.efs.openreports.providers.HibernateProvider; 28 import org.efs.openreports.providers.ProviderException; 29 import org.efs.openreports.util.LocalStrings; 30 import org.hibernate.HibernateException; 31 import org.hibernate.Session; 32 33 public class GroupPersistenceProvider 34 { 35 protected static Logger log = 36 Logger.getLogger(GroupPersistenceProvider.class.getName()); 37 38 public GroupPersistenceProvider() throws ProviderException 39 { 40 super(); 41 42 log.info("GroupPersistenceProvider Created."); 43 } 44 45 public ReportGroup getReportGroup(Integer id) throws ProviderException 46 { 47 return (ReportGroup) HibernateProvider.load(ReportGroup.class, id); 48 } 49 50 public List getReportGroups() throws ProviderException 51 { 52 String fromClause = 53 "from org.efs.openreports.objects.ReportGroup reportGroup order by reportGroup.name "; 54 55 return HibernateProvider.query(fromClause); 56 } 57 58 public List getGroupsForReport(Report report) throws ProviderException 59 { 60 try 61 { 62 Session session = HibernateProvider.openSession(); 63 64 try 65 { 66 List list = session.createQuery( 67 "from org.efs.openreports.objects.ReportGroup as reportGroup " 68 + "where ? in elements(reportGroup.reports)").setEntity(0, report).list(); 69 70 if (list.size() == 0) return null; 71 72 return list; 73 } 74 catch (HibernateException he) 75 { 76 throw he; 77 } 78 finally 79 { 80 session.close(); 81 } 82 } 83 catch (HibernateException he) 84 { 85 throw new ProviderException(he); 86 } 87 } 88 89 public ReportGroup insertReportGroup(ReportGroup reportGroup) 90 throws ProviderException 91 { 92 return (ReportGroup) HibernateProvider.save(reportGroup); 93 } 94 95 public void updateReportGroup(ReportGroup reportGroup) 96 throws ProviderException 97 { 98 HibernateProvider.update(reportGroup); 99 } 100 101 public void deleteReportGroup(ReportGroup reportGroup) 102 throws ProviderException 103 { 104 try 105 { 106 HibernateProvider.delete(reportGroup); 107 } 108 catch (ConstraintException ce) 109 { 110 throw new ProviderException(LocalStrings.getString(LocalStrings.ERROR_GROUP_DELETION)); 111 } 112 } 113 } | Popular Tags |