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 br...@apache.org on 2004/01/29 21:31:44 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/query ReportQueryByCriteria.java ReportQuery.java
brj 2004/01/29 12:31:44
Modified: src/java/org/apache/ojb/broker/accesslayer
MtoNCollectionPrefetcher.java
ReportQueryRsIterator.java
src/java/org/apache/ojb/broker/query
ReportQueryByCriteria.java ReportQuery.java
Log:
Fix for problem in MtoNPrefetcher where sqltypes of mn-implementors do not match sqltypes of connected classes
Revision Changes Path
1.4 +16 -3 db-ojb/src/java/org/apache/ojb/broker/accesslayer/MtoNCollectionPrefetcher.java
Index: MtoNCollectionPrefetcher.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/MtoNCollectionPrefetcher.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MtoNCollectionPrefetcher.java 24 Jan 2004 14:03:45 -0000 1.3
+++ MtoNCollectionPrefetcher.java 29 Jan 2004 20:31:43 -0000 1.4
@@ -159,19 +159,32 @@
*/
protected Query buildMtoNImplementorQuery(Collection ids)
{
- CollectionDescriptor cds = getCollectionDescriptor();
String[] indFkCols = getFksToThisClass();
String[] indItemFkCols = getFksToItemClass();
+ FieldDescriptor[] pkFields = getOwnerClassDescriptor().getPkFields();
FieldDescriptor[] itemPkFields = getItemClassDescriptor().getPkFields();
String[] cols = new String[indFkCols.length + indItemFkCols.length];
+ int[] jdbcTypes = new int[indFkCols.length + indItemFkCols.length];
+ // concatenate the columns[]
System.arraycopy(indFkCols,0,cols,0,indFkCols.length);
System.arraycopy(indItemFkCols,0,cols,indFkCols.length,indItemFkCols.length);
Criteria crit = buildPrefetchCriteria(ids, indFkCols, indItemFkCols, itemPkFields);
+ // determine the jdbcTypes of the pks
+ for (int i = 0; i < pkFields.length; i++)
+ {
+ jdbcTypes[i] = pkFields[i].getJdbcType().getType();
+ }
+ for (int i = 0; i < itemPkFields.length; i++)
+ {
+ jdbcTypes[pkFields.length + i] = itemPkFields[i].getJdbcType().getType();
+ }
+
ReportQueryByMtoNCriteria q = new ReportQueryByMtoNCriteria(getItemClassDescriptor().getClassOfObject(), cols, crit, true);
- q.setIndirectionTable(cds.getIndirectionTable());
+ q.setIndirectionTable(getCollectionDescriptor().getIndirectionTable());
+ q.setJdbcTypes(jdbcTypes);
return q;
}
1.10 +41 -14 db-ojb/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java
Index: ReportQueryRsIterator.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ReportQueryRsIterator.java 30 Dec 2003 19:15:32 -0000 1.9
+++ ReportQueryRsIterator.java 29 Jan 2004 20:31:44 -0000 1.10
@@ -71,9 +71,9 @@
public class ReportQueryRsIterator extends RsIterator
{
- private ResultSetMetaData rsMetaData;
- private int columnCount;
-
+ private int m_columnCount;
+ private int[] m_jdbcTypes;
+
/**
* Constructor for ReportQueryRsIterator.
*/
@@ -82,12 +82,12 @@
super(queryObject, broker);
try
{
- rsMetaData = getRsAndStmt().m_rs.getMetaData();
-
// BRJ: use only explicit columns !
// ignore those columns automatically added for ordering or grouping
ReportQuery q = (ReportQuery)queryObject.getQuery();
- columnCount = q.getColumns().length;
+ m_columnCount = q.getColumns().length;
+
+ init_jdbcTypes();
}
catch (SQLException e)
{
@@ -97,18 +97,45 @@
}
/**
- * returns an Object[] representing the columns of the current ResultSet row.
- * There is no OJB object materialization, Proxy generation etc. involved
- * to maximize performance.
+ * 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_columnCount];
+
+ // 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_columnCount; 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.
*/
protected Object getObjectFromResultSet() throws PersistenceBrokerException
{
- Object[] result = new Object[columnCount];
- for (int i = 0; i < columnCount; i++)
+ Object[] result = new Object[m_columnCount];
+
+ for (int i = 0; i < m_columnCount; i++)
{
try
{
- int jdbcType = rsMetaData.getColumnType(i + 1);
+ int jdbcType = m_jdbcTypes[i];
result[i] = JdbcTypesHelper.getObjectFromColumn(getRsAndStmt().m_rs, new Integer(jdbcType), i + 1);
}
catch (SQLException e)
@@ -118,6 +145,6 @@
}
return result;
}
-
+
}
1.5 +41 -21 db-ojb/src/java/org/apache/ojb/broker/query/ReportQueryByCriteria.java
Index: ReportQueryByCriteria.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/ReportQueryByCriteria.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ReportQueryByCriteria.java 1 Oct 2002 18:49:06 -0000 1.4
+++ ReportQueryByCriteria.java 29 Jan 2004 20:31:44 -0000 1.5
@@ -1,5 +1,6 @@
package org.apache.ojb.broker.query;
+
/* ====================================================================
* The Apache Software License, Version 1.1
*
@@ -64,8 +65,11 @@
public class ReportQueryByCriteria extends QueryByCriteria implements ReportQuery
{
// BRJ: define the columns to be selected for reports
- private String[] columns = null;
+ private String[] m_columns = null;
+ // BRJ: define the Jdbc-Types of the columns to be selected for reports
+ private int[] m_jdbcTypes = null;
+
/**
* Constructor for ReportQueryByCriteria.
* @param targetClass
@@ -117,7 +121,7 @@
*/
public String[] getColumns()
{
- return columns;
+ return m_columns;
}
/**
@@ -126,24 +130,40 @@
*/
public void setColumns(String[] columns)
{
- this.columns = columns;
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- public String toString()
- {
- String[] cols = getColumns();
- StringBuffer buf = new StringBuffer("ReportQuery from ");
- buf.append(getSearchClass() + " ");
- for (int i = 0; i < cols.length; i++)
- {
- buf.append(cols[i] + " ");
- }
- buf.append(" where " + getCriteria());
-
- return buf.toString();
+ this.m_columns = columns;
}
+ /**
+ * @return Returns the jdbcTypes.
+ */
+ public int[] getJdbcTypes()
+ {
+ return m_jdbcTypes;
+ }
+
+ /**
+ * @param jdbcTypes The jdbcTypes to set.
+ */
+ public void setJdbcTypes(int[] jdbcTypes)
+ {
+ this.m_jdbcTypes = jdbcTypes;
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ String[] cols = getColumns();
+ StringBuffer buf = new StringBuffer("ReportQuery from ");
+ buf.append(getSearchClass() + " ");
+ for (int i = 0; i < cols.length; i++)
+ {
+ buf.append(cols[i] + " ");
+ }
+ buf.append(" where " + getCriteria());
+
+ return buf.toString();
+ }
+
}
1.2 +10 -1 db-ojb/src/java/org/apache/ojb/broker/query/ReportQuery.java
Index: ReportQuery.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/ReportQuery.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ReportQuery.java 1 Oct 2002 18:49:06 -0000 1.1
+++ ReportQuery.java 29 Jan 2004 20:31:44 -0000 1.2
@@ -1,5 +1,6 @@
package org.apache.ojb.broker.query;
+
/* ====================================================================
* The Apache Software License, Version 1.1
*
@@ -68,4 +69,12 @@
* @return Returns a String[]
*/
public String[] getColumns();
+
+ /**
+ * Gets the Jdbc-Types of the columns used for the Report.
+ * If null the Jdbc-Type is taken from the ResultSet
+ * @return Returns an int[] of Jdbc-Types
+ * @see java.sql.Types
+ */
+ public int[] getJdbcTypes();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org