Package org.exolab.castor.jdo

Examples of org.exolab.castor.jdo.PersistenceException


                _lastIdentity = SQLTypes.getObject( _rs, 1, _sqlTypes[ 0 ] );
            }
            return new Complex( _lastIdentity );
        } catch ( SQLException except ) {
            _lastIdentity = null;
            throw new PersistenceException( Messages.format( "persist.nested", except ) );
        }
    }
View Full Code Here


            if ( _rs.next() )
                _lastIdentity = SQLTypes.getObject( _rs, 1, _sqlTypes[ 0 ] );
            else
                _lastIdentity = null;
        } catch ( SQLException except ) {
            throw new PersistenceException( Messages.format( "persist.nested", except ) );
        }
        return stamp;
    }
View Full Code Here

                  retval = _rset.absolute(row);
               }
            }
            catch (SQLException e)
            {
               throw new PersistenceException(e.getMessage());
            }
            return retval;
         }
View Full Code Here

                  }
               }
            }
            catch (SQLException se)
            {
               throw new PersistenceException(se.getMessage());
            }
            return retval;
         }
View Full Code Here

        retVal = _rset.getObject(1);
        _hasMore = _rset.next();
      }
      catch ( SQLException except ) {
        if ( ! skipError )
          throw new PersistenceException(except.toString());
      }
     
      return retVal;
   }
View Full Code Here

      Object getValue(PreparedStatement stmt) throws PersistenceException, SQLException {
        ResultSet rs = stmt.executeQuery();
        if (rs.next()) {
          return identityValue.getValue(rs.getInt(1));
        } else {
          throw new PersistenceException(Messages.message("persist.keyGenFailed"));
        }
      }
View Full Code Here

        PreparedStatement stmt = null;
        try {
          stmt = conn.prepareStatement(sql);
          return getValue(stmt);
        } catch (SQLException e) {
          throw new PersistenceException(Messages.format("persist.keyGenSQL", e.toString()));
        } finally {
          if (stmt != null) {
            try {
              stmt.close();
            } catch (SQLException ex) {
View Full Code Here

        Object v = null;
        try {
          stmt = conn.prepareCall("{call IDENTITY()}");
          v = getValue(stmt);
        } catch (SQLException e) {
          throw new PersistenceException(Messages.format("persist.keyGenSQL", e.toString()));
        } finally {
          if (stmt != null) {
            try {
              stmt.close();
            }
View Full Code Here

        Object temp;
        int fieldType;
        AccessMode accessMode = getAccessMode( suggestedAccessMode );

        if ( oid.getIdentity() == null )
            throw new PersistenceException("The identities of the object to be loaded is null");

        // load the fields from the persistent storage if the cache is empty
        // and the accessMode is readOnly.
        fields = (Object[]) locker.getObject( tx );
        if ( fields == null || accessMode == AccessMode.DbLocked ) {
            fields = new Object[_fhs.length];
            if( results != null ) {
                stamp = results.getQuery().fetch( fields, oid.getIdentity() );
            } else {
                conn = (Connection)tx.getConnection(oid.getLockEngine());
                stamp = _persistence.load( conn, fields, oid.getIdentity(), accessMode );
            }
            oid.setDbLock( accessMode == AccessMode.DbLocked );
            locker.setObject( tx, fields );
        }

        // set the timeStamp of the data object to locker's timestamp
        if ( object instanceof TimeStampable ) {
            ((TimeStampable)object).jdoSetTimeStamp( locker.getTimeStamp() );
        }

        // set the identities into the target object
        ids = oid.getIdentity();
        setIdentity( tx, object, ids );

        // iterates thur all the field of the object and bind all field.
        for ( int i = 0; i < _fhs.length; i++ ) {
            fieldType = _fhs[i].getFieldType();
            switch (fieldType) {
            case FieldMolder.PRIMITIVE:
                // simply set the corresponding Persistent field value into the object
                temp = fields[i];
                if ( temp != null )
                    _fhs[i].setValue( object, temp, tx.getClassLoader() );
                else
                    _fhs[i].setValue( object, null, tx.getClassLoader() );
                break;

            case FieldMolder.SERIALIZABLE:
                // deserialize byte[] into java object
                try {
                    byte[] bytes = (byte[]) fields[i];
                    if ( bytes != null ) {
                        // The following code can be updated, after Blob-->InputStream
                        // to enhance performance.
                        ByteArrayInputStream bis = new ByteArrayInputStream( bytes );
                        ObjectInputStream os = new ObjectInputStream( bis );
                        Object o = os.readObject();
                        _fhs[i].setValue( object, o, tx.getClassLoader() );
                    } else {
                        _fhs[i].setValue( object, null, tx.getClassLoader() );
                    }
                } catch ( OptionalDataException e ) {
                    throw new PersistenceException( "Error while deserializing an dependent object", e );
                } catch ( ClassNotFoundException e ) {
                    throw new PersistenceException( "Error while deserializing an dependent object", e );
                } catch ( IOException e ) {
                    throw new PersistenceException( "Error while deserializing an dependent object", e );
                }
                break;

            case FieldMolder.PERSISTANCECAPABLE:
                // field is not primitive type. Related object will be loaded
                // thru the transaction in action if needed.

                fieldClassMolder = _fhs[i].getFieldClassMolder();
                fieldEngine = _fhs[i].getFieldLockEngine();

                if ( fields[i] != null ) {
                    // use the corresponding Persistent fields as the identity,
                    // and we ask transactionContext in action to load it.
                    try {
            // should I use lazy loading for this object?
            if (_fhs[i].isLazy()) {
              temp = SingleProxy.getProxy(tx, fieldEngine, fieldClassMolder, fields[i], null, suggestedAccessMode);
            } else {
              temp = tx.load(fieldEngine, fieldClassMolder, fields[i], null, suggestedAccessMode);
            }
                    } catch (ObjectNotFoundException ex) {
                        temp = null;
                    }
                    _fhs[i].setValue( object, temp, tx.getClassLoader() );
                } else {
                    _fhs[i].setValue( object, null, tx.getClassLoader() );
                }
                break;
            case FieldMolder.ONE_TO_MANY:
            case FieldMolder.MANY_TO_MANY:
                // field is one-to-many and many-to-many type. All the related
                // object will be loaded and put in a Collection. And, the
                // collection will be set as the field.
                fieldClassMolder = _fhs[i].getFieldClassMolder();
                fieldEngine = _fhs[i].getFieldLockEngine();

                if ( !_fhs[i].isLazy() ) {
                    // lazy loading is not specified, load all objects into
                    // the collection and set the Collection as the data object
                    // field.
                    ArrayList v = (ArrayList)fields[i];
                    if ( v != null ) {
                      // simple array type support
                      Class collectionType = _fhs[i].getCollectionType();
                      if (collectionType.isArray()) {
                        Object[] value = (Object[])java.lang.reflect.Array.newInstance(
                                collectionType.getComponentType(), v.size());
                        for ( int j=0,l=v.size(); j<l; j++ ) {
                          value[j] = tx.load( oid.getLockEngine(), fieldClassMolder, v.get(j), null, suggestedAccessMode );
                        }
                        _fhs[i].setValue( object, value, tx.getClassLoader() );
                      } else {
                        CollectionProxy cp = CollectionProxy.create( _fhs[i], object, tx.getClassLoader() );
                        for ( int j=0,l=v.size(); j<l; j++ ) {
                            cp.add( v.get(j), tx.load( oid.getLockEngine(), fieldClassMolder, v.get(j), null, suggestedAccessMode ) );
                        }
                        cp.close();
                        //_fhs[i].setValue( object, cp.getCollection() );
                      }
                    } else {
                        _fhs[i].setValue( object, null, tx.getClassLoader() );
                    }
                } else {
                    // lazy loading is specified. Related object will not be loaded.
                    // A lazy collection with all the identity of the related object
                    // will constructed and set as the data object's field.
                    ArrayList list = (ArrayList) fields[i];
                    RelationCollection relcol = new RelationCollection( tx, oid, fieldEngine, fieldClassMolder, accessMode, list );
                    _fhs[i].setValue( object, relcol, tx.getClassLoader() );
                }
                break;
            default:
                throw new PersistenceException("Unexpected field type!");
            }
        }
        return stamp;
    }
View Full Code Here

        Object o;

        int fieldType;

        if ( _persistence == null )
            throw new PersistenceException("non persistence capable: "+oid.getName());

        fields = new Object[_fhs.length];
        ids = oid.getIdentity();

        // copy the object to cache should make a new field now,
        for ( int i=0; i<_fhs.length; i++ ) {
            fieldType = _fhs[i].getFieldType();

            switch (fieldType) {
            case FieldMolder.PRIMITIVE: // primitive includes int, float, Date, Time etc
                fields[i] = _fhs[i].getValue( object, tx.getClassLoader() );
                break;

            case FieldMolder.PERSISTANCECAPABLE:
                fieldClassMolder = _fhs[i].getFieldClassMolder();
                o = _fhs[i].getValue( object, tx.getClassLoader() );
                if ( o != null ) {
                    fid = fieldClassMolder.getIdentity( tx, o );
                    if ( fid != null ) {
                        fields[i] = fid;
                    }
                }
                break;

            case FieldMolder.SERIALIZABLE:
                try {
                    Object dependent = _fhs[i].getValue( object, tx.getClassLoader() );
                    if ( dependent != null ) {
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        ObjectOutputStream os = new ObjectOutputStream( bos );
                        os.writeObject( dependent );
                        fields[i] = bos.toByteArray();
                    } else {
                        fields[i] = null;
                    }
                } catch ( IOException e ) {
                    throw new PersistenceException( "Error during serializing dependent object", e );
                }
                break;

            case FieldMolder.ONE_TO_MANY:
                fieldClassMolder = _fhs[i].getFieldClassMolder();
                o = _fhs[i].getValue( object, tx.getClassLoader() );
                if ( o != null ) {
                    fids = extractIdentityList( tx, fieldClassMolder, o );
                    fields[i] = fids;
                }
                break;

            case FieldMolder.MANY_TO_MANY:
                fieldClassMolder = _fhs[i].getFieldClassMolder();
                o = _fhs[i].getValue( object, tx.getClassLoader() );
                if ( o != null ) {
                    fids = extractIdentityList( tx, fieldClassMolder, o );
                    fields[i] = fids;
                }

                break;

            default:
                throw new IllegalArgumentException("Field type invalid!");
            }
        }

        // ask Persistent to create the object into the persistence storage
        createdId = _persistence.create(tx.getDatabase(), (Connection)tx.getConnection(oid.getLockEngine()),
                fields, ids );

        if ( createdId == null )
            throw new PersistenceException("Identity can't be created!");

        // if the creation succeed, we set the field into the dirty checking
        // cache.
        locker.setObject( tx, fields );
        oid.setDbLock( true );
View Full Code Here

TOP

Related Classes of org.exolab.castor.jdo.PersistenceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.