1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.database;
17
18 import org.seasar.framework.container.ComponentDef;
19 import org.seasar.framework.container.S2Container;
20 import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
21 import org.seasar.tuigwaa.database.function.CriteriaExeFunction;
22 import org.seasar.tuigwaa.database.function.DaoMethod;
23 import org.seasar.tuigwaa.database.function.SearchExeFunction;
24 import org.seasar.tuigwaa.database.function.UpdateExeFunction;
25 import org.seasar.tuigwaa.database.function.aggregation.ProjectionFunction;
26 import org.seasar.tuigwaa.database.function.criteria.CriteriaFunction;
27 import org.seasar.tuigwaa.database.function.criteria.CriteriaListFunction;
28 import org.seasar.tuigwaa.database.function.criteria.SubcriteriaFunction;
29 import org.seasar.tuigwaa.database.function.criteria.UnaryCriteriaFunction;
30 import org.seasar.tuigwaa.model.core.TgwEntity;
31
32
33 public class CriteriaFunctionFactory {
34
35 public static S2Container container_;
36
37 private static S2Container getS2Container() {
38 if (container_ == null) {
39 S2Container root = SingletonS2ContainerFactory.getContainer();
40 container_ = root.getDescendant("dicon/criterion.dicon");
41 }
42 return container_;
43 }
44
45 public static SearchExeFunction createSearchExeFunction(TgwEntity entity,
46 String name, CriteriaListFunction listFunction) {
47 SearchExeFunction exeFunction = (SearchExeFunction) createDaoMethod(
48 entity, "searchExe");
49 exeFunction.setName(name);
50 exeFunction.setCriteriaListFunction(listFunction);
51 return exeFunction;
52 }
53
54 public static UpdateExeFunction createUpdateExeFunction(TgwEntity entity,
55 String name) {
56 UpdateExeFunction exeFunction = (UpdateExeFunction) createDaoMethod(
57 entity, "updateExe");
58 exeFunction.setName(name);
59 return exeFunction;
60 }
61
62 public static CriteriaExeFunction createCriteriaExeFunction(
63 TgwEntity entity, String name, UnaryCriteriaFunction function) {
64 CriteriaExeFunction exeFunction = (CriteriaExeFunction) createDaoMethod(
65 entity, "criteriaExe");
66 exeFunction.setName(name);
67 exeFunction.setUnaryCriteriaFunction(function);
68 return exeFunction;
69 }
70
71 public static CriteriaExeFunction createCriteriaExeFunction(
72 TgwEntity entity, String name) {
73 return createCriteriaExeFunction(entity, name, null);
74 }
75
76 public static CriteriaExeFunction createCriteriaExeFunction(TgwEntity entity) {
77 return createCriteriaExeFunction(entity, null, null);
78 }
79
80 public static DaoMethod createBasicDaoMethod(TgwEntity entity, String type) {
81 DaoMethod method = createDaoMethod(entity, type);
82 method.setName(type);
83 return method;
84 }
85
86 public static DaoMethod createDaoMethod(TgwEntity entity, String type) {
87 DaoMethod method = (DaoMethod) getComponent(type);
88 method.setEntityName(entity.getName());
89 method.setSchema(entity.getDomainName());
90 return method;
91 }
92
93 public static ProjectionFunction getProjectionFunction(String type) {
94 return (ProjectionFunction) getComponent(type);
95 }
96
97 public static CriteriaFunction getFunction(String type) {
98 return (CriteriaFunction) getComponent(type);
99 }
100
101 public static String getType(CriteriaFunction function) {
102 ComponentDef def = getS2Container().getComponentDef(
103 getFunctionClass(function));
104 String type = def.getComponentName();
105 return type;
106 }
107
108
109
110 private static Object getComponent(String type) {
111 return getS2Container().getComponent("criterion." + type);
112 }
113
114 public static Class getFunctionClass(CriteriaFunction function) {
115 if (function instanceof SubcriteriaFunction) {
116 return getFunctionClass(((SubcriteriaFunction) function)
117 .getSequentialFunction());
118 }
119 return function.getClass();
120 }
121
122 public static CriteriaFunction getFunction(CriteriaFunction function){
123 if(function instanceof SubcriteriaFunction){
124 return getFunction(((SubcriteriaFunction) function)
125 .getSequentialFunction());
126 }
127 return function;
128 }
129 }