Package org.hibernate.id

Examples of org.hibernate.id.IntegralDataTypeHolder


        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 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

        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

    // not synchronized. It is very important to work on the
    // local variable: the field lastSourceValue is not
    // reliable as it might be mutated by multipled threads.
    // The lastSourceValue field is only accessed by tests,
    // so this is not a concern.
    IntegralDataTypeHolder value = null;
    while ( value == null || value.lt( 1 ) ) {
      value = callback.getNextValue();
    }
    lastSourceValue = value;
    return value.makeValue();
  }
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

        //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.