panda.dao.entity.Entities Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of panda-core Show documentation
Show all versions of panda-core Show documentation
Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.
package panda.dao.entity;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import panda.bean.Beans;
import panda.lang.Collections;
/**
* !! thread-safe !!
*/
public class Entities {
private static Entities i = new Entities();
public static Entities i() {
return i;
}
protected Map, Entity>> entities;
protected Beans beans;
protected EntityMaker entityMaker;
public Entities() {
entities = new ConcurrentHashMap, Entity>>();
beans = Beans.i();
entityMaker = new AnnotationEntityMaker(this);
}
/**
* @return the entityMaker
*/
public EntityMaker getEntityMaker() {
return entityMaker;
}
/**
* @param entityMaker the entityMaker to set
*/
public void setEntityMaker(EntityMaker entityMaker) {
this.entityMaker = entityMaker;
}
/**
* @return the beans
*/
public Beans getBeans() {
return beans;
}
/**
* @param beans the beans to set
*/
public void setBeans(Beans beans) {
this.beans = beans;
}
/**
* @return the entities
*/
public Map, Entity>> getEntities() {
return Collections.unmodifiableMap(entities);
}
/**
* @param type record type
* @return the entity
*/
@SuppressWarnings("unchecked")
public Entity getEntity(Class type) {
Entity> entity = entities.get(type);
if (entity == null) {
synchronized(this) {
entity = entities.get(type);
if (entity == null) {
entity = entityMaker.create(type);
entities.put(type, entity);
entityMaker.initialize(entity);
}
}
}
return (Entity)entity;
}
}