Examples of PersistentField


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

     * associate the batched Children with their owner object loop over children
     */
    protected void associateBatched(Collection owners, Collection children)
    {
        CollectionDescriptor cds = getCollectionDescriptor();
        PersistentField field = cds.getPersistentField();
        PersistenceBroker pb = getBroker();
        Class ownerTopLevelClass = pb.getTopLevelClass(getOwnerClassDescriptor().getClassOfObject());
        Class collectionClass = cds.getCollectionClass(); // this collection type will be used:
        HashMap ownerIdsToLists = new HashMap(owners.size());

        IdentityFactory identityFactory = pb.serviceIdentity();
        // initialize the owner list map
        for (Iterator it = owners.iterator(); it.hasNext();)
        {
            Object owner = it.next();
            ownerIdsToLists.put(identityFactory.buildIdentity(getOwnerClassDescriptor(), owner), new ArrayList());
        }

        // build the children lists for the owners
        for (Iterator it = children.iterator(); it.hasNext();)
        {
            Object child = it.next();
            // BRJ: use cld for real class, relatedObject could be Proxy
            ClassDescriptor cld = getDescriptorRepository().getDescriptorFor(ProxyHelper.getRealClass(child));

            Object[] fkValues = cds.getForeignKeyValues(child, cld);
            Identity ownerId = identityFactory.buildIdentity(null, ownerTopLevelClass, fkValues);
            List list = (List) ownerIdsToLists.get(ownerId);
            if (list != null)
            {
                list.add(child);
            }
        }

        // connect children list to owners
        for (Iterator it = owners.iterator(); it.hasNext();)
        {
            Object result;
            Object owner = it.next();
            Identity ownerId = identityFactory.buildIdentity(owner);
            List list = (List) ownerIdsToLists.get(ownerId);

            if ((collectionClass == null) && field.getType().isArray())
            {
                int length = list.size();
                Class itemtype = field.getType().getComponentType();
                result = Array.newInstance(itemtype, length);
                for (int j = 0; j < length; j++)
                {
                    Array.set(result, j, list.get(j));
                }
            }
            else
            {
                ManageableCollection col = createCollection(cds, collectionClass);
                for (Iterator it2 = list.iterator(); it2.hasNext();)
                {
                    col.ojbAdd(it2.next());
                }
                result = col;
            }

            Object value = field.get(owner);
            if ((value instanceof CollectionProxyDefaultImpl) && (result instanceof Collection))
            {
                ((CollectionProxyDefaultImpl) value).setData((Collection) result);
            }
            else
            {
                field.set(owner, result);
            }
        }
    }
View Full Code Here

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

    {
        FieldDescriptor fields[] = cld.getLockingFields();

        for (int i=0; i<fields.length; i++)
        {
            PersistentField field = fields[i].getPersistentField();
            Object lockVal = oldLockingValues[i].getValue();

            field.set(obj, lockVal);
        }
    }
View Full Code Here

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

        Object freshInstance = getPlainDBObject(cld, 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

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

        DynaClass dynaClass = createDynaClass();
        DynaBean bean = dynaClass.newInstance();
        bean.set("name", "testDynaBean");

        PersistentField pf = new PersistentFieldDynaBeanImpl(String.class, "name");
        String result = (String) pf.get(bean);
        assertNotNull(result);
        assertEquals("testDynaBean", result);

        pf.set(bean, "XXXX");
        result = (String) pf.get(bean);
        assertNotNull(result);
        assertEquals("XXXX", result);
    }
View Full Code Here

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

    {
        DynaClass dynaClass = createDynaClass();
        DynaBean bean = dynaClass.newInstance();
        bean.set("name", "testDynaBean");

        PersistentField pf = new PersistentFieldAutoProxyImpl(String.class, "name");
        String result = (String) pf.get(bean);
        assertNotNull(result);
        assertEquals("testDynaBean", result);

        pf.set(bean, "XXXX");
        result = (String) pf.get(bean);
        assertNotNull(result);
        assertEquals("XXXX", result);
    }
View Full Code Here

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

        System.out.println("Field performance, set/get " + numberOfOperations + " times a field");
        System.out.println("----------------------------------------");
        for (int i = 0; i < persistentFieldClasses.length; i++)
        {
            Class persistentFieldClass = persistentFieldClasses[i];
            PersistentField p = newInstance(persistentFieldClass, testClass, fieldName);
            buildTestFor(p, false);
        }
        System.out.println("----------------------------------------");
        for (int i = 0; i < persistentFieldClasses.length; i++)
        {
            Class persistentFieldClass = persistentFieldClasses[i];
            PersistentField p = newInstance(persistentFieldClass, testClass, fieldName);
            buildTestFor(p, false);
        }
        System.out.println("----------------------------------------");
    }
View Full Code Here

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

        System.out.println("Nested Field performance, set/get " + numberOfOperations + " times a nested field");
        System.out.println("----------------------------------------");
        for (int i = 0; i < persistentFieldClasses.length; i++)
        {
            Class persistentFieldClass = persistentFieldClasses[i];
            PersistentField p = newInstance(persistentFieldClass, testClass, fieldNameNested);
            buildTestFor(p, true);
        }
        System.out.println("----------------------------------------");
        for (int i = 0; i < persistentFieldClasses.length; i++)
        {
            Class persistentFieldClass = persistentFieldClasses[i];
            PersistentField p = newInstance(persistentFieldClass, testClass, fieldNameNested);
            buildTestFor(p, true);
        }
        System.out.println("----------------------------------------");
    }
View Full Code Here

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

     * @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())
        {
            pb.getInternalCache().enableMaterializationCache();
            try
            {
                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);
                    if (rds.isSuperReferenceDescriptor())
                    {
                        // walk the super-references
                        ClassDescriptor superCld = cld.getRepository().getDescriptorFor(rds.getItemClass());
                        retrieveReferences(refObj, superCld, false);
                        retrieveCollections(refObj, superCld, false);                       
                    }
                }
                else if ((m_retrievalTasks != null)
                        && !rds.isLazy()
                        && (rds.getItemProxyClass() == null))
                {
                    addRetrievalTask(obj, rds);
                    isRefObjDefined = false;
                }
                else
                {
                    refObj = getReferencedObject(id, rds);
                }

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

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

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

     * @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 retrieveProxyReference(Object obj, ClassDescriptor cld, ObjectReferenceDescriptor rds, boolean forced)
    {
        PersistentField refField;
        Object refObj = null;

            pb.getInternalCache().enableMaterializationCache();
            try
            {
                Identity id = getReferencedObjectIdentity(obj, rds, cld);
                if (id != null){
                    refObj = pb.createProxy(rds.getItemClass(), id);
                }
                refField = rds.getPersistentField();
                refField.set(obj, refObj);

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

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

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

                pb.getInternalCache().enableMaterializationCache();
                try
                {
                    if (collectionClass == null)
                    {
                        Collection result = (Collection)getCollectionByQuery(getCollectionTypeClass(cds), fkQuery, lazyLoad);

                        // 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, lazyLoad);
                        collectionField.set(obj, result);
                        value = result;
                    }

                    if (prefetchProxies && (m_retrievalTasks != null)
                            && (cds.getProxyPrefetchingLimit() > 0)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.