Package org.apache.ojb.broker.metadata

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


        pb.getInternalCache().enableMaterializationCache();
        try
        {
            while (i.hasNext())
            {
                CollectionDescriptor cds = (CollectionDescriptor) i.next();
                if (forceProxyCollection){
                    retrieveProxyCollection(newObj, cld, cds, forced);
                } else {
                    retrieveCollection(newObj, cld, cds, forced);
                }
View Full Code Here


     * @param ids Collection containing all identities of objects of the M side
     * @return the prefetch Query
     */
    protected Query buildPrefetchQuery(Collection ids)
    {
        CollectionDescriptor cds = getCollectionDescriptor();
        String[] indFkCols = getFksToThisClass();
        String[] indItemFkCols = getFksToItemClass();
        FieldDescriptor[] itemPkFields = getItemClassDescriptor().getPkFields();

        Criteria crit = buildPrefetchCriteria(ids, indFkCols, indItemFkCols, itemPkFields);

        // BRJ: do not use distinct:
        //
        // ORA-22901 cannot compare nested table or VARRAY or LOB attributes of an object type
        // Cause: Comparison of nested table or VARRAY or LOB attributes of an
        // object type was attempted in the absence of a MAP or ORDER method.
        // Action: Define a MAP or ORDER method for the object type.
        //
        // Without the distinct the resultset may contain duplicate rows

        return new QueryByMtoNCriteria(cds.getItemClass(), cds.getIndirectionTable(), crit, false);
    }
View Full Code Here

        ReportQueryByMtoNCriteria q = new ReportQueryByMtoNCriteria(getItemClassDescriptor().getClassOfObject(), cols,
                crit, false);
        q.setIndirectionTable(getCollectionDescriptor().getIndirectionTable());
        q.setJdbcTypes(jdbcTypes);

        CollectionDescriptor cds = getCollectionDescriptor();
        //check if collection must be ordered
        if (!cds.getOrderBy().isEmpty())
        {
            Iterator iter = cds.getOrderBy().iterator();
            while (iter.hasNext())
            {
                q.addOrderBy((FieldHelper) iter.next());
            }
        }
View Full Code Here

     * This problem is documented in defect OJB296.
     * The conversion of the keys of the mToNImplementor should solve this problem.
     */
    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();
        FieldConversion[] ownerFc = getPkFieldConversion(getOwnerClassDescriptor());
        FieldConversion[] childFc = getPkFieldConversion(getItemClassDescriptor())

View Full Code Here

    }

    private void buildConstraints(ClassDescriptor cd) {
        Vector collectionDescriptors = cd.getCollectionDescriptors();
        for (int i = 0; i < collectionDescriptors.size(); i++) {
            CollectionDescriptor collectionDescriptor = (CollectionDescriptor) collectionDescriptors.get(i);
            if (collectionDescriptor.isMtoNRelation()) {
                buildManyToManyConstraints(cd, collectionDescriptor);
            } else {
                buildOneToManyReferences(cd, collectionDescriptor);
            }
        }
View Full Code Here

            }
        }
        if(cld.getCollectionDescriptors().size() > 0)
        {
            descriptors = cld.getCollectionDescriptors().iterator();
            CollectionDescriptor cod;
            while(descriptors.hasNext())
            {
                cod = (CollectionDescriptor) descriptors.next();
                if(doLink)
                {
                    if(cod.isMtoNRelation())
                    {
                        m_broker.linkMtoN(obj, cod, insert);
                    }
                    else
                    {
View Full Code Here

            }
            match = true;
        }
        else
        {
            CollectionDescriptor cod = cld.getCollectionDescriptorByName(attributeName);
            if(cod != null)
            {
                if(doLink)
                {
                    if(cod.isMtoNRelation())
                    {
                        m_broker.linkMtoN(obj, cod, insert);
                    }
                    else
                    {
View Full Code Here

    {
        Iterator i;
        i = cld.getCollectionDescriptors().iterator();
        while (i.hasNext())
        {
            CollectionDescriptor cds = (CollectionDescriptor) i.next();
            Object col = cds.getPersistentField().get(objectToReorder.getObject());
            if (col != null)
            {
                Iterator colIterator;
                if (ProxyHelper.isCollectionProxy(col) && !ProxyHelper.getCollectionProxy(col).isLoaded())
                {
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 = null;
    Object[] prevKeys = null;
    Object[] keys = null;
    ArrayList descriptors;
    boolean outer = useOuterJoins;
    int pathLength;

    String pathAlias = aUserAlias == null ? null : aUserAlias.getAlias(aPath);
    curr = getTableAliasForPath(aPath, pathAlias);

    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;
      }

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

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

        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);
          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

    {
        Iterator i;
        i = cld.getCollectionDescriptors().iterator();
        while (i.hasNext())
        {
            CollectionDescriptor cds = (CollectionDescriptor) i.next();
            Object col = cds.getPersistentField().get(newTxObject);
            if (col != null)
            {
                CollectionProxy proxy = ProxyHelper.getCollectionProxy(col);
                if (proxy != null)
                {
                    if (!proxy.isLoaded())
                    {
                        if (log.isDebugEnabled()) log.debug("adding self as listener to collection proxy");
                        proxy.addListener(this);
                        continue;
                    }
                }
                Iterator colIterator = BrokerHelper.getCollectionIterator(col);
                // get foreign info for collection elements
                ClassDescriptor itemCld = this.getBroker().getClassDescriptor(cds.getItemClass());
                // BRJ: do not convertToSql
                ValueContainer[] objPkValues = this.getBroker().serviceBrokerHelper().getKeyValues(cld, newTxObject, false);
                FieldDescriptor[] itemFkFields = cds.getForeignKeyFieldDescriptors(itemCld);

                Object item = null;
                try
                {
                    while (colIterator.hasNext())
                    {
                        item = colIterator.next();
                        IndirectionHandler handler = ProxyHelper.getIndirectionHandler(item);
                        if (handler != null)
                        {
                            if (!handler.alreadyMaterialized())
                            {
                                continue;
                            }
                            else
                            {
                                // @todo consider registering to hear when this is
                                // derefernced instead of just loading here -bmc
                                item = handler.getRealSubject();
                            }
                        }
                        if(!cds.isMtoNRelation())
                        {
                            //if itemCld refers to an interface the foreignKeyFieldDescriptors
                            //have to be computed again for each concrete class
                            if (itemCld.isInterface())
                            {
                                ClassDescriptor concreteItemCld = getBroker().getClassDescriptor(item.getClass());
                                itemFkFields = cds.getForeignKeyFieldDescriptors(concreteItemCld);
                            }
                            // provide all items in collection attributes
                            // with foreign key information before locking them!
                            for (int j = 0; j < itemFkFields.length; j++)
                            {
                                FieldDescriptor fld = itemFkFields[j];
                                fld.getPersistentField().set(item, objPkValues[j].getValue());
                            }
                        }
                        lock(item, lockMode);
                    }
                }
                catch (PersistenceBrokerException e)
                {
                    String eol = SystemUtils.LINE_SEPARATOR;
                    log.error("Error while set FK in collection references[" +
                            eol + "current reference descriptor:" +
                            eol + cds.toXML() +
                            eol + "current item object: " + item +
                            eol + "main object class: " + newTxObject.getClass().getName() +
                            eol + "]", e);
                    throw e;
                }
                catch (LockNotGrantedException e)
                {
                    String eol = SystemUtils.LINE_SEPARATOR;
                    log.error("Lock not granted, while set FK in collection references[" +
                            eol + "current reference descriptor:" +
                            eol + cds.toXML() +
                            eol + "object to lock: " + item +
                            eol + "main object class: " + newTxObject.getClass().getName() +
                            eol + "]", e);
                    throw e;
                }
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.