1 | |
package org.apache.ojb.broker.accesslayer; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
import org.apache.ojb.broker.query.Query; |
19 | |
import org.apache.ojb.broker.query.QueryBySQL; |
20 | |
import org.apache.ojb.broker.metadata.ClassDescriptor; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
public class RsQueryObject |
29 | |
{ |
30 | |
private Query query; |
31 | |
private ClassDescriptor cld; |
32 | |
private boolean isSQLBased; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
public static RsQueryObject get(ClassDescriptor cld, Query query) |
42 | |
{ |
43 | |
return new RsQueryObject(cld, query); |
44 | |
} |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
private RsQueryObject(ClassDescriptor cld, Query query) |
51 | |
{ |
52 | |
this.query = query; |
53 | |
this.cld = cld; |
54 | |
if(query instanceof QueryBySQL) |
55 | |
{ |
56 | |
isSQLBased = true; |
57 | |
} |
58 | |
} |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
public ResultSetAndStatement performQuery(JdbcAccess jdbcAccess) |
64 | |
{ |
65 | |
if (isSQLBased()) |
66 | |
{ |
67 | |
|
68 | |
return jdbcAccess.executeSQL(((QueryBySQL) query).getSql(), cld, Query.SCROLLABLE); |
69 | |
} |
70 | |
else |
71 | |
{ |
72 | |
return jdbcAccess.executeQuery(query, cld); |
73 | |
} |
74 | |
} |
75 | |
|
76 | |
public boolean usePaging() |
77 | |
{ |
78 | |
return query.usePaging(); |
79 | |
} |
80 | |
|
81 | |
public int getStartIndex() |
82 | |
{ |
83 | |
return query.getStartAtIndex(); |
84 | |
} |
85 | |
|
86 | |
public int getEndIndex() |
87 | |
{ |
88 | |
return query.getEndAtIndex(); |
89 | |
} |
90 | |
|
91 | |
public ClassDescriptor getClassDescriptor() |
92 | |
{ |
93 | |
return cld; |
94 | |
} |
95 | |
|
96 | |
public Query getQuery() |
97 | |
{ |
98 | |
return query; |
99 | |
} |
100 | |
|
101 | |
public boolean isSQLBased() |
102 | |
{ |
103 | |
return isSQLBased; |
104 | |
} |
105 | |
|
106 | |
public String getSQLBasedQuery() |
107 | |
{ |
108 | |
if(isSQLBased()) |
109 | |
{ |
110 | |
return ((QueryBySQL)query).getSql(); |
111 | |
} |
112 | |
else |
113 | |
{ |
114 | |
return null; |
115 | |
} |
116 | |
} |
117 | |
|
118 | |
public String toString() |
119 | |
{ |
120 | |
return this.getClass().getName() + |
121 | |
"[" + "query: " + query + ", class descriptor: " + cld.getClassNameOfObject() + "]"; |
122 | |
} |
123 | |
} |