Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Hibernate OGM, Domain model persistence for NoSQL datastores
   *
   * License: GNU Lesser General Public License (LGPL), version 2.1 or later
   * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
   */
  package org.hibernate.ogm.persister.impl;
  
 
Updates the inverse side of bi-directional many-to-one/one-to-one associations, managed by the entity on the main side.

Tied to one specific entity on the main side, so instances of this class must not be cached or re-used.

Author(s):
Gunnar Morling
Emmanuel Bernard
 
 
 	private static final Log log = LoggerFactory.make();
 
 	private final OgmEntityPersister persister;
 
 	private final GridDialect gridDialect;
 	private Tuple resultset;
 	private int tableIndex;
 	private Serializable id;
 
 		this. = persister;
 		this. = persister.getFactory().getServiceRegistry().getServiceGridDialect.class );
 	}
 
 	// fluent methods populating data
 
Sets the tuple representing the entity whose inverse associations should be updated.
 
 	public EntityAssociationUpdater resultset(Tuple resultset) {
 		this. = resultset;
 		return this;
 	}
 
 	public EntityAssociationUpdater tableIndex(int tableIndex) {
 		this. = tableIndex;
 		return this;
 	}
 
 		this. = id;
 		return this;
 	}
 
 		this. = session;
 		return this;
 	}
 
 	public EntityAssociationUpdater propertyMightRequireInverseAssociationManagement(boolean[] propertyInverseAssociationManagementMayBeRequired) {
 		this. = propertyInverseAssociationManagementMayBeRequired;
 		return this;
 	}
 
 	//action methods
 
Updates all inverse associations managed by a given entity.
 
 		if ( .isTraceEnabled() ) {
 			.trace"Adding inverse navigational information for entity: " + MessageHelper.infoString.getFactory() ) );
 		}
 
 		for ( int propertyIndex = 0; propertyIndex < .getEntityMetamodel().getPropertySpan(); propertyIndex++ ) {
 			if ( .isPropertyOfTablepropertyIndex ) ) {
				AssociationKeyMetadata associationKeyMetadata = getInverseAssociationKeyMetadatapropertyIndex );
				// there is no inverse association for the given property
				if ( associationKeyMetadata == null ) {
					continue;
				}
				Object[] newColumnValues = LogicalPhysicalConverterHelper.getColumnValuesFromResultset(
				);
				//don't index null columns, this means no association
				if ( ! CollectionHelper.isEmptyOrContainsOnlyNull( ( newColumnValues ) ) ) {
					addNavigationalInformationForInverseSidepropertyIndexassociationKeyMetadatanewColumnValues );
				}
			}
		}
	}

Removes all inverse associations managed by a given entity.
		if ( .isTraceEnabled() ) {
			.trace"Removing inverse navigational information for entity: " + MessageHelper.infoString.getFactory() ) );
		}
		for ( int propertyIndex = 0; propertyIndex < .getEntityMetamodel().getPropertySpan(); propertyIndex++ ) {
			if ( .isPropertyOfTablepropertyIndex ) ) {
				AssociationKeyMetadata associationKeyMetadata = getInverseAssociationKeyMetadatapropertyIndex );
				// there is no inverse association for the given property
				if ( associationKeyMetadata == null ) {
					continue;
				}
				Object[] oldColumnValues = LogicalPhysicalConverterHelper.getColumnValuesFromResultset(
				);
				//don't index null columns, this means no association
				if ( ! CollectionHelper.isEmptyOrContainsOnlyNulloldColumnValues ) ) {
					removeNavigationalInformationFromInverseSidepropertyIndexassociationKeyMetadataoldColumnValues );
				}
			}
		}
	}
	private void addNavigationalInformationForInverseSide(int propertyIndexAssociationKeyMetadata associationKeyMetadataObject[] newColumnValue) {
		AssociationPersister associationPersister = createAssociationPersisterpropertyIndexassociationKeyMetadatanewColumnValue );
		RowKey rowKey = getInverseRowKeyassociationKeyMetadatanewColumnValue );
		Tuple associationRow = new Tuple();
		for ( String column : rowKey.getColumnNames() ) {
			associationRow.putcolumnrowKey.getColumnValuecolumn ) );
		}
		associationPersister.getAssociation().putrowKeyassociationRow );
		associationPersister.flushToDatastore();
	}
	private void removeNavigationalInformationFromInverseSide(int propertyIndexAssociationKeyMetadata associationKeyMetadataObject[] oldColumnValue) {
		AssociationPersister associationPersister = createAssociationPersisterpropertyIndexassociationKeyMetadataoldColumnValue );
		Association association = associationPersister.getAssociationOrNull();
		if ( association != null ) {
			RowKey rowKey = getInverseRowKeyassociationKeyMetadataoldColumnValue );
			association.removerowKey );
			associationPersister.flushToDatastore();
		}
	}
	private AssociationPersister createAssociationPersister(int propertyIndexAssociationKeyMetadata associationKeyMetadataObject[] keyColumnValues) {
		AssociationTypeContext associationTypeContext = new AssociationTypeContextImpl(
				serviceContext.getPropertyOptions.getPropertyTypes()[propertyIndex].getReturnedClass(), associationKeyMetadata.getCollectionRole() ),
				associationKeyMetadata.getAssociatedEntityKeyMetadata(),
				.getPropertyNames()[propertyIndex]
		);
				)
				.hostingEntitygetReferencedEntitypropertyIndex ) )
				.associationKeyMetadata(  associationKeyMetadata )
				.keyColumnValueskeyColumnValues )
				.associationTypeContextassociationTypeContext );
	}

Returns the object referenced by the specified property (which represents an association).
	private Object getReferencedEntity(int propertyIndex) {
		GridType propertyType = .getGridPropertyTypes()[propertyIndex];
		Serializable id = (SerializablepropertyType.hydrate(
				.getPropertyColumnNamespropertyIndex ), null
		);
		if ( id != null ) {
					propertyType.getReturnedClass().getName()
			);
					.generateEntityKeyidhostingEntityPersister )
			);
		}
		return null;
	}

Gets the row key of the inverse association represented by the given meta-data, pointing the entity with current id

Parameters:
associationKeyMetadata meta-data for the inverse association of interest
associationColumnValues the column values identifying the entity on the inverse side of the association
Returns:
the row key of the inverse association
	private RowKey getInverseRowKey(AssociationKeyMetadata associationKeyMetadataObject[] associationColumnValues) {
		Tuple rowKeyValues = new Tuple();
		// add the fk column
		for (int index = 0 ; index < associationKeyMetadata.getColumnNames().length ; index++) {
			rowKeyValues.putassociationKeyMetadata.getColumnNames()[index], associationColumnValues[index] );
		}
		// add the id column
		return new RowKeyBuilder()
			.addColumnsassociationKeyMetadata.getRowKeyColumnNames() )
			.valuesrowKeyValues )
	}
		// a quick test for excluding properties which for sure don't manage an inverse association
			return null;
		}
		return BiDirectionalAssociationHelper.getInverseAssociationKeyMetadatapropertyIndex );
	}
New to GrepCode? Check out our FAQ X