Package org.hibernate.ogm.util.impl

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


        throw new AssertionFailure( "Found an unexpected number of collection persisters: " + getCollectionPersisters().length );
      }
      final OgmCollectionPersister persister = (OgmCollectionPersister) getCollectionPersisters()[0];
      Object owner = session.getPersistenceContext().getCollectionOwner( id, persister );

      AssociationPersister associationPersister = new AssociationPersister(
          persister.getOwnerEntityPersister().getMappedClass()
        )
        .gridDialect( gridDialect )
        .key( id, persister.getKeyGridType() )
        .associationKeyMetadata( persister.getAssociationKeyMetadata() )
        .associationTypeContext( persister.getAssociationTypeContext() )
        .hostingEntity( owner )
        .session( session );

      Association assoc = associationPersister.getAssociationOrNull();
      if ( assoc != null ) {
        for ( RowKey rowKey : assoc.getKeys() ) {
          resultset.addTuple( assoc.get( rowKey ) );
        }
      }
View Full Code Here


      return 0;
    }
    int count = 0;
    int i = 0;
    Iterator<?> entries = collection.entries( this );
    AssociationPersister associationPersister = getAssociationPersister( collection.getOwner(), key, session );

    while ( entries.hasNext() ) {
      Object entry = entries.next();
      if ( collection.needsUpdating( entry, i, elementType ) ) {
        // find the matching element
        RowKey assocEntryKey = getTupleKeyForUpdate( key, collection, session, i, entry, associationPersister );
        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 + "}" );
        }
        // update the matching element
        // FIXME update the associated entity key data
        updateInverseSideOfAssociationNavigation( session, entry, assocEntryTuple, Action.REMOVE, assocEntryKey );

        getElementGridType().nullSafeSet(
            assocEntryTuple,
            collection.getElement( entry ),
            getElementColumnNames(),
            session
        );

        // put back entry tuple to actually apply changes to the store
        associationPersister.getAssociation().put( assocEntryKey, assocEntryTuple );

        updateInverseSideOfAssociationNavigation( session, entry, assocEntryTuple, Action.ADD, assocEntryKey );

        count++;
      }
      i++;
    }

    // need to put the data back in the cache
    associationPersister.flushToDatastore();

    return count;
  }
View Full Code Here

    return rowKeyBuilder.build();
  }

  @Override
  public int getSize(Serializable key, SessionImplementor session) {
    AssociationPersister associationPersister = getAssociationPersister( session.getPersistenceContext().getEntity( new org.hibernate.engine.spi.EntityKey( key, getOwnerEntityPersister() ) ), key, session );
    final Association collectionMetadata = associationPersister.getAssociationOrNull();

    return collectionMetadata == null ? 0 : collectionMetadata.size();
  }
View Full Code Here

        log.debug( "Deleting rows of collection: " + MessageHelper.collectionInfoString( this, id, getFactory() ) );
      }

      boolean deleteByIndex = !isOneToMany() && hasIndex && !indexContainsFormula;

      AssociationPersister associationPersister = getAssociationPersister( collection.getOwner(), id, session );

      // delete all the deleted entries
      Iterator<?> deletes = collection.getDeletes( this, !deleteByIndex );
      if ( deletes.hasNext() ) {
        int count = 0;
        while ( deletes.hasNext() ) {
          Object entry = deletes.next();
          // find the matching element
          RowKey assocEntryKey = getTupleKeyForDelete( id, collection, session, entry, deleteByIndex, associationPersister );
          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 + "}" );
          }
          // delete the tuple
          updateInverseSideOfAssociationNavigation( session, entry, assocEntryTuple, Action.REMOVE, assocEntryKey );
          associationPersister.getAssociation().remove( assocEntryKey );

          count++;
        }

        associationPersister.flushToDatastore();

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

      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, 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" );
      }
    }
View Full Code Here

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

      AssociationPersister associationPersister = getAssociationPersister( collection.getOwner(), id, 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 ( entity == null ) {
        entity = session.getPersistenceContext().getEntity( session.generateEntityKey( entityId, getElementPersister() ) );
      }

      AssociationPersister associationPersister = inverseCollectionPersister.getAssociationPersister( entity, elementColumnValues, session );

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

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

      }

      Object owner = session.getPersistenceContext().getCollectionOwner( id, this );

      // Remove all the old entries
      AssociationPersister associationPersister = getAssociationPersister( owner, id, 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();

        associationPersister.flushToDatastore();
      }

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

    return associationTypeContext;
  }

  private AssociationPersister getAssociationPersister(Object collectionOwner, Serializable id, SessionImplementor session) {
    return new AssociationPersister(
        getOwnerEntityPersister().getMappedClass()
      )
      .hostingEntity( collectionOwner )
      .gridDialect( gridDialect )
      .key( id, getKeyGridType() )
View Full Code Here

      .associationTypeContext( associationTypeContext )
      .session( session );
  }

  private AssociationPersister getAssociationPersister(Object collectionOwner, Object[] keyColumnValues, SessionImplementor session) {
    return new AssociationPersister(
        getOwnerEntityPersister().getMappedClass()
      )
      .hostingEntity( collectionOwner )
      .gridDialect( gridDialect )
      .keyColumnValues( keyColumnValues )
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.