Package org.apache.ojb.broker.metadata

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



    private void buildOneToOneConstraints(ClassDescriptor classDescriptor) {
        Vector referenceDescriptors = classDescriptor.getObjectReferenceDescriptors();
        for (int i = 0; i < referenceDescriptors.size(); i++) {
            ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) referenceDescriptors.get(i);

            Vector foreignKeyIndices = ord.getForeignKeyFields();
            ClassDescriptor foreignClassDescriptor = this.repository.getDescriptorFor(ord.getItemClass());
            buildForeignKey(foreignClassDescriptor, foreignKeyIndices, classDescriptor);
        }
    }
View Full Code Here


        if (aTableAlias != null)
        {
            fld = aTableAlias.cld.getFieldDescriptorByName(colName);
            if (fld == null)
            {
                ObjectReferenceDescriptor ord = aTableAlias.cld.getObjectReferenceDescriptorByName(colName);
                if (ord != null)
                {
                    fld = getFldFromReference(aTableAlias, ord);
                }
                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 = 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
      {
        // must be n:1 or 1:1
        cld = getItemClassDescriptor(ord, attrPath, pathClasses);

          // BRJ : if ord is taken from 'super' we have to change prev accordingly
        if (!prev.cld.equals(ord.getClassDescriptor()))
        {
            prev = getTableAliasForClassDescriptor(ord.getClassDescriptor());
       

        prevKeys = ord.getForeignKeyFieldDescriptors(prev.cld);
        keys = cld.getPkFields();

        // [olegnitz]
        // a special case: the last element of the path is
        // reference and the field is one of PK fields =>
View Full Code Here

    protected void buildSuperJoinTree(TableAlias left, ClassDescriptor cld, String name)
    {
        Iterator objRefs = cld.getObjectReferenceDescriptors().iterator();
        while (objRefs.hasNext())
        {
            ObjectReferenceDescriptor objRef = (ObjectReferenceDescriptor) objRefs.next();
            FieldDescriptor[] leftFields = objRef.getForeignKeyFieldDescriptors(cld);

            ClassDescriptor refCld = cld.getRepository().getDescriptorFor(objRef.getItemClassName());
            if (objRef.getPersistentField() instanceof AnonymousPersistentFieldForInheritance)
            {
                TableAlias base_alias = getTableAliasForPath(name, null);

                String aliasName = String.valueOf(getAliasChar()) + m_aliasCount++;
                TableAlias right = new TableAlias(refCld, aliasName, false, null);
View Full Code Here

    public void testShallowAndDeepRetrieval() throws Exception
    {
        String name = "testShallowAndDeepRetrieval_" + System.currentTimeMillis();

        ObjectReferenceDescriptor ord = null;

        try
        {
            // prepare test, create article with ProductGroup
            Article tmpArticle = createArticle(name);
            ProductGroup pg = createProductGroup(name);
            tmpArticle.setProductGroup(pg);
            pg.add(tmpArticle);

            broker.beginTransaction();
            // in repository Article 1:1 refererence to PG hasn't enabled auto-update,
            // so first store the PG. PG has enabled auto-update and will store the
            // article automatic
            broker.store(pg);
            broker.commitTransaction();
            // after insert we can build the Article identity
            Identity tmpOID = broker.serviceIdentity().buildIdentity(tmpArticle);
            broker.clearCache();

            // switch to shallow retrieval
            ClassDescriptor cld = broker.getClassDescriptor(Article.class);
            ord = (ObjectReferenceDescriptor) cld.getObjectReferenceDescriptorByName("productGroup");
            ord.setCascadeRetrieve(false);

            Article article = (Article) broker.getObjectByIdentity(tmpOID);
            assertNull("now reference should be null", article.getProductGroup());

            // now switch to deep retrieval
            ord.setCascadeRetrieve(true);
            // should work without setting cld
            // broker.setClassDescriptor(cld);
            broker.clearCache();
            article = (Article) broker.getObjectByIdentity(tmpOID);
            assertNotNull("now reference should NOT be null", article.getProductGroup());
        }
        finally
        {
            // restore old value
            if(ord != null) ord.setCascadeRetrieve(true);
        }
    }
View Full Code Here

        broker.store(tmpArticle);
        broker.commitTransaction();
        Identity tmpOID = broker.serviceIdentity().buildIdentity(tmpArticle);
        broker.clearCache();

        ObjectReferenceDescriptor ord = null;
        try
        {
            // switch to shallow retrieval
            ClassDescriptor cld = broker.getClassDescriptor(Article.class);
            // article only has one ord
            ord = (ObjectReferenceDescriptor) cld.getObjectReferenceDescriptorByName("productGroup");
            ord.setCascadeRetrieve(false);

            Article article = (Article) broker.getObjectByIdentity(tmpOID);
            assertNull("now reference should be null", article.getProductGroup());

            // now force loading:
            broker.retrieveReference(article, "productGroup");
            assertNotNull("now reference should NOT be null", article.getProductGroup());

            // repair cld
            ord.setCascadeRetrieve(true);
            // should work without setting cld
            // broker.setClassDescriptor(cld);
        }
        finally
        {
            // restore old value
            if(ord != null) ord.setCascadeRetrieve(true);
        }
    }
View Full Code Here

        broker.store(pg);
        broker.store(tmpArticle);
        broker.commitTransaction();
        Identity tmpOID = broker.serviceIdentity().buildIdentity(tmpArticle);
        broker.clearCache();
        ObjectReferenceDescriptor ord = null;
        try
        {
            // switch to shallow retrieval
            ClassDescriptor cld = broker.getClassDescriptor(Article.class);
            ord = (ObjectReferenceDescriptor) cld.getObjectReferenceDescriptors().get(0);
            ord.setCascadeRetrieve(false);

            Article article = (Article) broker.getObjectByIdentity(tmpOID);
            assertNull("now reference should be null", article.getProductGroup());

            // now force loading:
            broker.retrieveAllReferences(article);
            assertNotNull("now reference should NOT be null", article.getProductGroup());

            // clean up cld
            ord.setCascadeRetrieve(true);
        }
        finally
        {
            // restore old value
            if(ord != null) ord.setCascadeRetrieve(true);
        }

    }
View Full Code Here

                if (!(key instanceof ObjectReferenceDescriptor))
                {
                    continue;
                }

                ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) key;
                RelationshipPrefetcher prefetcher;
                ArrayList owners = (ArrayList) entry.getValue();

                if (ord.isLazy() || (ord.getItemProxyClass() != null))
                {
                    continue;
                }

                prefetcher = pb.getRelationshipPrefetcherFactory().createRelationshipPrefetcher(ord);
View Full Code Here

        pb.getInternalCache().enableMaterializationCache();
        try
        {
            while (i.hasNext())
            {
                ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) i.next();
                retrieveReference(newObj, cld, rds, forced);
            }

            pb.getInternalCache().disableMaterializationCache();
        }
View Full Code Here

    {
        // get all members of obj that are references and delete them
        Iterator i = listRds.iterator();
        while (i.hasNext())
        {
            ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) i.next();
            if (rds.getCascadingDelete() == ObjectReferenceDescriptor.CASCADE_OBJECT)
            {
                Object referencedObject = rds.getPersistentField().get(obj);
                if (referencedObject != null)
                {
                    doDelete(referencedObject);
                }
            }
View Full Code Here

TOP

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

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.