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 java.sql.ResultSetMetaData; |
19 | |
import java.sql.SQLException; |
20 | |
|
21 | |
import org.apache.ojb.broker.PersistenceBrokerException; |
22 | |
import org.apache.ojb.broker.core.PersistenceBrokerImpl; |
23 | |
import org.apache.ojb.broker.metadata.FieldDescriptor; |
24 | |
import org.apache.ojb.broker.metadata.JdbcTypesHelper; |
25 | |
import org.apache.ojb.broker.query.ReportQuery; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
public class ReportQueryRsIterator extends RsIterator |
34 | |
{ |
35 | |
|
36 | |
private int m_attributeCount; |
37 | |
private int[] m_jdbcTypes; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public ReportQueryRsIterator(RsQueryObject queryObject, PersistenceBrokerImpl broker) |
43 | |
{ |
44 | |
super(queryObject, broker); |
45 | |
try |
46 | |
{ |
47 | |
|
48 | |
|
49 | |
ReportQuery q = (ReportQuery)queryObject.getQuery(); |
50 | |
m_attributeCount = q.getAttributes().length; |
51 | |
|
52 | |
init_jdbcTypes(); |
53 | |
} |
54 | |
catch (SQLException e) |
55 | |
{ |
56 | |
releaseDbResources(); |
57 | |
throw new PersistenceBrokerException(e); |
58 | |
} |
59 | |
} |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
private void init_jdbcTypes() throws SQLException |
66 | |
{ |
67 | |
ReportQuery q = (ReportQuery) getQueryObject().getQuery(); |
68 | |
m_jdbcTypes = new int[m_attributeCount]; |
69 | |
|
70 | |
|
71 | |
if (q.getJdbcTypes() != null) |
72 | |
{ |
73 | |
m_jdbcTypes = q.getJdbcTypes(); |
74 | |
} |
75 | |
else |
76 | |
{ |
77 | |
ResultSetMetaData rsMetaData = getRsAndStmt().m_rs.getMetaData(); |
78 | |
for (int i = 0; i < m_attributeCount; i++) |
79 | |
{ |
80 | |
m_jdbcTypes[i] = rsMetaData.getColumnType(i + 1); |
81 | |
} |
82 | |
|
83 | |
} |
84 | |
} |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
protected Object getObjectFromResultSet() throws PersistenceBrokerException |
93 | |
{ |
94 | |
Object[] result = new Object[m_attributeCount]; |
95 | |
ReportQuery q =(ReportQuery) getQueryObject().getQuery(); |
96 | |
|
97 | |
for (int i = 0; i < m_attributeCount; i++) |
98 | |
{ |
99 | |
try |
100 | |
{ |
101 | |
int jdbcType = m_jdbcTypes[i]; |
102 | |
String attr = q.getAttributes()[i]; |
103 | |
FieldDescriptor fld = (FieldDescriptor) q.getAttributeFieldDescriptors().get(attr); |
104 | |
Object val =JdbcTypesHelper.getObjectFromColumn(getRsAndStmt().m_rs, new Integer(jdbcType), i + 1); |
105 | |
|
106 | |
if (fld != null && fld.getFieldConversion() != null) |
107 | |
{ |
108 | |
val = fld.getFieldConversion().sqlToJava(val); |
109 | |
} |
110 | |
result[i] = val; |
111 | |
} |
112 | |
catch (SQLException e) |
113 | |
{ |
114 | |
throw new PersistenceBrokerException(e); |
115 | |
} |
116 | |
} |
117 | |
return result; |
118 | |
} |
119 | |
|
120 | |
|
121 | |
} |