Package org.exolab.castor.jdo

Examples of org.exolab.castor.jdo.PersistenceException


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


                _lastIdentity = new Identity(SQLTypeInfos.getValue(_rs, 1, _sqlTypes[0]));
            } else {
                _lastIdentity = null;
            }
        } catch (SQLException except) {
            throw new PersistenceException(Messages.format("persist.nested",
                    except));
        }
    }
View Full Code Here

                ObjectOutputStream os = new ObjectOutputStream(bos);
                os.writeObject(dependent);
                field = bos.toByteArray();
            }
        } catch (IOException e) {
            throw new PersistenceException(
                    "Error during serializing dependent object", e);
        }
        return field;
    }
View Full Code Here

                    flags.setUpdatePersist(true);
                }
                flags.setUpdateCache(true);
            }
        } 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);
        }
        return flags;
    }
View Full Code Here

                ObjectOutputStream os = new ObjectOutputStream(bos);
                os.writeObject(dependent);
                newField = bos.toByteArray();
            }
        } catch (IOException e) {
            throw new PersistenceException(
                    "Error during serializing dependent object", e);
        }
        return newField;
    }
View Full Code Here

                _fieldMolder.setValue(object, o, tx.getClassLoader());
            } else {
                _fieldMolder.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);
        }
    }
View Full Code Here

            } else {
                _fieldMolder.setValue(proposedObject.getEntity(), 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);
        }
    }
View Full Code Here

                    }
                } else {
                    // fail-fast principle: if the object depend on another object,
                    // throw exception
                    if (!tx.isDepended(oid, o)) {
                        throw new PersistenceException(
                                "Dependent object may not change its master. Object: " + o
                                + " new master: " + oid);
                    }
                }
            } else if (tx.isAutoStore()) {
View Full Code Here

                    if (fieldValue != null) {
                        ProposedEntity temp = new ProposedEntity(fieldClassMolder);
                        tx.load(fieldValue, temp, null);
                        _fieldMolder.setValue(object, temp.getEntity(), tx.getClassLoader());
                    } else {
                        throw new PersistenceException(
                            "Object, " + object + ", links to another object, " + value
                            + " that is not loaded/updated/created in this transaction");
                    }
                }
            }
View Full Code Here

            }
           
            int fieldIndex = 1;
            // bind the identity of the preparedStatement
            if (identity.size() != ids.length) {
                throw new PersistenceException(
                        "Size of identity field mismatched! expected: " + ids.length
                        + " found: " + identity.size());
            }

            for (int i = 0; i < ids.length; i++) {
                stmt.setObject(fieldIndex++, ids[i].toSQL(identity.get(i)));
            }

            if (LOG.isDebugEnabled()) {
                LOG.debug(Messages.format("jdo.loading", _type, stmt.toString()));
            }

            // execute the SQL query
            rs = stmt.executeQuery();
            if (!rs.next()) {
                throw new ObjectNotFoundException(Messages.format(
                        "persist.objectNotFound", _type, identity));
            }

            // if this class is part of an extend relation (hierarchy), let's investigate
            // what the real class type is vs. the specified one as part of the load statement;
            // this is done by looking at (the id fields of all) the extending class
            // desriptors, and by trying to find a (if not the) potential leaf descriptor;
            // if there's no potential leaf descriptor, let's simply continue; if there's
            // one, set the actual values in the ProposedEntity instance and return
            // to indicate that the load shoul dbe re-tried with the correct ClassMolder
            if (_extendingClassDescriptors.size() > 0) {
                Object[] returnValues =
                    SQLHelper.calculateNumberOfFields(_extendingClassDescriptors,
                            ids.length, fields.length, _numberOfExtendLevels, rs);
                ClassDescriptor potentialLeafDescriptor = (ClassDescriptor) returnValues[0];
               
                if ((potentialLeafDescriptor != null)
                        && !potentialLeafDescriptor.getJavaClass().getName().equals(_type)) {
                   
                    entity.initializeFields(potentialLeafDescriptor.getFields().length);
                    entity.setActualEntityClass(potentialLeafDescriptor.getJavaClass());
                    entity.setExpanded(true);
                }

                // make sure that we only return early (as described above), if we actually
                // found a potential leaf descriptor
                if (potentialLeafDescriptor != null) {
                    return;
                }
            }
           
            // Load all the fields of the object including one-one relations
            // index to use during ResultSet.getXXX(); don't forget to ignore
            // the identity columns
            int columnIndex = ids.length + 1;
           
            Set processedTables = new HashSet();
            if (fields.length > 0 && fields[0].isJoined()) {
                ClassDescriptor clsDesc = _engine.getDescriptor();
                processedTables.add(new ClassDescriptorJDONature(clsDesc).getTableName());
            }
            boolean notNull;
            // index in fields[] for storing result of SQLTypes.getObject()
            fieldIndex = 1;
            String tableName = null;
            for (int i = 0; i < fields.length; ++i) {
                SQLFieldInfo field = fields[i];
                SQLColumnInfo[] columns = field.getColumnInfo();
                tableName = field.getTableName();
                if (i > 0 && !field.isJoined() && !processedTables.contains(tableName)) {
                    columnIndex = columnIndex + ids.length;
                }
                processedTables.add(tableName);
               
                if (!field.isJoined() && (field.getJoinFields() == null)) {
                    entity.setField(columns[0].toJava(SQLTypeInfos.getValue(
                            rs, columnIndex++, columns[0].getSqlType())), i);
                    fieldIndex++;
                } else if (!field.isMulti()) {
                    notNull = false;
                    Object[] id = new Object[columns.length];
                    for (int j = 0; j < columns.length; j++) {
                        id[j] = columns[j].toJava(SQLTypeInfos.getValue(
                                rs, columnIndex++, columns[j].getSqlType()));
                        fieldIndex++;
                        if (id[j] != null) { notNull = true; }
                    }
                    entity.setField(((notNull) ? new Identity(id) : null), i);
                } else {
                    ArrayList res = new ArrayList();
                    notNull = false;
                    Object[] id = new Object[columns.length];
                    for (int j = 0; j < columns.length; j++) {
                        id[j] = columns[j].toJava(SQLTypeInfos.getValue(
                                rs, columnIndex, columns[j].getSqlType()));
                        if (id[j] != null) { notNull = true; }
                        fieldIndex++;
                        columnIndex++;
                    }
                    if (notNull) { res.add(new Identity(id)); }
                    entity.setField(res, i);
                }
            }

            while (rs.next()) {
                fieldIndex = 1;
                columnIndex = ids.length + 1;
                processedTables.clear();
                if (fields[0].isJoined()) {
                    ClassDescriptor clsDesc = _engine.getDescriptor();
                    processedTables.add(new ClassDescriptorJDONature(clsDesc).getTableName());
                }

                for (int i = 0; i < fields.length; ++i) {
                    SQLFieldInfo field = fields[i];
                    SQLColumnInfo[] columns = field.getColumnInfo();
                    tableName = field.getTableName();
                    if (i > 0 && !field.isJoined() && !processedTables.contains(tableName)) {
                        columnIndex = columnIndex + ids.length;
                    }
                    processedTables.add(tableName);
                   
                    if (field.isMulti()) {
                        ArrayList res = (ArrayList) entity.getField(i);
                        notNull = false;
                        Object[] id = new Object[columns.length];
                        for (int j = 0; j < columns.length; j++) {
                            id[j] = columns[j].toJava(SQLTypeInfos.getValue(
                                    rs, columnIndex, columns[j].getSqlType()));
                            if (id[j] != null) { notNull = true; }
                            columnIndex++;
                        }
                        fieldIndex++;
                        if (notNull) {
                            Identity com = new Identity(id);
                            if (!res.contains(com)) { res.add(com); }
                        }
                    } else {
                        fieldIndex++;
                        columnIndex += columns.length;
                    }
                }
            }
        } catch (SQLException except) {
            LOG.fatal(Messages.format("jdo.loadFatal", _type,
                    (accessMode == AccessMode.DbLocked) ? _statementLock : _statementNoLock),
                    except);
            throw new PersistenceException(Messages.format("persist.nested", except), except);
        } finally {
            JDOUtils.closeResultSet(rs);
            JDOUtils.closeStatement(stmt);
        }
    }
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.