Package org.apache.ojb.broker.metadata

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


    //============================================================================

    void changeAutoSetting(Class clazz, String referenceField, boolean autoRetrieve, boolean autoUpdate, boolean autoDelete, boolean useProxy)
    {
        ClassDescriptor cld = broker.getClassDescriptor(clazz);
        ObjectReferenceDescriptor ref = cld.getCollectionDescriptorByName(referenceField);
        if(ref == null) ref = cld.getObjectReferenceDescriptorByName(referenceField);
        ref.setLazy(useProxy);
        ref.setCascadeRetrieve(autoRetrieve);
        ref.setCascadeStore(autoUpdate);
        ref.setCascadeDelete(autoDelete);
    }
View Full Code Here


    }

    void changeAutoSetting(Class clazz, String referenceField, boolean autoRetrieve, int autoUpdate, int autoDelete, boolean useProxy)
    {
        ClassDescriptor cld = broker.getClassDescriptor(clazz);
        ObjectReferenceDescriptor ref = cld.getCollectionDescriptorByName(referenceField);
        if(ref == null) ref = cld.getObjectReferenceDescriptorByName(referenceField);
        ref.setLazy(useProxy);
        ref.setCascadeRetrieve(autoRetrieve);
        ref.setCascadingStore(autoUpdate);
        ref.setCascadingDelete(autoDelete);
    }
View Full Code Here

    public void testSerializedObjectsRefreshWithProxy()
    {
        String prefix = "testSerializedObjectsRefreshWithProxy_" + System.currentTimeMillis() + "_";

        ClassDescriptor cld = broker.getClassDescriptor(ObjectRepository.Component.class);
        ObjectReferenceDescriptor ord = cld.getObjectReferenceDescriptorByName("parentComponent");
        boolean oldState = ord.isLazy();
        try
        {
            ord.setLazy(true);
            ObjectRepository.Component parent = new ObjectRepository.Component();
            parent.setName(prefix + "main_component");

            ObjectRepository.Component compSub1 = new ObjectRepository.Component();
            compSub1.setName(prefix + "sub_1");

            ObjectRepository.Component compSub2 = new ObjectRepository.Component();
            compSub2.setName(prefix + "sub_2");

            ObjectRepository.Component compSub3 = new ObjectRepository.Component();
            compSub2.setName(prefix + "sub_3");

            ObjectRepository.Group group = new ObjectRepository.Group();
            group.setName(prefix + "test_group");

            compSub1.setParentComponent(parent);
            compSub2.setParentComponent(parent);
            compSub3.setParentComponent(parent);
            ArrayList list = new ArrayList();
            list.add(compSub1);
            list.add(compSub2);
            list.add(compSub3);
            parent.setChildComponents(list);
            parent.setGroup(group);

            broker.beginTransaction();
            broker.store(parent);
            broker.commitTransaction();

            broker.clearCache();
            Query query = QueryFactory.newQuery(parent);
            parent = (ObjectRepository.Component) broker.getObjectByQuery(query);

            Query groupQuery = QueryFactory.newQuery(group);
            ObjectRepository.Group lookedUpGroup = (ObjectRepository.Group) broker.getObjectByQuery(groupQuery);

            assertNotNull(parent);
            assertNotNull(parent.getGroup());
            assertNotNull(parent.getChildComponents());
            assertNotNull(parent.getName());
            assertEquals(3, parent.getChildComponents().size());
            assertEquals(group.getName(), (parent.getGroup().getName()));
            ObjectRepository.Component aChild = (ObjectRepository.Component) parent.getChildComponents().iterator().next();
            assertNotNull(aChild);
            assertNotNull(aChild.getParentComponent());
            assertEquals(parent, aChild.getParentComponent());
            assertNotNull(lookedUpGroup);

            //*************************************
            assertNotNull(parent);
            assertNotNull(parent.getGroup());
            parent = (ObjectRepository.Component) serializeDeserializeObject(parent);
            broker.retrieveAllReferences(parent);
            assertNotNull(parent);
            /*
            Now we have a problem! After serialization we can't find the anonymous keys
            for parent object, because object identity has changed!!
            This is now fixed in class QueryReferenceBroker#getReferencedObjectIdentity
            */
            assertNotNull(parent.getGroup());
            //*************************************
            assertNotNull(parent.getChildComponents());
            assertNotNull(parent.getName());
            assertEquals(3, parent.getChildComponents().size());
            aChild = (ObjectRepository.Component) parent.getChildComponents().iterator().next();
            assertNotNull(aChild);
            assertNotNull(aChild.getParentComponent());
            assertEquals(parent, aChild.getParentComponent());

            broker.beginTransaction();
            broker.store(parent);
            broker.commitTransaction();

            // now nothing should happen, because we don't make any changes
            broker.clearCache();
            query = QueryFactory.newQuery(parent);
            parent = (ObjectRepository.Component) broker.getObjectByQuery(query);
            groupQuery = QueryFactory.newQuery(group);
            lookedUpGroup = (ObjectRepository.Group) broker.getObjectByQuery(groupQuery);
            assertNotNull(parent);
            assertNotNull(parent.getGroup());
            assertNotNull(parent.getChildComponents());
            assertNotNull(parent.getName());
            assertEquals(3, parent.getChildComponents().size());
            assertEquals(group.getName(), (parent.getGroup().getName()));
            aChild = (ObjectRepository.Component) parent.getChildComponents().iterator().next();
            assertNotNull(aChild);
            assertNotNull(aChild.getParentComponent());
            assertEquals(parent, aChild.getParentComponent());
            assertNotNull(lookedUpGroup);
        }
        finally
        {
            ord.setLazy(oldState);
        }
    }
View Full Code Here

    }

    private void setReferenceMetadata(Class clazz, String reference, boolean autoretrieve, int autoupdate, int autodelete, boolean useProxy)
    {
        ClassDescriptor cld = broker.getClassDescriptor(clazz);
        ObjectReferenceDescriptor ord = cld.getObjectReferenceDescriptorByName(reference);
        if(ord == null)
        {
            ord = cld.getCollectionDescriptorByName(reference);
        }
        if(ord == null)
        {
            throw new MetadataException("Reference with name '" + reference + "' does not exist in " + clazz.getName());
        }
        ord.setCascadeRetrieve(autoretrieve);
        ord.setCascadingStore(autoupdate);
        ord.setCascadingDelete(autodelete);
        ord.setLazy(useProxy);
    }
View Full Code Here

            f.set(oldObj, f.get(newObj));
        }

        // N:1 relations
        Iterator iter = mif.getObjectReferenceDescriptors().iterator();
        ObjectReferenceDescriptor rds;
        PersistentField field;
        Object newRelObj;
        Identity newRelOid;
        Object oldRelObj;

        while (iter.hasNext())
        {
            rds = (ObjectReferenceDescriptor) iter.next();
            field = rds.getPersistentField();
            newRelObj = field.get(newObj);
            oldRelObj = field.get(oldObj);
            if ((newRelObj == null) && (oldRelObj != null))
            {
                field.set(oldObj, null);
View Full Code Here

            if (!ordList.isEmpty())
            {
                HashSet fkTables = getFKTablesFor(desc.getFullTableName());
                for (Iterator it2 = ordList.iterator(); it2.hasNext();)
                {
                    ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) it2.next();
                    ClassDescriptor oneDesc = repos.getDescriptorFor(ord.getItemClass());
                    fkTables.addAll(getFullTableNames(oneDesc, repos));
                }
            }

            List codList = desc.getCollectionDescriptors();
View Full Code Here

     * sophisticated.
     */
    public void testBidirectionalWithConstraint_1e() throws Exception
    {
        String name = "testBidirectionalWithConstraint_1e_" + System.currentTimeMillis();
        ObjectReferenceDescriptor ord = null;

        try
        {
            CircularTest.Shop s1 = new CircularTest.Shop(name + "_1");
            CircularTest.ShopDetail sd = new CircularTest.ShopDetail(name + "_1");
            s1.setDetail(sd);
            sd.setShop(s1);

            TransactionExt tx = (TransactionExt) odmg.newTransaction();
            tx.begin();
            // now we tell OJB that one 1:1 reference of the bidirectional 1:1 reference
            // between Shop and ShopDetail has a FK constraint
            ClassDescriptor cld = tx.getBroker().getClassDescriptor(CircularTest.Shop.class);
            ord = cld.getObjectReferenceDescriptorByName("detail");
            // current DB schema create a foreign key constraint and we can
            // inform OJB
            ord.setConstraint(true);
            // now it doesn't matter in which order we persist the new objects, OJB should
            // always reorder the objects before insert/update call
            database.makePersistent(sd);
            // or
            // database.makePersistent(s1);
            tx.commit();

            tx.begin();
            // with cascading delete and the declared FK constraint OJB
            // always use the correct order on delete.
            tx.setCascadingDelete(CircularTest.ShopDetail.class, true);
            database.deletePersistent(sd);
            // or
            // database.deletePersistent(s1);
            tx.commit();
        }
        finally
        {
            // restore old setting
            if(ord != null) ord.setConstraint(false);
        }
    }
View Full Code Here

      // Get references ObjectReferenceDescriptor
      it = cld.getObjectReferenceDescriptors().iterator();
      while (it.hasNext())
      {
        ObjectReferenceDescriptor objRefDesc = (ObjectReferenceDescriptor)it.next();
        newChildren.add(new OjbMetaObjectReferenceDescriptorNode(
          this.getOjbMetaTreeModel().getRepository(),
          this.getOjbMetaTreeModel(),
          this,
          objRefDesc));
View Full Code Here

        {
            // never returns null, thus we can direct call iterator
            Iterator descriptors = cld.getObjectReferenceDescriptors().iterator();
            while (descriptors.hasNext())
            {
                ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) descriptors.next();
                linkOrUnlinkOneToOne(doLink, obj, ord, insert);
            }
        }
        if (cld.getCollectionDescriptors().size() > 0)
        {
View Full Code Here

     * @return true if the specified reference was found and linking was successful
     */
    public boolean link(Object obj, String attributeName, Object reference, boolean insert)
    {
        ClassDescriptor cld = m_broker.getDescriptorRepository().getDescriptorFor(ProxyHelper.getRealClass(obj));
        ObjectReferenceDescriptor ord;
        boolean match = false;
        // first look for reference then for collection
        ord = cld.getObjectReferenceDescriptorByName(attributeName);
        if (ord != null)
        {
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.