Package org.hibernate.id

Examples of org.hibernate.id.IntegralDataTypeHolder


            optimizer.applyIncrementSizeToSourceValues() ? incrementSize : 1,
            initialValue
        )
    );

    IntegralDataTypeHolder value = IdentifierGeneratorHelper.getIntegralDataTypeHolder( identifierType.getReturnedClass() );
    value.initialize( nextValue.longValue() );

    return value;
  }
View Full Code Here


            optimizer.applyIncrementSizeToSourceValues() ? incrementSize : 1,
            initialValue
        )
    );

    IntegralDataTypeHolder value = IdentifierGeneratorHelper.getIntegralDataTypeHolder( identifierType.getReturnedClass() );
    value.initialize( nextValue.longValue() );

    return value;
  }
View Full Code Here

     * {@inheritDoc}
     */
    public Serializable generate(AccessCallback callback) {
      // IMPL NOTE : it is incredibly important that the method-local variable be used here to
      //    avoid concurrency issues.
      IntegralDataTypeHolder value = null;
      while ( value == null || value.lt( 1 ) ) {
        value = callback.getNextValue();
      }
      lastSourceValue = value;
      return value.makeValue();
    }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  public Serializable doWorkInCurrentTransaction(Connection conn, String sql) throws SQLException {
    IntegralDataTypeHolder value = IdentifierGeneratorHelper.getIntegralDataTypeHolder( identifierType.getReturnedClass() );
    int rows;
    do {
      SQL_STATEMENT_LOGGER.logStatement( selectQuery, FormatStyle.BASIC );
      PreparedStatement selectPS = conn.prepareStatement( selectQuery );
      try {
        selectPS.setString( 1, segmentValue );
        ResultSet selectRS = selectPS.executeQuery();
        if ( !selectRS.next() ) {
          value.initialize( initialValue );
          PreparedStatement insertPS = null;
          try {
            SQL_STATEMENT_LOGGER.logStatement( insertQuery, FormatStyle.BASIC );
            insertPS = conn.prepareStatement( insertQuery );
            insertPS.setString( 1, segmentValue );
            value.bind( insertPS, 2 );
            insertPS.execute();
          }
          finally {
            if ( insertPS != null ) {
              insertPS.close();
            }
          }
        }
        else {
          value.initialize( selectRS, 1 );
        }
        selectRS.close();
      }
      catch ( SQLException sqle ) {
        log.error( "could not read or init a hi value", sqle );
        throw sqle;
      }
      finally {
        selectPS.close();
      }

      SQL_STATEMENT_LOGGER.logStatement( updateQuery, FormatStyle.BASIC );
      PreparedStatement updatePS = conn.prepareStatement( updateQuery );
      try {
        final IntegralDataTypeHolder updateValue = value.copy();
        if ( optimizer.applyIncrementSizeToSourceValues() ) {
          updateValue.add( incrementSize );
        }
        else {
          updateValue.increment();
        }
        updateValue.bind( updatePS, 1 );
        value.bind( updatePS, 2 );
        updatePS.setString( 3, segmentValue );
        rows = updatePS.executeUpdate();
      }
      catch ( SQLException sqle ) {
View Full Code Here

          final PreparedStatement st = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql );
          try {
            final ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
            try {
              rs.next();
              final IntegralDataTypeHolder value = IdentifierGeneratorHelper.getIntegralDataTypeHolder( numberType );
              value.initialize( rs, 1 );
              if ( LOG.isDebugEnabled() ) {
                LOG.debugf( "Sequence value obtained: %s", value.makeValue() );
              }
              return value;
            }
            finally {
              try {
View Full Code Here

      public IntegralDataTypeHolder getNextValue() {
        return session.getTransactionCoordinator().getTransaction().createIsolationDelegate().delegateWork(
            new AbstractReturningWork<IntegralDataTypeHolder>() {
              @Override
              public IntegralDataTypeHolder execute(Connection connection) throws SQLException {
                final IntegralDataTypeHolder value = makeValue();
                int rows;
                do {
                  final PreparedStatement selectStatement = prepareStatement( connection, selectQuery, statementLogger, statsCollector );
                  try {
                    final ResultSet selectRS = executeQuery( selectStatement, statsCollector );
                    if ( !selectRS.next() ) {
                      final String err = "could not read a hi value - you need to populate the table: " + tableName;
                      LOG.error( err );
                      throw new IdentifierGenerationException( err );
                    }
                    value.initialize( selectRS, 1 );
                    selectRS.close();
                  }
                  catch (SQLException sqle) {
                    LOG.error( "could not read a hi value", sqle );
                    throw sqle;
                  }
                  finally {
                    selectStatement.close();
                  }


                  final PreparedStatement updatePS = prepareStatement( connection, updateQuery, statementLogger, statsCollector );
                  try {
                    final int increment = applyIncrementSizeToSourceValues ? incrementSize : 1;
                    final IntegralDataTypeHolder updateValue = value.copy().add( increment );
                    updateValue.bind( updatePS, 1 );
                    value.bind( updatePS, 2 );
                    rows = executeUpdate( updatePS, statsCollector );
                  }
                  catch (SQLException e) {
                    LOG.unableToUpdateQueryHiValue( tableName, e );
View Full Code Here

  @Override
  public synchronized Serializable generate(AccessCallback callback) {
    // IMPL NOTE : it is incredibly important that the method-local variable be used here to
    //    avoid concurrency issues.
    IntegralDataTypeHolder value = null;
    while ( value == null || value.lt( 1 ) ) {
      value = callback.getNextValue();
    }
    lastSourceValue = value;
    return value.makeValue();
  }
View Full Code Here

          public IntegralDataTypeHolder getNextValue() {
            return session.getTransactionCoordinator().getTransaction().createIsolationDelegate().delegateWork(
                new AbstractReturningWork<IntegralDataTypeHolder>() {
                  @Override
                  public IntegralDataTypeHolder execute(Connection connection) throws SQLException {
                    final IntegralDataTypeHolder value = makeValue();
                    int rows;
                    do {
                      final PreparedStatement selectPS = prepareStatement( connection, selectQuery, statementLogger, statsCollector );

                      try {
                        selectPS.setString( 1, segmentValue );
                        final ResultSet selectRS = executeQuery( selectPS, statsCollector );
                        if ( !selectRS.next() ) {
                          value.initialize( initialValue );

                          final PreparedStatement insertPS = prepareStatement( connection, insertQuery, statementLogger, statsCollector );
                          try {
                            insertPS.setString( 1, segmentValue );
                            value.bind( insertPS, 2 );
                            executeUpdate( insertPS, statsCollector );
                          }
                          finally {
                            insertPS.close();
                          }
                        }
                        else {
                          value.initialize( selectRS, 1 );
                        }
                        selectRS.close();
                      }
                      catch (SQLException e) {
                        LOG.unableToReadOrInitHiValue( e );
                        throw e;
                      }
                      finally {
                        selectPS.close();
                      }


                      final PreparedStatement updatePS = prepareStatement( connection, updateQuery, statementLogger, statsCollector );
                      try {
                        final IntegralDataTypeHolder updateValue = value.copy();
                        if ( optimizer.applyIncrementSizeToSourceValues() ) {
                          updateValue.add( incrementSize );
                        }
                        else {
                          updateValue.increment();
                        }
                        updateValue.bind( updatePS, 1 );
                        value.bind( updatePS, 2 );
                        updatePS.setString( 3, segmentValue );
                        rows = executeUpdate( updatePS, statsCollector );
                      }
                      catch (SQLException e) {
View Full Code Here

        //read the value from the table
        value.initialize( ( (Number) valueFromDb ).longValue() );
      }

      //update value
      final IntegralDataTypeHolder updateValue = value.copy();
      //increment value
      updateValue.add( increment );
      //TODO should we use GridTypes here?
      final Object newValueFromDb = updateValue.makeValue();
      done = identifierCache.replace( key, valueFromDb, newValueFromDb );
    }
    while ( !done );
  }
View Full Code Here

        //read the value from the table
        value.initialize( ( (Number) valueFromDb ).longValue() );
      }

      //update value
      final IntegralDataTypeHolder updateValue = value.copy();
      //increment value
      updateValue.add( increment );
      //TODO should we use GridTypes here?
      final Object newValueFromDb = updateValue.makeValue();
      done = identifierCache.replace( key, valueFromDb, newValueFromDb );
    }
    while ( !done );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.id.IntegralDataTypeHolder

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.