Пример #1
0
  private void recreateAdapters(final ObjectStoreInstances objectStoreInstances) {
    for (final Oid oid : objectStoreInstances.getOids()) {

      // it's important not to "touch" the pojo, not even in log messages.
      // That's because
      // the toString() will cause bytecode enhancement to try to resolve
      // references.

      if (LOG.isDebugEnabled()) {
        LOG.debug("recreating adapter: oid=" + oid);
      }
      final Object pojo = objectStoreInstances.getPojo(oid);

      final ObjectAdapter existingAdapterLookedUpByPojo = getAdapterManager().getAdapterFor(pojo);
      if (existingAdapterLookedUpByPojo != null) {
        // this could happen if we rehydrate a persisted object that
        // depends on another persisted object
        // not yet rehydrated.
        getPersistenceSession().removeAdapter(existingAdapterLookedUpByPojo);
      }

      final ObjectAdapter existingAdapterLookedUpByOid = getAdapterManager().getAdapterFor(oid);
      if (existingAdapterLookedUpByOid != null) {
        throw new IsisException(
            "A mapping already exists for " + oid + ": " + existingAdapterLookedUpByOid);
      }

      final ObjectAdapter recreatedAdapter = getPersistenceSession().mapRecreatedPojo(oid, pojo);

      final Version version = objectStoreInstances.getVersion(oid);
      recreatedAdapter.setVersion(version);
    }
  }