com.jpattern.orm.classtool.OrmClassToolMap Maven / Gradle / Ivy
package com.jpattern.orm.classtool;
import java.util.HashMap;
import java.util.Map;
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(JPO jpOrm) {
this.jpOrm = jpOrm;
}
@Override
public void put(Class clazz, IOrmClassTool ormClassTool) {
this.classToolMap.put(clazz, ormClassTool);
}
@Override
public boolean containsTool(Class> clazz) {
return this.classToolMap.containsKey(clazz);
}
@SuppressWarnings("unchecked")
@Override
public IOrmClassTool getOrmClassTool(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 - 2024 Weber Informatics LLC | Privacy Policy