Package org.apache.ojb.broker.metadata.fieldaccess

Examples of org.apache.ojb.broker.metadata.fieldaccess.PersistentField


        {
            ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) it.next();

            if (rds.getOtmDependent())
            {
                PersistentField f = rds.getPersistentField();
                Object relObj = f.get(obj);

                if (relObj != null)
                {
                    countCascadeDeleted +=
                            markDelete(new Identity(relObj, _pb), oid, false);
                }
            }
        }

        for (Iterator it = colDescs.iterator(); it.hasNext(); )
        {
            CollectionDescriptor cds = (CollectionDescriptor) it.next();

            if (cds.getOtmDependent())
            {
                PersistentField f = cds.getPersistentField();
                Class type = f.getType();
                Object col = f.get(obj);

                if (col != null)
                {
                    Iterator colIterator;
View Full Code Here


    private void setFieldValue(Object obj, FieldDescriptor field, Long identifier) throws SequenceManagerException
    {
        Object result = field.getJdbcType().sequenceKeyConversion(identifier);
        result = field.getFieldConversion().sqlToJava(result);
        PersistentField pf = field.getPersistentField();
        pf.set(obj, result);
    }
View Full Code Here

        for (int i = 0; i < fields.length; i++)
        {
            FieldDescriptor fmd = fields[i];
            if (fmd.isUpdateLock())
            {
                PersistentField f = fmd.getPersistentField();
                Object cv = null;
                cv = f.get(obj);

                // int
                if ((f.getType() == int.class) || (f.getType() == Integer.class))
                {
                    int newCv = 0;
                    if (cv != null)
                    {
                        newCv = ((Number) cv).intValue();
                    }
                    newCv++;
                    f.set(obj, new Integer(newCv));
                }
                // long
                else if ((f.getType() == long.class) || (f.getType() == Long.class))
                {
                    long newCv = 0;
                    if (cv != null)
                    {
                        newCv = ((Number) cv).longValue();
                    }
                    newCv++;
                    f.set(obj, new Long(newCv));
                }
                // Timestamp
                else if (f.getType() == Timestamp.class)
                {
                    long newCv = (new Date()).getTime();
                    Timestamp ts = new Timestamp(newCv);
                    ts.setNanos(0);
                    f.set(obj, ts);
                }
            }
        }
    }
View Full Code Here

        Object freshInstance = getDBObject(oid);

        // update all primitive typed attributes
        FieldDescriptor[] fields = cld.getFieldDescriptions();
        FieldDescriptor fmd;
        PersistentField fld;
        for (int i = 0; i < fields.length; i++)
        {
            fmd = fields[i];
            fld = fmd.getPersistentField();
            fld.set(cachedInstance, fld.get(freshInstance));
        }
    }
View Full Code Here

         */
        FieldDescriptor[] fieldDescs = mif.getFieldDescriptions();
        for(int i = 0; i < fieldDescs.length; i++)
        {
            FieldDescriptor fd = fieldDescs[i];
            PersistentField f = fd.getPersistentField();
            fieldValues.put(fd.getColumnName(), f.get(myObj));
        }
        /**
         * MBAIRD
         * 2. register all 1:1 references
         * field changes to 1:1 mapped objects should also be registered in the map,
View Full Code Here

     * @param rds - the ObjectReferenceDescriptor of the reference attribute to be loaded
     * @param forced - if set to true, the reference is loaded even if the rds differs.
     */
    public void retrieveReference(Object obj, ClassDescriptor cld, ObjectReferenceDescriptor rds, boolean forced)
    {
        PersistentField refField;
        Object refObj = null;

        if (forced || rds.getCascadeRetrieve())
        {
            Identity id = getReferencedObjectIdentity(obj, rds, cld);
            boolean isRefObjDefined = true;

            if (id == null)
            {
                refObj = null;
            } //JMM : why not see if the object has already been loaded
            else if ( pb.serviceObjectCache().lookup(id) != null )
            {
                refObj = pb.doGetObjectByIdentity(id);
            }
            else if ((m_retrievalTasks != null)
                    && !rds.isLazy()
                    && (rds.getItemProxyClass() == null))
            {
                addRetrievalTask(obj, rds);
                isRefObjDefined = false;
            }
            else
            {
                refObj = getReferencedObject(id, rds, cld);
            }

            if (isRefObjDefined)
            {
                refField = rds.getPersistentField();
                refField.set(obj, refObj);

                if ((refObj != null) && prefetchProxies
                        && (m_retrievalTasks != null)
                        && (rds.getProxyPrefetchingLimit() > 0))
                {
View Full Code Here

            }
            else
            {
                // this collection type will be used:
                Class collectionClass = cds.getCollectionClass();
                PersistentField collectionField = cds.getPersistentField();
                Query fkQuery = getFKQuery(obj, cld, cds);
                Object value;

                if (collectionClass == null)
                {
                    Collection result = getCollectionByQuery(fkQuery, cds);

                    // assign collection to objects attribute
                    // if attribute has an array type build an array, else assign collection directly
                    if (collectionField.getType().isArray())
                    {
                        int length = result.size();
                        Class itemtype = collectionField.getType().getComponentType();
                        Object resultArray = Array.newInstance(itemtype, length);
                        int j = 0;
                        for (Iterator iter = result.iterator(); iter.hasNext();j++)
                        {
                            Array.set(resultArray, j, iter.next());
                        }
                        collectionField.set(obj, resultArray);
                    }
                    else
                    {
                        collectionField.set(obj, result);
                    }
                    value = result;
                }
                else
                {
                    ManageableCollection result = getCollectionByQuery(collectionClass, fkQuery, cds.isLazy());
                    collectionField.set(obj, result);
                    value = result;
                }

                if (prefetchProxies && (m_retrievalTasks != null)
                        && (cds.getProxyPrefetchingLimit() > 0)
View Full Code Here

            super(owner, retrievalTasks, key, limit);
        }

        protected void addThisListenerTo(Object owner)
        {
            PersistentField collectionField =
                    ((CollectionDescriptor) _key).getPersistentField();
            _listenedCollection = (CollectionProxyDefaultImpl) collectionField.get(owner);
            _listenedCollection.addListener(this);
        }
View Full Code Here

                            anonymous.setPersistentField(null,fieldName);
                        }
                        else
                        {
                            String classname = m_CurrentCLD.getClassNameOfObject();
              PersistentField pf = PersistentFieldFactory.createPersistentField(m_CurrentCLD.getPersistentFieldClassName(),ClassHelper.getClass(classname),fieldName);
                            m_CurrentFLD.setPersistentField(pf);
                        }

                        String columnName = atts.getValue(tags.getTagById(COLUMN_NAME));
                        if (isDebug) logger.debug("     " + tags.getTagById(COLUMN_NAME) + ": " + columnName);
                        m_CurrentFLD.setColumnName(columnName);

                        String jdbcType = atts.getValue(tags.getTagById(JDBC_TYPE));
                        if (isDebug) logger.debug("     " + tags.getTagById(JDBC_TYPE) + ": " + jdbcType);
                        m_CurrentFLD.setColumnType(jdbcType);

                        String primaryKey = atts.getValue(tags.getTagById(PRIMARY_KEY));
                        if (isDebug) logger.debug("     " + tags.getTagById(PRIMARY_KEY) + ": " + primaryKey);
                        boolean b = (Boolean.valueOf(primaryKey)).booleanValue();
                        m_CurrentFLD.setPrimaryKey(b);

                        String nullable = atts.getValue(tags.getTagById(NULLABLE));
                        if (nullable != null)
                        {
                            if (isDebug) logger.debug("     " + tags.getTagById(NULLABLE) + ": " + nullable);
                            b = !(Boolean.valueOf(nullable)).booleanValue();
                            m_CurrentFLD.setRequired(b);
                        }

                        String indexed = atts.getValue(tags.getTagById(INDEXED));
                        if (isDebug) logger.debug("     " + tags.getTagById(INDEXED) + ": " + indexed);
                        b = (Boolean.valueOf(indexed)).booleanValue();
                        m_CurrentFLD.setIndexed(b);

                        String autoincrement = atts.getValue(tags.getTagById(AUTO_INCREMENT));
                        if (isDebug) logger.debug("     " + tags.getTagById(AUTO_INCREMENT) + ": " + autoincrement);
                        b = (Boolean.valueOf(autoincrement)).booleanValue();
                        m_CurrentFLD.setAutoIncrement(b);

                        String sequenceName = atts.getValue(tags.getTagById(SEQUENCE_NAME));
                        if (isDebug) logger.debug("     " + tags.getTagById(SEQUENCE_NAME) + ": " + sequenceName);
                        m_CurrentFLD.setSequenceName(sequenceName);

                        String locking = atts.getValue(tags.getTagById(LOCKING));
                        if (isDebug) logger.debug("     " + tags.getTagById(LOCKING) + ": " + locking);
                        b = (Boolean.valueOf(locking)).booleanValue();
                        m_CurrentFLD.setLocking(b);

                        String updateLock = atts.getValue(tags.getTagById(UPDATE_LOCK));
                        if (isDebug) logger.debug("     " + tags.getTagById(UPDATE_LOCK) + ": " + updateLock);
                        b = (Boolean.valueOf(updateLock)).booleanValue();
                        m_CurrentFLD.setUpdateLock(b);

                        String fieldConversion = atts.getValue(tags.getTagById(FIELD_CONVERSION));
                        if (isDebug) logger.debug("     " + tags.getTagById(FIELD_CONVERSION) + ": " + fieldConversion);
                        if (fieldConversion != null)
                        {
                            m_CurrentFLD.setFieldConversionClassName(fieldConversion);
                        }

                        // set length attribute
                        String length = atts.getValue(tags.getTagById(LENGTH));
                        if (length != null)
                        {
                            int i = Integer.parseInt(length);
                            if (isDebug) logger.debug("     " + tags.getTagById(LENGTH) + ": " + i);
                            m_CurrentFLD.setLength(i);
                            m_CurrentFLD.setLengthSpecified(true);
                        }

                        // set precision attribute
                        String precision = atts.getValue(tags.getTagById(PRECISION));
                        if (precision != null)
                        {
                            int i = Integer.parseInt(precision);
                            if (isDebug) logger.debug("     " + tags.getTagById(PRECISION) + ": " + i);
                            m_CurrentFLD.setPrecision(i);
                            m_CurrentFLD.setPrecisionSpecified(true);
                        }

                        // set scale attribute
                        String scale = atts.getValue(tags.getTagById(SCALE));
                        if (scale != null)
                        {
                            int i = Integer.parseInt(scale);
                            if (isDebug) logger.debug("     " + tags.getTagById(SCALE) + ": " + i);
                            m_CurrentFLD.setScale(i);
                            m_CurrentFLD.setScaleSpecified(true);
                        }

                        break;
                    }

                case REFERENCE_DESCRIPTOR:
                    {
                        if (isDebug) logger.debug("    > " + tags.getTagById(REFERENCE_DESCRIPTOR));
                        // set name attribute
                        name = atts.getValue(tags.getTagById(FIELD_NAME));
                        if (isDebug) logger.debug("     " + tags.getTagById(FIELD_NAME) + ": " + name);

                        // set class-ref attribute
                        String classRef = atts.getValue(tags.getTagById(REFERENCED_CLASS));
                        if (isDebug) logger.debug("     " + tags.getTagById(REFERENCED_CLASS) + ": " + classRef);

                        ObjectReferenceDescriptor ord = null;
                        if (name.equals(TAG_SUPER))
                        {
                            checkThis(classRef);
                            AnonymousObjectReferenceDescriptor aord =
                                new AnonymousObjectReferenceDescriptor(m_CurrentCLD);
                            aord.setPersistentField(null, TAG_SUPER);
                            ord = aord;
                        }
                        else
                        {
                            ord = new ObjectReferenceDescriptor(m_CurrentCLD);
                            PersistentField pf = PersistentFieldFactory.createPersistentField(m_CurrentCLD.getPersistentFieldClassName(),m_CurrentCLD.getClassOfObject(),name);
                            ord.setPersistentField(pf);
                        }
                        m_CurrentORD = ord;

                        // now we add the new descriptor
                        m_CurrentCLD.addObjectReferenceDescriptor(m_CurrentORD);
                        m_CurrentORD.setItemClass(ClassHelper.getClass(classRef));

                        // prepare for custom attributes
                        this.m_CurrentAttrContainer = m_CurrentORD;

                        // set proxy attribute
                        String proxy = atts.getValue(tags.getTagById(PROXY_REFERENCE));
                        if (isDebug) logger.debug("     " + tags.getTagById(PROXY_REFERENCE) + ": " + proxy);
                        boolean b = (Boolean.valueOf(proxy)).booleanValue();
                        m_CurrentORD.setLazy(b);

                        // set proxyPrefetchingLimit attribute
                        String proxyPrefetchingLimit = atts.getValue(tags.getTagById(PROXY_PREFETCHING_LIMIT));
                        if (isDebug) logger.debug("     " + tags.getTagById(PROXY_PREFETCHING_LIMIT) + ": " + proxyPrefetchingLimit);
                        if (proxyPrefetchingLimit == null)
                        {
                            m_CurrentORD.setProxyPrefetchingLimit(defProxyPrefetchingLimit);
                        }
                        else
                        {
                            m_CurrentORD.setProxyPrefetchingLimit(Integer.parseInt(proxyPrefetchingLimit));
                        }

                        // set refresh attribute
                        String refresh = atts.getValue(tags.getTagById(REFRESH));
                        if (isDebug) logger.debug("     " + tags.getTagById(REFRESH) + ": " + refresh);
                        b = (Boolean.valueOf(refresh)).booleanValue();
                        m_CurrentORD.setRefresh(b);

                        // set auto-retrieve attribute
                        String autoRetrieve = atts.getValue(tags.getTagById(AUTO_RETRIEVE));
                        if (isDebug) logger.debug("     " + tags.getTagById(AUTO_RETRIEVE) + ": " + autoRetrieve);
                        b = (Boolean.valueOf(autoRetrieve)).booleanValue();
                        m_CurrentORD.setCascadeRetrieve(b);

                        // set auto-update attribute
                        String autoUpdate = atts.getValue(tags.getTagById(AUTO_UPDATE));
                        if (isDebug) logger.debug("     " + tags.getTagById(AUTO_UPDATE) + ": " + autoUpdate);
                        if(autoUpdate != null)
                        {
                            m_CurrentORD.setCascadingStore(autoUpdate);
                        }

                        //set auto-delete attribute
                        String autoDelete = atts.getValue(tags.getTagById(AUTO_DELETE));
                        if (isDebug) logger.debug("     " + tags.getTagById(AUTO_DELETE) + ": " + autoDelete);

                        if(autoDelete != null)
                        {
                            m_CurrentORD.setCascadingDelete(autoDelete);
                        }

                        //set otm-dependent attribute
                        String otmDependent = atts.getValue(tags.getTagById(OTM_DEPENDENT));
                        if (isDebug) logger.debug("     " + tags.getTagById(OTM_DEPENDENT) + ": " + otmDependent);
                        b = (Boolean.valueOf(otmDependent)).booleanValue();
                        m_CurrentORD.setOtmDependent(b);

                        break;
                    }

                case FOREIGN_KEY:
                    {
                        if (isDebug) logger.debug("    > " + tags.getTagById(FOREIGN_KEY));
                        String fieldIdRef = atts.getValue(tags.getTagById(FIELD_ID_REF));

                        if (fieldIdRef != null)
                        {
                            if (isDebug) logger.debug("      " + tags.getTagById(FIELD_ID_REF) + ": " + fieldIdRef);

                            try
                            {
                                int fieldId;
                                fieldId = Integer.parseInt(fieldIdRef);
                                m_CurrentORD.addForeignKeyField(fieldId);
                            }
                            catch (NumberFormatException rex)
                            {
                                throw new MetadataException(tags.getTagById(FIELD_ID_REF)
                                        + " attribute must be an int. Found: "
                                        + fieldIdRef + ". Please check your repository file.", rex);
                            }
                        }
                        else
                        {
                            String fieldRef = atts.getValue(tags.getTagById(FIELD_REF));
                            if (isDebug) logger.debug("      " + tags.getTagById(FIELD_REF) + ": " + fieldRef);
                            m_CurrentORD.addForeignKeyField(fieldRef);
                        }
                        break;
                    }

                case COLLECTION_DESCRIPTOR:
                    {
                        if (isDebug) logger.debug("    > " + tags.getTagById(COLLECTION_DESCRIPTOR));
                        m_CurrentCOD = new CollectionDescriptor(m_CurrentCLD);


                        // prepare for custom attributes
                        this.m_CurrentAttrContainer = m_CurrentCOD;

                        // set name attribute
                        name = atts.getValue(tags.getTagById(FIELD_NAME));
                        if (isDebug) logger.debug("     " + tags.getTagById(FIELD_NAME) + ": " + name);
            PersistentField pf = PersistentFieldFactory.createPersistentField(m_CurrentCLD.getPersistentFieldClassName(),m_CurrentCLD.getClassOfObject(),name);
                        m_CurrentCOD.setPersistentField(pf);

                        // set collection-class attribute
                        String collectionClassName = atts.getValue(tags.getTagById(COLLECTION_CLASS));
                        if (collectionClassName != null)
View Full Code Here

    ClassDescriptor cld = descriptorRepository.getDescriptorFor(obj.getClass());
    for (Iterator i = cld.getObjectReferenceDescriptors().iterator(); i.hasNext(); )
    {
      ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) i.next();
      Object refObj = getReferenceProxy(cld, rds, obj);
      PersistentField refField = rds.getPersistentField();
      if (logger.isDebugEnabled())
        logger.debug("setting reference: " + refField.getName() + ", " + (refObj == null ? ("<null>") : refObj.getClass().getName()));
      refField.set(obj, refObj);
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.ojb.broker.metadata.fieldaccess.PersistentField

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.