Package org.hibernate.ogm.dialect

Examples of org.hibernate.ogm.dialect.GridDialect


public class TypeTranslatorInitiator extends OptionalServiceInitiator<TypeTranslator> {
  public static final TypeTranslatorInitiator INSTANCE = new TypeTranslatorInitiator();

  @Override
  public TypeTranslator buildServiceInstance(Map configurationValues, ServiceRegistryImplementor registry) {
    GridDialect dialect = registry.getService( DatastoreServices.class ).getGridDialect();
    return new TypeTranslatorImpl(dialect);
  }
View Full Code Here


        tableName,
        new String[] { segmentColumnName },
        new Object[] { segmentColumnValue }
    );

    GridDialect dialect = getDialect( session );
    IntegralDataTypeHolder value = IdentifierGeneratorHelper.getIntegralDataTypeHolder( identifierType.getReturnedClass() );
    dialect.nextValue( key, value, optimizer.applyIncrementSizeToSourceValues() ? incrementSize : 1, initialValue );

    accessCount++;

    return value;
  }
View Full Code Here

  public TypeTranslator initiateService(SessionFactoryImplementor sessionFactory, MetadataImplementor metadata, ServiceRegistryImplementor registry) {
    return createService( registry );
  }

  private TypeTranslator createService(ServiceRegistryImplementor registry) {
    GridDialect dialect = registry.getService( GridDialect.class );
    return new TypeTranslatorImpl( dialect );
  }
View Full Code Here

          .id( entityId )
          .getKey();
      final Cache<EntityKey,Map<String,Object>> entityCache = GridMetadataManagerHelper.getEntityCache(
          gridManager
      );
      final GridDialect gridDialect = gridManager.getGridDialect();
      final Map<String, Object> entityTuple = gridDialect.getTuple( entityKey, entityCache );
      //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 ( Map.Entry<String, Object> tupleEntry : tuple.entrySet() ) {
          entityTuple.put( tupleEntry.getKey(), tupleEntry.getValue() );
        }
      }
      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.updateTuple( entityTuple, entityKey, entityCache ); //update cache
    }
    else if ( associationType == AssociationType.ASSOCIATION_TABLE_TO_ENTITY ) {
      String[] elementColumnNames = getElementColumnNames();
      Object[] elementColumnValues = LogicalPhysicalConverterHelper.getColumnValuesFromResultset(tuple, elementColumnNames);
      PropertyMetadataProvider associationProvider = new PropertyMetadataProvider()
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 = new EntityKeyBuilder().entityPersister( this ).id(id).getKey();
    final GridDialect gridDialect = gridManager.getGridDialect();
    final Map<String, Object> resultset = gridDialect.getTuple( key, entityCache );
    checkVersionAndRaiseSOSE(id, currentVersion, session, resultset);
    gridVersionType.nullSafeSet( resultset, nextVersion, new String[] { getVersionColumnName() }, session );
    gridDialect.updateTuple( resultset, key, entityCache );
    return nextVersion;
  }
View Full Code Here

        log.trace( "Existing version: " + oldVersion + " -> New version: " + fields[getVersionProperty()] );
      }
    }

    final Cache<EntityKey, Map<String, Object>> entityCache = GridMetadataManagerHelper.getEntityCache( gridManager );
    final GridDialect gridDialect = gridManager.getGridDialect();
    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 = new EntityKeyBuilder().entityPersister( this ).id(id).getKey();
        Map<String, Object> resultset = gridDialect.getTuple( key, entityCache );
        final boolean useVersion = j == 0 && isVersioned();

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

        final EntityMetamodel entityMetamodel = getEntityMetamodel();

        // Write any appropriate versioning conditional parameters
        if ( useVersion && Versioning.OPTIMISTIC_LOCK_VERSION == entityMetamodel.getOptimisticLockMode() ) {
          if ( checkVersion( propsToUpdate ) ) {
            checkVersionAndRaiseSOSE( id, oldVersion, session, resultset );
          }
        }
        else if ( entityMetamodel.getOptimisticLockMode() > Versioning.OPTIMISTIC_LOCK_VERSION && oldFields != null ) {
          boolean[] versionability = getPropertyVersionability(); //TODO: is this really necessary????
          boolean[] includeOldField = entityMetamodel.getOptimisticLockMode() == Versioning.OPTIMISTIC_LOCK_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
              );
              comparePropertyAndRaiseSOSE(
                  id,
                  oldFields[i],
                  factory,
                  !type.isEqual( oldFields, snapshotValue, EntityMode.POJO, factory )
              );

            }
          }
        }

        //dehydrate
        dehydrate(resultset, fields, propsToUpdate, getPropertyColumnUpdateable(), j, id, session );
        gridDialect.updateTuple( resultset, key, entityCache );
      }
    }
  }
View Full Code Here

    final int span = getTableSpan();
    //insert operations are always dynamic in OGM
    boolean[] propertiesToInsert = getPropertiesToInsert( fields );
    final Cache<EntityKey, Map<String, Object>> entityCache = GridMetadataManagerHelper.getEntityCache( gridManager );
    final GridDialect gridDialect = gridManager.getGridDialect();
    for ( int j = 0; j < span; j++ ) {
      if ( isInverseTable( j ) ) {
        return;
      }

      //note: it is conceptually possible that a UserType could map null to
      //    a non-null value, so the following is arguable:
      if ( isNullableTable( j ) && isAllNull( fields, j ) ) {
        return;
      }

      if ( log.isTraceEnabled() ) {
        log.trace( "Inserting entity: " + MessageHelper.infoString( this, id, getFactory() ) );
        if ( j == 0 && isVersioned() ) {
          log.trace( "Version: " + Versioning.getVersion( fields, this ) );
        }
      }

      final EntityKey key = new EntityKeyBuilder().entityPersister( this ).id(id).getKey();
      Map<String, Object> resultset = gridDialect.getTuple( key, entityCache );
      // add the discriminator
      if ( j == 0 ) {
        if (resultset != null) {
          throw new HibernateException( "trying to insert an already existing entity: "
              +  MessageHelper.infoString( this, id, getFactory() ) );
        }
        //TODO add discriminator

      }

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

      //dehydrate
      dehydrate(resultset, fields, propertiesToInsert, getPropertyColumnInsertable(), j, id, session );
      gridDialect.updateTuple( resultset, key, entityCache );
    }
  }
View Full Code Here

      }
    }

    final Cache<EntityKey, Map<String, Object>> entityCache = GridMetadataManagerHelper.getEntityCache( gridManager );
    final EntityKey key = new EntityKeyBuilder().entityPersister( this ).id(id).getKey();
    final GridDialect gridDialect = gridManager.getGridDialect();
    final Map<String, Object> resultset = gridDialect.getTuple( key, entityCache );
    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, EntityMode.POJO, 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-- ) {
      if ( isInverseTable( j ) ) {
        return;
      }
      if ( log.isTraceEnabled() ) {
        log.trace( "Deleting entity: " + MessageHelper.infoString( this, id, factory ) );
        if ( j == 0 && isVersioned() ) {
          log.trace( "Version: " + version );
        }
      }

      //delete association information
      //needs to be executed before the tuple removal because the AtomicMap in ISPN is cleared upon removal
      new EntityDehydrator()
        .gridManager( gridManager )
        .gridPropertyTypes( gridPropertyTypes )
        .gridIdentifierType( gridIdentifierType )
        .id( id )
        .persister( this )
        .resultset( resultset )
        .session( session )
        .tableIndex( j )
        .onlyRemovePropertyMetadata()
        .dehydrate();

      gridDialect.removeTuple( key, entityCache );
    }

  }
View Full Code Here

          }
        }
        if ( injector == null ) {
          log.gridDialectHasNoProperConstructor( clazz );
        }
        GridDialect gridDialect = (GridDialect) injector.newInstance( datastore );

        if ( gridDialect instanceof BatchableGridDialect ) {
          BatchOperationsDelegator delegator = new BatchOperationsDelegator( (BatchableGridDialect) gridDialect );
          addListeners( delegator );
          gridDialect = delegator;
        }

        log.useGridDialect( gridDialect.getClass().getName() );
        if ( GridDialectLogger.activationNeeded() ) {
          gridDialect = new GridDialectLogger( gridDialect );
          log.info( "Grid dialect logs are active" );
        }
        else {
View Full Code Here

          }
        }
        if ( injector == null ) {
          log.gridDialectHasNoProperConstructor( clazz );
        }
        GridDialect gridDialect = (GridDialect) injector.newInstance( datastore );

        if ( gridDialect instanceof ServiceRegistryAwareService ) {
          ( (ServiceRegistryAwareService) gridDialect ).injectServices( registry );
        }

        if ( gridDialect instanceof BatchableGridDialect ) {
          BatchOperationsDelegator delegator = new BatchOperationsDelegator( (BatchableGridDialect) gridDialect );
          addListeners( delegator );
          gridDialect = delegator;
        }

        log.useGridDialect( gridDialect.getClass().getName() );
        if ( GridDialectLogger.activationNeeded() ) {
          gridDialect = new GridDialectLogger( gridDialect );
          log.info( "Grid dialect logs are active" );
        }
        else {
View Full Code Here

TOP

Related Classes of org.hibernate.ogm.dialect.GridDialect

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.