Package org.hibernate.ogm.model.spi

Examples of org.hibernate.ogm.model.spi.Tuple


   * persister.
   */
  private RowKeyAndTuple createAndPutAssociationRowForInsert(Serializable key, PersistentCollection collection,
      AssociationPersister associationPersister, SessionImplementor session, int i, Object entry) {
    RowKeyBuilder rowKeyBuilder = initializeRowKeyBuilder();
    Tuple associationRow = new Tuple();

    // the collection has a surrogate key (see @CollectionId)
    if ( hasIdentifier ) {
      final Object identifier = collection.getIdentifier( entry, i );
      String[] names = { getIdentifierColumnName() };
View Full Code Here


    return builder;
  }

  private RowKey getTupleKeyForUpdate(Serializable key, PersistentCollection collection, SessionImplementor session, int i, Object entry, AssociationPersister associationPersister) {
    RowKeyBuilder rowKeyBuilder = initializeRowKeyBuilder();
    Tuple tuple = new Tuple();
    if ( hasIdentifier ) {
      final Object identifier = collection.getIdentifier( entry, i );
      String[] names = { getIdentifierColumnName() };
      identifierGridType.nullSafeSet( tuple, identifier, names, session );
    }
View Full Code Here

    return rowKeyBuilder.build();
  }

  private RowKey getTupleKeyForDelete(Serializable key, PersistentCollection collection, SessionImplementor session, Object entry, boolean findByIndex, AssociationPersister associationPersister) {
    RowKeyBuilder rowKeyBuilder = initializeRowKeyBuilder();
    Tuple tuple = new Tuple();
    if ( hasIdentifier ) {
      final Object identifier = entry;
      String[] names = { getIdentifierColumnName() };
      identifierGridType.nullSafeSet( tuple, identifier, names, session );
    }
View Full Code Here

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

      // update the associated object
      Serializable entityId = (Serializable) gridTypeOfAssociatedId.nullSafeGet( associationRow, getElementColumnNames(), session, null );
      OgmEntityPersister persister = (OgmEntityPersister) getElementPersister();
      final EntityKey entityKey = EntityKeyBuilder.fromPersister( persister, entityId, session );

      final Tuple entityTuple = gridDialect.getTuple( entityKey, persister.getTupleContext() );
      // the entity tuple could already be gone (not 100% sure this can happen but that feels right)
      if ( entityTuple == null ) {
        return;
      }
      if ( action == Action.ADD ) {
        // copy all collection tuple entries in the entity tuple as this is the same table essentially
        for ( String columnName : associationRow.getColumnNames() ) {
          entityTuple.put( columnName, associationRow.get( columnName ) );
        }
      }
      else if ( action == Action.REMOVE ) {
        if ( hasIdentifier ) {
          throw new AssertionFailure( "A true OneToMany with an identifier for the collection: " + getRole() );
        }
        if ( hasIndex ) {
          // nullify the index
          indexGridType.nullSafeSet( entityTuple, null, getIndexColumnNames(), session );
        }
        keyGridType.nullSafeSet( entityTuple, null, getKeyColumnNames(), session );
      }
      else {
        throw new AssertionFailure( "Unknown action type: " + action );
      }
      gridDialect.insertOrUpdateTuple( entityKey, entityTuple, persister.getTupleContext() ); // update cache
    }
    else if ( associationType == AssociationType.ASSOCIATION_TABLE_TO_ENTITY ) {
      String[] elementColumnNames = getElementColumnNames();
      Object[] elementColumnValues = LogicalPhysicalConverterHelper.getColumnValuesFromResultset( associationRow, elementColumnNames );
      Serializable entityId = (Serializable) gridTypeOfAssociatedId.nullSafeGet( associationRow, getElementColumnNames(), session, null );

      if ( inverseCollectionPersister == null ) {
        return;
      }

      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
View Full Code Here

    }
  }

  @Override
  public Tuple getTuple(EntityKey key, TupleContext tupleContext) {
    Tuple tuple = super.getTuple( key, tupleContext );
    log( "getTuple", key.toString(), tuple != null ? tuple.toString() : "null" );
    return tuple;
  }
View Full Code Here

    return tuple;
  }

  @Override
  public Tuple createTuple(EntityKey key, TupleContext tupleContext) {
    Tuple tuple = super.createTuple( key, tupleContext );
    log( "createTuple", key.toString(), tuple != null ? tuple.toString() : "null" );
    return tuple;
  }
View Full Code Here

    }

    @Override
    public Tuple next() {
      DBObject dbObject = cursor.next();
      return new Tuple( new MongoDBTupleSnapshot( dbObject, metadata, UPDATE ) );
    }
View Full Code Here

  @JsonIgnore
  public List<Tuple> getTuples() {
    List<Tuple> tuples = new ArrayList<Tuple>( rows.size() );
    if ( rows.size() > 0 ) {
      for ( Row row : rows ) {
        tuples.add( new Tuple( new CouchDBTupleSnapshot( row.getValue().getProperties() ) ) );
      }
    }
    return tuples;
  }
View Full Code Here

  @Override
  public Tuple getTuple(EntityKey key, TupleContext tupleContext) {
    DBObject found = this.getObject( key, tupleContext );
    if ( found != null ) {
      return new Tuple( new MongoDBTupleSnapshot( found, key.getMetadata(), UPDATE ) );
    }
    else if ( isInTheQueue( key, tupleContext ) ) {
      // The key has not been inserted in the db but it is in the queue
      return new Tuple( new MongoDBTupleSnapshot( prepareIdObject( key ), key.getMetadata(), INSERT ) );
    }
    else {
      return null;
    }
  }
View Full Code Here

TOP

Related Classes of org.hibernate.ogm.model.spi.Tuple

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.