uk.ac.soton.itinnovation.grid.service.sla.dao.hibernate
Class UsageSummaryDAOImpl

java.lang.Object
  extended by uk.ac.soton.itinnovation.grid.service.sla.dao.GenericHibernateDAO<UsageSummary,Long>
      extended by uk.ac.soton.itinnovation.grid.service.sla.dao.hibernate.UsageSummaryDAOImpl
All Implemented Interfaces:
GenericDAO<UsageSummary,Long>, UsageSummaryDAO

public class UsageSummaryDAOImpl
extends GenericHibernateDAO<UsageSummary,Long>
implements UsageSummaryDAO


Constructor Summary
UsageSummaryDAOImpl()
           
 
Method Summary
 UsageSummary findByIdWithMinimalSelect(Long usageSummaryId)
          Find a UsageSummary by its id, but load only certain primitive properties.
 List<Long> findByNonZeroRateAtInstant(String resourceId, long instant)
          Find entity IDs for UsageSummarys belonging to the resource identified by resourceId and having a non-zero absolute rate at time instant instant
 UsageSummary findByResourceAndMetric(Long entityId, Long metricId)
          Find by the owning ResourceWithUsageByMetric and a Metric.
 List<UsageSummary> findByResourceId(String resourceId)
          Find all UsageSummarys belonging to the owning ResourceWithUsageByMetric that has a resource id of resourceId.
 UsageSummary findByResourceIdAndMetric(String resourceId, Long metricId)
          Find by the owning ResourceWithUsageByMetric and a Metric.
 UsageSummaryElement findElementByInstant(Long usageSummaryId, long instant)
          Find the child UsageSummaryElement at an instant in time.
 Long findIdByResourceAndMetric(Long entityId, Long metricId)
          Find by the owning ResourceWithUsageByMetric and a Metric, but select only the entity id.
 Long findIdByResourceIdAndMetric(String resourceId, Long metricId)
          Find by the owning ResourceWithUsageByMetric and a Metric, but select only the entity id.
 List<Metric> findMetricsForResource(Long entityId)
          Get a list of Metrics associated witht the ResourceWithUsageByMetric identified by entityId.
 UsageSummaryElement findNextElement(Long usageSummaryId, long instant)
          Find the next UsageSummaryElement after an instant in time.
 UsageSummaryElement findNextElementWithNonZeroRate(Long usageSummaryId, long instant)
          Find the next UsageSummaryElement with a non zero rate after an instant in time.
 UsageSummaryElement findPreviousElement(Long usageSummaryId, long instant)
          Find the previous UsageSummaryElement before an instant in time.
 long getPreviousInstant(Long usageSummaryId, long instant)
          Get the time instant of the UsageSummaryElement previous to instant.
 double getRate(Long usageSummaryId)
          Calculate the current rate for the UsageSummary identified by usageSummaryId.
 double getRate(Long usageSummaryId, long instant)
          Calculate the rate at an instant in time, for the UsageSummary identified by usageSummaryId and at the time instant, instant,
 double getTotalPositiveRateChange(Long usageSummaryId, long startInstant, long endInstant)
          Aggregate all positive rate changes between startInstant and endInstant for the for the UsageSummary identified by usageSummaryId.
 double getUsage(Long usageSummaryId)
          Calculate the current usage for the UsageSummary identified by usageSummaryId.
 double getUsage(Long usageSummaryId, long instant)
          Calculate the usage at an instant in time, for the UsageSummary identified by usageSummaryId and at the time instant, instant,
 boolean isElementAtInstant(Long usageSummaryId, long instant)
          Determine if there is a UsageSummaryElement whose time instant at instant.
 void updateLastElement(UsageSummary usageSummary, long latestElementId, long latestElementInstant)
          Update the record for the latest element (by time instant, not time report received).
 void updateTotalRate(UsageSummary usageSummary, double totalRate)
          Each UsageSummary maintains an aggregation of the total rate over the UsageSummaryElements it contains.
 
Methods inherited from class uk.ac.soton.itinnovation.grid.service.sla.dao.GenericHibernateDAO
delete, findAll, findByCriteria, findById, findById, getPersistentClass, saveOrUpdate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface uk.ac.soton.itinnovation.grid.service.sla.dao.GenericDAO
delete, findAll, findById, findById, saveOrUpdate
 

Constructor Detail

UsageSummaryDAOImpl

public UsageSummaryDAOImpl()
Method Detail

findByIdWithMinimalSelect

public UsageSummary findByIdWithMinimalSelect(Long usageSummaryId)
Description copied from interface: UsageSummaryDAO
Find a UsageSummary by its id, but load only certain primitive properties. This is a more efficient finder than findById, for when only these fields are required.

Specified by:
findByIdWithMinimalSelect in interface UsageSummaryDAO
Parameters:
usageSummaryId - the id of the UsageSummary
Returns:
the entity or null.

findByResourceId

public List<UsageSummary> findByResourceId(String resourceId)
Description copied from interface: UsageSummaryDAO
Find all UsageSummarys belonging to the owning ResourceWithUsageByMetric that has a resource id of resourceId. A minimal select only occurs.

Specified by:
findByResourceId in interface UsageSummaryDAO
Returns:
list of UsageSummary entities for the resource

findMetricsForResource

public List<Metric> findMetricsForResource(Long entityId)
Description copied from interface: UsageSummaryDAO
Get a list of Metrics associated witht the ResourceWithUsageByMetric identified by entityId.

Specified by:
findMetricsForResource in interface UsageSummaryDAO
Parameters:
entityId - the id for the owning ResourceWithUsageByMetric
Returns:
List of Metrics associated with the resource

findByResourceAndMetric

public UsageSummary findByResourceAndMetric(Long entityId,
                                            Long metricId)
Description copied from interface: UsageSummaryDAO
Find by the owning ResourceWithUsageByMetric and a Metric.

Specified by:
findByResourceAndMetric in interface UsageSummaryDAO
Parameters:
entityId - the id for the owning ResourceWithUsageByMetric
metricId - the id for the Metric
Returns:
the entity or null.

findIdByResourceAndMetric

public Long findIdByResourceAndMetric(Long entityId,
                                      Long metricId)
Description copied from interface: UsageSummaryDAO
Find by the owning ResourceWithUsageByMetric and a Metric, but select only the entity id.

Specified by:
findIdByResourceAndMetric in interface UsageSummaryDAO
Parameters:
entityId - the id for the owning ResourceWithUsageByMetric
metricId - the id for the Metric
Returns:
the entity id or null.

findIdByResourceIdAndMetric

public Long findIdByResourceIdAndMetric(String resourceId,
                                        Long metricId)
Description copied from interface: UsageSummaryDAO
Find by the owning ResourceWithUsageByMetric and a Metric, but select only the entity id.

Specified by:
findIdByResourceIdAndMetric in interface UsageSummaryDAO
Parameters:
resourceId - the resource id for the owning ResourceWithUsageByMetric
metricId - the id for the Metric
Returns:
the entity id or null.

findByResourceIdAndMetric

public UsageSummary findByResourceIdAndMetric(String resourceId,
                                              Long metricId)
Description copied from interface: UsageSummaryDAO
Find by the owning ResourceWithUsageByMetric and a Metric.

Specified by:
findByResourceIdAndMetric in interface UsageSummaryDAO
Parameters:
resourceId - the resource id for the owning ResourceWithUsageByMetric
metricId - the id for the Metric
Returns:
the entity or null.

findByNonZeroRateAtInstant

public List<Long> findByNonZeroRateAtInstant(String resourceId,
                                             long instant)
Description copied from interface: UsageSummaryDAO
Find entity IDs for UsageSummarys belonging to the resource identified by resourceId and having a non-zero absolute rate at time instant instant

Specified by:
findByNonZeroRateAtInstant in interface UsageSummaryDAO
Parameters:
resourceId - the resource id for the owning ResourceWithUsageByMetric
instant - the time instant for which there may be a non zero rate.

getRate

public double getRate(Long usageSummaryId)
Description copied from interface: UsageSummaryDAO
Calculate the current rate for the UsageSummary identified by usageSummaryId.

Specified by:
getRate in interface UsageSummaryDAO
Parameters:
usageSummaryId - the id of the UsageSummary
Returns:
the current rate

getUsage

public double getUsage(Long usageSummaryId)
Description copied from interface: UsageSummaryDAO
Calculate the current usage for the UsageSummary identified by usageSummaryId.

Specified by:
getUsage in interface UsageSummaryDAO
Parameters:
usageSummaryId - the id of the UsageSummary
Returns:
the current usage.

getRate

public double getRate(Long usageSummaryId,
                      long instant)
Description copied from interface: UsageSummaryDAO
Calculate the rate at an instant in time, for the UsageSummary identified by usageSummaryId and at the time instant, instant,

Specified by:
getRate in interface UsageSummaryDAO
Parameters:
usageSummaryId - the id of the UsageSummary
instant - the time instant in milliseconds
Returns:
the rate at the time instant

getTotalPositiveRateChange

public double getTotalPositiveRateChange(Long usageSummaryId,
                                         long startInstant,
                                         long endInstant)
Description copied from interface: UsageSummaryDAO
Aggregate all positive rate changes between startInstant and endInstant for the for the UsageSummary identified by usageSummaryId.

Note that only positive rate changes are included in the result. Also, a rate change at startInstant is excluded whereas a rate change at endInstant is included.

Specified by:
getTotalPositiveRateChange in interface UsageSummaryDAO
Parameters:
usageSummaryId - the id of the UsageSummary
startInstant - the time instant in milliseconds at the start of the period
endInstant - the time instant in milliseconds at the end of the period
Returns:
the total of positive rate changes in the time period

getUsage

public double getUsage(Long usageSummaryId,
                       long instant)
Description copied from interface: UsageSummaryDAO
Calculate the usage at an instant in time, for the UsageSummary identified by usageSummaryId and at the time instant, instant,

Specified by:
getUsage in interface UsageSummaryDAO
Parameters:
usageSummaryId - the id of the UsageSummary
instant - the time instant in milliseconds
Returns:
the usage at the time instant

getPreviousInstant

public long getPreviousInstant(Long usageSummaryId,
                               long instant)
Description copied from interface: UsageSummaryDAO
Get the time instant of the UsageSummaryElement previous to instant.

Note that if there is a UsageSummaryElement whose time instant is actually at instant, it is ignored.

Specified by:
getPreviousInstant in interface UsageSummaryDAO
Parameters:
usageSummaryId - the id of the owning UsageSummary
instant - the time instant in milliseconds
Returns:
the instant of the previous UsageSummaryElement or -1, if there is not a previous element.

isElementAtInstant

public boolean isElementAtInstant(Long usageSummaryId,
                                  long instant)
Description copied from interface: UsageSummaryDAO
Determine if there is a UsageSummaryElement whose time instant at instant.

Specified by:
isElementAtInstant in interface UsageSummaryDAO
Parameters:
usageSummaryId - the id of the owning UsageSummary
instant - the time instant in milliseconds
Returns:
true if there is an element at instant, or false, if there is not.

findElementByInstant

public UsageSummaryElement findElementByInstant(Long usageSummaryId,
                                                long instant)
Description copied from interface: UsageSummaryDAO
Find the child UsageSummaryElement at an instant in time.

Specified by:
findElementByInstant in interface UsageSummaryDAO
Parameters:
usageSummaryId - the id of the owning UsageSummary
instant - the time instant in milliseconds
Returns:
the child UsageSummaryElement or null

findPreviousElement

public UsageSummaryElement findPreviousElement(Long usageSummaryId,
                                               long instant)
Description copied from interface: UsageSummaryDAO
Find the previous UsageSummaryElement before an instant in time.

Note that the UsageSummaryElement whose time instant is actually at instant (if any), is excluded from the search.

Specified by:
findPreviousElement in interface UsageSummaryDAO
Parameters:
usageSummaryId - the id of the owning UsageSummary
instant - the time instant in milliseconds
Returns:
the previous UsageSummaryElement or null

findNextElement

public UsageSummaryElement findNextElement(Long usageSummaryId,
                                           long instant)
Description copied from interface: UsageSummaryDAO
Find the next UsageSummaryElement after an instant in time.

Note that the UsageSummaryElement whose time instant is actually at instant (if any), is excluded from the search.

Specified by:
findNextElement in interface UsageSummaryDAO
Parameters:
usageSummaryId - the id of the owning UsageSummary
instant - the time instant in milliseconds
Returns:
the next UsageSummaryElement or null

findNextElementWithNonZeroRate

public UsageSummaryElement findNextElementWithNonZeroRate(Long usageSummaryId,
                                                          long instant)
Description copied from interface: UsageSummaryDAO
Find the next UsageSummaryElement with a non zero rate after an instant in time.

Note that the UsageSummaryElement whose time instant is actually at instant (if any), is excluded from the search.

Specified by:
findNextElementWithNonZeroRate in interface UsageSummaryDAO
Parameters:
usageSummaryId - the id of the owning UsageSummary
instant - the time instant in milliseconds
Returns:
the next UsageSummaryElement or null

updateLastElement

public void updateLastElement(UsageSummary usageSummary,
                              long latestElementId,
                              long latestElementInstant)
Description copied from interface: UsageSummaryDAO
Update the record for the latest element (by time instant, not time report received). This method updates the database appropriately. It also updates the in-memory UsageSummary argument. This is because the implementation uses SQL to update the database rather than using hibernate, so that the UsageSummary can be partially loaded for efficiency. We therefore have to be careful to update the in memory object also.

Specified by:
updateLastElement in interface UsageSummaryDAO
Parameters:
usageSummary - the owning UsageSummary
latestElementId - the entity id for the latest element
latestElementInstant - the time instant in millis for the latest element

updateTotalRate

public void updateTotalRate(UsageSummary usageSummary,
                            double totalRate)
Description copied from interface: UsageSummaryDAO
Each UsageSummary maintains an aggregation of the total rate over the UsageSummaryElements it contains. This method updates the database appropriately. It also updates the in-memory UsageSummary argument. This is because the implementation uses SQL to update the database rather than using hibernate, so that the UsageSummary can be partially loaded for efficiency. We therefore have to be careful to update the in memory object also.

Specified by:
updateTotalRate in interface UsageSummaryDAO
Parameters:
usageSummary - the UsageSummary to update
totalRate - the new total rate for the usage summary


Copyright © 2001-2008 University of Southampton IT Innovation Centre. All Rights Reserved.