001 package railo.runtime.orm.naming; 002 003 import railo.runtime.Component; 004 import railo.runtime.engine.ThreadLocalPageContext; 005 import railo.runtime.exp.PageException; 006 import railo.runtime.exp.PageRuntimeException; 007 import railo.runtime.op.Caster; 008 import railo.runtime.type.UDF; 009 010 public class CFCNamingStrategy implements NamingStrategy { 011 012 Component cfc; 013 014 015 public CFCNamingStrategy(String cfcName) throws PageException{ 016 this.cfc=ThreadLocalPageContext.get().loadComponent(cfcName); 017 } 018 019 020 @Override 021 public String convertTableName(String tableName) { 022 return call("getTableName",tableName); 023 } 024 025 @Override 026 public String convertColumnName(String columnName) { 027 return call("getColumnName",columnName); 028 } 029 030 private String call(String functionName, String name) { 031 Object res = cfc.get(functionName,null); 032 if(!(res instanceof UDF)) return name; 033 034 try { 035 return Caster.toString(cfc.call(ThreadLocalPageContext.get(), functionName, new Object[]{name})); 036 } catch (PageException pe) { 037 throw new PageRuntimeException(pe); 038 } 039 } 040 041 @Override 042 public String getType() { 043 return "cfc"; 044 } 045 046 }