1 16 package com.blandware.atleap.persistence.hibernate.core; 17 18 import com.blandware.atleap.common.util.PartialCollection; 19 import com.blandware.atleap.common.util.QueryInfo; 20 import com.blandware.atleap.model.core.ApplicationResource; 21 import com.blandware.atleap.persistence.core.ApplicationResourceDAO; 22 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import java.util.Map ; 26 27 34 public class ApplicationResourceDAOHibernate extends BaseDAOHibernate implements ApplicationResourceDAO { 35 36 39 public ApplicationResourceDAOHibernate() { 40 } 41 42 45 public void createApplicationResource(ApplicationResource applicationResource) { 46 getHibernateTemplate().save(applicationResource); 47 } 48 49 52 public ApplicationResource retrieveApplicationResource(ApplicationResource.ApplicationResourceID id) { 53 return (ApplicationResource) getHibernateTemplate().get(ApplicationResource.class, id); 54 } 55 56 59 public void updateApplicationResource(ApplicationResource applicationResource) { 60 getHibernateTemplate().saveOrUpdate(applicationResource); 61 } 62 63 66 public void deleteApplicationResource(ApplicationResource applicationResource) { 67 getHibernateTemplate().delete(applicationResource); 68 } 69 70 73 public PartialCollection listApplicationResources(QueryInfo queryInfo) { 74 String whereClause = new String (); 75 String orderByClause = new String (); 76 if ( queryInfo != null ) { 77 whereClause = queryInfo.getWhereClause(); 78 orderByClause = queryInfo.getOrderByClause(); 79 if ( whereClause == null ) { 80 whereClause = new String (); 81 } 82 if ( orderByClause != null && orderByClause.length() != 0 ) { 83 orderByClause = " order by " + orderByClause; 84 } else { 85 orderByClause = " order by r.id.key"; 86 } 87 } 88 89 90 ArrayList args = new ArrayList (); 91 String localeIdentifier = null; 92 if ( queryInfo != null ) { 93 Map queryParameters = queryInfo.getQueryParameters(); 94 localeIdentifier = (String ) queryParameters.get("localeIdentifier"); 95 } 96 97 if ( localeIdentifier != null ) { 98 if ( whereClause.length() > 0 ) { 99 whereClause += " and"; 100 } 101 whereClause += " (r.id.locale.identifier = ? or r.id.locale.defaultInstance = 'T')"; 102 args.add(localeIdentifier); 103 } 104 105 if ( whereClause.trim().length() > 0 ) { 106 whereClause = " where " + whereClause; 107 } 108 109 List list = null; 110 Integer total = null; 111 String hqlPart = "from ApplicationResource r" + whereClause; 112 if ( queryInfo != null && (queryInfo.getLimit() != null || queryInfo.getOffset() != null) ) { 113 String hqlForTotal = "select count(distinct r.id.key) " + hqlPart; 114 total = (Integer ) findUniqueResult(hqlForTotal, args.toArray()); 115 if ( total == null ) { 116 total = new Integer (0); 117 } 118 } 119 if ( total == null || total.intValue() > 0 ) { 122 String hql = "select r " + hqlPart + orderByClause; 123 list = executeFind(hql, queryInfo, args.toArray()); 124 if ( total == null ) { 125 total = new Integer (list.size()); 126 } 127 } else { 128 list = new ArrayList (); 129 } 130 return new PartialCollection(list, total); 131 } 132 133 } 134 | Popular Tags |