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

com.jpattern.orm.mapper.OrmClassToolMap Maven / Gradle / Ivy

There is a newer version: 6.3.0
Show newest version
package com.jpattern.orm.mapper;

import java.util.Map;
import java.util.HashMap;

import com.jpattern.orm.JPO;
import com.jpattern.orm.exception.OrmException;


/**
 * 
 * @author Francesco Cina
 *
 * 22/mag/2011
 */
public class OrmClassToolMap implements IOrmClassToolMap {

	private final Map, IOrmClassTool> classToolMap = new HashMap, IOrmClassTool>();
	private final JPO jpOrm;

	public OrmClassToolMap(final JPO jpOrm) {
		this.jpOrm = jpOrm;
	}

	@Override
	public  void put(final Class clazz, final IOrmClassTool ormClassTool) {
		this.classToolMap.put(clazz, ormClassTool);
	}

	@Override
	public boolean containsTool(final Class clazz) {
		return this.classToolMap.containsKey(clazz);
	}

	@SuppressWarnings("unchecked")
	@Override
	public  IOrmClassTool getOrmClassTool(final Class clazz) throws OrmException {
		IOrmClassTool ormClazzTool = this.classToolMap.get(clazz);
		if (ormClazzTool==null) {
			this.jpOrm.register(clazz);
			ormClazzTool = this.classToolMap.get(clazz);
			//			throw new OrmException("Class " + clazz.getName() + " is not registered as an ORM entity!");
		}
		return (IOrmClassTool) this.classToolMap.get(clazz);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy