1 /**
2 * Copyright 2005-2006 the original author or authors.
3 *
4 * Licensed under the Gnu General Pubic License, Version 2.0 (the
5 * "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/gpl-license.php
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the Gnu General Public License for more details.
14 */
15 package org.figure8.join.businessobjects.environment.persistence;
16
17 import org.figure8.join.core.persistence.HibernateObjectDao;
18 import org.figure8.join.businessobjects.environment.VersionedResource;
19 import org.figure8.join.businessobjects.environment.VersionedResourceUpdate;
20 import org.figure8.join.util.LogUtil;
21
22 import org.apache.commons.logging.Log;
23
24 import java.util.Date;
25 import java.util.List;
26 /**
27 * Implementation of VersionedResourceUpdateDao using Hibernate ORM system.
28 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
29 * @version $Revision: 1.1 $
30 */
31 public class HibernateVersionedResourceUpdateDao extends HibernateObjectDao implements VersionedResourceUpdateDao{
32
33
34
35 /** Get a commons logger. */
36 private static final Log log = LogUtil.getLog(HibernateVersionedResourceUpdateDao.class);
37
38
39
40
41 /** Creates a new HibernateVersionedResourceUpdateDao */
42 public HibernateVersionedResourceUpdateDao(){
43 }
44
45
46
47
48 /**
49 * Retrieve the VersionedResourceUpdate having this identifier
50 * @param id The unique identifier of update to retrieve
51 * @return The VersionedResourceUpdate having this identifier or null if no one match
52 */
53 public VersionedResourceUpdate getVersionedResourceUpdate(long id){
54 return (VersionedResourceUpdate)getById(id);
55 }
56
57 /**
58 * Retrieve the resource update for a resource that was active at specified date
59 * @param resource The VersionedResource to retrieve update for
60 * @param date The date to retrieve active update
61 * @return The active {@link org.figure8.join.businessobjects.environment.VersionedResourceUpdate} at date
62 */
63 public VersionedResourceUpdate getVersionedResourceUpdateForResource(VersionedResource resource, Date date){
64 VersionedResourceUpdate result = (VersionedResourceUpdate)findSingleObject(
65 findNamedQueryStringParams("join.resourceupdate_findByDateAndResource", "resource", resource, "date", date));
66 if (log.isDebugEnabled())
67 log.debug("Found an active VersionedResourceUpdate for resource " + resource.getName() + " at "
68 + date + "? " + ((result != null ? "yes" : "no")));
69 return result;
70 }
71
72 /**
73 * Retrieve a list of resource updates done onto a resource during a specified interval
74 * @param resource The VersionedResource to retrieve updates for
75 * @param startDate The starting date of time interval to search
76 * @param endDate The ending date of time interval to search
77 * @return A list of {@link org.figure8.join.businessobjects.environment.VersionedResourceUpdate} objects
78 */
79 public List getVersionedResourceUpdatesForResource(VersionedResource resource, Date startDate, Date endDate){
80 List result = findNamedQueryStringParams("join.resourceupdate_findByIntervalAndResource", "resource", resource,
81 "startDate", startDate, "endDate", endDate);
82 if (log.isDebugEnabled())
83 log.debug("Found " + result.size() + " VersionedResourceUpdates for resource " + resource.getName());
84 return result;
85 }
86
87
88
89
90 /**
91 * Get the persistent class associated to this Dao.
92 * @return The org.figure8.join.businessobjects.environment.VersionedResourceUpdate class
93 */
94 public Class getPersistentClass(){
95 return org.figure8.join.businessobjects.environment.VersionedResourceUpdate.class;
96 }
97 }