Package org.hibernate.ogm.util.impl

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


    String[] rowKeyColumnNames = buildRowKeyColumnNamesForStarToOne( persister, propertyColumnNames );

    AssociationKeyMetadata associationKeyMetadata = new AssociationKeyMetadata( persister.getTableName( tableIndex ), propertyColumnNames );
    associationKeyMetadata.setRowKeyColumnNames( rowKeyColumnNames );

    AssociationPersister associationPersister = new AssociationPersister(
          persister.getPropertyTypes()[propertyIndex].getReturnedClass()
        )
        .hostingEntity( getReferencedEntity( propertyIndex ) )
        .gridDialect( gridDialect )
        .associationKeyMetadata( associationKeyMetadata )
        .keyColumnValues( oldColumnValue )
        .session( session )
        //does not set .collectionPersister as it does not make sense here for a ToOne or a unique key
        .propertyType( persister.getPropertyTypes()[propertyIndex] );
    //add fk column value in TupleKey
    Tuple tupleKey = new Tuple();
    for (int index = 0 ; index < propertyColumnNames.length ; index++) {
      tupleKey.put( propertyColumnNames[index], oldColumnValue[index] );
    }
    //add id value in TupleKey
    gridIdentifierType.nullSafeSet( tupleKey, id, persister.getIdentifierColumnNames(), session );

    Association propertyValues = associationPersister.getAssociation();
    if ( propertyValues != null ) {
      //Map's equals operation delegates to all it's key and value, should be fine for now
      //this is a StarToOne case ie the FK is on the owning entity
      final RowKey matchingTuple = new RowKeyBuilder()
          .tableName( persister.getTableName() )
          .addColumns( buildRowKeyColumnNamesForStarToOne( persister, propertyColumnNames ) )
          .values( tupleKey )
          .build();
      //TODO what should we do if that's null?
      associationPersister.getAssociation().remove( matchingTuple );

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


      throw new AssertionFailure( "loadByUniqueKey on a non EntityType:" + propertyName );
    }

    OgmEntityPersister inversePersister = (OgmEntityPersister) ((EntityType) getPropertyTypes()[propertyIndex]).getAssociatedJoinable( session.getFactory() );

    AssociationPersister associationPersister = new AssociationPersister(
        inversePersister.getMappedClass()
        )
        .gridDialect( gridDialect )
        .key( uniqueKey )
        .keyGridType( gridUniqueKeyType )
        .associationKeyMetadata( associationKeyMetadata )
        .session( session )
        .roleOnMainSide( getPropertyNames()[propertyIndex] );

    final Association ids = associationPersister.getAssociationOrNull();

    if (ids == null || ids.size() == 0 ) {
      return null;
    }
    else if (ids.size() == 1) {
View Full Code Here

      if ( getCollectionPersisters().length != 1 ) {
        throw new AssertionFailure( "Found an unexpected number of collection persisters: " + getCollectionPersisters().length );
      }
      final OgmCollectionPersister persister = (OgmCollectionPersister) getCollectionPersisters()[0];

      AssociationPersister associationPersister = new AssociationPersister(
          persister.getOwnerEntityPersister().getMappedClass()
        )
        .gridDialect( gridDialect )
        .key( id )
        .keyGridType( persister.getKeyGridType() )
        .associationKeyMetadata( persister.getAssociationKeyMetadata() )
        // we can be on the main or on the inverse side, so we cannot simply use the unqualified role
        .roleOnMainSide( persister.getMainSidePropertyName() )
        .session( session );

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

      }
    }
  }

  private void addNavigationalInformationForInverseSide(int propertyIndex, AssociationKeyMetadata associationKeyMetadata, Object[] newColumnValue) {
    AssociationPersister associationPersister = createAssociationPersister( propertyIndex, associationKeyMetadata, newColumnValue );

    RowKey rowKey = getInverseRowKey( associationKeyMetadata, newColumnValue );

    Tuple associationRow = new Tuple();
    for ( String column : rowKey.getColumnNames() ) {
      associationRow.put( column, rowKey.getColumnValue( column ) );
    }
    associationPersister.getAssociation().put( rowKey, associationRow );

    associationPersister.flushToDatastore();
  }
View Full Code Here

    associationPersister.flushToDatastore();
  }

  private void removeNavigationalInformationFromInverseSide(int propertyIndex, AssociationKeyMetadata associationKeyMetadata, Object[] oldColumnValue) {
    AssociationPersister associationPersister = createAssociationPersister( propertyIndex, associationKeyMetadata, oldColumnValue );

    Association association = associationPersister.getAssociation();

    if ( association != null ) {
      RowKey rowKey = getInverseRowKey( associationKeyMetadata, oldColumnValue );
      association.remove( rowKey );
      associationPersister.flushToDatastore();
    }
  }
View Full Code Here

      associationPersister.flushToDatastore();
    }
  }

  private AssociationPersister createAssociationPersister(int propertyIndex, AssociationKeyMetadata associationKeyMetadata, Object[] keyColumnValues) {
    return new AssociationPersister(
          persister.getPropertyTypes()[propertyIndex].getReturnedClass()
        )
        .hostingEntity( getReferencedEntity( propertyIndex ) )
        .gridDialect( gridDialect )
        .associationKeyMetadataassociationKeyMetadata )
View Full Code Here

      return 0;
    }
    int count = 0;
    int i = 0;
    Iterator<?> entries = collection.entries( this );
    AssociationPersister associationPersister = new AssociationPersister(
          getOwnerEntityPersister().getMappedClass()
        )
        .hostingEntity( collection.getOwner() )
        .gridDialect( gridDialect )
        .key( key )
        .keyGridType( getKeyGridType() )
        .associationKeyMetadata( associationKeyMetadata )
        .roleOnMainSide( getUnqualifiedRole() )
        .session( 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 = new AssociationPersister(
          getOwnerEntityPersister().getMappedClass()
        )
        .key( key )
        .session( session )
        .gridDialect( gridDialect )
        .keyGridType( getKeyGridType() )
        .associationKeyMetadata( associationKeyMetadata )
        .roleOnMainSide( mainSidePropertyName );

    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 = new AssociationPersister(
          getOwnerEntityPersister().getMappedClass()
        )
        .hostingEntity( collection.getOwner() )
        .gridDialect( gridDialect )
        .key( id )
        .keyGridType( getKeyGridType() )
        .associationKeyMetadata( associationKeyMetadata )
        .roleOnMainSide( getUnqualifiedRole() )
        .session( 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 = new AssociationPersister(
          getOwnerEntityPersister().getMappedClass()
        )
        .hostingEntity( collection.getOwner() )
        .gridDialect( gridDialect )
        .key( id )
        .keyGridType( getKeyGridType() )
        .associationKeyMetadata( associationKeyMetadata )
        .roleOnMainSide( getUnqualifiedRole() )
        .session( 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

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.