entitystore.java
来自「Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI」· Java 代码 · 共 151 行
JAVA
151 行
/**
*
*/
package org.rapla.storage.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import org.rapla.components.util.Assert;
import org.rapla.entities.EntityNotFoundException;
import org.rapla.entities.RaplaObject;
import org.rapla.entities.RaplaType;
import org.rapla.entities.dynamictype.DynamicType;
import org.rapla.entities.internal.CategoryImpl;
import org.rapla.entities.storage.EntityResolver;
import org.rapla.entities.storage.RefEntity;
import org.rapla.storage.LocalCache;
public class EntityStore implements EntityResolver {
HashMap entities = new HashMap();
HashSet idsToRemove = new HashSet();
LocalCache parent;
HashMap dynamicTypes = new HashMap();
CategoryImpl superCategory;
HashMap passwordList = new HashMap();
long repositoryVersion;
public EntityStore(LocalCache parent,CategoryImpl superCategory) {
this.parent = parent;
this.superCategory = superCategory;
// put( superCategory);
}
public void addAll(Collection collection) {
Iterator it = collection.iterator();
while (it.hasNext())
{
put((RefEntity)it.next());
}
}
public void put(RefEntity entity) {
Object id = entity.getId();
Assert.notNull(id);
if ( entity.getRaplaType().equals( DynamicType.TYPE))
{
DynamicType dynamicType = (DynamicType) entity;
dynamicTypes.put ( dynamicType.getElementKey(), entity);
}
entities.put(id,entity);
}
public void addRemoveId(Object id)
{
idsToRemove.add(id);
}
public DynamicType getDynamicType(String key)
{
// todo super
DynamicType type = (DynamicType) dynamicTypes.get( key);
if ( type == null && parent != null)
{
type = parent.getDynamicType( key);
}
return type;
}
public Collection getList() {
return entities.values();
}
public Collection getRemoveIds() {
return idsToRemove;
}
// Implementation of EntityResolver
public RefEntity resolve(Object id) throws EntityNotFoundException {
RefEntity result = get (id );
if ( result == null)
{
throw new EntityNotFoundException("Object for id " + id.toString() + " not found");
}
return result;
}
public CategoryImpl getSuperCategory()
{
return superCategory;
}
public void putPassword( Object userid, String password )
{
passwordList.put(userid, password);
}
public String getPassword( Object userid)
{
return (String)passwordList.get(userid);
}
public RefEntity get( Object id )
{
if ( id.equals( superCategory.getId()))
{
return superCategory;
}
RefEntity entity = (RefEntity) entities.get(id);
if (entity != null)
return entity;
if (parent != null)
{
return parent.get(id);
}
return null;
}
public Collection getCollection( RaplaType raplaType )
{
List collection = new ArrayList();
Iterator it = entities.values().iterator();
while (it.hasNext())
{
RaplaObject obj = (RaplaObject)it.next();
if ( obj.getRaplaType().equals( raplaType))
{
collection.add( obj);
}
}
return collection;
}
public long getRepositoryVersion()
{
return repositoryVersion;
}
public void setRepositoryVersion( long repositoryVersion )
{
this.repositoryVersion = repositoryVersion;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?