Package org.exolab.castor.jdo

Examples of org.exolab.castor.jdo.PersistenceException


    /**
     * {@inheritDoc}
     */
    public Identity getIdentity(final Object object) throws PersistenceException {
        if (_scope == null) {
            throw new PersistenceException(Messages.message("jdo.dbClosed"));
        }

        ClassMolder molder = _scope.getClassMolder(object.getClass());
        return molder.getActualIdentity(_classLoader, object);
    }
View Full Code Here


            typeInfo.rename(internaloid, newoid, tx);

            return newoid;
        } catch (LockNotGrantedException e) {
//            e.printStackTrace();
            throw new PersistenceException(Messages.format(
                    "persist.nested", "Key Generator Failure. Duplicated Identity is generated!"));
        } finally {
            if (lock != null) {
                lock.confirm(tx, succeed);
            }
View Full Code Here

    throws PersistenceException {
        Object loadObject = null;
        try {
            loadObject = newInstance(tx.getClassLoader());
        } catch (Exception ex) {
            throw new PersistenceException("failed to load object", ex);
        }

        ProposedEntity proposedObject = new ProposedEntity(this);
        proposedObject.setProposedEntityClass(loadObject.getClass());
        proposedObject.setEntity(loadObject);
View Full Code Here

            final ProposedEntity proposedObject, final AccessMode suggestedAccessMode,
            final QueryResults results)
    throws PersistenceException {
        OID oid = locker.getOID();
        if (oid.getIdentity() == null) {
            throw new PersistenceException(
                    "The identities of the object to be loaded is null");
        }
       
        // try to load the field values from the cache, except when being told
        // to ignore them
View Full Code Here

            case FieldMolder.ONE_TO_MANY:
            case FieldMolder.MANY_TO_MANY:
                _resolvers[i].load(tx, oid, proposedObject, accessMode);
                break;
            default:
                throw new PersistenceException("Unexpected field type!");
            }
        }
       
        // set the timeStamp of locker to the one of data object
        if (proposedObject.getEntity() instanceof TimeStampable) {
View Full Code Here

                                stmt.setNull(count++, columns[j].getSqlType());
                            }
                        } else if (value instanceof Identity) {
                            Identity id = (Identity) value;
                            if (id.size() != columns.length) {
                                throw new PersistenceException("Size of identity field mismatch!");
                            }
                           
                            for (int j = 0; j < columns.length; j++) {
                                SQLTypeInfos.setValue(stmt, count++,
                                        columns[j].toSQL(id.get(j)), columns[j].getSqlType());
                            }
                        } else {
                            if (columns.length != 1) {
                                throw new PersistenceException("Complex field expected!");
                            }
                           
                            SQLTypeInfos.setValue(stmt, count++, columns[0].toSQL(value),
                                    columns[0].getSqlType());
                        }
                    }
                }
               
                // bind the identity of the row to be stored into the preparedStatement
                SQLColumnInfo[] ids = _engine.getColumnInfoForIdentities();
                if (identity.size() != ids.length) {
                    throw new PersistenceException("Size of identity field mismatched!");
                }
               
                for (int i = 0; i < ids.length; i++) {
                    stmt.setObject(count++, ids[i].toSQL(identity.get(i)));
                    if (LOG.isTraceEnabled()) {
                        LOG.trace(Messages.format("jdo.bindingIdentity", ids[i].getName(),
                                ids[i].toSQL(identity.get(i))));
                    }
                }                   
               
                // bind the old fields of the row to be stored into the preparedStatement
                if (oldentity.getFields() != null) {
                    boolean supportsSetNull = _factory.supportsSetNullInWhere();
                   
                    for (int i = 0; i < fields.length; ++i) {
                        if (fields[i].isStore() && fields[i].isDirtyCheck()) {
                            SQLColumnInfo[] columns = fields[i].getColumnInfo();
                            Object value = oldentity.getField(i);
                            if (value == null) {
                                if (supportsSetNull) {
                                    for (int j = 0; j < columns.length; j++) {
                                        stmt.setNull(count++, columns[j].getSqlType());
                                    }
                                }
                            } else if (value instanceof Identity) {
                                Identity id = (Identity) value;
                                if (id.size() != columns.length) {
                                    throw new PersistenceException(
                                            "Size of identity field mismatch!");
                                }
                               
                                for (int j = 0; j < columns.length; j++) {
                                    SQLTypeInfos.setValue(stmt, count++,
                                            columns[j].toSQL(id.get(j)), columns[j].getSqlType());
                                   
                                    if (LOG.isTraceEnabled()) {
                                        LOG.trace(Messages.format("jdo.bindingField",
                                                columns[j].getName(), columns[j].toSQL(id.get(j))));
                                    }
                                }
                            } else {
                                if (columns.length != 1) {
                                    throw new PersistenceException("Complex field expected!");
                                }
                               
                                SQLTypeInfos.setValue(stmt, count++, columns[0].toSQL(value),
                                        columns[0].getSqlType());
                           
                                if (LOG.isTraceEnabled()) {
                                    LOG.trace(Messages.format("jdo.bindingField",
                                            columns[0].getName(), columns[0].toSQL(value)));
                                }
                            }
                        }
                    }
                }
               
                if (LOG.isDebugEnabled()) {
                    LOG.debug(Messages.format("jdo.storing", _type, stmt.toString()));
                }

                if (stmt.executeUpdate() <= 0) { // SAP DB returns -1 here
                    // If no update was performed, the object has been previously
                    // removed from persistent storage or has been modified if
                    // dirty checking. Determine which is which.
                    stmt.close();

                    if (oldentity.getFields() != null) {
                        stmt = conn.prepareStatement(_statementLoad);
                       
                        if (LOG.isTraceEnabled()) {
                            LOG.trace(Messages.format("jdo.storing", _type, stmt.toString()));
                        }
                       
                        // bind the identity to the prepareStatement
                        count = 1;
                        for (int i = 0; i < ids.length; i++) {
                            stmt.setObject(count++, ids[i].toSQL(identity.get(i)));
                        }
                       
                        ResultSet res = stmt.executeQuery();
                        if (res.next()) {                    
                            StringBuffer enlistFieldsNotMatching = new StringBuffer();
                           
                            int numberOfFieldsNotMatching = 0;
                            for (int i = 0; i < fields.length; i++) {
                                SQLColumnInfo[] columns = fields[i].getColumnInfo();
                                Object value = oldentity.getField(i);
                                Object currentField = columns[0].toJava(res.getObject(
                                        columns[0].getName()));
                                if (fields[i].getTableName().compareTo(_mapTo) == 0) {
                                    if ((value == null) || ((value != null)
                                            && (currentField == null))) {
                                        enlistFieldsNotMatching.append("(" + _type + ")."
                                                + columns[0].getName() + ": ");
                                        enlistFieldsNotMatching.append("[" + value + "/"
                                                + currentField + "]");
                                    } else if (!value.equals(currentField)) {
                                        if (numberOfFieldsNotMatching >= 1) {
                                            enlistFieldsNotMatching.append(", ");
                                        }
                                        enlistFieldsNotMatching.append("(" + _type + ")."
                                                + columns[0].getName() + ": ");
                                        enlistFieldsNotMatching.append("[" + value + "/"
                                                + currentField + "]");
                                        numberOfFieldsNotMatching++;
                                    }
                                }
                            }
                            throw new ObjectModifiedException(Messages.format(
                                    "persist.objectModified", _type, identity,
                                    enlistFieldsNotMatching.toString()));
                        }
                    }
                    throw new ObjectDeletedException(Messages.format(
                            "persist.objectDeleted", _type, identity));
                }               
            } catch (SQLException except) {
                LOG.fatal(Messages.format("jdo.storeFatal", _type,  storeStatement), except);
                throw new PersistenceException(Messages.format("persist.nested", except), except);
            } finally {
                try {
                    // Close the insert/select statement
                    if (stmt != null) { stmt.close(); }
                } catch (SQLException except2) {
View Full Code Here

        int fieldType;

        resetResolvers();

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

        ProposedEntity entity = new ProposedEntity();
        entity.initializeFields(_fhs.length);
        Identity ids = oid.getIdentity();

        // set the new timeStamp into the data object
        long timeStamp = System.currentTimeMillis();
        if (object instanceof TimeStampable) {
            ((TimeStampable) object).jdoSetTimeStamp(timeStamp);
        }

        // 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:
            case FieldMolder.PERSISTANCECAPABLE:
            case FieldMolder.SERIALIZABLE:
            case FieldMolder.ONE_TO_MANY:
            case FieldMolder.MANY_TO_MANY:
                entity.setField(_resolvers[i].create(tx, object), i);
                break;

            default:
                throw new IllegalArgumentException("Field type invalid!");
            }
        }
       
        // ask Persistent to create the object into the persistence storage
        Identity createdId = _persistence.create(tx.getDatabase(),
                tx.getConnection(oid.getMolder().getLockEngine()), entity, ids);

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

        // set the field values into the cache
        locker.setObject(tx, entity.getFields(), timeStamp);
        oid.setDbLock(true);
View Full Code Here

                            pos = nextParameter(true, sql, pos);
                        }
                    } else if (value instanceof Identity) {
                        Identity identity = (Identity) value;
                        if (identity.size() != columns.length) {
                            throw new PersistenceException("Size of identity field mismatch!");
                        }

                        for (int j = columns.length - 1; j >= 0; j--) {
                            pos = nextParameter((identity.get(j) == null), sql, pos);
                        }
                    } else {
                        if (columns.length != 1) {
                            throw new PersistenceException("Complex field expected!");
                        }

                        pos = nextParameter(false, sql, pos);
                    }
                }
View Full Code Here

     */
    public boolean preStore(final TransactionContext tx, final OID oid, final DepositBox locker,
            final Object object, final int timeout) throws PersistenceException {

        if (oid.getIdentity() == null) {
            throw new PersistenceException(Messages.format(
                    "persist.missingIdentityForStore", _name));
        }

        if (!oid.getIdentity().equals(getIdentity(tx, object))) {
            throw new PersistenceException(Messages.format(
                    "jdo.identityChanged", _name, oid.getIdentity(),
                    getIdentity(tx, object)));
        }

        Object[] fields = locker.getObject(tx);

        if (fields == null) {
            throw new PersistenceException(
                    Messages.format("persist.objectNotFound", _name, oid));
        }

        Object[] newfields = new Object[_fhs.length];
        boolean updateCache = false;
View Full Code Here

     */
    public void store(final TransactionContext tx, final OID oid, final DepositBox locker,
            final Object object) throws PersistenceException {

        if (oid.getIdentity() == null) {
            throw new PersistenceException(Messages.format(
                    "persist.missingIdentityForStore", _name));
        }

        if (!oid.getIdentity().equals(getIdentity(tx, object))) {
            throw new PersistenceException(Messages.format(
                    "jdo.identityChanged", _name, oid.getIdentity(),
                    getIdentity(tx, object)));
        }

        // load field values from cache (if availabe)
        ProposedEntity oldentity = new ProposedEntity();
        oldentity.setFields(locker.getObject(tx));

        if (oldentity.getFields() == null) {
            throw new PersistenceException(
                    Messages.format("persist.objectNotFound", _name, oid));
        }

        // set the new timeStamp into the data object
        long timeStamp = System.currentTimeMillis();
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.