/** * Return a transaction context given the session; it never returns {@code null}. * * @param session current {@link Session} * @return the {@link TransactionContext} */ public static TransactionContext transactionContext(Session session) { return transactionContext( (SharedSessionContractImplementor) session ); }
/** * Returns the {@link TupleContext}. * * @param session the current session, cannot be null. If you don't have a session, you probably want to use {@code getTupleTypeContext()}. * @return the tupleContext for the session */ public TupleContext getTupleContext(SharedSessionContractImplementor session) { return new TupleContextImpl( tupleTypeContext, TransactionContextHelper.transactionContext( session ) ); }
public TupleContextBuilder transactionContext(Session session) { this.transactionContext = TransactionContextHelper.transactionContext( session ); return this; }
/** * Returns an {@link AssociationContext} to be passed to {@link GridDialect} operations targeting the association * managed by this persister. */ public AssociationContext getAssociationContext() { if ( associationContext == null ) { associationContext = new AssociationContextImpl( associationTypeContext, hostingEntity != null ? OgmEntityEntryState.getStateFor( session, hostingEntity ).getTuplePointer() : new TuplePointer(), transactionContext( session ) ); } return associationContext; } }
private void consumeInTransaction(TuplesSupplier supplier) { TransactionManager transactionManager = getTransactionManager(); try { transactionManager.begin(); final Session session = factory.openSession(); try { TransactionContext transactionContext = TransactionContextHelper.transactionContext( session ); ClosableIterator<Tuple> tuples = supplier.get( transactionContext ); try { while ( tuples.hasNext() ) { Tuple tuple = tuples.next(); delegate.run( session, tuple ); } transactionManager.commit(); } finally { tuples.close(); } } finally { session.close(); } } catch ( Throwable e ) { errorHandler.handleException( log.massIndexerUnexpectedErrorMessage(), e ); rollback( transactionManager, e ); } }
/** * Given a {@link SessionImplementor} returns the {@link TupleContext} associated to an entity. * * @param session the current session * @param metadata the {@link EntityMetadataInformation} of the entity associated to the TupleContext * @return the TupleContext associated to the current session for the entity specified */ public static TupleContext tupleContext(SharedSessionContractImplementor session, EntityMetadataInformation metadata) { if ( metadata != null ) { OgmEntityPersister persister = (OgmEntityPersister) session.getFactory().getMetamodel().entityPersister( metadata.getTypeName() ); return persister.getTupleContext( session ); } else if ( session != null ) { // We are not dealing with a single entity but we might still need the transactionContext TransactionContext transactionContext = TransactionContextHelper.transactionContext( session ); TupleContext tupleContext = new OnlyWithTransactionContext( transactionContext ); return tupleContext; } else { return null; } }