Package org.hibernate.ogm.model.spi

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


  public Object getCurrentVersion(Serializable id, SessionImplementor session) throws HibernateException {

    if ( log.isTraceEnabled() ) {
      log.trace( "Getting version: " + MessageHelper.infoString( this, id, getFactory() ) );
    }
    final Tuple resultset = getResultsetById( id, session );

    if (resultset == null) {
      return null;
    }
    else {
View Full Code Here


     * We get the value from the grid and compare the version values before putting the next version in
     * Contrary to the database version, there is
     * TODO should we use cache.replace() it seems more expensive to pass the resultset around "just" the atomicity of the operation
     */
    final EntityKey key = EntityKeyBuilder.fromPersister( this, id, session );
    final Tuple resultset = gridDialect.getTuple( key, getTupleContext() );
    checkVersionAndRaiseSOSE( id, currentVersion, session, resultset );
    gridVersionType.nullSafeSet( resultset, nextVersion, new String[] { getVersionColumnName() }, session );
    gridDialect.insertOrUpdateTuple( key, resultset, getTupleContext() );
    return nextVersion;
  }
View Full Code Here

      return null;
    }
    else if (ids.size() == 1) {
      //EntityLoader#loadByUniqueKey uses a null object and LockMode.NONE
      //there is only one element in the list, so get the first
      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 );
    }
    else {
      throw new AssertionFailure(
View Full Code Here

    for ( int j = 0; j < span; j++ ) {
      // Now update only the tables with dirty properties (and the table with the version number)
      if ( tableUpdateNeeded[j] ) {
        final EntityKey key = EntityKeyBuilder.fromPersister( this, id, session );
        Tuple resultset = null;

        if ( mightRequireInverseAssociationManagement || usesNonAtomicOptimisticLocking ) {
          resultset = gridDialect.getTuple( key, getTupleContext() );
        }
        else {
          OgmEntityEntryState extraState = entry.getExtraState( OgmEntityEntryState.class );
          if ( extraState != null ) {
            resultset = extraState.getTuple();
          }
          if ( resultset == null ) {
            resultset = gridDialect.getTuple( key, getTupleContext() );
          }
        }

        final boolean useVersion = j == 0 && isVersioned();

        resultset = createNewResultSetIfNull( key, resultset, id, session );

        final EntityMetamodel entityMetamodel = getEntityMetamodel();

        if ( usesNonAtomicOptimisticLocking ) {
          // Write any appropriate versioning conditional parameters
          if ( useVersion && entityMetamodel.getOptimisticLockStyle() == OptimisticLockStyle.VERSION ) {
            if ( checkVersion( propsToUpdate ) ) {
              checkVersionAndRaiseSOSE( id, oldVersion, session, resultset );
            }
          }
          else if ( isAllOrDirtyOptLocking() && oldFields != null ) {
            boolean[] versionability = getPropertyVersionability(); //TODO: is this really necessary????
            boolean[] includeOldField = entityMetamodel.getOptimisticLockStyle() == OptimisticLockStyle.ALL
                ? getPropertyUpdateability()
                    : propsToUpdate;

            //TODO do a diff on the properties value from resultset and the dirty value
            GridType[] types = gridPropertyTypes;

            for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) {
              boolean include = includeOldField[i] &&
                  isPropertyOfTable( i, j ) &&
                  versionability[i]; //TODO: is this really necessary????
              if ( include ) {
                final GridType type = types[i];
                //FIXME what do do with settable?
                boolean[] settable = type.toColumnNullness( oldFields[i], factory );
                final Object snapshotValue = type.nullSafeGet(
                    resultset, getPropertyColumnNames( i ), session, object
                    );

                if ( !type.isEqual( oldFields[i], snapshotValue, factory ) ) {
                  raiseStaleObjectStateException( id );
                }
              }
            }
          }
        }

        if ( mightRequireInverseAssociationManagement ) {
          removeFromInverseAssociations( resultset, j, id, session );
        }
        dehydrate( resultset, fields, propsToUpdate, j, id, session );

        // TODO OGM-616 Also use this facet for "all columns" optimistic locking strategy
        if ( isVersioned() && optimisticLockingAwareGridDialect != null ) {
          Tuple oldVersionTuple = new Tuple();
          oldVersionTuple.put( getVersionColumnName(), oldVersion );

          boolean success = optimisticLockingAwareGridDialect.updateTupleWithOptimisticLock( key, oldVersionTuple, resultset, getTupleContext() );

          if ( !success ) {
            raiseStaleObjectStateException( id );
View Full Code Here

      throws HibernateException {

    //insert operations are always dynamic in OGM
    boolean[] propertiesToInsert = getPropertiesToInsert( fields );

    Tuple tuple = identityColumnAwareGridDialect.createTuple( entityKeyMetadata, getTupleContext() );

    // add the discriminator
    if ( discriminator.isNeeded() ) {
      tuple.put( getDiscriminatorColumnName(), getDiscriminatorValue() );
    }

    // dehydrate
    dehydrate( tuple, fields, propertiesToInsert, 0, null, session );
    identityColumnAwareGridDialect.insertTuple( entityKeyMetadata, tuple, getTupleContext() );
View Full Code Here

          log.trace( "Version: " + Versioning.getVersion( fields, this ) );
        }
      }

      final EntityKey key = EntityKeyBuilder.fromPersister( this, id, session );
      Tuple resultset = gridDialect.getTuple( key, this.getTupleContext() );
      // add the discriminator
      if ( j == 0 ) {
        if (resultset != null) {
          throw new HibernateException( "trying to insert an already existing entity: "
              +  MessageHelper.infoString( this, id, getFactory() ) );
        }

        if ( discriminator.isNeeded() ) {
          resultset = createNewResultSetIfNull( key, resultset, id, session );
          resultset.put( getDiscriminatorColumnName(), getDiscriminatorValue() );
        }
      }

      resultset = createNewResultSetIfNull( key, resultset, id, session );
View Full Code Here

      throw new HibernateException( "Hibernate OGM does not yet support entities spanning multiple tables");
    }

    final EntityKey key = EntityKeyBuilder.fromPersister( this, id, session );
    Object[] loadedState = getLoadedState( id, session );
    Tuple currentState = null;

    if ( mightRequireInverseAssociationManagement || usesNonAtomicOptimisticLocking ) {
      currentState = gridDialect.getTuple( key, getTupleContext() );
    }

    if ( usesNonAtomicOptimisticLocking ) {
      checkOptimisticLockingState( id, key, object, loadedState, version, session, currentState );
    }

    for ( int j = span - 1; j >= 0; j-- ) {
      if ( isInverseTable( j ) ) {
        return;
      }
      if ( log.isTraceEnabled() ) {
        log.trace( "Deleting entity: " + MessageHelper.infoString( this, id, getFactory() ) );
        if ( j == 0 && isVersioned() ) {
          log.trace( "Version: " + version );
        }
      }

      //delete inverse association information
      //needs to be executed before the tuple removal because the AtomicMap in ISPN is cleared upon removal
      if ( mightRequireInverseAssociationManagement ) {
        new EntityAssociationUpdater( this )
          .id( id )
          .resultset( currentState )
          .session( session )
          .tableIndex( j )
          .propertyMightRequireInverseAssociationManagement( propertyMightRequireInverseAssociationManagement )
          .removeNavigationalInformationFromInverseSide();
      }

      if ( optimisticLockingAwareGridDialect != null && isVersioned() ) {
        Tuple versionTuple = new Tuple();
        versionTuple.put( getVersionColumnName(), version );

        boolean success = optimisticLockingAwareGridDialect.removeTupleWithOptimisticLock( key, versionTuple, getTupleContext() );

        if ( !success ) {
          raiseStaleObjectStateException( id );
View Full Code Here

      Object entity,
      Object[] state,
      SessionImplementor session,
      GenerationTiming matchTiming) {

    Tuple tuple = getResultsetById( id, session );

    if ( tuple == null || tuple.getSnapshot().isEmpty() ) {
      throw log.couldNotRetrieveEntityForRetrievalOfGeneratedProperties( getEntityName(), id );
    }

    int propertyIndex = -1;
    for ( NonIdentifierAttribute attribute : getEntityMetamodel().getProperties() ) {
View Full Code Here

    session.clear();

    transaction = session.beginTransaction();
    EntityKey key = new EntityKey( new EntityKeyMetadata( "Feeling", new String[] { "UUID" } ), new Object[] { feeling.getUUID() } );
    Map<String, Object> entityTuple = extractEntityTuple( sessions, key );
    final Tuple tuple = new Tuple( new MapTupleSnapshot( entityTuple ) );

    EntityPersister persister = ( (SessionFactoryImplementor) session.getSessionFactory() )
        .getEntityPersister( Feeling.class.getName() );
    OgmLoader loader = new OgmLoader( new OgmEntityPersister[] { (OgmEntityPersister) persister } );
    OgmLoadingContext ogmLoadingContext = new OgmLoadingContext();
View Full Code Here

  }

  @Override
  public Tuple get(RowKey rowKey) {
    AssociationRow<?> row = rows.get( rowKey );
    return row != null ? new Tuple( row ) : 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.