Package org.apache.ojb.broker.metadata

Examples of org.apache.ojb.broker.metadata.CollectionDescriptor


     *
     * @param ids Collection containing all identities of objects of the ONE side
     */
    protected Query buildPrefetchQuery(Collection ids)
    {
        CollectionDescriptor cds = getCollectionDescriptor();
        QueryByCriteria query = buildPrefetchQuery(ids, cds.getForeignKeyFieldDescriptors(getItemClassDescriptor()));

        // check if collection must be ordered
        if (!cds.getOrderBy().isEmpty())
        {
            Iterator iter = cds.getOrderBy().iterator();
            while (iter.hasNext())
            {
                query.addOrderBy((FieldHelper) iter.next());
            }
        }
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);
View Full Code Here

    {
        if(left == null || right == null)
        {
            throw new IllegalArgumentException("both objects must exist");
        }
        CollectionDescriptor cod = pb.getClassDescriptor(ProxyHelper.getRealClass(left)).getCollectionDescriptorByName(leftFieldName);
        init(cod, left, right);
    }
View Full Code Here

        // get all members of obj that are collections and delete all their elements
        Iterator i = listCds.iterator();

        while (i.hasNext())
        {
            CollectionDescriptor cds = (CollectionDescriptor) i.next();
            if(cds.getCascadingDelete() != ObjectReferenceDescriptor.CASCADE_NONE)
            {
                if(cds.isMtoNRelation())
                {
                    // if this is a m:n mapped table, remove entries from indirection table
                    mtoNBroker.deleteMtoNImplementor(cds, obj);
                }
                /*
                if cascading delete is on, delete all referenced objects.
                NOTE: User has to take care to populate all referenced objects before delete
                the main object to avoid referential constraint violation
                 */
                if (cds.getCascadingDelete() == ObjectReferenceDescriptor.CASCADE_OBJECT)
                {
                    Object col = cds.getPersistentField().get(obj);
                    if (col != null)
                    {
                        Iterator colIterator = BrokerHelper.getCollectionIterator(col);
                        while (colIterator.hasNext())
                        {
View Full Code Here

            return;
        }
        Iterator i = listCods.iterator();
        while (i.hasNext())
        {
            CollectionDescriptor cod = (CollectionDescriptor) i.next();

            // if CASCADE_NONE was set, do nothing with referenced objects
            if (cod.getCascadingStore() != ObjectReferenceDescriptor.CASCADE_NONE)
            {
                Object referencedObjects = cod.getPersistentField().get(obj);
                if (cod.isMtoNRelation())
                {
                    storeAndLinkMtoN(false, obj, cod, referencedObjects, insert);
                }
                else
                {
                    storeAndLinkOneToMany(false, obj, cod, referencedObjects, insert);
                }

                // BRJ: only when auto-update = object (CASCADE_OBJECT)
                //
                if ((cod.getCascadingStore() == ObjectReferenceDescriptor.CASCADE_OBJECT)
                        && (referencedObjects instanceof ManageableCollection))
                {
                    ((ManageableCollection) referencedObjects).afterStore(this);
                }
            }
View Full Code Here

        {
          logger.debug("Retrieving reference named ["+pAttributeName+"] on object of type ["+
                      pInstance.getClass().getName()+"]");
        }
        ClassDescriptor cld = getClassDescriptor(pInstance.getClass());
        CollectionDescriptor cod = cld.getCollectionDescriptorByName(pAttributeName);
        getInternalCache().enableMaterializationCache();
        // to avoid problems with circular references, locally cache the current object instance
        Identity oid = serviceIdentity().buildIdentity(pInstance);
        boolean needLocalRemove = false;
        if(getInternalCache().doLocalLookup(oid) == null)
View Full Code Here

     * @param cld The {@link org.apache.ojb.broker.metadata.ClassDescriptor} of the object.
     */
    public void checkRefreshRelationships(Object obj, Identity oid, ClassDescriptor cld)
    {
        Iterator iter;
        CollectionDescriptor cds;
        ObjectReferenceDescriptor rds;
        // to avoid problems with circular references, locally cache the current object instance
        Object tmp = getInternalCache().doLocalLookup(oid);
        if(tmp != null && getInternalCache().isEnabledMaterialisationCache())
        {
            /*
            arminw: This should fix OJB-29, infinite loops on bidirectional 1:1 relations with
            refresh attribute 'true' for both references. OJB now assume that the object is already
            refreshed when it's cached in the materialisation cache
            */
            return;
        }
        try
        {
            getInternalCache().enableMaterializationCache();
            if(tmp == null)
            {
                getInternalCache().doInternalCache(oid, obj, MaterializationCache.TYPE_TEMP);
            }
            if(logger.isDebugEnabled()) logger.debug("Refresh relationships for " + oid);
            iter = cld.getCollectionDescriptors().iterator();
            while (iter.hasNext())
            {
                cds = (CollectionDescriptor) iter.next();
                if (cds.isRefresh())
                {
                    referencesBroker.retrieveCollection(obj, cld, cds, false);
                }
            }
            iter = cld.getObjectReferenceDescriptors().iterator();
View Full Code Here

        //so let's look for collection descriptors on the left class and try to
        // handle extents on teh right class
        ClassDescriptor leftCld = dr.getDescriptorFor(leftClass);
        ClassDescriptor rightCld = dr.getDescriptorFor(rightClass);
        //Vector leftColds = leftCld.getCollectionDescriptors();
        CollectionDescriptor wanted = m2nImpl.getLeftDescriptor();

        if(leftObject == null || rightObject == null)
        {
            //TODO: to be implemented, must change MtoNImplementor
            //deleteMtoNImplementor(wanted,leftObject) || deleteMtoNImplementor(wanted,rightObject)
            log.error("Can't handle MtoNImplementor in correct way, found a 'null' object");
        }
        else
        {
            //delete only one row
            ValueContainer[] leftPkValues = pb.serviceBrokerHelper().getKeyValues(leftCld, leftObject);
            ValueContainer[] rightPkValues = pb.serviceBrokerHelper().getKeyValues(rightCld, rightObject);
            String[] pkLeftColumns = wanted.getFksToThisClass();
            String[] pkRightColumns = wanted.getFksToItemClass();
            String table = wanted.getIndirectionTable();
            if(table == null) throw new PersistenceBrokerException("Can't remove MtoN implementor without an indirection table");

            String stmt;
            String[] cols = mergeColumns(pkLeftColumns, pkRightColumns);
            ValueContainer[] values = mergeContainer(leftPkValues, rightPkValues);
View Full Code Here

     */
    public RelationshipPrefetcher createRelationshipPrefetcher(ObjectReferenceDescriptor ord)
    {
        if (ord instanceof CollectionDescriptor)
        {
            CollectionDescriptor cds = (CollectionDescriptor)ord;
            if (cds.isMtoNRelation())
            {
                return new MtoNCollectionPrefetcher(broker, cds);
            }
            else
            {
View Full Code Here

  private TableAlias getTableAlias(String aPath, boolean useOuterJoins, UserAlias aUserAlias, String[] fieldRef, Map pathClasses)
  {
        TableAlias curr, prev, indirect;
        String attr, attrPath = null;
        ObjectReferenceDescriptor ord;
        CollectionDescriptor cod;
        ClassDescriptor cld;
        Object[] prevKeys;
        Object[] keys;
        ArrayList descriptors;
        boolean outer = useOuterJoins;
        int pathLength;
        List hintClasses = null;      
        String pathAlias = aUserAlias == null ? null : aUserAlias.getAlias(aPath);
       
        if (pathClasses != null)
        {
            hintClasses = (List) pathClasses.get(aPath);
        }   
       
        curr = getTableAliasForPath(aPath, pathAlias, hintClasses);
        if (curr != null)
        {
            return curr;
        }

    descriptors = getRoot().cld.getAttributeDescriptorsForPath(aPath, pathClasses);
    prev = getRoot();

    if (descriptors == null || descriptors.size() == 0)
    {
      if (prev.hasJoins())
      {
        for (Iterator itr = prev.iterateJoins(); itr.hasNext();)
        {
          prev = ((Join) itr.next()).left;
          descriptors = prev.cld.getAttributeDescriptorsForPath(aPath, pathClasses);
          if (descriptors.size() > 0)
          {
            break;
          }
        }
      }
    }

    pathLength = descriptors.size();
    for (int i = 0; i < pathLength; i++)
    {
      if (!(descriptors.get(i) instanceof ObjectReferenceDescriptor))
      {
        // only use Collection- and ObjectReferenceDescriptor
        continue;
      }

      ord = (ObjectReferenceDescriptor) descriptors.get(i);
      attr = ord.getAttributeName();
      if (attrPath == null)
      {
        attrPath = attr;
      }
      else
      {
        attrPath = attrPath + "." + attr;
      }

            // use clas hints for path
            if (pathClasses != null)
            {
                hintClasses = (List) pathClasses.get(attrPath);    
            }   

      // look for outer join hint
      outer = outer || getQuery().isPathOuterJoin(attrPath);

      // look for 1:n or m:n
      if (ord instanceof CollectionDescriptor)
      {
        cod = (CollectionDescriptor) ord;
        cld = getItemClassDescriptor(cod, hintClasses);

        if (!cod.isMtoNRelation())
        {
          prevKeys = prev.cld.getPkFields();
          keys = cod.getForeignKeyFieldDescriptors(cld);
        }
        else
        {
          String mnAttrPath = attrPath + "*";
          String mnUserAlias = (aUserAlias == null ? null : aUserAlias + "*");
          indirect = getTableAliasForPath(mnAttrPath, mnUserAlias, null);
          if (indirect == null)
          {
            indirect = createTableAlias(cod.getIndirectionTable(), mnAttrPath, mnUserAlias);

            // we need two Joins for m:n
            // 1.) prev class to indirectionTable
            prevKeys = prev.cld.getPkFields();
            keys = cod.getFksToThisClass();
            addJoin(prev, prevKeys, indirect, keys, outer, attr + "*");
          }
          // 2.) indirectionTable to the current Class
          prev = indirect;
          prevKeys = cod.getFksToItemClass();
          keys = cld.getPkFields();
        }
      }
      else
      {
View Full Code Here

TOP

Related Classes of org.apache.ojb.broker.metadata.CollectionDescriptor

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.