org.apache.jdo.impl.sco
Class Freezer

java.lang.Object
  extended byorg.apache.jdo.impl.sco.Freezer

public class Freezer
extends java.lang.Object

Freezer is a helper class with static methods to assist transcribing non-ordered collection and map classes. When an unordered collection or map is written to the datastore and subsequently fetched, the order of elements can change. This causes optimistic failures for persistent instances that contain unordered collections even if the collection has not changed. Another issue solved by the Freezer is that if the user defines an ordering or hashing based on persistent values of the elements, during transcribing while fetching the instance from the datastore the persistent instance must be fetched. This causes recursion in the fetch process. Freezing is the process of iterating the elements of a collection or iterating the entrySet elements of a map and constructing an array of elements in an absolute ordering. Freezing is done during transcribing for storage. Thawing is the process of iterating the frozen elements and storing them in their user-visible order or using their user-visible hashCode. A collection or map is frozen when read from the datastore, and thawed upon first application use.

Since:
1.0.1
Version:
1.0.2
Author:
Craig Russell

Nested Class Summary
protected static class Freezer.FrozenIterator
          This class iterates over an array.
 
Constructor Summary
protected Freezer()
          This class currently is not used as a class but only as a helper.
 
Method Summary
static java.util.Map createAbsoluteOrderMap()
          Create a map whose elements are ordered according to an absolute ordering.
static java.util.Iterator createFrozenIterator(java.lang.Object[] frozen)
          Create an iterator over frozen elements or entries.
static java.lang.Object[] freeze(java.util.Collection set, int size)
          Provide a frozen array of elements from a Set.
static java.util.Map.Entry[] freeze(java.util.Map map, int size)
          Provide a frozen array of elements from the entrySet of a Map.
static java.util.Iterator frozenIterator(java.util.Map map, int size)
          Provide a frozen iterator of elements from the entrySet of a Map.
static void printElements(java.io.PrintStream p, java.lang.String s, java.lang.Object[] elements)
          For debugging, print the contents of a frozen collection.
static void printEntries(java.io.PrintStream p, java.lang.String s, java.util.Map.Entry[] entries)
          For debugging, print the contents of a frozen entrySet.
static java.lang.Object[] thaw(SCOCollection sco, StateManagerInternal owner, java.lang.Object[] frozenElements)
          Thaw the frozen elements of a collection.
static java.util.Map.Entry[] thaw(SCOMap map, StateManagerInternal owner, java.util.Map.Entry[] frozenEntries)
          Thaw the frozen elements of a map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Freezer

protected Freezer()
This class currently is not used as a class but only as a helper. This constructor is for future use if needed.

Method Detail

freeze

public static java.lang.Object[] freeze(java.util.Collection set,
                                        int size)
Provide a frozen array of elements from a Set. This method does not actually freeze the Set but simply calculates the frozen elements.

Parameters:
size - the number of elements in the collection.
set - the Set whose elements are to be ordered.
Returns:
the Object[] containing the frozen elements.

freeze

public static java.util.Map.Entry[] freeze(java.util.Map map,
                                           int size)
Provide a frozen array of elements from the entrySet of a Map. This method does not actually freeze the Map but simply calculates the frozen elements.

Parameters:
size - the number of entries in the map.
map - the Map whose entrySet elements are to be calculated.
Returns:
the Map.Entry[] of elements in the map.

frozenIterator

public static java.util.Iterator frozenIterator(java.util.Map map,
                                                int size)
Provide a frozen iterator of elements from the entrySet of a Map. This method does not actually freeze the Map but simply calculates the frozen elements and returns an iterator over them.

Parameters:
size - the number of entries in the map.
map - the Map whose entrySet elements are to be calculated.
Returns:
an iterator over Map.Entry[] of elements in the map.

createAbsoluteOrderMap

public static java.util.Map createAbsoluteOrderMap()
Create a map whose elements are ordered according to an absolute ordering.

Returns:
the map with an absolute ordering Comparator.

createFrozenIterator

public static java.util.Iterator createFrozenIterator(java.lang.Object[] frozen)
Create an iterator over frozen elements or entries.

Parameters:
frozen - the array of frozen entries or elements.
Returns:
the iterator over the entries or elements.

thaw

public static java.util.Map.Entry[] thaw(SCOMap map,
                                         StateManagerInternal owner,
                                         java.util.Map.Entry[] frozenEntries)
Thaw the frozen elements of a map. If the elements are frozen, retrieve them from the datastore and internally add them. Then return the frozen state since they're not frozen any more.

Parameters:
map - the Map to be thawed.
owner - the StateManager that owns this Map.
frozenEntries - the frozen entries to be thawed.
Returns:
the new contents of frozenEntries.

thaw

public static java.lang.Object[] thaw(SCOCollection sco,
                                      StateManagerInternal owner,
                                      java.lang.Object[] frozenElements)
Thaw the frozen elements of a collection. If the elements are frozen, retrieve them from the datastore and internally add them. Then reset the frozen state since they're not frozen any more.

Parameters:
sco - the frozen collection to be thawed.
owner - the StateManager that owns this collection.
frozenElements - the elements to be thawed.
Returns:
the new contents of frozenElements.

printEntries

public static void printEntries(java.io.PrintStream p,
                                java.lang.String s,
                                java.util.Map.Entry[] entries)
For debugging, print the contents of a frozen entrySet.

Parameters:
p - where to write the output.
s - an identifying string.
entries - the Map.Entry[] to print.

printElements

public static void printElements(java.io.PrintStream p,
                                 java.lang.String s,
                                 java.lang.Object[] elements)
For debugging, print the contents of a frozen collection.

Parameters:
p - where to write the output.
s - an identifying string.
elements - the Object[] to print.


Copyright © 2005 Apache Software Foundation. All Rights Reserved.