_log.debug( Messages.format( "jdo.load", ( accessMode == AccessMode.DbLocked ) ? _sqlLoadLock : _sqlLoad ) );
_log.debug( Messages.format( "jdo.loading", ( accessMode == AccessMode.DbLocked ) ? _sqlLoadLock : _sqlLoad ) );
    public Object load( Object conn, Object[] fields, Object identity, AccessMode accessMode )            throws ObjectNotFoundException, PersistenceException {        PreparedStatement stmt  = null;        ResultSet         rs    = null;        Object            stamp = null;        boolean           notNull;        try {            stmt = ( (Connection) conn ).prepareStatement( ( accessMode == AccessMode.DbLocked ) ? _sqlLoadLock : _sqlLoad );                        _log.debug( Messages.format( "jdo.load", ( accessMode == AccessMode.DbLocked ) ? _sqlLoadLock : _sqlLoad ) );                        int count = 1;            // bind the identity of the preparedStatement            if ( identity instanceof Complex ) {                Complex id = (Complex) identity;                if ( id.size() != _ids.length || _ids.length <= 1 )                    throw new PersistenceException( "Size of complex field mismatched! expected: "+_ids.length+" found: "+id.size() );                for ( int i=0; i<_ids.length; i++ )                    stmt.setObject( count++, idToSQL( i, id.get(i) ) );            } else {                if ( _ids.length != 1 )                    throw new PersistenceException( "Complex field expected!" );                stmt.setObject( count++, idToSQL( 0, identity ) );            }            // query the object            rs = stmt.executeQuery();            if ( ! rs.next() )                throw new ObjectNotFoundException( Messages.format("persist.objectNotFound", _clsDesc.getJavaClass().getName(), identity) );            // Load all the fields of the object including one-one relations            count = 1;            Object[] temp = new Object[10]; // assume complex field max at 10            for ( int i = 0 ; i < _fields.length ; ++i  ) {                if ( !_fields[i].load )                    continue;                if ( !_fields[i].multi ) {                    notNull = false;                    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 ) {                                notNull = true;                            }                        }                        if ( notNull )                            fields[i] = new Complex( _fields[i].columns.length, temp );                        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 ) {                            notNull = true;                        }                        count++;                    }                    if ( notNull ) {                        if ( _fields[i].columns.length == 1 )                            res.add( temp[0] );                        else                            res.add( new Complex( _fields[i].columns.length, temp ) );                    }                    fields[i] = res;                }            }            while ( rs.next() ) {                count = 1;                for ( int i = 0; i < _fields.length ; ++i  ) {                    if ( !_fields[i].load )                        continue;                    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 ) {                                notNull = true;                            }                            count++;                        }                        if ( notNull ) {                            if ( _fields[i].columns.length == 1 ) {                                if ( !res.contains( temp[0] ) )                                    res.add( temp[0] );                            } else {                                Complex com = new Complex( _fields[i].columns.length, temp );                                if ( !res.contains( com ) )                                    res.add( new Complex( _fields[i].columns.length, temp ) );                            }                        }                    } else {                        count += _fields[i].columns.length;                    }                }            }        } catch ( SQLException except ) {            _log.fatal( Messages.format( "jdo.loadFatal", _type, (( accessMode == AccessMode.DbLocked ) ? _sqlLoadLock : _sqlLoad ) ) );            throw new PersistenceException( Messages.format("persist.nested", except), except );        } finally {            try {                if ( rs != null ) rs.close();            } catch ( SQLException sqle ) {            }            try {                if ( stmt != null ) stmt.close();            } catch ( SQLException sqle ) {            }        }        return stamp;    }