Ejemplo n.º 1
0
  public void open() {
    ensureNotYetOpen();

    openSession();
    ensureThatState(persistenceManager, is(notNullValue()));

    addPersistenceQueryProcessors(persistenceManager);

    state = State.OPEN;
  }
Ejemplo n.º 2
0
  /** Walking the graph. */
  public void resolveField(final ObjectAdapter object, final ObjectAssociation association) {
    ensureOpened();
    ensureInTransaction();

    final ObjectAdapter referencedCollectionAdapter = association.get(object);

    // this code originally brought in from the JPA impl, but seems reasonable.
    if (association.isOneToManyAssociation()) {
      ensureThatState(referencedCollectionAdapter, is(notNullValue()));

      final Object referencedCollection = referencedCollectionAdapter.getObject();
      ensureThatState(referencedCollection, is(notNullValue()));

      // if a proxy collection, then force it to initialize.  just 'touching' the object is
      // sufficient.
      // REVIEW: I wonder if this is actually needed; does JDO use proxy collections?
      referencedCollection.hashCode();
    }

    // the JPA impl used to also call its lifecycle listener on the referenced collection object, eg
    // List,
    // itself.  I don't think this makes sense to do for JDO (the collection is not a
    // PersistenceCapable).
  }
Ejemplo n.º 3
0
  /**
   * {@inheritDoc}
   *
   * <p>Automatically {@link IsisTransactionManager#endTransaction() ends (commits)} the current
   * (Isis) {@link Transaction}. This in turn {@link DataNucleusObjectStore#commitJdoTransaction()
   * commits the underlying JPA transaction}.
   *
   * <p>The corresponding DataNucleus {@link Entity} is then {@link EntityManager#close() close}d.
   */
  public void close() {
    ensureOpened();
    ensureThatState(persistenceManager, is(notNullValue()));

    try {
      final IsisTransaction currentTransaction = getTransactionManager().getTransaction();
      if (currentTransaction != null && !currentTransaction.getState().isComplete()) {
        if (currentTransaction.getState().canCommit()) {
          getTransactionManager().endTransaction();
        } else if (currentTransaction.getState().canAbort()) {
          getTransactionManager().abortTransaction();
        }
      }
    } finally {
      // make sure release everything ok.
      persistenceManager.close();
      state = State.CLOSED;
    }
  }
Ejemplo n.º 4
0
 private void ensureInHibernateTransaction() {
   javax.jdo.Transaction currentTransaction = getPersistenceManager().currentTransaction();
   ensureThatState(currentTransaction, is(notNullValue()));
   ensureThatState(currentTransaction.isActive(), is(true));
 }