org.olat.core.commons.persistence
Class PersistenceHelper

java.lang.Object
  extended by org.olat.core.commons.persistence.PersistenceHelper

public class PersistenceHelper
extends java.lang.Object

Description:
Helper methods to work with persistable objects

Initial Date: Nov 30, 2004

Author:
gnaegi

Constructor Summary
PersistenceHelper()
           
 
Method Summary
static Persistable getPersistableByPersistableKey(java.util.Iterator iter, Persistable persistable)
          FIXME:fj:c cleanup up these methods here and class SyncHelper Checks if the given persistable is in the given iterator (database identity).
static int indexOf(java.util.List objects, java.lang.Long key)
          Returns the position of the object in the list.
static int indexOf(java.util.List objects, Persistable persistable)
          Returns the position of the object in the list.
static boolean listContainsObjectByKey(java.util.List objects, java.lang.Long key)
          Iterates over a list to see if there is an object in the list with the given persistable key that is used by the hibernate layer.
static boolean listContainsObjectByKey(java.util.List objects, Persistable persistable)
          Iterates over a list to see if the given persistable object is already in this list.
static int removeObjectsFromList(java.util.List originalList, java.util.List toBeRemovedObjects)
          Removes a list of persistable objects from another list with persistable objects by comparing the hibernate key instead of the object identity.
static boolean replaceObjectInListByKey(java.util.List objects, Persistable toBeReplacedObject)
          Replace an object in the given list that has the same persistance key.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistenceHelper

public PersistenceHelper()
Method Detail

getPersistableByPersistableKey

public static Persistable getPersistableByPersistableKey(java.util.Iterator iter,
                                                         Persistable persistable)
FIXME:fj:c cleanup up these methods here and class SyncHelper Checks if the given persistable is in the given iterator (database identity). If so, the persistable from the iterator is returned. If not, null is returned.

Parameters:
iter - Iterator of persistable objects
persistable - The persistable object that is looked for in the iterator
Returns:
null if not found or the persistable object that has the same key as the given persistable object. The object might also have object identity, but this is not guaranteed.

listContainsObjectByKey

public static boolean listContainsObjectByKey(java.util.List objects,
                                              Persistable persistable)
Iterates over a list to see if the given persistable object is already in this list. This differs from list.contains() in the way that it does not check object identity but hibernate identity. The object list contains the object if it contains any object with object.getKey() equals persistable.getKey()

Parameters:
objects - List of persistable objects
persistable - Persistable object
Returns:
boolean

listContainsObjectByKey

public static boolean listContainsObjectByKey(java.util.List objects,
                                              java.lang.Long key)
Iterates over a list to see if there is an object in the list with the given persistable key that is used by the hibernate layer.

Parameters:
objects - List of persistable objects
persistable - Persistable object
Returns:
boolean

indexOf

public static int indexOf(java.util.List objects,
                          Persistable persistable)
Returns the position of the object in the list. An object is found when it has the same hibernate key as the given object (!= java object identity)

Parameters:
objects -
persistable -
Returns:
int position of object in list

indexOf

public static int indexOf(java.util.List objects,
                          java.lang.Long key)
Returns the position of the object in the list. An object is found when it has the same hibernate key as the given object (!= java object identity)

Parameters:
objects -
key -
Returns:
int position of object in list

replaceObjectInListByKey

public static boolean replaceObjectInListByKey(java.util.List objects,
                                               Persistable toBeReplacedObject)
Replace an object in the given list that has the same persistance key.

Parameters:
objects - List ob original objects
toBeReplacedObject - The object that should be searched for in the list and the replace value
Returns:
boolean true: object replaced; false: object was not found in list

removeObjectsFromList

public static int removeObjectsFromList(java.util.List originalList,
                                        java.util.List toBeRemovedObjects)
Removes a list of persistable objects from another list with persistable objects by comparing the hibernate key instead of the object identity.

Parameters:
originalList -
toBeRemovedObjects -
Returns:
int number of objects removed from the originalList After calling this operation the originalList will contain less or the same amount of objects