FileDocCategorySizeDatePackage
MemoryStorage.javaAPI DocApache Struts 2.0.9 Apps4789Mon Jul 23 13:43:26 BST 2007org.apache.struts2.showcase.application

MemoryStorage

public class MemoryStorage extends Object implements Storage
MemoryStorage. Very simple in-memory persistence emulation.

Fields Summary
private static final long
serialVersionUID
private Map
memory
Constructors Summary
Methods Summary
public java.io.Serializablecreate(org.apache.struts2.showcase.model.IdEntity object)

        if (object == null) {
            throw new CreateException("Either given class or object was null");
        }
        if (object.getId() == null) {
            throw new CreateException("Cannot store object with null id");
        }
        if (get(object.getClass(), object.getId()) != null) {
            throw new DuplicateKeyException("Object with this id already exists.");
        }
        return intStore(object.getClass(), object).getId();
    
public intdelete(java.lang.Class entityClass, java.io.Serializable id)

        try {
            if (get(entityClass, id) != null) {
                getEntityMap(entityClass).remove(id);
                return 1;
            } else {
                return 0;
            }
        } catch (Exception e) {
            throw new CreateException(e);
        }
    
public intdelete(org.apache.struts2.showcase.model.IdEntity object)

        if (object == null) {
            throw new CreateException("Cannot delete null object");
        }
        return delete(object.getClass(), object.getId());
    
public java.util.CollectionfindAll(java.lang.Class entityClass)

        if (entityClass != null) {
            return getEntityMap(entityClass).values();
        } else {
            return new ArrayList();
        }
    
public org.apache.struts2.showcase.model.IdEntityget(java.lang.Class entityClass, java.io.Serializable id)

        if (entityClass != null && id != null) {
            return (IdEntity) getEntityMap(entityClass).get(id);
        } else {
            return null;
        }
    
private java.util.MapgetEntityMap(java.lang.Class entityClass)


           
        if (entityClass != null) {
            Map tryMap = (Map) memory.get(entityClass);
            if (tryMap == null) {
                synchronized(memory) {
                    tryMap = new HashMap();
                    memory.put(entityClass, tryMap);
                }
            }
            return tryMap;
        } else {
            return null;
        }
    
private org.apache.struts2.showcase.model.IdEntityintStore(java.lang.Class entityClass, org.apache.struts2.showcase.model.IdEntity object)

        getEntityMap(entityClass).put(object.getId(), object);
        return object;
    
public java.io.Serializablemerge(org.apache.struts2.showcase.model.IdEntity object)

        if (object == null) {
            throw new StorageException("Cannot merge null object");
        }
        if (object.getId() == null || get(object.getClass(), object.getId())==null) {
            return create(object);
        } else {
            return update(object).getId();
        }
    
public voidreset()

        this.memory = new HashMap();
    
public org.apache.struts2.showcase.model.IdEntityupdate(org.apache.struts2.showcase.model.IdEntity object)

        if (object == null) {
            throw new UpdateException("Cannot update null object.");
        }
        if ( get(object.getClass(), object.getId())==null ) {
            throw new UpdateException("Object to update not found.");
        }
        return intStore(object.getClass(), object);