Package org.olat.core.id

Examples of org.olat.core.id.Persistable


   * persistable object. The object might also have object identity, but this is not guaranteed.
   */
  // TODO:cg: not used => Remove it, ask fj
  public static Persistable getPersistableByPersistableKey(Iterator iter, Persistable persistable) {
    while (iter.hasNext()) {
      Persistable persistableFromIterator = (Persistable) iter.next();
      if (persistable.equalsByPersistableKey(persistableFromIterator))
        return persistableFromIterator;
    }
    return null;
  }
View Full Code Here


   * @return boolean
   */
  public static boolean listContainsObjectByKey(List objects, Long key) {
    for (Iterator iter = objects.iterator(); iter.hasNext();) {
      try {
        Persistable listObject = (Persistable) iter.next();
        if (listObject.getKey().equals(key))  {
          return true;
        }
      } catch (ClassCastException e) {
        throw new AssertionError("Class cast exception: objects list must contain object only of type persistable!");
      }
View Full Code Here

   * @return int position of object in list
   */
  public static int indexOf(List objects, Long key) {
    for (Iterator iter = objects.iterator(); iter.hasNext();) {
      try {
        Persistable listObject = (Persistable) iter.next();
        if (listObject.getKey().equals(key))  {
          return objects.indexOf(listObject);
        }
      } catch (ClassCastException e) {
        throw new AssertionError("Class cast exception: objects list must contain object only of type persistable!");
      }
View Full Code Here

   */
  public static int removeObjectsFromList(List originalList, List toBeRemovedObjects) { 
    int counter = 0;
    Iterator removeIter = toBeRemovedObjects.iterator();
    while (removeIter.hasNext()) {
      Persistable toBeRemoved = (Persistable) removeIter.next();
      Iterator originalIter = originalList.iterator();
      while (originalIter.hasNext()) {
        Persistable fromOriginal = (Persistable) originalIter.next();
        if (fromOriginal.getKey().equals(toBeRemoved.getKey())) {
          originalList.remove(fromOriginal);
          counter++;
          break;
        }
      }
View Full Code Here

   * @return Persistable
   */
  public static Persistable findInListByKey(List persistables, Persistable persistable) {
    Long key = persistable.getKey();
    for (Iterator iter = persistables.iterator(); iter.hasNext();) {
      Persistable ppit  = (Persistable) iter.next();
      if (ppit.getKey().equals(key)) {
        return ppit;
      }
    }
    return null;
  }
View Full Code Here

   * @return True if listOfPersistable contains persistable
   */
  public static boolean containsPersistable(List listOfPersistables, Persistable persistable) {
    Long key = persistable.getKey();
    for (Iterator iter = listOfPersistables.iterator(); iter.hasNext();) {
      Persistable entry = (Persistable) iter.next();
      if (entry.getKey().equals(key)) {
        return true;
      }
    }
    return false;
  }
View Full Code Here

   * @param persistables a List of Persistable objects
   * @return true if at least one of the objects in the list has the same key as the keys given.
   */
  public boolean isAtLeastOneKeyInList(List persistables) {
    for (Iterator it_per = persistables.iterator(); it_per.hasNext();) {
      Persistable per = (Persistable) it_per.next();
      Long key = per.getKey();
      if (keys.contains(key)) return true;
    }
    return false;
  }
View Full Code Here

   * @return the loaded Object
   */
  public Persistable loadObject(Persistable persistable, boolean forceReloadFromDB) {
    if (persistable == null) throw new AssertException("persistable must not be null");
    beginTransaction(persistable);
    Persistable ret;
    Class theClass = persistable.getClass();
    if (forceReloadFromDB) {
      // we want to reload it from the database.
      // there are 3 scenarios possible:
      // a) the object is not yet in the hibernate cache
      // b) the object is in the hibernate cache
      // c) the object is detached and there is an object with the same id in the hibernate cache
     
      if (contains(persistable)) {
        // case b - then we can use evict and load
        getDBManager().evict(persistable);
        return (Persistable) loadObject(theClass, persistable.getKey());
      } else {
        // case a or c - unfortunatelly we can't distinguish these two cases
        // and session.refresh(Object) doesn't work.
        // the only scenario that works is load/evict/load
        Persistable attachedObj = (Persistable) loadObject(theClass, persistable.getKey());
        getDBManager().evict(attachedObj);
        return (Persistable) loadObject(theClass, persistable.getKey());
      }
    } else if (!contains(persistable)) {
      // forceReloadFromDB is false - hence it is OK to take it from the cache if it would be there
View Full Code Here

TOP

Related Classes of org.olat.core.id.Persistable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.