1 17 package org.alfresco.repo.admin.patch.hibernate; 18 19 import java.util.Date ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 import org.alfresco.error.AlfrescoRuntimeException; 24 import org.alfresco.repo.admin.patch.PatchDaoService; 25 import org.alfresco.repo.domain.AppliedPatch; 26 import org.alfresco.repo.domain.hibernate.AppliedPatchImpl; 27 import org.hibernate.Query; 28 import org.hibernate.Session; 29 import org.springframework.orm.hibernate3.HibernateCallback; 30 import org.springframework.orm.hibernate3.support.HibernateDaoSupport; 31 32 38 public class HibernatePatchDaoServiceImpl extends HibernateDaoSupport implements PatchDaoService 39 { 40 public static final String QUERY_GET_ALL_APPLIED_PATCHES = "patch.GetAllAppliedPatches"; 41 public static final String QUERY_GET_APPLIED_PATCHES_BY_DATE = "patch.GetAppliedPatchesByDate"; 42 43 public AppliedPatch newAppliedPatch(String id) 44 { 45 AppliedPatch existing = getAppliedPatch(id); 47 if (existing != null) 48 { 49 throw new AlfrescoRuntimeException("An applied patch already exists: \n" + 50 " id: " + id); 51 } 52 AppliedPatchImpl patch = new AppliedPatchImpl(); 54 patch.setId(id); 55 getHibernateTemplate().save(patch); 57 return patch; 59 } 60 61 public AppliedPatch getAppliedPatch(String id) 62 { 63 AppliedPatch patch = (AppliedPatch) getHibernateTemplate().get(AppliedPatchImpl.class, id); 64 return patch; 66 } 67 68 public void detach(AppliedPatch appliedPatch) 69 { 70 getSession().evict(appliedPatch); 71 } 72 73 76 @SuppressWarnings ("unchecked") 77 public List <AppliedPatch> getAppliedPatches() 78 { 79 HibernateCallback callback = new HibernateCallback() 80 { 81 public Object doInHibernate(Session session) 82 { 83 Query query = session.getNamedQuery(HibernatePatchDaoServiceImpl.QUERY_GET_ALL_APPLIED_PATCHES); 84 return query.list(); 85 } 86 }; 87 List <AppliedPatch> queryResults = (List ) getHibernateTemplate().execute(callback); 88 return queryResults; 90 } 91 92 95 @SuppressWarnings ("unchecked") 96 public List <AppliedPatch> getAppliedPatches(final Date fromDate, final Date toDate) 97 { 98 HibernateCallback callback = new HibernateCallback() 99 { 100 public Object doInHibernate(Session session) 101 { 102 Query query = session.getNamedQuery(HibernatePatchDaoServiceImpl.QUERY_GET_ALL_APPLIED_PATCHES); 103 return query.list(); 104 } 105 }; 106 List <AppliedPatch> queryResults = (List ) getHibernateTemplate().execute(callback); 107 Iterator <AppliedPatch> iterator = queryResults.iterator(); 109 while (iterator.hasNext()) 110 { 111 AppliedPatch appliedPatch = iterator.next(); 112 Date appliedOnDate = appliedPatch.getAppliedOnDate(); 113 if (fromDate.compareTo(appliedOnDate) >= 0 || toDate.compareTo(appliedOnDate) <= 0) 114 { 115 iterator.remove(); 117 } 118 } 119 return queryResults; 121 } 122 } 123 | Popular Tags |