All Downloads are FREE. Search and download functionalities are using the official Maven repository.

panda.dao.entity.Entities Maven / Gradle / Ivy

Go to download

Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.

There is a newer version: 1.8.0
Show newest version
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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy