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.ContentDocument; 21 import com.blandware.atleap.model.core.ResourceData; 22 import com.blandware.atleap.model.core.ContentLocale; 23 import com.blandware.atleap.model.core.Role; 24 import com.blandware.atleap.persistence.core.ContentDocumentDAO; 25 import com.blandware.atleap.persistence.exception.DeleteException; 26 27 import java.util.ArrayList ; 28 import java.util.List ; 29 import java.util.Date ; 30 31 38 public class ContentDocumentDAOHibernate extends ContentResourceDAOHibernate implements ContentDocumentDAO { 39 40 43 public ContentDocumentDAOHibernate() { 44 } 45 46 48 51 public Long createContentDocument(ContentDocument contentDocument, ResourceData resourceData, ContentLocale contentLocale) { 52 contentDocument.setLastUpdatedDatetime(new Date ()); 53 contentDocument.setContentLocale(contentLocale); 54 contentDocument.setUsageCounter(new Integer (0)); 55 getHibernateTemplate().save(resourceData); 56 contentDocument.setResourceData(resourceData); 57 return (Long ) getHibernateTemplate().save(contentDocument); 58 } 59 60 63 public ContentDocument retrieveContentDocument(Long contentDocumentId) { 64 return (ContentDocument) getHibernateTemplate().get(ContentDocument.class, contentDocumentId); 65 } 66 67 70 public void updateContentDocument(ContentDocument contentDocument, ResourceData resourceData, ContentLocale contentLocale) { 71 contentDocument.setLastUpdatedDatetime(new Date ()); 72 contentDocument.setContentLocale(contentLocale); 73 getHibernateTemplate().saveOrUpdate(resourceData); 74 contentDocument.setResourceData(resourceData); 75 getHibernateTemplate().update(contentDocument); 76 } 77 78 81 public void deleteContentDocument(ContentDocument contentDocument) throws DeleteException { 82 getHibernateTemplate().delete(contentDocument); 83 84 List roles = new ArrayList (contentDocument.getRoles()); 86 for ( int i = 0; i < roles.size(); i++ ) { 87 Role role = (Role) roles.get(i); 88 contentDocument.removeRole(role); 89 } 90 } 91 92 94 97 public PartialCollection listContentDocuments(QueryInfo queryInfo) { 98 String whereClause = new String (); 99 String orderByClause = new String (); 100 if ( queryInfo != null ) { 101 whereClause = queryInfo.getWhereClause(); 102 orderByClause = queryInfo.getOrderByClause(); 103 if ( whereClause != null && whereClause.length() != 0 ) { 104 whereClause = " where " + whereClause; 105 } else { 106 whereClause = new String (); 107 } 108 if ( orderByClause != null && orderByClause.length() != 0 ) { 109 orderByClause = " order by " + orderByClause; 110 } else { 111 orderByClause = new String (); 112 } 113 } 114 115 List list = null; 116 Integer total = null; 117 String hqlPart = null; 118 hqlPart = "from ContentDocument r left outer join r.roles as role"; 119 120 hqlPart += whereClause; 121 122 if ( queryInfo != null && (queryInfo.getLimit() != null || queryInfo.getOffset() != null) ) { 123 String hqlForTotal = "select count(distinct r.id) " + hqlPart; 124 total = (Integer ) findUniqueResult(hqlForTotal); 125 if ( total == null ) { 126 total = new Integer (0); 127 } 128 } 129 130 if ( total == null || total.intValue() > 0 ) { 133 String hql = "select distinct r " + hqlPart + orderByClause; 134 list = executeFind(hql, queryInfo); 135 if ( total == null ) { 136 total = new Integer (list.size()); 137 } 138 } else { 139 list = new ArrayList (); 140 } 141 return new PartialCollection(list, total); 142 143 } 144 145 148 public ContentDocument findContentDocumentByUri(String uri) { 149 return (ContentDocument) findUniqueResult("from ContentDocument r where r.uri = ?", new Object []{uri}); 150 } 151 } 152 | Popular Tags |