Methods Summary |
---|
public java.io.Serializable | create(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 int | delete(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 int | delete(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.Collection | findAll(java.lang.Class entityClass)
if (entityClass != null) {
return getEntityMap(entityClass).values();
} else {
return new ArrayList();
}
|
public org.apache.struts2.showcase.model.IdEntity | get(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.Map | getEntityMap(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.IdEntity | intStore(java.lang.Class entityClass, org.apache.struts2.showcase.model.IdEntity object)
getEntityMap(entityClass).put(object.getId(), object);
return object;
|
public java.io.Serializable | merge(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 void | reset()
this.memory = new HashMap();
|
public org.apache.struts2.showcase.model.IdEntity | update(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);
|