Package org.exolab.castor.persist.spi

Examples of org.exolab.castor.persist.spi.Identity


                        if (value == null) {
                            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());
                            }
                        } 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!");
View Full Code Here


                    if (value == null) {
                        for (int j = columns.length - 1; j >= 0; j--) {
                            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!");
                        }
View Full Code Here

                    + 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!");
        }
View Full Code Here

     */
    public void delete(final TransactionContext tx, final OID oid) throws PersistenceException {

        resetResolvers();

        Identity ids = oid.getIdentity();

        for (int i = 0; i < _fhs.length; i++) {
            if (_fhs[i].isManyToMany()) {
                _fhs[i].getRelationLoader().deleteRelation(
                        tx.getConnection(oid.getMolder().getLockEngine()), ids);
View Full Code Here

        Object[] ids = new Object[_ids.length];
        for (int i = 0; i < ids.length; i++) {
            ids[i] = _ids[i].getValue(o, loader);
        }
        if (ids[0] == null) { return null; }
        return new Identity(ids);
    }
View Full Code Here

                typeArray[3] = LazyAddress.class;
                typeArray[4] = LazyEmployee.class;
                cacheManager.expireCache(typeArray);
            } else {
                Object[] identityArray = new Object[1];
                identityArray[0] = new Identity("First", "Person");
                cacheManager.expireCache(LazyEmployee.class, identityArray);
            }
        } catch (Exception e) {
            LOG.error("expireCache: exception encountered clearing cache", e);
        }
View Full Code Here

        boolean valid = true;
        try {
            db = _category.getDatabase();
            db.begin();
           
            Identity fullname = new Identity("First", "Person");
            LazyEmployee person;
           
            person = (LazyEmployee) db.load(LazyEmployee.class, fullname);
            if (person.getBirthday().compareTo(JDBC_UPDATED_DATE) != 0) {
                LOG.debug("validReadTransaction: birthdate for "
View Full Code Here

        Database db = null;
        try {
            db = _category.getDatabase();
            db.begin();
           
            Identity fullname = new Identity("First", "Person");
            LazyEmployee person;
           
            person = (LazyEmployee) db.load(LazyEmployee.class, fullname);
            person.setBirthday(JDO_UPDATED_DATE);
            Iterator itor = person.getAddress().iterator();
View Full Code Here

                if (paramClass.isAssignableFrom(valueClass)) {
                    LockEngine lockEngine = ((AbstractDatabaseImpl) _database).getLockEngine();
                    ClassMolder molder = lockEngine.getClassMolder(valueClass);

                    if (molder != null) {
                        Identity temp = molder.getActualIdentity(
                                _database.getClassLoader(), internalValue);
                        if (temp == null) {
                            internalValue = null;
                        } else  if (temp.size() == 1) {
                            internalValue = temp.get(0);
                        } else {
                            throw new IllegalArgumentException(
                                    "Unable to bind multi column identities");
                        }
                    }
View Full Code Here

        }

        LockEngine engine = molder.getLockEngine();
       
        // Make sure the object has not beed persisted in this transaction.
        Identity identity = molder.getIdentity(this, object);

        // if autoStore is specified, we relieve user life a little bit here
        // so that if an object create automatically and user create it
        // again, it won't receive exception
        if (_autoStore && _tracker.isTracking(object)) {
View Full Code Here

TOP

Related Classes of org.exolab.castor.persist.spi.Identity

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.