Package org.apache.isis.core.metamodel.adapter.oid

Examples of org.apache.isis.core.metamodel.adapter.oid.RootOid


        // given persisted
        iswf.beginTran();
        resetPersistenceStore();
        ObjectAdapter adapter = iswf.persist(iswf.fixtures.smpl2);
        final RootOid oid = (RootOid) adapter.getOid();
        iswf.commitTran();
       
        iswf.bounceSystem();

        // when destroy
View Full Code Here


        }
        if(Bookmark.class != argType) {
            return adapterFor(arg);
        } else {
            final Bookmark argBookmark = (Bookmark)arg;
            final RootOid rootOid = RootOidDefault.create(argBookmark);
            return adapterFor(rootOid);
        }
    }
View Full Code Here

            // a slight compromise? close enough.
            if(!(oid instanceof RootOid)) {
                throw new IllegalArgumentException("oid is view model but not a RootOid; " + oid.toString());
            }
            final RootOid rootOid = (RootOid) oid;
            final String memento = rootOid.getIdentifier();

            facet.initialize(pojo, memento);
        }
        return pojo;
    }
View Full Code Here

    }

    @Override
    public RootOid getOidForService(ObjectSpecification serviceSpec) {
        final ObjectSpecId objectSpecId = serviceSpec.getSpecId();
        RootOid oid = servicesByObjectSpecId.get(objectSpecId);
        if (oid == null) {
            final String id = database.getService(objectSpecId);
            if (id == null) {
                oid = null;
            } else {
View Full Code Here

    @Override
    public void writeOid(final TypedOid typedOid) {
        writeField(PropertyNames.OID, typedOid.enString(getOidMarshaller()));
        if(typedOid instanceof RootOid) {
            RootOid rootOid = (RootOid) typedOid;
            writeField(PropertyNames.MONGO_INTERNAL_ID, rootOid.getIdentifier());
        }
    }
View Full Code Here

        }

        // sync versions of original, with concurrency checking if required
        Oid adapterOid = adapter.getOid();
        if(adapterOid instanceof RootOid) {
            final RootOid recreatedOid = (RootOid) adapterOid;
            final RootOid originalOid = (RootOid) typedOid;
           
            try {
                if(concurrencyChecking.isChecking()) {
                   
                    // check for exception, but don't throw if suppressed through thread-local
                    final Version otherVersion = originalOid.getVersion();
                    final Version thisVersion = recreatedOid.getVersion();
                    if(thisVersion != null &&
                       otherVersion != null &&
                       thisVersion.different(otherVersion)) {
                       
                        if(isConcurrencyCheckingGloballyEnabled() && ConcurrencyChecking.isCurrentlyEnabled()) {
                            LOG.info("concurrency conflict detected on " + recreatedOid + " (" + otherVersion + ")");
                            final String currentUser = getAuthenticationSession().getUserName();
                            throw new ConcurrencyException(currentUser, recreatedOid, thisVersion, otherVersion);
                        } else {
                            LOG.warn("concurrency conflict detected but suppressed, on " + recreatedOid + " (" + otherVersion + ")");
                        }
                    }
                }
            } finally {
                final Version originalVersion = originalOid.getVersion();
                final Version recreatedVersion = recreatedOid.getVersion();
                if(recreatedVersion != null && (
                        originalVersion == null ||
                        recreatedVersion.different(originalVersion))
                    ) {
                    if(LOG.isDebugEnabled()) {
                        LOG.debug("updating version in oid, on " + originalOid + " (" + originalVersion + ") to (" + recreatedVersion +")");
                    }
                    originalOid.setVersion(recreatedVersion);
                }
            }
        }

        return adapter;
View Full Code Here

    }

    private ObjectAdapter createRootOrAggregatedAdapter(final Oid oid, final Object pojo) {
        final ObjectAdapter createdAdapter;
        if(oid instanceof RootOid) {
            final RootOid rootOid = (RootOid) oid;
            createdAdapter = createRootAdapterAndInferResolveState(pojo, rootOid);
        } else if (oid instanceof CollectionOid){
            final CollectionOid collectionOid = (CollectionOid) oid;
            createdAdapter = createCollectionAdapterAndInferResolveState(pojo, collectionOid);
        } else {
View Full Code Here

     */
    @Override
    public void remapAsPersistent(final ObjectAdapter adapter, RootOid hintRootOid) {
       
        final ObjectAdapter rootAdapter = adapter.getAggregateRoot()// REVIEW: think this is redundant; would seem this method is only ever called for roots anyway.
        final RootOid transientRootOid = (RootOid) rootAdapter.getOid();

        Ensure.ensureThatArg(rootAdapter.isTransient(), is(true), "root adapter should be transient; oid:" + transientRootOid);
        Ensure.ensureThatArg(transientRootOid.isTransient(), is(true), "root adapter's OID should be transient; oid:" + transientRootOid);
       
        final RootAndCollectionAdapters rootAndCollectionAdapters = new RootAndCollectionAdapters(adapter, this);
       
       
        if (LOG.isDebugEnabled()) {
            LOG.debug("remapAsPersistent: " + transientRootOid);
        }
       
        if (LOG.isDebugEnabled()) {
            LOG.debug("removing root adapter from oid map");
        }
       
        boolean removed = oidAdapterMap.remove(transientRootOid);
        if (!removed) {
            LOG.warn("could not remove oid: " + transientRootOid);
            // should we fail here with a more serious error?
        }
       
        if (LOG.isDebugEnabled()) {
            LOG.debug("removing collection adapter(s) from oid map");
        }
        for (final ObjectAdapter collectionAdapter : rootAndCollectionAdapters) {
            final Oid collectionOid = collectionAdapter.getOid();
            removed = oidAdapterMap.remove(collectionOid);
            if (!removed) {
                LOG.warn("could not remove collectionOid: " + collectionOid);
                // should we fail here with a more serious error?
            }
        }
       
        if (LOG.isDebugEnabled()) {
            LOG.debug("updating the Oid");
        }
       
        // intended for testing (bit nasty)
        final RootOid persistedRootOid;
        if(hintRootOid != null) {
            if(hintRootOid.isTransient()) {
                throw new IsisAssertException("hintRootOid must be persistent");
            }
            final ObjectSpecId hintRootOidObjectSpecId = hintRootOid.getObjectSpecId();
            final ObjectSpecId adapterObjectSpecId = adapter.getSpecification().getSpecId();
            if(!hintRootOidObjectSpecId.equals(adapterObjectSpecId)) {
                throw new IsisAssertException("hintRootOid's objectType must be same as that of adapter " +
                    "(was: '" + hintRootOidObjectSpecId + "'; adapter's is " + adapterObjectSpecId + "'");
            }
            // ok
            persistedRootOid = hintRootOid;
        } else {
            // normal flow - delegate to OidGenerator to obtain a persistent root oid
            persistedRootOid = getOidGenerator().createPersistentOrViewModelOid(adapter.getObject(), transientRootOid);
        }
       
        // associate root adapter with the new Oid, and remap
        if (LOG.isDebugEnabled()) {
            LOG.debug("replacing Oid for root adapter and re-adding into maps; oid is now: " + persistedRootOid.enString(getOidMarshaller()) + " (was: " + transientRootOid.enString(getOidMarshaller()) + ")");
        }
        adapter.replaceOid(persistedRootOid);
        oidAdapterMap.add(persistedRootOid, adapter);
       
        // associate the collection adapters with new Oids, and re-map
View Full Code Here

     *
     * <p>
     * Has <tt>protected</tt> visibility just so can be used by subclasses if required.
     */
    protected final ObjectAdapter createTransientOrViewModelRootAdapter(final Object pojo) {
        final RootOid rootOid = getOidGenerator().createTransientOrViewModelOid(pojo);
        return createRootAdapterAndInferResolveState(pojo, rootOid);
    }
View Full Code Here

        assertEquals(SIZE, manager.numberOfInstances(pattern));
    }

    @Test
    public void testRemove() throws Exception {
        final RootOid oid = oids[2];
        manager.remove(oid);

        assertEquals(SIZE - 1, manager.numberOfInstances(pattern));

        final ObjectDataVector instances = manager.getInstances(pattern);
View Full Code Here

TOP

Related Classes of org.apache.isis.core.metamodel.adapter.oid.RootOid

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.