01: /*
02: * JFox - The most lightweight Java EE Application Server!
03: * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
04: *
05: * JFox is licenced and re-distributable under GNU LGPL.
06: */
07: package org.jfox.entity;
08:
09: import java.util.Collection;
10:
11: import org.apache.log4j.Logger;
12:
13: /**
14: * 通过 createQuery 调用创建的 SQLTemplate,没有å??称
15: *
16: * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
17: */
18:
19: public class SQLTemplate {
20:
21: protected String templateSQL;
22:
23: protected Class<?> resultClass;
24:
25: /**
26: * ä¿?å˜ä¸€ä¸ª Result Class çš„ column name=>column entry 的对应关系
27: * result class => {column name=> column entry}
28: */
29: // protected static Map<Class<?>, Map<String, ColumnEntry>> resultClass2MappedColumnMap = new HashMap<Class<?>, Map<String, ColumnEntry>>();
30: protected Logger logger = Logger.getLogger(this .getClass());
31:
32: // @SuppressWarnings({"unchecked"})
33: public SQLTemplate(String sqlTemplate, Class<?> resultClass) {
34: this .templateSQL = sqlTemplate;
35: this .resultClass = resultClass;
36: if (resultClass.equals(void.class)) {
37: // @NamedNativeQuery default value is void.class, we want to use EntityObject.class as default
38: this .resultClass = MappedEntity.class;
39: }
40:
41: // å˜å‚¨ ResultClass çš„ column å?Š 类型
42: introspectResultClass(getResultClass());
43: }
44:
45: protected void introspectResultClass(Class<?> resultClass) {
46: EntityFactory.introspectResultClass(resultClass);
47: }
48:
49: public Class<?> getColumnClass(String columnName) {
50: EntityFactory.ColumnEntry columnEntry = EntityFactory
51: .getColumnEntry(getResultClass(), columnName);
52: if (columnEntry == null) {
53: return null;
54: } else {
55: return columnEntry.field.getType();
56: }
57: }
58:
59: /**
60: * 得到所有的 ColumnEntry
61: */
62: public Collection<EntityFactory.MappedColumnEntry> getMappedColumnEntries() {
63: return EntityFactory.getMappedColumnEntries(getResultClass());
64: }
65:
66: public String getTemplateSQL() {
67: return templateSQL;
68: }
69:
70: public Class<?> getResultClass() {
71: return this.resultClass;
72: }
73:
74: }
|