JTemporal Home
Tutorial

net.sf.jtemporal.spi
Class ORMTemporalAttributeStorage<V>

java.lang.Object
  extended by net.sf.jtemporal.spi.ORMTemporalAttributeStorage<V>
All Implemented Interfaces:
java.io.Serializable, TemporalAttributeStorage

public class ORMTemporalAttributeStorage<V>
extends java.lang.Object
implements TemporalAttributeStorage, java.io.Serializable

An implementation of TemporalAttributeStorage#, based on a TreeMap, mapped by an ORM tool.

Version:
$Id: ORMTemporalAttributeStorage.java,v 1.10 2007/09/23 20:07:16 tabeck Exp $
See Also:
Serialized Form

Constructor Summary
ORMTemporalAttributeStorage(java.util.SortedMap<Period,TimedObject<V>> sortedMap, TimedObjectFactory<V> toFactory)
          You specify an instance of SortedMap to be used internally by the storage.
 
Method Summary
 void beginAtomicOperation()
          Tells the storage that the JTemporal client is calling a method that can result in multiples updates in the storage.
 void clear()
          Removes all the stored mappings.
 boolean containsValue(java.lang.Object value)
          Returns true if this map maps one or more Periods to the specified value.
 boolean containsValue(java.lang.Object value, Period range)
          Returns true if this map maps one or more Periods to the specified value, during the specified period.
 void endAtomicOperation()
          Tells the storage that an atomic operation has finished.
 CloseableIterator entryIterator()
          Iterates over all the entries of the storage.
 CloseableIterator entryIterator(Period range)
          Iterates over all the entries of the storage that intersects the period P.
 Period firstPeriod()
          Returns the first (lowest) period currently in this storage.
 Period firstPeriod(Period range)
          Returns the first (lowest) period currently in this storage, that intersects the given period.
 TimedObject getEntry(Instant instant)
          Returns the entry valid at the given instant, if any is found.
 TimedObject getEntryEndingAt(Instant instant)
          Returns the entry finishing exactly at the given instant, if any is found.
 TimedObject getEntryStartingAt(Instant instant)
          Returns the entry starting exactly at the given instant, if any is found.
 Period getPeriod(Instant instant)
          Returns the period that encloses the given instant, if any is found.
 V getValue(Instant instant)
          Returns the value to which this map maps the specified Instant.
 boolean isEmpty()
          Returns true if this storage does not contain objects.
 boolean isEmpty(Period range)
          Returns true if this storage does not contain objects intersecting the given period.
 Period lastPeriod()
          Returns the last (highest) period currently in this storage.
 Period lastPeriod(Period range)
          Returns the last (highest) period currently in this storage, that intersects the given period.
 CloseableIterator periodIterator()
          Iterates over all the periods of the storage.
 CloseableIterator periodIterator(Period range)
          Iterates over all the periods of the storage that intersects the period P.
 void put(Period p, java.lang.Object value)
          Stores a mapping (entry, tuple, row) composed by period and value.
 void removeEntry(Period p)
          Removes an entry composed by period and value previously stored.
 int removeRange(Period range)
          Removes all the entries whose period indersects the given period.
 int size()
          Returns the number of Period-value mappings in this map.
 int size(Period range)
          Returns the number of Period-value mappings in this map, for the given priod.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ORMTemporalAttributeStorage

public ORMTemporalAttributeStorage(java.util.SortedMap<Period,TimedObject<V>> sortedMap,
                                   TimedObjectFactory<V> toFactory)
You specify an instance of SortedMap to be used internally by the storage. This can be useful in the case your Object-Relational mapping tool can provide a persistent implementation of the sorted Map.
The SortedMap instance must comply with the following requirements:
- use StartComparator.COMPARATOR or a new instance of net.sf.jtemporal.spi.TreeTemporalAttributeStorage$StartComparator
- have the key containing Periods and the value containing the value to be returned by TemporalAttribute.get(Instant).

Parameters:
sortedMap - a map mapped by an ORM tools, whose key is composed of Period and the value of TimedObject, using as a comparator StartComparator.COMPARATOR. Note that the getValue(Instant) will return just the value held in the TimedObject and not the timedObject itself. This, because the TimedObject is the closed representation of a row in your database, that is mapped by your ORM tool.
Note that the TimedObjects and their components must immutable. They will be created and deleted from the database, but never updated.
toFactory - a callback for creating and destroying instances of TimedObject
Throws:
java.lang.IllegalArgumentException - if the map does not use StartComparator.COMPARATOR. or if the map is null
Method Detail

lastPeriod

public Period lastPeriod()
Description copied from interface: TemporalAttributeStorage
Returns the last (highest) period currently in this storage.

Specified by:
lastPeriod in interface TemporalAttributeStorage
Returns:
the last (highest) period currently in this storage.

lastPeriod

public Period lastPeriod(Period range)
Description copied from interface: TemporalAttributeStorage
Returns the last (highest) period currently in this storage, that intersects the given period.
Note the the returned period may be larger than p.

Specified by:
lastPeriod in interface TemporalAttributeStorage
Parameters:
range - the intersecting period
Returns:
the last (highest) period currently in this storage.

firstPeriod

public Period firstPeriod()
Description copied from interface: TemporalAttributeStorage
Returns the first (lowest) period currently in this storage.

Specified by:
firstPeriod in interface TemporalAttributeStorage
Returns:
the first (lowest) period currently in this storage.

firstPeriod

public Period firstPeriod(Period range)
Description copied from interface: TemporalAttributeStorage
Returns the first (lowest) period currently in this storage, that intersects the given period.
Note the the returned period may be larger than p.

Specified by:
firstPeriod in interface TemporalAttributeStorage
Parameters:
range - the intersecting period
Returns:
the first (lowest) period currently in this storage.

isEmpty

public boolean isEmpty()
Description copied from interface: TemporalAttributeStorage
Returns true if this storage does not contain objects.

Specified by:
isEmpty in interface TemporalAttributeStorage
Returns:
true if this storage does not contain objects..

getValue

public V getValue(Instant instant)
Description copied from interface: TemporalAttributeStorage
Returns the value to which this map maps the specified Instant. Returns null if the map contains no mapping at this Instant. It is not possible to map to a null Instant.

Specified by:
getValue in interface TemporalAttributeStorage
Parameters:
instant - instant whose associated value is to be returned
Returns:
the value to which this map maps the specified instant. returns null if this map does not contain a mapping for the specified instant.

getPeriod

public Period getPeriod(Instant instant)
Description copied from interface: TemporalAttributeStorage
Returns the period that encloses the given instant, if any is found.

Specified by:
getPeriod in interface TemporalAttributeStorage
Parameters:
instant - instant whose associated value is to be returned
Returns:
the value to which this map maps the specified instant. returns null if this map does not contain a mapping for the specified instant.

getEntry

public TimedObject getEntry(Instant instant)
Description copied from interface: TemporalAttributeStorage
Returns the entry valid at the given instant, if any is found.

Specified by:
getEntry in interface TemporalAttributeStorage
Parameters:
instant - instant whose associated value is to be returned
Returns:
the period and value to which this map maps the specified instant. returns null if this map does not contain a mapping for the specified instant.

getEntryEndingAt

public TimedObject getEntryEndingAt(Instant instant)
Description copied from interface: TemporalAttributeStorage
Returns the entry finishing exactly at the given instant, if any is found.

Specified by:
getEntryEndingAt in interface TemporalAttributeStorage
Parameters:
instant - the instant the equals the entry end
Returns:
the entry ending exactly at the given instant, or null.

getEntryStartingAt

public TimedObject getEntryStartingAt(Instant instant)
Description copied from interface: TemporalAttributeStorage
Returns the entry starting exactly at the given instant, if any is found.

Specified by:
getEntryStartingAt in interface TemporalAttributeStorage
Parameters:
instant - the instant the equals the entry end
Returns:
the entry starting exactly at the given instant, or null.

beginAtomicOperation

public void beginAtomicOperation()
Description copied from interface: TemporalAttributeStorage
Tells the storage that the JTemporal client is calling a method that can result in multiples updates in the storage.
This is not exactly a transaction.
If the storage supports transactions, this method suggests to perform all the following operations inside the same transaction.
For example, this method is called by TemporalAttributeImpl at the beginning of the put(Period, Object) method, then TemporalAttributeImpl calls some times the put and remove methods, then finally it calls TemporalAttributeStorage.endAtomicOperation().
If your storage supports nested transactions, this is the inner one. Non persistent implemetations just return with no action.
Must not throw any exception (including unchecked exceptions).

Specified by:
beginAtomicOperation in interface TemporalAttributeStorage
See Also:
TemporalAttributeStorage.endAtomicOperation()

endAtomicOperation

public void endAtomicOperation()
Description copied from interface: TemporalAttributeStorage
Tells the storage that an atomic operation has finished. If the storage supports transactions, it should commit if a transaction has been started by TemporalAttributeStorage.beginAtomicOperation().
Non persistent implemetations just return with no action.
Must not throw any exception (including unchecked exceptions).

Specified by:
endAtomicOperation in interface TemporalAttributeStorage
See Also:
TemporalAttributeStorage.beginAtomicOperation()

clear

public void clear()
Description copied from interface: TemporalAttributeStorage
Removes all the stored mappings.

Specified by:
clear in interface TemporalAttributeStorage

size

public int size()
Description copied from interface: TemporalAttributeStorage
Returns the number of Period-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in interface TemporalAttributeStorage
Returns:
the number of Instant-value mappings in this map.

size

public int size(Period range)
Description copied from interface: TemporalAttributeStorage
Returns the number of Period-value mappings in this map, for the given priod. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in interface TemporalAttributeStorage
Parameters:
range - the intersecting period
Returns:
the number of Instant-value mappings in this map.

isEmpty

public boolean isEmpty(Period range)
Description copied from interface: TemporalAttributeStorage
Returns true if this storage does not contain objects intersecting the given period.

Specified by:
isEmpty in interface TemporalAttributeStorage
Parameters:
range - the intersecting period
Returns:
true if this storage does not contain objects intersecting the given period.

containsValue

public boolean containsValue(java.lang.Object value)
Description copied from interface: TemporalAttributeStorage
Returns true if this map maps one or more Periods to the specified value.

Specified by:
containsValue in interface TemporalAttributeStorage
Parameters:
value - value whose presence in this map is to be tested.
Returns:
true if this map maps one or more keys to the specified value.

containsValue

public boolean containsValue(java.lang.Object value,
                             Period range)
Description copied from interface: TemporalAttributeStorage
Returns true if this map maps one or more Periods to the specified value, during the specified period.

Specified by:
containsValue in interface TemporalAttributeStorage
Parameters:
value - value whose presence in this map is to be tested.
range - the period intersecting the value mappings
Returns:
true if this map maps one or more keys to the specified value.

put

public void put(Period p,
                java.lang.Object value)
Description copied from interface: TemporalAttributeStorage
Stores a mapping (entry, tuple, row) composed by period and value.
No particular check or rich semantics is expected, this method just stores.

Specified by:
put in interface TemporalAttributeStorage
Parameters:
p - period with which the specified value is associated. Cannot be null.
value - value to be associated with the specified key. Cannot be null.

entryIterator

public CloseableIterator entryIterator()
Description copied from interface: TemporalAttributeStorage
Iterates over all the entries of the storage.
The instances are sorted by Period.equals(Object)

Specified by:
entryIterator in interface TemporalAttributeStorage
Returns:
instances of TimedObject
See Also:
TimedObject

entryIterator

public CloseableIterator entryIterator(Period range)
Description copied from interface: TemporalAttributeStorage
Iterates over all the entries of the storage that intersects the period P.
Note that the CloseableIterator#remove() method, removes the whole entry, even if the entry has a period lager then the period p.
The instances are sorted by Period.equals(Object)

Specified by:
entryIterator in interface TemporalAttributeStorage
Parameters:
range - the intersecting period.
Returns:
instances of TimedObject
See Also:
TimedObject

periodIterator

public CloseableIterator periodIterator()
Description copied from interface: TemporalAttributeStorage
Iterates over all the periods of the storage.
The instances are sorted by Period.equals(Object)

Specified by:
periodIterator in interface TemporalAttributeStorage
Returns:
instances of Period
See Also:
Period

periodIterator

public CloseableIterator periodIterator(Period range)
Description copied from interface: TemporalAttributeStorage
Iterates over all the periods of the storage that intersects the period P.
Note that the CloseableIterator#remove() method, removes the whole entry, even if the entry has a period lager then the period p.
The instances are sorted by Period.equals(Object)

Specified by:
periodIterator in interface TemporalAttributeStorage
Parameters:
range - the intersecting period.
Returns:
instances of Period
See Also:
Period

removeEntry

public void removeEntry(Period p)
Description copied from interface: TemporalAttributeStorage
Removes an entry composed by period and value previously stored.

Specified by:
removeEntry in interface TemporalAttributeStorage
Parameters:
p - period whose mapping is to be removed from the storage. It must exactly match the key of an existing entry.

removeRange

public int removeRange(Period range)
Description copied from interface: TemporalAttributeStorage
Removes all the entries whose period indersects the given period.

Specified by:
removeRange in interface TemporalAttributeStorage
Parameters:
range - the period specifying that range whose interecting entries are to be deleted.
Returns:
the number of deleted entries (or Integer.MAX_VALUE if bigger than that).

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

JTemporal Home
Tutorial