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

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


      logger.debug("unsetting references");
    ClassDescriptor cld = descriptorRepository.getDescriptorFor(cacheObj.getClass());
    for (Iterator i = cld.getObjectReferenceDescriptors().iterator(); i.hasNext(); )
    {
      ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) i.next();
      PersistentField refField = rds.getPersistentField();
      if (logger.isDebugEnabled())
        logger.debug("unsetting reference: " + refField.getName());
      refField.set(cacheObj, null);
    }

    for (Iterator i = cld.getCollectionDescriptors().iterator(); i.hasNext(); )
    {
      CollectionDescriptor colDesc = (CollectionDescriptor) i.next();
View Full Code Here


   * @param cacheObj the copy of the object in the cache
   * @param origObject the copy of the object in the scope of some PersistenceBroker
   */
  protected void initCacheCollectionField(CollectionDescriptor colDesc, Object cacheObj, Object origObject)
  {
    PersistentField refField = colDesc.getPersistentField();
    refField.set(cacheObj, null);
  }
View Full Code Here

     * @return the autoincremented value set on given object
     * @throws PersistenceBrokerException if there is an erros accessing obj field values
     */
    private Object setAutoIncrementValue(FieldDescriptor fd, Object obj, Object cv)
    {
        PersistentField f = fd.getPersistentField();
        try
        {
            // lookup SeqMan for a value matching db column an
            Object result = m_broker.serviceSequenceManager().getUniqueValue(fd);
            // reflect autoincrement value back into object
            f.set(obj, result);
            return result;
        }
        catch(MetadataException e)
        {
            throw new PersistenceBrokerException(
                    "Error while trying to autoincrement field " + f.getDeclaringClass() + "#" + f.getName(),
                    e);
        }
        catch(SequenceManagerException e)
        {
            throw new PersistenceBrokerException("Could not get key value", e);
View Full Code Here

     * Integer[] {10,20,30} is not equal Long[] {10,20,30}
     */
    protected void associateBatched(Collection owners, Collection children, Collection mToNImplementors)
    {
        CollectionDescriptor cds = getCollectionDescriptor();
        PersistentField field = cds.getPersistentField();
        PersistenceBroker pb = getBroker();
        Class ownerTopLevelClass = pb.getTopLevelClass(getOwnerClassDescriptor().getClassOfObject());
        Class childTopLevelClass = pb.getTopLevelClass(getItemClassDescriptor().getClassOfObject());
        Class collectionClass = cds.getCollectionClass(); // this collection type will be used:
        HashMap childMap = new HashMap();
        HashMap ownerIdsToLists = new HashMap();

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

        // build the children map
        for (Iterator it = children.iterator(); it.hasNext();)
        {
            Object child = it.next();
            childMap.put(new Identity(child, pb), child);
        }

        int ownerPkLen = getOwnerClassDescriptor().getPkFields().length;
        int childPkLen = getItemClassDescriptor().getPkFields().length;
        Object[] ownerPk = new Object[ownerPkLen];
        Object[] childPk = new Object[childPkLen];

        // build list of children based on m:n implementors
        for (Iterator it = mToNImplementors.iterator(); it.hasNext();)
        {
            Object[] mToN = (Object[]) it.next();
            System.arraycopy(mToN, 0, ownerPk, 0, ownerPkLen);
            System.arraycopy(mToN, ownerPkLen, childPk, 0, childPkLen);

            Identity ownerId = new Identity(null, ownerTopLevelClass, ownerPk);
            Identity childId = new Identity(null, childTopLevelClass, childPk);

            // Identities may not be equal due to type-mismatch
            Collection list = (Collection) ownerIdsToLists.get(ownerId);
            Object child = childMap.get(childId);
            list.add(child);
        }

        // connect children list to owners
        for (Iterator it = owners.iterator(); it.hasNext();)
        {
            Object result;
            Object owner = it.next();
            Identity ownerId = new Identity(owner, pb);

            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(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

    {
        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

     * @return the autoincremented value set on given object
     * @throws PersistenceBrokerException if there is an erros accessing obj field values
     */
    private Object setAutoIncrementValue(FieldDescriptor fd, Object obj)
    {
        PersistentField f = fd.getPersistentField();
        try
        {
            // lookup SeqMan for a value matching db column an
            Object result = m_broker.serviceSequenceManager().getUniqueValue(fd);
            // reflect autoincrement value back into object
            f.set(obj, result);
            return result;
        }
        catch(MetadataException e)
        {
            throw new PersistenceBrokerException(
                    "Error while trying to autoincrement field " + f.getDeclaringClass() + "#" + f.getName(),
                    e);
        }
        catch(SequenceManagerException e)
        {
            throw new PersistenceBrokerException("Could not get key value", e);
View Full Code Here

     * 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(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

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.