Package org.hibernate.tuple.entity

Examples of org.hibernate.tuple.entity.EntityMetamodel


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


    }
  }

  //Copied from AbstractEntityPersister
  private boolean isAllOrDirtyOptLocking() {
    EntityMetamodel entityMetamodel = getEntityMetamodel();
    return entityMetamodel.getOptimisticLockStyle() == OptimisticLockStyle.DIRTY
        || entityMetamodel.getOptimisticLockStyle() == OptimisticLockStyle.ALL;
  }
View Full Code Here

   * <b>Note:</b> Naturally, that approach is not completely fail-safe, it only minimizes the time window for
   * undiscovered concurrent updates.
   */
  private void checkOptimisticLockingState(Serializable id, EntityKey key, Object object, Object[] loadedState, Object version, SessionImplementor session, Tuple resultset) {
    int tableSpan = getTableSpan();
    EntityMetamodel entityMetamodel = getEntityMetamodel();

    boolean isImpliedOptimisticLocking = !entityMetamodel.isVersioned() && isAllOrDirtyOptLocking();

    // Compare all the columns against their current state in the datastore
    if ( isImpliedOptimisticLocking && loadedState != null ) {
      // we need to utilize dynamic delete statements
      for ( int j = tableSpan - 1; j >= 0; j-- ) {
        boolean[] versionability = getPropertyVersionability();

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

        for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) {
          boolean include = isPropertyOfTable( i, j ) && versionability[i];
          if ( include ) {
            final GridType type = types[i];
            final Object snapshotValue = type.nullSafeGet(
                resultset, getPropertyColumnNames( i ), session, object
            );
            //TODO support other entity modes
            if ( ! type.isEqual( loadedState[i], snapshotValue, getFactory() ) ) {
              raiseStaleObjectStateException( id );
            }
          }
        }
      }
    }
    // compare the version column only
    else if ( entityMetamodel.isVersioned() ) {
      checkVersionAndRaiseSOSE( id, version, session, resultset );
    }
  }
View Full Code Here

  public void dehydrate() {
    if ( log.isTraceEnabled() ) {
      log.trace( "Dehydrating entity: " + MessageHelper.infoString( persister, id, persister.getFactory() ) );
    }
    final EntityMetamodel entityMetamodel = persister.getEntityMetamodel();
    final boolean[] uniqueness = persister.getPropertyUniqueness();
    final Type[] propertyTypes = persister.getPropertyTypes();
    for ( int propertyIndex = 0; propertyIndex < entityMetamodel.getPropertySpan(); propertyIndex++ ) {
      if ( persister.isPropertyOfTable( propertyIndex, tableIndex ) ) {
        final Type propertyType = propertyTypes[propertyIndex];
        boolean isStarToOne = propertyType.isAssociationType() && ! propertyType.isCollectionType();
        final boolean createMetadata = isStarToOne || uniqueness[propertyIndex];
        if ( removePropertyMetadata && createMetadata ) {
View Full Code Here

        Tuple resultset = gridDialect.getTuple( key, this.getTupleContext() );
        final boolean useVersion = j == 0 && isVersioned();

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

        final EntityMetamodel entityMetamodel = getEntityMetamodel();

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

    }
  }

  //Copied from AbstractEntityPersister
  private boolean isAllOrDirtyOptLocking() {
    EntityMetamodel entityMetamodel = getEntityMetamodel();
    return entityMetamodel.getOptimisticLockStyle() == OptimisticLockStyle.DIRTY
        || entityMetamodel.getOptimisticLockStyle() == OptimisticLockStyle.ALL;
  }
View Full Code Here

      throws HibernateException {
    final int span = getTableSpan();
    if ( span > 1 ) {
      throw new HibernateException( "Hibernate OGM does not yet support entities spanning multiple tables");
    }
    final EntityMetamodel entityMetamodel = getEntityMetamodel();
    boolean isImpliedOptimisticLocking = !entityMetamodel.isVersioned() && isAllOrDirtyOptLocking();
    Object[] loadedState = null;
    if ( isImpliedOptimisticLocking ) {
      // need to treat this as if it where optimistic-lock="all" (dirty does *not* make sense);
      // first we need to locate the "loaded" state
      //
      // Note, it potentially could be a proxy, so doAfterTransactionCompletion the location the safe way...
      org.hibernate.engine.spi.EntityKey key = session.generateEntityKey( id, this );
      Object entity = session.getPersistenceContext().getEntity( key );
      if ( entity != null ) {
        EntityEntry entry = session.getPersistenceContext().getEntry( entity );
        loadedState = entry.getLoadedState();
      }
    }

    final EntityKey key = EntityKeyBuilder.fromPersister( this, id, session );
    final Tuple resultset = gridDialect.getTuple( key, this.getTupleContext() );
    final SessionFactoryImplementor factory = getFactory();
    if ( isImpliedOptimisticLocking && loadedState != null ) {
      // we need to utilize dynamic delete statements
      for ( int j = span - 1; j >= 0; j-- ) {
        boolean[] versionability = getPropertyVersionability();

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

        for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) {
          boolean include = isPropertyOfTable( i, j ) && versionability[i];
          if ( include ) {
            final GridType type = types[i];
            final Object snapshotValue = type.nullSafeGet(
                resultset, getPropertyColumnNames( i ), session, object
            );
            //TODO support other entity modes
            if ( ! type.isEqual( loadedState[i], snapshotValue, factory ) ) {
              if ( factory.getStatistics().isStatisticsEnabled() ) {
                factory.getStatisticsImplementor()
                    .optimisticFailure( getEntityName() );
              }
              throw new StaleObjectStateException( getEntityName(), id );
            }
          }
        }
      }
    }
    else {
      if ( entityMetamodel.isVersioned() ) {
        checkVersionAndRaiseSOSE( id, version, session, resultset );
      }
    }

    for ( int j = span - 1; j >= 0; j-- ) {
View Full Code Here

    isLazyPropertiesCacheable = persistentClass.isLazyPropertiesCacheable();
    this.cacheEntryStructure = factory.getSettings().isStructuredCacheEntriesEnabled() ?
        (CacheEntryStructure) new StructuredCacheEntry(this) :
        (CacheEntryStructure) new UnstructuredCacheEntry();

    this.entityMetamodel = new EntityMetamodel( persistentClass, factory );

    if ( persistentClass.hasPojoRepresentation() ) {
      //TODO: this is currently specific to pojos, but need to be available for all entity-modes
      Iterator iter = persistentClass.getSubclassIterator();
      while ( iter.hasNext() ) {
View Full Code Here

    isLazyPropertiesCacheable = persistentClass.isLazyPropertiesCacheable();
    this.cacheEntryStructure = factory.getSettings().isStructuredCacheEntriesEnabled() ?
        (CacheEntryStructure) new StructuredCacheEntry(this) :
        (CacheEntryStructure) new UnstructuredCacheEntry();

    this.entityMetamodel = new EntityMetamodel( persistentClass, factory );
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    int batch = persistentClass.getBatchSize();
    if ( batch == -1 ) {
      batch = factory.getSettings().getDefaultBatchFetchSize();
View Full Code Here

    this.factory = factory;
    this.cacheAccessStrategy = cacheAccessStrategy;
    this.naturalIdRegionAccessStrategy = naturalIdRegionAccessStrategy;
    isLazyPropertiesCacheable = persistentClass.isLazyPropertiesCacheable();

    this.entityMetamodel = new EntityMetamodel( persistentClass, this, factory );
    this.entityTuplizer = this.entityMetamodel.getTuplizer();
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    int batch = persistentClass.getBatchSize();
    if ( batch == -1 ) {
View Full Code Here

TOP

Related Classes of org.hibernate.tuple.entity.EntityMetamodel

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.