Search in sources :

Example 11 with Transaction

use of org.datanucleus.Transaction in project datanucleus-api-jdo by datanucleus.

the class PersistentNontransactional method transitionWriteField.

/**
 * Method to transition to write-field state.
 * @param op ObjectProvider.
 * @return new LifeCycle state.
 */
public LifeCycleState transitionWriteField(ObjectProvider op) {
    Transaction tx = op.getExecutionContext().getTransaction();
    if (!tx.isActive() && !tx.getNontransactionalWrite()) {
        throw new TransactionNotWritableException(Localiser.msg("027001"), op.getInternalObjectId());
    }
    if (tx.isActive()) {
        // Save the fields for rollback.
        op.saveFields();
        return changeState(op, P_DIRTY);
    }
    // Save the fields for rollback.
    op.saveFields();
    return changeState(op, P_NONTRANS_DIRTY);
}
Also used : Transaction(org.datanucleus.Transaction) TransactionNotWritableException(org.datanucleus.api.jdo.exceptions.TransactionNotWritableException)

Example 12 with Transaction

use of org.datanucleus.Transaction in project datanucleus-api-jdo by datanucleus.

the class PersistentNontransactional method transitionReadField.

/**
 * Method to transition to read-field state.
 * @param op ObjectProvider.
 * @param isLoaded if the field was previously loaded.
 * @return new LifeCycle state.
 */
public LifeCycleState transitionReadField(ObjectProvider op, boolean isLoaded) {
    Transaction tx = op.getExecutionContext().getTransaction();
    if (!tx.isActive() && !tx.getNontransactionalRead()) {
        throw new TransactionNotReadableException(Localiser.msg("027002"), op.getInternalObjectId());
    }
    if (tx.isActive() && !tx.getOptimistic()) {
        // Save the fields for rollback.
        op.saveFields();
        op.refreshLoadedFields();
        return changeState(op, P_CLEAN);
    }
    return this;
}
Also used : Transaction(org.datanucleus.Transaction) TransactionNotReadableException(org.datanucleus.api.jdo.exceptions.TransactionNotReadableException)

Example 13 with Transaction

use of org.datanucleus.Transaction in project datanucleus-api-jdo by datanucleus.

the class PersistentDirty method transitionRefresh.

/**
 * Method to transition to refresh state.
 * @param op ObjectProvider.
 * @return new LifeCycle state.
 */
public LifeCycleState transitionRefresh(ObjectProvider op) {
    op.clearSavedFields();
    // Refresh the FetchPlan fields and unload all others
    op.refreshFieldsInFetchPlan();
    op.unloadNonFetchPlanFields();
    Transaction tx = op.getExecutionContext().getTransaction();
    if (tx.isActive() && !tx.getOptimistic()) {
        return changeState(op, P_CLEAN);
    }
    return changeState(op, P_NONTRANS);
}
Also used : Transaction(org.datanucleus.Transaction)

Aggregations

Transaction (org.datanucleus.Transaction)13 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 SQLException (java.sql.SQLException)7 ExecutionContext (org.datanucleus.ExecutionContext)7 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)7 ManagedConnection (org.datanucleus.store.connection.ManagedConnection)7 SQLController (org.datanucleus.store.rdbms.SQLController)7 StatementMappingIndex (org.datanucleus.store.rdbms.query.StatementMappingIndex)7 PersistentClassROF (org.datanucleus.store.rdbms.query.PersistentClassROF)6 ResultObjectFactory (org.datanucleus.store.rdbms.query.ResultObjectFactory)6 MappedDatastoreException (org.datanucleus.store.rdbms.exceptions.MappedDatastoreException)5 SQLStatement (org.datanucleus.store.rdbms.sql.SQLStatement)5 ReferenceMapping (org.datanucleus.store.rdbms.mapping.java.ReferenceMapping)3 NoSuchElementException (java.util.NoSuchElementException)2 ObjectProvider (org.datanucleus.state.ObjectProvider)2 EmbeddedKeyPCMapping (org.datanucleus.store.rdbms.mapping.java.EmbeddedKeyPCMapping)2 SerialisedPCMapping (org.datanucleus.store.rdbms.mapping.java.SerialisedPCMapping)2 SerialisedReferenceMapping (org.datanucleus.store.rdbms.mapping.java.SerialisedReferenceMapping)2 StatementClassMapping (org.datanucleus.store.rdbms.query.StatementClassMapping)2