use of org.datanucleus.Transaction in project datanucleus-rdbms by datanucleus.
the class MapKeySetStore method iterator.
/**
* Accessor for an iterator for the set.
* @param ownerOP ObjectProvider for the set.
* @return Iterator for the set.
*/
public Iterator<K> iterator(ObjectProvider ownerOP) {
ExecutionContext ec = ownerOP.getExecutionContext();
if (iteratorStmtLocked == null) {
synchronized (// Make sure this completes in case another thread needs the same info
this) {
// Generate the statement, and statement mapping/parameter information
SQLStatement sqlStmt = getSQLStatementForIterator(ownerOP);
iteratorStmtUnlocked = sqlStmt.getSQLText().toSQL();
sqlStmt.addExtension(SQLStatement.EXTENSION_LOCK_FOR_UPDATE, true);
iteratorStmtLocked = sqlStmt.getSQLText().toSQL();
}
}
Transaction tx = ec.getTransaction();
String stmt = (tx.getSerializeRead() != null && tx.getSerializeRead() ? iteratorStmtLocked : iteratorStmtUnlocked);
try {
ManagedConnection mconn = storeMgr.getConnectionManager().getConnection(ec);
SQLController sqlControl = storeMgr.getSQLController();
try {
// Create the statement and set the owner
PreparedStatement ps = sqlControl.getStatementForQuery(mconn, stmt);
StatementMappingIndex ownerIdx = iteratorMappingParams.getMappingForParameter("owner");
int numParams = ownerIdx.getNumberOfParameterOccurrences();
for (int paramInstance = 0; paramInstance < numParams; paramInstance++) {
ownerIdx.getMapping().setObject(ec, ps, ownerIdx.getParameterPositionsForOccurrence(paramInstance), ownerOP.getObject());
}
try {
ResultSet rs = sqlControl.executeStatementQuery(ec, mconn, stmt, ps);
try {
ResultObjectFactory rof = null;
if (elementsAreEmbedded || elementsAreSerialised) {
// No ResultObjectFactory needed - handled by SetStoreIterator
return new CollectionStoreIterator(ownerOP, rs, null, this);
}
rof = new PersistentClassROF(ec, rs, false, iteratorMappingDef, elementCmd, clr.classForName(elementType));
return new CollectionStoreIterator(ownerOP, rs, rof, this);
} finally {
rs.close();
}
} finally {
sqlControl.closeStatement(mconn, ps);
}
} finally {
mconn.release();
}
} catch (SQLException e) {
throw new NucleusDataStoreException(Localiser.msg("056006", stmt), e);
} catch (MappedDatastoreException e) {
throw new NucleusDataStoreException(Localiser.msg("056006", stmt), e);
}
}
use of org.datanucleus.Transaction in project datanucleus-api-jdo by datanucleus.
the class Hollow method transitionRetrieve.
/**
* Method to transition to retrieve state.
* @param op ObjectProvider.
* @param fetchPlan the fetch plan to load fields
* @return new LifeCycle state.
*/
public LifeCycleState transitionRetrieve(ObjectProvider op, FetchPlan fetchPlan) {
op.loadUnloadedFieldsOfClassInFetchPlan(fetchPlan);
Transaction tx = op.getExecutionContext().getTransaction();
if (!tx.getOptimistic() && tx.isActive()) {
return changeState(op, P_CLEAN);
} else if (tx.getOptimistic()) {
return changeState(op, P_NONTRANS);
}
return super.transitionRetrieve(op, fetchPlan);
}
use of org.datanucleus.Transaction in project datanucleus-api-jdo by datanucleus.
the class PersistentClean 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()) {
return changeState(op, P_CLEAN);
}
return changeState(op, P_NONTRANS);
}
use of org.datanucleus.Transaction in project datanucleus-rdbms by datanucleus.
the class MapValueCollectionStore method iterator.
/**
* Accessor for an iterator for the set.
* @param ownerOP ObjectProvider for the set.
* @return Iterator for the set.
*/
public Iterator<V> iterator(ObjectProvider ownerOP) {
ExecutionContext ec = ownerOP.getExecutionContext();
if (iteratorStmtLocked == null) {
synchronized (// Make sure this completes in case another thread needs the same info
this) {
// Generate the statement, and statement mapping/parameter information
SQLStatement sqlStmt = getSQLStatementForIterator(ownerOP);
iteratorStmtUnlocked = sqlStmt.getSQLText().toSQL();
sqlStmt.addExtension(SQLStatement.EXTENSION_LOCK_FOR_UPDATE, true);
iteratorStmtLocked = sqlStmt.getSQLText().toSQL();
}
}
Transaction tx = ec.getTransaction();
String stmt = (tx.getSerializeRead() != null && tx.getSerializeRead() ? iteratorStmtLocked : iteratorStmtUnlocked);
try {
ManagedConnection mconn = storeMgr.getConnectionManager().getConnection(ec);
SQLController sqlControl = storeMgr.getSQLController();
try {
// Create the statement and set the owner
PreparedStatement ps = sqlControl.getStatementForQuery(mconn, stmt);
StatementMappingIndex ownerIdx = iteratorMappingParams.getMappingForParameter("owner");
int numParams = ownerIdx.getNumberOfParameterOccurrences();
for (int paramInstance = 0; paramInstance < numParams; paramInstance++) {
ownerIdx.getMapping().setObject(ec, ps, ownerIdx.getParameterPositionsForOccurrence(paramInstance), ownerOP.getObject());
}
try {
ResultSet rs = sqlControl.executeStatementQuery(ec, mconn, stmt, ps);
try {
ResultObjectFactory rof = null;
if (elementsAreEmbedded || elementsAreSerialised) {
// No ResultObjectFactory needed - handled by SetStoreIterator
return new CollectionStoreIterator(ownerOP, rs, null, this);
}
rof = new PersistentClassROF(ec, rs, false, iteratorMappingDef, elementCmd, clr.classForName(elementType));
return new CollectionStoreIterator(ownerOP, rs, rof, this);
} finally {
rs.close();
}
} finally {
sqlControl.closeStatement(mconn, ps);
}
} finally {
mconn.release();
}
} catch (SQLException e) {
throw new NucleusDataStoreException(Localiser.msg("056006", stmt), e);
} catch (MappedDatastoreException e) {
throw new NucleusDataStoreException(Localiser.msg("056006", stmt), e);
}
}
use of org.datanucleus.Transaction in project datanucleus-api-jdo by datanucleus.
the class PersistentNontransactional method transitionRetrieve.
/**
* Method to transition to retrieve state.
* @param op ObjectProvider.
* @param fetchPlan the fetch plan to load fields
* @return new LifeCycle state.
*/
public LifeCycleState transitionRetrieve(ObjectProvider op, FetchPlan fetchPlan) {
Transaction tx = op.getExecutionContext().getTransaction();
if (tx.isActive() && !tx.getOptimistic()) {
// Save the fields for rollback.
op.saveFields();
op.loadUnloadedFieldsOfClassInFetchPlan(fetchPlan);
return changeState(op, P_CLEAN);
} else if (tx.isActive() && tx.getOptimistic()) {
// Save the fields for rollback.
// TODO this is wrong... saving all the time, retrieve is asked... side effects besides performance?
op.saveFields();
op.loadUnloadedFieldsOfClassInFetchPlan(fetchPlan);
return this;
} else {
op.loadUnloadedFieldsOfClassInFetchPlan(fetchPlan);
return this;
}
}
Aggregations