You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2006/03/02 20:02:39 UTC
svn commit: r382471 -
/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java
Author: arminw
Date: Thu Mar 2 11:02:38 2006
New Revision: 382471
URL: http://svn.apache.org/viewcvs?rev=382471&view=rev
Log:
improve report query iterator, use field-descriptor to lookup jdbc type whenever it is possible
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java?rev=382471&r1=382470&r2=382471&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java Thu Mar 2 11:02:38 2006
@@ -42,49 +42,13 @@
public ReportQueryRsIterator(RsQueryObject queryObject, PersistenceBrokerImpl broker)
{
super(queryObject, broker);
- try
- {
- // BRJ: use only explicit attributes (columns) !
- // ignore those automatically added for ordering or grouping
- ReportQuery q = (ReportQuery)queryObject.getQuery();
- m_attributeCount = q.getAttributes().length;
-
- init_jdbcTypes();
- }
- catch (SQLException e)
- {
- releaseDbResources();
- throw new PersistenceBrokerException(e);
- }
+ // BRJ: use only explicit attributes (columns) !
+ // ignore those automatically added for ordering or grouping
+ ReportQuery q = (ReportQuery)queryObject.getQuery();
+ m_attributeCount = q.getAttributes().length;
}
/**
- * get the jdbcTypes from the Query or the ResultSet if not available from the Query
- * @throws SQLException
- */
- private void init_jdbcTypes() throws SQLException
- {
- ReportQuery q = (ReportQuery) getQueryObject().getQuery();
- m_jdbcTypes = new int[m_attributeCount];
-
- // try to get jdbcTypes from Query
- if (q.getJdbcTypes() != null)
- {
- m_jdbcTypes = q.getJdbcTypes();
- }
- else
- {
- ResultSetMetaData rsMetaData = getRsAndStmt().m_rs.getMetaData();
- for (int i = 0; i < m_attributeCount; i++)
- {
- m_jdbcTypes[i] = rsMetaData.getColumnType(i + 1);
- }
-
- }
- }
-
-
- /**
* returns an Object[] representing the columns of the current ResultSet
* row. There is no OJB object materialization, Proxy generation etc.
* involved to maximize performance.
@@ -98,15 +62,19 @@
{
try
{
- int jdbcType = m_jdbcTypes[i];
String attr = q.getAttributes()[i];
FieldDescriptor fld = (FieldDescriptor) q.getAttributeFieldDescriptors().get(attr);
- Object val =JdbcTypesHelper.getObjectFromColumn(getRsAndStmt().m_rs, new Integer(jdbcType), i + 1);
-
- if (fld != null && fld.getFieldConversion() != null)
+ Object val;
+ if(fld != null)
{
+ val = fld.getJdbcType().getObjectFromColumn(getRsAndStmt().m_rs, i + 1);
val = fld.getFieldConversion().sqlToJava(val);
}
+ else
+ {
+ int jdbcType = extractJdbcType(i);
+ val =JdbcTypesHelper.getObjectFromColumn(getRsAndStmt().m_rs, new Integer(jdbcType), i + 1);
+ }
result[i] = val;
}
catch (SQLException e)
@@ -116,6 +84,34 @@
}
return result;
}
-
+
+ /**
+ * Extracts the jdbc type of the specified result set column index.
+ *
+ * @param rsIndex The result set column index.
+ * @return The jdbc {@link java.sql.Types} type.
+ * @throws SQLException
+ */
+ private int extractJdbcType(int rsIndex) throws SQLException
+ {
+ if(m_jdbcTypes == null)
+ {
+ ReportQuery q = (ReportQuery) getQueryObject().getQuery();
+ if(q.getJdbcTypes() != null)
+ {
+ m_jdbcTypes = q.getJdbcTypes();
+ }
+ else
+ {
+ m_jdbcTypes = new int[m_attributeCount];
+ ResultSetMetaData rsMetaData = getRsAndStmt().m_rs.getMetaData();
+ for (int i = 0; i < m_attributeCount; i++)
+ {
+ m_jdbcTypes[i] = rsMetaData.getColumnType(i + 1);
+ }
+ }
+ }
+ return m_jdbcTypes[rsIndex];
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org