1 19 20 package org.efs.openreports.providers.persistence; 21 22 import java.util.List ; 23 24 import org.hibernate.HibernateException; 25 import org.hibernate.Session; 26 27 import org.apache.log4j.Logger; 28 import org.efs.openreports.objects.ORProperty; 29 import org.efs.openreports.providers.HibernateProvider; 30 import org.efs.openreports.providers.ProviderException; 31 32 public class PropertiesPersistenceProvider 33 { 34 protected static Logger log = Logger 35 .getLogger(PropertiesPersistenceProvider.class.getName()); 36 37 public PropertiesPersistenceProvider() throws ProviderException 38 { 39 super(); 40 41 log.info("PropertiesPersistenceProvider Created."); 42 } 43 44 public ORProperty getProperty(String key) throws ProviderException 45 { 46 try 47 { 48 Session session = HibernateProvider.openSession(); 49 50 try 51 { 52 List list = session.createQuery( 53 "from org.efs.openreports.objects.ORProperty as orProperty " 54 + "where orProperty.key = ?").setCacheable(true).setString(0, key).list(); 55 56 if (list.size() == 0) 57 return null; 58 59 ORProperty property = (ORProperty) list.get(0); 60 61 return property; 62 } 63 catch (HibernateException he) 64 { 65 throw he; 66 } 67 finally 68 { 69 session.close(); 70 } 71 } 72 catch (HibernateException he) 73 { 74 throw new ProviderException(he); 75 } 76 } 77 78 public ORProperty insertProperty(ORProperty property) 79 throws ProviderException 80 { 81 return (ORProperty) HibernateProvider.save(property); 82 } 83 84 public void updateProperty(ORProperty property) throws ProviderException 85 { 86 HibernateProvider.update(property); 87 } 88 89 public void deleteProperty(ORProperty property) throws ProviderException 90 { 91 try 92 { 93 HibernateProvider.delete(property); 94 } 95 catch (ConstraintException ce) 96 { 97 throw new ProviderException(ce.getMessage()); 98 } 99 } 100 101 } | Popular Tags |