/** * 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(); }
Tuple assocEntryTuple = associationPersister.getAssociation().get( assocEntryKey ); if ( assocEntryTuple == null ) { throw new AssertionFailure( "Updating a collection tuple that is not present: " + "table {" + getTableName() + "} collectionKey {" + key + "} entry {" + entry + "}" ); associationPersister.getAssociation().put( assocEntryKey, assocEntryTuple );
associationPersister.getAssociation().put( inverseRowKey, inverseAssociationRow ); for ( String columnName : inverseRowKey.getColumnNames() ) { inverseAssociationRow.put( columnName, associationRow.get( columnName ) ); associationPersister.getAssociation().put( inverseRowKey, inverseAssociationRow ); associationPersister.getAssociation().remove( inverseRowKey );
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(); }
Tuple assocEntryTuple = associationPersister.getAssociation().get( assocEntryKey ); if ( assocEntryTuple == null ) { throw new AssertionFailure( "Deleting a collection tuple that is not present: " + "table {" + getTableName() + "} collectionKey {" + id + "} entry {" + entry + "}" ); associationPersister.getAssociation().remove( assocEntryKey );
/** * Creates an association row representing the given entry and adds it to the association managed by the given * persister. */ private RowKeyAndTuple createAndPutAssociationRowForInsert(Serializable key, PersistentCollection collection, AssociationPersister associationPersister, SharedSessionContractImplementor session, int i, Object entry) { RowKeyBuilder rowKeyBuilder = initializeRowKeyBuilder(); Tuple associationRow = new Tuple(); // the collection has a surrogate key (see @CollectionId) if ( hasIdentifier ) { final Object identifier = collection.getIdentifier( entry, i ); String[] names = { getIdentifierColumnName() }; identifierGridType.nullSafeSet( associationRow, identifier, names, session ); } getKeyGridType().nullSafeSet( associationRow, key, getKeyColumnNames(), session ); // No need to write to where as we don't do where clauses in OGM :) if ( hasIndex ) { Object index = collection.getIndex( entry, i, this ); indexGridType.nullSafeSet( associationRow, incrementIndexByBase( index ), getIndexColumnNames(), session ); } // columns of referenced key final Object element = collection.getElement( entry ); getElementGridType().nullSafeSet( associationRow, element, getElementColumnNames(), session ); RowKeyAndTuple result = new RowKeyAndTuple(); result.key = rowKeyBuilder.values( associationRow ).build(); result.tuple = associationRow; associationPersister.getAssociation().put( result.key, result.tuple ); return result; }