Package org.apache.ojb.broker

Examples of org.apache.ojb.broker.IdentityFactory


  public void testGetObjectById() {
    MockControl pbControl = MockControl.createControl(PersistenceBroker.class);
    final PersistenceBroker pb = (PersistenceBroker) pbControl.getMock();
    MockControl idfControl = MockControl.createControl(IdentityFactory.class);
    final IdentityFactory idf = (IdentityFactory) idfControl.getMock();

    Identity identity = new Identity(String.class, Object.class, new Object[] {"id"});
    pb.serviceIdentity();
    pbControl.setReturnValue(idf, 1);
    idf.buildIdentity(String.class, "id");
    idfControl.setReturnValue(identity, 1);
    pb.getObjectByIdentity(identity);
    pbControl.setReturnValue("", 1);
    pb.close();
    pbControl.setReturnValue(true, 1);
View Full Code Here


        void handleReferencedObjects(Iterator it)
        {
            if(it == null) return;
            references = new HashMap();
            if(log.isDebugEnabled()) log.debug("Handle collection references");
            IdentityFactory idFac = listener.getBroker().serviceIdentity();
            Identity oid;
            Object obj;
            while(it.hasNext())
            {
                obj = it.next();
                oid = idFac.buildIdentity(obj);
                if(!hasTransientIdentity && oid.isTransient())
                {
                    hasTransientIdentity = true;
                }
                references.put(oid, obj);
View Full Code Here

            if(hasTransientIdentity && references.size() > 0)
            {
                hasTransientIdentity = false;
                // we need independent key list from Map
                List list = new ArrayList(references.keySet());
                IdentityFactory idFac = listener.getBroker().serviceIdentity();
                Identity oid, newOid;
                Object obj;
                for(int i = 0; i < list.size(); i++)
                {
                    oid = (Identity) list.get(i);
                    if(oid.isTransient())
                    {
                        obj = references.remove(oid);
                        newOid = idFac.buildIdentity(obj);
                        references.put(newOid, obj);
                        if(!hasTransientIdentity && oid.isTransient())
                        {
                            hasTransientIdentity = true;
                        }
View Full Code Here

        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();
View Full Code Here

        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();
View Full Code Here

TOP

Related Classes of org.apache.ojb.broker.IdentityFactory

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.