Package org.hibernate.ogm.util.impl

Examples of org.hibernate.ogm.util.impl.AssociationPersister


      if ( log.isDebugEnabled() ) {
        log.debug( "Inserting collection: " + MessageHelper.collectionInfoString( this, id, getFactory() ) );
      }

      AssociationPersister associationPersister = new AssociationPersister(
          getOwnerEntityPersister().getMappedClass()
        )
        .hostingEntity( collection.getOwner() )
        .gridDialect( gridDialect )
        .key( id )
        .keyGridType( getKeyGridType() )
        .associationKeyMetadata( associationKeyMetadata )
        .roleOnMainSide( getUnqualifiedRole() )
        .session( session );

      // create all the new entries
      Iterator<?> entries = collection.entries( this );
      if ( entries.hasNext() ) {
        collection.preInsert( this );
        int i = 0;
        int count = 0;
        while ( entries.hasNext() ) {
          final Object entry = entries.next();
          if ( collection.entryExists( entry, i ) ) {
            // TODO: copy/paste from insertRows()
            RowKeyAndTuple keyAndTuple = createAndPutAssociationRowForInsert( id, collection, associationPersister, session, i, entry );
            updateInverseSideOfAssociationNavigation( session, entry, keyAndTuple.tuple, Action.ADD, keyAndTuple.key );
            collection.afterRowInsert( this, entry, i );
            count++;
          }
          i++;
        }

        associationPersister.flushToDatastore();

        if ( log.isDebugEnabled() ) {
          log.debug( "done inserting collection: " + count + " rows inserted" );
        }
View Full Code Here


      if ( inverseAssociationKeymetadata == null ) {
        return;
      }

      AssociationPersister associationPersister = new AssociationPersister(
            getElementPersister().getMappedClass()
          )
          .gridDialect( gridDialect )
          .keyColumnValues( elementColumnValues )
          .session( session )
          .associationKeyMetadata( inverseAssociationKeymetadata )
          .roleOnMainSide( getUnqualifiedRole() )
          .key( entityId );

      // TODO what happens when a row should be *updated* ?: I suspect ADD works OK as it's a put()
      if ( action == Action.ADD ) {
        RowKey inverseRowKey = getInverseRowKey( associationRow );

        Tuple inverseAssociationRow = new Tuple();
        associationPersister.getAssociation().put( inverseRowKey, inverseAssociationRow );
        for ( String columnName : associationRow.getColumnNames() ) {
          inverseAssociationRow.put( columnName, associationRow.get( columnName ) );
        }
        associationPersister.getAssociation().put( inverseRowKey, inverseAssociationRow );
      }
      else if ( action == Action.REMOVE ) {
        // we try and match the whole tuple as it should be on both sides of the navigation
        if ( rowKey == null ) {
          throw new AssertionFailure( "Deleting a collection tuple that is not present: " + "table {"
              + getTableName() + "} key column names {" + Arrays.toString( elementColumnNames )
              + "} key column values {" + Arrays.toString( elementColumnValues ) + "}" );
        }

        RowKey inverseRowKey = getInverseRowKey( associationRow );
        associationPersister.getAssociation().remove( inverseRowKey );
      }
      else {
        throw new AssertionFailure( "Unknown action type: " + action );
      }

      if ( associationPersister.hostingEntityRequiresReadAfterUpdate() && entity == null ) {
        entity = session.getPersistenceContext().getEntity( session.generateEntityKey( entityId, getElementPersister() ) );
      }

      associationPersister.hostingEntity( entity );

      associationPersister.flushToDatastore();
    }
  }
View Full Code Here

      if ( log.isDebugEnabled() ) {
        log.debug( "Deleting collection: " + MessageHelper.collectionInfoString( this, id, getFactory() ) );
      }

      // Remove all the old entries
      AssociationPersister associationPersister = new AssociationPersister(
            getOwnerEntityPersister().getMappedClass()
          )
          .gridDialect( gridDialect )
          .key( id )
          .keyGridType( getKeyGridType() )
          .associationKeyMetadata( associationKeyMetadata )
          .roleOnMainSide( getUnqualifiedRole() )
          .session( session );

      Association association = associationPersister.getAssociationOrNull();

      if ( association != null ) {
        // shortcut to avoid loop if we can
        if ( associationType != AssociationType.OTHER ) {
          for ( RowKey assocEntryKey : association.getKeys() ) {
            // we unfortunately cannot mass change the update of the associated entity
            updateInverseSideOfAssociationNavigation(
                session,
                null,
                association.get( assocEntryKey ),
                Action.REMOVE,
                assocEntryKey
                );
          }
        }
        association.clear();

        if ( associationPersister.hostingEntityRequiresReadAfterUpdate() ) {
          Object owner = session.getPersistenceContext().getCollectionOwner( id, this );
          associationPersister.hostingEntity( owner );
        }

        associationPersister.flushToDatastore();
      }

      if ( log.isDebugEnabled() ) {
        log.debug( "done deleting collection" );
      }
View Full Code Here

TOP

Related Classes of org.hibernate.ogm.util.impl.AssociationPersister

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.