*/
@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