Hey there :)
Was having a problem with the hardcoded limit of 10
cols for a complex type (don't ask), so I changed the
code so its not arbitarily limited.
The patch is attached.
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
Index: SQLEngine.java
===================================================================
RCS file:
/cvs/castor/castor/src/main/org/exolab/castor/jdo/engine/SQLEngine.java,v
retrieving revision 1.111
diff -u -r1.111 SQLEngine.java
--- SQLEngine.java 25 Feb 2002 01:02:14 -0000 1.111
+++ SQLEngine.java 16 May 2002 12:22:47 -0000
@@ -1005,7 +1005,9 @@
// Load all the fields of the object including one-one
relations
count = 1;
- Object[] temp = new Object[10]; // assume complex field max at
10
+ //a List for temporarily storing the field columns
+ ArrayList temp = new ArrayList( 10 );
+ //the objective of this loop is to: ?
for ( int i = 0 ; i < _fields.length ; ++i ) {
if ( !_fields[i].load )
continue;
@@ -1015,32 +1017,44 @@
if ( _fields[i].columns.length == 1 ) {
fields[i] = toJava( i, 0, SQLTypes.getObject( rs,
count++, _fields[i].columns[0].sqlType ) );
} else {
- for ( int j=0; j<_fields[i].columns.length; j++ ) {
- temp[j] = toJava( i, j, SQLTypes.getObject( rs,
count++, _fields[i].columns[j].sqlType ) );
- if ( temp[j] != null ) {
+ //number of cols this field has
+ int numberOfColumns = _fields[i].columns.length;
+ //make sure the list has enough space for all the
cols
+ temp.ensureCapacity( numberOfColumns );
+ //go through the columns and add non-null columns
to the temp list
+ for ( int j=0; j < numberOfColumns; j++ ) {
+ Object currentColumn = toJava( i, j,
SQLTypes.getObject( rs, count++, _fields[i].columns[j].sqlType ) );
+ if ( currentColumn != null ) {
+ temp.set( j, currentColumn );
notNull = true;
}
}
if ( notNull )
- fields[i] = new Complex(
_fields[i].columns.length, temp );
+ fields[i] = new Complex(
_fields[i].columns.length, temp.toArray() );
else
fields[i] = null;
}
} else {
ArrayList res = new ArrayList();
notNull = false;
- for ( int j=0; j<_fields[i].columns.length; j++ ) {
- temp[j] = toJava( i, j, SQLTypes.getObject( rs,
count, _fields[i].columns[j].sqlType ) );
- if ( temp[j] != null ) {
+ //number of cols this field has
+ int numberOfColumns = _fields[i].columns.length;
+ //make sure the list has enough space for all the cols
+ temp.ensureCapacity( numberOfColumns );
+ //go through the columns and add non-null columns to
the temp list
+ for ( int j=0; j < numberOfColumns; j++ ) {
+ Object currentColumn = toJava( i, j,
SQLTypes.getObject( rs, count, _fields[i].columns[j].sqlType ) );
+ if ( currentColumn != null ) {
+ temp.set( j, currentColumn );
notNull = true;
}
count++;
}
if ( notNull ) {
if ( _fields[i].columns.length == 1 )
- res.add( temp[0] );
+ res.add( temp.get( 0 ) );
else
- res.add( new Complex(
_fields[i].columns.length, temp ) );
+ res.add( new Complex(
_fields[i].columns.length, temp.toArray() ) );
}
fields[i] = res;
}
@@ -1055,21 +1069,27 @@
if ( _fields[i].multi ) {
ArrayList res = (ArrayList)fields[i];
notNull = false;
- for ( int j=0; j<_fields[i].columns.length; j++ ) {
- temp[j] = toJava( i, j, SQLTypes.getObject( rs,
count, _fields[i].columns[j].sqlType ) );
- if ( temp[j] != null ) {
+ //number of cols this field has
+ int numberOfColumns = _fields[i].columns.length;
+ //make sure the list has enough space for all the
cols
+ temp.ensureCapacity( numberOfColumns );
+ //go through the columns and add non-null columns
to the temp list
+ for ( int j=0; j < numberOfColumns; j++ ) {
+ Object currentColumn = toJava( i, j,
SQLTypes.getObject( rs, count, _fields[i].columns[j].sqlType ) );
+ if ( currentColumn != null ) {
+ temp.set( j, currentColumn );
notNull = true;
}
count++;
}
if ( notNull ) {
if ( _fields[i].columns.length == 1 ) {
- if ( !res.contains( temp[0] ) )
- res.add( temp[0] );
+ if ( !res.contains( temp.get( 0 ) ) )
+ res.add( temp.get( 0 ) );
} else {
- Complex com = new Complex(
_fields[i].columns.length, temp );
+ Complex com = new Complex(
_fields[i].columns.length, temp.toArray() );
if ( !res.contains( com ) )
- res.add( new Complex(
_fields[i].columns.length, temp ) );
+ res.add( new Complex(
_fields[i].columns.length, temp.toArray() ) );
}
}
} else {
@@ -1776,15 +1796,16 @@
private Object loadSingleField( int i, int count ) throws
SQLException, PersistenceException
{
- Object[] temp = new Object[10]; // bad practice, assume
complex field smaller than 10
+ int columnLength = _engine._fields[i].columns.length;
+ Object[] temp = new Object[ columnLength ];
boolean notNull = false;
Object field;
- if ( _engine._fields[i].columns.length == 1 ) {
+ if ( columnLength == 1 ) {
field = _engine.toJava( i, 0, SQLTypes.getObject( _rs,
count++,
_engine._fields[i].columns[0].sqlType ) );
} else {
- for ( int j=0; j<_engine._fields[i].columns.length; j++ ) {
+ for ( int j=0; j < columnLength; j++ ) {
temp[j] = _engine.toJava( i, j, SQLTypes.getObject(
_rs, count++,
_engine._fields[i].columns[j].sqlType ) );
if ( temp[j] != null ) {
@@ -1792,7 +1813,7 @@
}
}
if ( notNull )
- field = new Complex( _engine._fields[i].columns.length,
temp );
+ field = new Complex( columnLength, temp );
else
field = null;
}
@@ -1802,7 +1823,8 @@
private Object loadMultiField( int i, int count, Object field )
throws SQLException, PersistenceException
{
- Object[] temp = new Object[10]; // bad practice, assume
complex field smaller than 10
+ int columnLength = _engine._fields[i].columns.length;
+ Object[] temp = new Object[ columnLength ];
boolean notNull = false;
ArrayList res;
@@ -1811,7 +1833,7 @@
else
res = (ArrayList) field;
- for ( int j=0; j<_engine._fields[i].columns.length; j++ ) {
+ for ( int j=0; j < columnLength; j++ ) {
temp[j] = _engine.toJava( i, j,
SQLTypes.getObject( _rs, count,
_engine._fields[i].columns[j].sqlType ) );
if ( temp[j] != null ) {
@@ -1820,11 +1842,11 @@
count++;
}
if ( notNull ) {
- if ( _engine._fields[i].columns.length == 1 ) {
+ if ( columnLength == 1 ) {
if ( !res.contains( temp[0] ) )
res.add( temp[0] );
} else {
- Complex com = new Complex(
_engine._fields[i].columns.length, temp );
+ Complex com = new Complex( columnLength, temp );
if ( !res.contains( com ) )
res.add( com );
}