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 javax.persistence.NamedNativeQuery;
10: import javax.persistence.QueryHint;
11:
12: /**
13: * 用æ?¥ä¿?å˜ NamedQuery
14: * 然å?Žæ ¹æ?®å?‚数,使用 velocity æž„é€ SQL
15: *
16: * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
17: */
18: public class NamedSQLTemplate extends SQLTemplate {
19:
20: /**
21: * 定义 NamedQuery 的 DAO class
22: */
23: private Class<?> definedClass = null;
24:
25: private NamedNativeQuery namedNativeQuery = null;
26:
27: /**
28: * 使用的 cache partition,如果没有,则ä¸?使用缓å˜
29: * cache partition 在 NamedNativeQuery ä¸å®šä¹‰
30: */
31: protected String cachePartition = "";
32:
33: public static final String CACHE_PARTITION_NAME = "cache.partition";
34:
35: public NamedSQLTemplate(NamedNativeQuery namedNativeQuery,
36: Class<?> definedClass) {
37: super (namedNativeQuery.query(), namedNativeQuery.resultClass());
38: this .namedNativeQuery = namedNativeQuery;
39: // 解� QueryHint,比如 (name="cache.config", value="product")
40: for (QueryHint hint : namedNativeQuery.hints()) {
41: String name = hint.name();
42: if (name.equals(CACHE_PARTITION_NAME)) {
43: cachePartition = hint.value();
44: logger.info("Use cache partition: " + cachePartition
45: + " for named query: " + getName());
46: }
47: }
48:
49: this .definedClass = definedClass;
50: }
51:
52: public Class<?> getDefinedClass() {
53: return definedClass;
54: }
55:
56: /**
57: * the name of NamedQuery
58: */
59: public String getName() {
60: return namedNativeQuery.name();
61: }
62:
63: public String getCachePartition() {
64: return cachePartition;
65: }
66:
67: public static void main(String[] args) {
68:
69: }
70: }
|