org.hibernate.ogm.model.spi.Association类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中org.hibernate.ogm.model.spi.Association类的一些代码示例,展示了Association类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Association类的具体详情如下:
包路径:org.hibernate.ogm.model.spi.Association
类名称:Association

Association介绍

[英]Represents an association (think of it as a set of rows, each representing a specific link).

An association accepts a AssociationSnapshot which is a read-only state of the association when read from the database or freshly created.

An association collects changes applied to it. These changes are represented by a list of AssociationOperation. It is intended that GridDialects retrieve these actions and apply them to the datastore. The list of changes is computed against the snapshot.

Note that the Tuples representing association rows always also contain the columns of their RowKey.
[中]表示关联(将其视为一组行,每个行表示一个特定链接)。
关联接受AssociationSnapshot,该快照是从数据库读取或新创建时关联的只读状态。
关联收集应用于它的更改。这些更改由AssociationOperation列表表示。GridDiagnols旨在检索这些操作并将其应用于数据存储。根据快照计算更改列表。
请注意,表示关联行的元组也始终包含其RowKey的列。

代码示例

代码示例来源:origin: hibernate/hibernate-ogm

@Override
public Association createAssociation(AssociationKey associationKey, AssociationContext associationContext) {
  return new Association();
}

代码示例来源:origin: hibernate/hibernate-ogm

public static void updateAssociation(Association association) {
  Map<RowKey, Map<String, Object>> underlyingMap = ( (MapAssociationSnapshot) association.getSnapshot() ).getUnderlyingMap();
  for ( AssociationOperation action : association.getOperations() ) {
    switch ( action.getType() ) {
      case CLEAR:
        underlyingMap.clear();
        break;
      case PUT:
        underlyingMap.put( action.getKey(), MapHelpers.associationRowToMap( action.getValue() ) );
        break;
      case REMOVE:
        underlyingMap.remove( action.getKey() );
        break;
    }
  }
  // the snapshot has been updated so we have to clear the various operations added to the Association
  association.reset();
}

代码示例来源:origin: hibernate/hibernate-ogm

@Override
  public String toString() {
    StringBuilder sb = new StringBuilder( "Association[" ).append( StringHelper.lineSeparator() );

    Iterator<RowKey> rowKeys = getKeys().iterator();

    while ( rowKeys.hasNext() ) {
      RowKey rowKey = rowKeys.next();
      sb.append( "  " ).append( rowKey ).append( "=" ).append( get( rowKey ) );

      if ( rowKeys.hasNext() ) {
        sb.append( "," ).append( StringHelper.lineSeparator() );
      }
    }

    sb.append( StringHelper.lineSeparator() ).append( "]" );
    return sb.toString();
  }
}

代码示例来源:origin: hibernate/hibernate-ogm

@Override
public Association createAssociation(AssociationKey key, AssociationContext associationContext) {
  AssociationStorageStrategy storageStrategy = getAssociationStorageStrategy( key, associationContext );
  Document document = storageStrategy == AssociationStorageStrategy.IN_ENTITY
      ? getEmbeddingEntity( key, associationContext )
      : associationKeyToObject( key, storageStrategy );
  Association association = new Association( new MongoDBAssociationSnapshot( document, key, storageStrategy ) );
  // in the case of an association stored in the entity structure, we might end up with rows present in the
  // current snapshot of the entity while we want an empty association here. So, in this case, we clear the
  // snapshot to be sure the association created is empty.
  if ( !association.isEmpty() ) {
    association.clear();
  }
  return association;
}

代码示例来源:origin: hibernate/hibernate-ogm

/**
 * Whether the rows of the given association should be stored in a hash using the single row key column as key or
 * not.
 */
public static boolean organizeAssociationMapByRowKey(
    org.hibernate.ogm.model.spi.Association association,
    AssociationKey key,
    AssociationContext associationContext) {
  if ( association.isEmpty() ) {
    return false;
  }
  if ( key.getMetadata().getRowKeyIndexColumnNames().length != 1 ) {
    return false;
  }
  Object valueOfFirstRow = association.get( association.getKeys().iterator().next() )
      .get( key.getMetadata().getRowKeyIndexColumnNames()[0] );
  if ( !( valueOfFirstRow instanceof String ) ) {
    return false;
  }
  // The list style may be explicitly enforced for compatibility reasons
  return getMapStorage( associationContext ) == MapStorageType.BY_KEY;
}

代码示例来源:origin: org.hibernate.ogm/hibernate-ogm-couchdb

Map<String, Object> rows = new HashMap<>();
  for ( RowKey rowKey : association.getKeys() ) {
    Map<String, Object> row = (Map<String, Object>) getAssociationRow( association.get( rowKey ), associationKey );
List<Object> rows = new ArrayList<Object>( association.size() );
for ( RowKey rowKey : association.getKeys() ) {
  rows.add( getAssociationRow( association.get( rowKey ), associationKey ) );

代码示例来源:origin: hibernate/hibernate-ogm

@Override
public void insertOrUpdateAssociation(AssociationKey key, Association association, AssociationContext associationContext) {
  // If this is the inverse side of a bi-directional association, we don't create a relationship for this; this
  // will happen when updating the main side
  if ( key.getMetadata().isInverse() ) {
    return;
  }
  for ( AssociationOperation action : association.getOperations() ) {
    applyAssociationOperation( association, key, action, associationContext );
  }
}

代码示例来源:origin: hibernate/hibernate-ogm

for ( RowKey assocEntryKey : association.getKeys() ) {
    Tuple associationRow = association.get( assocEntryKey );
    Serializable entityId = (Serializable) gridTypeOfAssociatedId.nullSafeGet( associationRow, getElementColumnNames(), session, null );
    @SuppressWarnings("unchecked")
association.clear();

代码示例来源:origin: org.hibernate.ogm/hibernate-ogm-ignite

boolean thirdTableAssociation = IgniteAssociationSnapshot.isThirdTableAssociation( key.getMetadata() );
for ( AssociationOperation op : association.getOperations() ) {
  AssociationSnapshot snapshot = association.getSnapshot();
  Tuple previousStateTuple = snapshot.get( op.getKey() );
  Tuple currentStateTuple = op.getValue();
for ( AssociationOperation op : association.getOperations() ) {
  int index = findIndexByRowKey( associationObjects, op.getKey(), indexColumnName );
  switch ( op.getType() ) {

代码示例来源:origin: hibernate/hibernate-ogm

@Override
public void insertOrUpdateAssociation(AssociationKey key, Association association, AssociationContext associationContext) {
  MapHelpers.updateAssociation( association );
  // the association might have been removed prior to the update so we need to be sure it is present in the Map
  provider.putAssociation( key, ( (MapAssociationSnapshot) association.getSnapshot() ).getUnderlyingMap() );
}

代码示例来源:origin: hibernate/hibernate-ogm

/**
 * 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();
}

代码示例来源:origin: hibernate/hibernate-ogm

private void removeNavigationInformation(Serializable id, Object entity, SharedSessionContractImplementor session) {
  for ( int propertyIndex = 0; propertyIndex < getEntityMetamodel().getPropertySpan(); propertyIndex++ ) {
    if ( propertyMightHaveNavigationalInformation[propertyIndex] ) {
      CollectionType collectionType = (CollectionType) getPropertyTypes()[propertyIndex];
      OgmCollectionPersister collectionPersister = (OgmCollectionPersister) getFactory()
          .getMetamodel().collectionPersister( collectionType.getRole() );
      AssociationPersister associationPersister = new AssociationPersister.Builder( collectionPersister.getOwnerEntityPersister().getMappedClass() )
          .hostingEntity( entity )
          .gridDialect( gridDialect )
          .key( id, collectionPersister.getKeyGridType() )
          .associationKeyMetadata( collectionPersister.getAssociationKeyMetadata() )
          .associationTypeContext( collectionPersister.getAssociationTypeContext() )
          .session( session )
          .build();
      Association association = associationPersister.getAssociationOrNull();
      if ( association != null && !association.isEmpty() ) {
        association.clear();
        associationPersister.flushToDatastore();
      }
    }
  }
}

代码示例来源:origin: hibernate/hibernate-ogm

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 );

代码示例来源:origin: hibernate/hibernate-ogm

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 );

代码示例来源:origin: hibernate/hibernate-ogm

private void removeNavigationalInformationFromInverseSide(int propertyIndex, AssociationKeyMetadata associationKeyMetadata, Object[] oldColumnValue) {
  // If the association involves entities deleted by a previous operation of the current batch,
  // it does not make sense trying to update association itself
  EntityKey entityKey = new EntityKey( associationKeyMetadata.getEntityKeyMetadata(), oldColumnValue );
  if ( gridDialect instanceof BatchOperationsDelegator && ( (BatchOperationsDelegator) gridDialect ).isMarkedForRemoval( entityKey ) ) {
    return;
  }
  AssociationPersister associationPersister = createInverseAssociationPersister( propertyIndex, associationKeyMetadata, oldColumnValue );
  Association association = associationPersister.getAssociationOrNull();
  // The association might be empty if the navigation information have already been removed.
  // This typically happens when the entity owning the inverse association has already been deleted prior to
  // deleting the entity owning the association and a {@code @NotFound(action = NotFoundAction.IGNORE)} is
  // involved.
  if ( association != null && !association.isEmpty() ) {
    RowKey rowKey = getInverseRowKey( associationKeyMetadata, oldColumnValue );
    association.remove( rowKey );
    associationPersister.flushToDatastore();
  }
}

代码示例来源:origin: org.hibernate.ogm/hibernate-ogm-infinispan-remote

private void insertOrUpdateAssociation(InsertOrUpdateAssociationOperation insertOrUpdateAssociationOperation) {
  AssociationKey associationKey = insertOrUpdateAssociationOperation.getAssociationKey();
  org.hibernate.ogm.model.spi.Association association = insertOrUpdateAssociationOperation.getAssociation();
  AssociationContext associationContext = insertOrUpdateAssociationOperation.getContext();
  if ( !associationStoredWithinEntityEntry( associationKey, associationContext ) ) {
    insertOrUpdateAssociationMappedAsDedicatedEntries( associationKey, association, associationContext );
  }
  association.reset();
}

代码示例来源:origin: org.hibernate.ogm/hibernate-ogm-mongodb

@Override
public Association createAssociation(AssociationKey key, AssociationContext associationContext) {
  AssociationStorageStrategy storageStrategy = getAssociationStorageStrategy( key, associationContext );
  Document document = storageStrategy == AssociationStorageStrategy.IN_ENTITY
      ? getEmbeddingEntity( key, associationContext )
      : associationKeyToObject( key, storageStrategy );
  Association association = new Association( new MongoDBAssociationSnapshot( document, key, storageStrategy ) );
  // in the case of an association stored in the entity structure, we might end up with rows present in the
  // current snapshot of the entity while we want an empty association here. So, in this case, we clear the
  // snapshot to be sure the association created is empty.
  if ( !association.isEmpty() ) {
    association.clear();
  }
  return association;
}

代码示例来源:origin: hibernate/hibernate-ogm

if ( ids == null || ids.size() == 0 ) {
  return null;
else if ( ids.size() == 1 ) {
  Tuple tuple = ids.get( ids.getKeys().iterator().next() );
  final Serializable id = (Serializable) getGridIdentifierType().nullSafeGet( tuple, getIdentifierColumnNames(), session, null );
  return load( id, null, LockMode.NONE, session );

代码示例来源:origin: hibernate/hibernate-ogm

@Override
public void insertOrUpdateAssociation(AssociationKey key, Association association, AssociationContext associationContext) {
  // If this is the inverse side of a bi-directional association, we don't create a relationship for this; this
  // will happen when updating the main side
  if ( key.getMetadata().isInverse() ) {
    return;
  }
  for ( AssociationOperation action : association.getOperations() ) {
    applyAssociationOperation( association, key, action, associationContext );
  }
}

代码示例来源:origin: hibernate/hibernate-ogm

@Override
public void insertOrUpdateAssociation(AssociationKey key, Association association, AssociationContext associationContext) {
  if ( association.getSnapshot().size() == 0 ) {
    log.tracef( "Creating association with key %1$s in datastore", key );
  }
  else {
    log.tracef( "Updating association with key %1$s in datastore", key );
  }
  super.insertOrUpdateAssociation( key, association, associationContext );
}

相关文章