/** * Writes out the changes gathered in the {@link Association} managed by this persister to the datastore. */ public void flushToDatastore() { if ( getAssociation().isEmpty() ) { gridDialect.removeAssociation( getAssociationKey(), getAssociationContext() ); association = null; OgmEntityEntryState.getStateFor( session, hostingEntity ).setAssociation( associationKeyMetadata.getCollectionRole(), null ); } else if ( !getAssociation().getOperations().isEmpty() ) { gridDialect.insertOrUpdateAssociation( getAssociationKey(), getAssociation(), getAssociationContext() ); } updateHostingEntityIfRequired(); }
/** * Reads the entity hosting the association from the datastore and applies any property changes from the server * side. */ private void updateHostingEntityIfRequired() { if ( hostingEntity != null && hostingEntityRequiresReadAfterUpdate() ) { OgmEntityPersister entityPersister = getHostingEntityPersister(); if ( GridDialects.hasFacet( gridDialect, GroupingByEntityDialect.class ) ) { ( (GroupingByEntityDialect) gridDialect ).flushPendingOperations( getAssociationKey().getEntityKey(), entityPersister.getTupleContext( session ) ); } entityPersister.processUpdateGeneratedProperties( entityPersister.getIdentifier( hostingEntity, session ), hostingEntity, new Object[entityPersister.getPropertyNames().length], session ); } }
updateInverseSideOfAssociationNavigation( session, entry, associationPersister.getAssociationKey(), assocEntryTuple, Action.REMOVE, assocEntryKey ); updateInverseSideOfAssociationNavigation( session, entry, associationPersister.getAssociationKey(), assocEntryTuple, Action.ADD, assocEntryKey );
public Association getAssociationOrNull() { if ( association == null ) { if ( hostingEntity != null ) { OgmEntityEntryState entryState = OgmEntityEntryState.getStateFor( session, hostingEntity ); if ( entryState.hasAssociation( associationKeyMetadata.getCollectionRole() ) ) { association = entryState.getAssociation( associationKeyMetadata.getCollectionRole() ); return association; } } if ( association == null ) { association = gridDialect.getAssociation( getAssociationKey(), getAssociationContext() ); if ( hostingEntity != null ) { OgmEntityEntryState.getStateFor( session, hostingEntity ) .setAssociation( associationKeyMetadata.getCollectionRole(), association ); } } } return association; }
updateInverseSideOfAssociationNavigation( session, entry, associationPersister.getAssociationKey(), keyAndTuple.tuple, Action.ADD, keyAndTuple.key ); collection.afterRowInsert( this, entry, i ); count++;
@Override public void insertRows(PersistentCollection collection, Serializable id, SharedSessionContractImplementor session) throws HibernateException { if ( !isInverse && isRowInsertEnabled() ) { if ( log.isDebugEnabled() ) { log.debug( "Inserting rows of collection: " + MessageHelper.collectionInfoString( this, id, getFactory() ) ); } AssociationPersister associationPersister = getAssociationPersister( collection.getOwner(), id, session ); // insert all the new entries collection.preInsert( this ); Iterator<?> entries = collection.entries( this ); int i = 0; int count = 0; while ( entries.hasNext() ) { Object entry = entries.next(); if ( collection.needsInserting( entry, i, elementType ) ) { // TODO: copy/paste from recreate() RowKeyAndTuple associationRow = createAndPutAssociationRowForInsert( id, collection, associationPersister, session, i, entry ); updateInverseSideOfAssociationNavigation( session, entry, associationPersister.getAssociationKey(), associationRow.tuple, Action.ADD, associationRow.key ); collection.afterRowInsert( this, entry, i ); count++; } i++; } associationPersister.flushToDatastore(); if ( log.isDebugEnabled() ) { log.debug( "done inserting rows: " + count + " inserted" ); } } }
updateInverseSideOfAssociationNavigation( session, entry, associationPersister.getAssociationKey(), assocEntryTuple, Action.REMOVE, assocEntryKey ); associationPersister.getAssociation().remove( assocEntryKey );
private void addNavigationalInformationForInverseSide(int propertyIndex, AssociationKeyMetadata associationKeyMetadata, Object[] newColumnValue) { RowKey rowKey = getInverseRowKey( associationKeyMetadata, newColumnValue ); Tuple associationRow = new Tuple(); for ( String column : rowKey.getColumnNames() ) { associationRow.put( column, rowKey.getColumnValue( column ) ); } AssociationPersister associationPersister = createInverseAssociationPersister( propertyIndex, associationKeyMetadata, newColumnValue ); associationPersister.getAssociation().put( rowKey, associationRow ); if ( associationPersister.getAssociationContext().getEntityTuplePointer().getTuple() == null ) { throw log.entityTupleNotFound( associationKeyMetadata.getCollectionRole(), associationPersister.getAssociationKey().getEntityKey() ); } associationPersister.flushToDatastore(); }
session, entity, associationPersister.getAssociationKey(), associationRow, Action.REMOVE,
public Association getAssociation() { if ( association == null ) { AssociationKey key = getAssociationKey(); if ( hostingEntity != null ) { OgmEntityEntryState entryState = OgmEntityEntryState.getStateFor( session, hostingEntity ); if ( entryState.hasAssociation( associationKeyMetadata.getCollectionRole() ) ) { association = entryState.getAssociation( associationKeyMetadata.getCollectionRole() ); } else { association = gridDialect.getAssociation( key, getAssociationContext() ); OgmEntityEntryState.getStateFor( session, hostingEntity ) .setAssociation( associationKeyMetadata.getCollectionRole(), association ); } } else { association = gridDialect.getAssociation( key, getAssociationContext() ); } if ( association == null ) { association = gridDialect.createAssociation( key, getAssociationContext() ); if ( hostingEntity != null ) { OgmEntityEntryState.getStateFor( session, hostingEntity ) .setAssociation( associationKeyMetadata.getCollectionRole(), association ); } } } return association; }