001 package railo.runtime.orm.hibernate.tuplizer.accessors; 002 003 import java.lang.reflect.Member; 004 import java.lang.reflect.Method; 005 import java.util.Map; 006 007 import org.hibernate.HibernateException; 008 import org.hibernate.engine.SessionImplementor; 009 import org.hibernate.metadata.ClassMetadata; 010 import org.hibernate.property.Getter; 011 import org.hibernate.type.Type; 012 013 import railo.runtime.Component; 014 import railo.runtime.PageContext; 015 import railo.runtime.config.ConfigImpl; 016 import railo.runtime.engine.ThreadLocalPageContext; 017 import railo.runtime.exp.PageException; 018 import railo.runtime.op.Caster; 019 import railo.runtime.orm.hibernate.HibernateCaster; 020 import railo.runtime.orm.hibernate.HibernateORMEngine; 021 import railo.runtime.orm.hibernate.HibernateRuntimeException; 022 import railo.runtime.orm.hibernate.HibernateUtil; 023 import railo.runtime.type.Collection; 024 import railo.runtime.type.Collection.Key; 025 import railo.runtime.type.KeyImpl; 026 027 public class CFCGetter implements Getter { 028 029 private Key key; 030 031 /** 032 * Constructor of the class 033 * @param key 034 */ 035 public CFCGetter(String key){ 036 this(KeyImpl.getInstance(key)); 037 } 038 039 /** 040 * Constructor of the class 041 * @param engine 042 * @param key 043 */ 044 public CFCGetter( Collection.Key key){ 045 this.key=key; 046 } 047 048 @Override 049 public Object get(Object trg) throws HibernateException { 050 try { 051 // MUST cache this, perhaps when building xml 052 HibernateORMEngine engine = getHibernateORMEngine(); 053 PageContext pc = ThreadLocalPageContext.get(); 054 Component cfc = Caster.toComponent(trg); 055 String name = HibernateCaster.getEntityName(cfc); 056 ClassMetadata metaData = engine.getSessionFactory(pc).getClassMetadata(name); 057 Type type = HibernateUtil.getPropertyType(metaData, key.getString()); 058 059 Object rtn = cfc.getComponentScope().get(key,null); 060 return HibernateCaster.toSQL(engine, type, rtn,null); 061 } 062 catch (PageException e) { 063 throw new HibernateRuntimeException(e); 064 } 065 } 066 067 068 public HibernateORMEngine getHibernateORMEngine(){ 069 try { 070 // TODO better impl 071 PageContext pc = ThreadLocalPageContext.get(); 072 ConfigImpl config=(ConfigImpl) pc.getConfig(); 073 return (HibernateORMEngine) config.getORMEngine(pc); 074 } 075 catch (PageException e) {} 076 077 return null; 078 } 079 080 081 @Override 082 public Object getForInsert(Object trg, Map arg1, SessionImplementor arg2)throws HibernateException { 083 return get(trg);// MUST better solution? this is from MapGetter 084 } 085 086 @Override 087 public Member getMember() { 088 return null; 089 } 090 091 @Override 092 public Method getMethod() { 093 return null; 094 } 095 096 public String getMethodName() { 097 return null;// MUST macht es sinn den namen zur�ck zu geben? 098 } 099 100 public Class getReturnType() { 101 return Object.class;// MUST more concrete? 102 } 103 104 }