Package org.hibernate.type

Examples of org.hibernate.type.VersionType


      Queryable persister = fromClause.getFromElement().getQueryable();
      if ( !persister.isVersioned() ) {
        throw new SemanticException( "increment option specified for update of non-versioned entity" );
      }

      VersionType versionType = persister.getVersionType();
      if ( versionType instanceof UserVersionType ) {
        throw new SemanticException( "user-defined version types not supported for increment option" );
      }

      AST eq = getASTFactory().create( HqlSqlTokenTypes.EQ, "=" );
      AST versionPropertyNode = generateVersionPropertyNode( persister );

      eq.setFirstChild( versionPropertyNode );

      AST versionIncrementNode = null;
      if ( Date.class.isAssignableFrom( versionType.getReturnedClass() ) ) {
        versionIncrementNode = getASTFactory().create( HqlSqlTokenTypes.PARAM, "?" );
        ParameterSpecification paramSpec = new VersionTypeSeedParameterSpecification( versionType );
        ( ( ParameterNode ) versionIncrementNode ).setHqlParameterSpecification( paramSpec );
        parameters.add( 0, paramSpec );
      }
View Full Code Here


    final boolean includeVersionProperty = persister.isVersioned() &&
        !insertStatement.getIntoClause().isExplicitVersionInsertion() &&
        persister.isVersionPropertyInsertable();
    if ( includeVersionProperty ) {
      // We need to seed the version value as part of this bulk insert
      VersionType versionType = persister.getVersionType();
      AST versionValueNode = null;

      if ( sessionFactoryHelper.getFactory().getDialect().supportsParametersInInsertSelect() ) {
        int sqlTypes[] = versionType.sqlTypes( sessionFactoryHelper.getFactory() );
        if ( sqlTypes == null || sqlTypes.length == 0 ) {
          throw new IllegalStateException( versionType.getClass() + ".sqlTypes() returns null or empty array" );
        }
        if ( sqlTypes.length > 1 ) {
          throw new IllegalStateException(
              versionType.getClass() +
                  ".sqlTypes() returns > 1 element; only single-valued versions are allowed."
          );
        }
        versionValueNode = getASTFactory().create( HqlSqlTokenTypes.PARAM, "?" );
        ParameterSpecification paramSpec = new VersionTypeSeedParameterSpecification( versionType );
        ( ( ParameterNode ) versionValueNode ).setHqlParameterSpecification( paramSpec );
        parameters.add( 0, paramSpec );

        if ( sessionFactoryHelper.getFactory().getDialect().requiresCastingOfParametersInSelectClause() ) {
          // we need to wrtap the param in a cast()
          MethodNode versionMethodNode = ( MethodNode ) getASTFactory().create( HqlSqlTokenTypes.METHOD_CALL, "(" );
          AST methodIdentNode = getASTFactory().create( HqlSqlTokenTypes.IDENT, "cast" );
          versionMethodNode.addChild( methodIdentNode );
          versionMethodNode.initializeMethodNode(methodIdentNode, true );
          AST castExprListNode = getASTFactory().create( HqlSqlTokenTypes.EXPR_LIST, "exprList" );
          methodIdentNode.setNextSibling( castExprListNode );
          castExprListNode.addChild( versionValueNode );
          versionValueNode.setNextSibling(
              getASTFactory().create(
                  HqlSqlTokenTypes.IDENT,
                  sessionFactoryHelper.getFactory().getDialect().getTypeName( sqlTypes[0] ) )
          );
          processFunction( versionMethodNode, true );
          versionValueNode = versionMethodNode;
        }
      }
      else {
        if ( isIntegral( versionType ) ) {
          try {
            Object seedValue = versionType.seed( null );
            versionValueNode = getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, seedValue.toString() );
          }
          catch( Throwable t ) {
            throw new QueryException( "could not determine seed value for version on bulk insert [" + versionType + "]" );
          }
View Full Code Here

      Queryable persister = fromClause.getFromElement().getQueryable();
      if ( !persister.isVersioned() ) {
        throw new SemanticException( "increment option specified for update of non-versioned entity" );
      }

      VersionType versionType = persister.getVersionType();
      if ( versionType instanceof UserVersionType ) {
        throw new SemanticException( "user-defined version types not supported for increment option" );
      }

      AST eq = getASTFactory().create( HqlSqlTokenTypes.EQ, "=" );
      AST versionPropertyNode = generateVersionPropertyNode( persister );

      eq.setFirstChild( versionPropertyNode );

      AST versionIncrementNode = null;
      if ( Date.class.isAssignableFrom( versionType.getReturnedClass() ) ) {
        versionIncrementNode = getASTFactory().create( HqlSqlTokenTypes.PARAM, "?" );
        ParameterSpecification paramSpec = new VersionTypeSeedParameterSpecification( versionType );
        ( ( ParameterNode ) versionIncrementNode ).setHqlParameterSpecification( paramSpec );
        parameters.add( 0, paramSpec );
      }
View Full Code Here

    );
  }

  private static Comparator getVersionComparator(EntityBinding model ) {
    if ( model.isVersioned() ) {
      final VersionType versionType = (VersionType) model.getHierarchyDetails()
          .getVersioningAttributeBinding()
          .getHibernateTypeDescriptor()
          .getResolvedTypeMapping();

      return versionType.getComparator();
    }

    return null;
  }
View Full Code Here

    final boolean includeVersionProperty = persister.isVersioned() &&
        !insertStatement.getIntoClause().isExplicitVersionInsertion() &&
        persister.isVersionPropertyInsertable();
    if ( includeVersionProperty ) {
      // We need to seed the version value as part of this bulk insert
      VersionType versionType = persister.getVersionType();
      AST versionValueNode = null;

      if ( sessionFactoryHelper.getFactory().getDialect().supportsParametersInInsertSelect() ) {
        int sqlTypes[] = versionType.sqlTypes( sessionFactoryHelper.getFactory() );
        if ( sqlTypes == null || sqlTypes.length == 0 ) {
          throw new IllegalStateException( versionType.getClass() + ".sqlTypes() returns null or empty array" );
        }
        if ( sqlTypes.length > 1 ) {
          throw new IllegalStateException(
              versionType.getClass() +
                  ".sqlTypes() returns > 1 element; only single-valued versions are allowed."
          );
        }
        versionValueNode = getASTFactory().create( HqlSqlTokenTypes.PARAM, "?" );
        ParameterSpecification paramSpec = new VersionTypeSeedParameterSpecification( versionType );
        ( ( ParameterNode ) versionValueNode ).setHqlParameterSpecification( paramSpec );
        parameters.add( 0, paramSpec );

        if ( sessionFactoryHelper.getFactory().getDialect().requiresCastingOfParametersInSelectClause() ) {
          // we need to wrtap the param in a cast()
          MethodNode versionMethodNode = ( MethodNode ) getASTFactory().create( HqlSqlTokenTypes.METHOD_CALL, "(" );
          AST methodIdentNode = getASTFactory().create( HqlSqlTokenTypes.IDENT, "cast" );
          versionMethodNode.addChild( methodIdentNode );
          versionMethodNode.initializeMethodNode(methodIdentNode, true );
          AST castExprListNode = getASTFactory().create( HqlSqlTokenTypes.EXPR_LIST, "exprList" );
          methodIdentNode.setNextSibling( castExprListNode );
          castExprListNode.addChild( versionValueNode );
          versionValueNode.setNextSibling(
              getASTFactory().create(
                  HqlSqlTokenTypes.IDENT,
                  sessionFactoryHelper.getFactory().getDialect().getTypeName( sqlTypes[0] ) )
          );
          processFunction( versionMethodNode, true );
          versionValueNode = versionMethodNode;
        }
      }
      else {
        if ( isIntegral( versionType ) ) {
          try {
            Object seedValue = versionType.seed( null );
            versionValueNode = getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, seedValue.toString() );
          }
          catch( Throwable t ) {
            throw new QueryException( "could not determine seed value for version on bulk insert [" + versionType + "]" );
          }
View Full Code Here

      Queryable persister = fromClause.getFromElement().getQueryable();
      if ( !persister.isVersioned() ) {
        throw new SemanticException( "increment option specified for update of non-versioned entity" );
      }

      VersionType versionType = persister.getVersionType();
      if ( versionType instanceof UserVersionType ) {
        throw new SemanticException( "user-defined version types not supported for increment option" );
      }

      AST eq = getASTFactory().create( HqlSqlTokenTypes.EQ, "=" );
View Full Code Here

  throws HibernateException, SQLException {

    Object version = session.getPersistenceContext().getEntry( entity ).getVersion();

    if ( version != null ) { //null version means the object is in the process of being loaded somewhere else in the ResultSet
      VersionType versionType = persister.getVersionType();
      Object currentVersion = versionType.nullSafeGet(
          rs,
          getEntityAliases()[i].getSuffixedVersionAliases(),
          session,
          null
        );
      if ( !versionType.isEqual(version, currentVersion) ) {
        if ( session.getFactory().getStatistics().isStatisticsEnabled() ) {
          session.getFactory().getStatisticsImplementor()
              .optimisticFailure( persister.getEntityName() );
        }
        throw new StaleObjectStateException( persister.getEntityName(), id );
View Full Code Here

  throws HibernateException, SQLException {

    Object version = session.getPersistenceContext().getEntry( entity ).getVersion();

    if ( version != null ) { //null version means the object is in the process of being loaded somewhere else in the ResultSet
      VersionType versionType = persister.getVersionType();
      Object currentVersion = versionType.nullSafeGet(
          rs,
          getEntityAliases()[i].getSuffixedVersionAliases(),
          session,
          null
        );
      if ( !versionType.isEqual(version, currentVersion) ) {
        if ( session.getFactory().getStatistics().isStatisticsEnabled() ) {
          session.getFactory().getStatisticsImplementor()
              .optimisticFailure( persister.getEntityName() );
        }
        throw new StaleObjectStateException( persister.getEntityName(), id );
View Full Code Here

  throws HibernateException, SQLException {

    Object version = session.getPersistenceContext().getEntry( entity ).getVersion();

    if ( version != null ) { //null version means the object is in the process of being loaded somewhere else in the ResultSet
      VersionType versionType = persister.getVersionType();
      Object currentVersion = versionType.nullSafeGet(
          rs,
          getEntityAliases()[i].getSuffixedVersionAliases(),
          session,
          null
        );
      if ( !versionType.isEqual(version, currentVersion) ) {
        if ( session.getFactory().getStatistics().isStatisticsEnabled() ) {
          session.getFactory().getStatisticsImplementor()
              .optimisticFailure( persister.getEntityName() );
        }
        throw new StaleObjectStateException( persister.getEntityName(), id );
View Full Code Here

  throws HibernateException, SQLException {

    Object version = session.getPersistenceContext().getEntry( entity ).getVersion();

    if ( version != null ) { //null version means the object is in the process of being loaded somewhere else in the ResultSet
      VersionType versionType = persister.getVersionType();
      Object currentVersion = versionType.nullSafeGet(
          rs,
          getEntityAliases()[i].getSuffixedVersionAliases(),
          session,
          null
        );
      if ( !versionType.isEqual(version, currentVersion) ) {
        if ( session.getFactory().getStatistics().isStatisticsEnabled() ) {
          session.getFactory().getStatisticsImplementor()
              .optimisticFailure( persister.getEntityName() );
        }
        throw new StaleObjectStateException( persister.getEntityName(), id );
View Full Code Here

TOP

Related Classes of org.hibernate.type.VersionType

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.