Example usage for org.hibernate.collection.internal AbstractPersistentCollection getKey

List of usage examples for org.hibernate.collection.internal AbstractPersistentCollection getKey

Introduction

In this page you can find the example usage for org.hibernate.collection.internal AbstractPersistentCollection getKey.

Prototype

@Override
    public final Serializable getKey() 

Source Link

Usage

From source file:ch.algotrader.cache.CollectionHandler.java

License:Open Source License

@Override
protected CacheResponse initialize(Object obj) {

    if (!(obj instanceof AbstractPersistentCollection)) {
        throw new IllegalArgumentException("none PersistentCollection passed " + obj);
    }//from   w w  w  . ja v a 2  s.c  o m

    AbstractPersistentCollection col = (AbstractPersistentCollection) obj;
    if (col.wasInitialized()) {
        throw new IllegalArgumentException("PersistentCollection is already initialized " + obj);
    }

    if (col.getRole() == null) {
        throw new IllegalArgumentException("missing role on " + obj);
    }

    synchronized (obj) {

        Object initializedObj = this.cacheManager.getGenericDao().getInitializedCollection(col.getRole(),
                (Long) col.getKey());

        CacheResponse response = this.cacheManager.put(initializedObj);

        if (response.getState() == CacheState.EXISTING) {
            return response;
        } else {
            return CacheResponse.updatedObject(initializedObj);
        }
    }
}