Package org.hibernate.id

Examples of org.hibernate.id.IntegralDataTypeHolder


          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

                final SqlStatementLogger statementLogger = session
                    .getFactory()
                    .getServiceRegistry()
                    .getService( JdbcServices.class )
                    .getSqlStatementLogger();
                IntegralDataTypeHolder value = IdentifierGeneratorHelper.getIntegralDataTypeHolder( numberType );
                int rows;
                do {
                  statementLogger.logStatement( selectQuery, FormatStyle.BASIC.getFormatter() );
                  PreparedStatement selectStatement = connection.prepareStatement( selectQuery );
                  try {
                    ResultSet selectRS = selectStatement.executeQuery();
                    if ( !selectRS.next() ) {
                      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();
                  }

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

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

          public IntegralDataTypeHolder getNextValue() {
            return session.getTransactionCoordinator().getTransaction().createIsolationDelegate().delegateWork(
                new AbstractReturningWork<IntegralDataTypeHolder>() {
                  @Override
                  public IntegralDataTypeHolder execute(Connection connection) throws SQLException {
                    IntegralDataTypeHolder value = IdentifierGeneratorHelper.getIntegralDataTypeHolder( identifierType.getReturnedClass() );
                    int rows;
                    do {
                      statementLogger.logStatement( selectQuery, FormatStyle.BASIC.getFormatter() );
                      PreparedStatement selectPS = connection.prepareStatement( selectQuery );
                      try {
                        selectPS.setString( 1, segmentValue );
                        ResultSet selectRS = selectPS.executeQuery();
                        if ( !selectRS.next() ) {
                          value.initialize( initialValue );
                          PreparedStatement insertPS = null;
                          try {
                            statementLogger.logStatement( insertQuery, FormatStyle.BASIC.getFormatter() );
                            insertPS = connection.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 e ) {
                          LOG.unableToReadOrInitHiValue(e);
                        throw e;
                      }
                      finally {
                        selectPS.close();
                      }

                      statementLogger.logStatement( updateQuery, FormatStyle.BASIC.getFormatter() );
                      PreparedStatement updatePS = connection.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 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

          public IntegralDataTypeHolder getNextValue() {
            return session.getTransactionCoordinator().getTransaction().createIsolationDelegate().delegateWork(
                new AbstractReturningWork<IntegralDataTypeHolder>() {
                  @Override
                  public IntegralDataTypeHolder execute(Connection connection) throws SQLException {
                    IntegralDataTypeHolder value = IdentifierGeneratorHelper.getIntegralDataTypeHolder( identifierType.getReturnedClass() );
                    int rows;
                    do {
                      statementLogger.logStatement( selectQuery, FormatStyle.BASIC.getFormatter() );
                      PreparedStatement selectPS = connection.prepareStatement( selectQuery );
                      try {
                        selectPS.setString( 1, segmentValue );
                        ResultSet selectRS = selectPS.executeQuery();
                        if ( !selectRS.next() ) {
                          value.initialize( initialValue );
                          PreparedStatement insertPS = null;
                          try {
                            statementLogger.logStatement( insertQuery, FormatStyle.BASIC.getFormatter() );
                            insertPS = connection.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 e ) {
                          LOG.unableToReadOrInitHiValue(e);
                        throw e;
                      }
                      finally {
                        selectPS.close();
                      }

                      statementLogger.logStatement( updateQuery, FormatStyle.BASIC.getFormatter() );
                      PreparedStatement updatePS = connection.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 e ) {
View Full Code Here

          PreparedStatement st = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql );
          try {
            ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
            try {
              rs.next();
              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

                final SqlStatementLogger statementLogger = session
                    .getFactory()
                    .getServiceRegistry()
                    .getService( JdbcServices.class )
                    .getSqlStatementLogger();
                IntegralDataTypeHolder value = IdentifierGeneratorHelper.getIntegralDataTypeHolder( numberType );
                int rows;
                do {
                  statementLogger.logStatement( selectQuery, FormatStyle.BASIC.getFormatter() );
                  PreparedStatement selectStatement = connection.prepareStatement( selectQuery );
                  try {
                    ResultSet selectRS = selectStatement.executeQuery();
                    if ( !selectRS.next() ) {
                      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();
                  }

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

                final SqlStatementLogger statementLogger = session
                    .getFactory()
                    .getServiceRegistry()
                    .getService( JdbcServices.class )
                    .getSqlStatementLogger();
                IntegralDataTypeHolder value = IdentifierGeneratorHelper.getIntegralDataTypeHolder( numberType );
                int rows;
                do {
                  statementLogger.logStatement( selectQuery, FormatStyle.BASIC.getFormatter() );
                  PreparedStatement selectStatement = connection.prepareStatement( selectQuery );
                  try {
                    ResultSet selectRS = selectStatement.executeQuery();
                    if ( !selectRS.next() ) {
                      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();
                  }

                  statementLogger.logStatement( updateQuery, FormatStyle.BASIC.getFormatter() );
                  PreparedStatement updatePS = connection.prepareStatement( updateQuery );
                  try {
                    final int increment = applyIncrementSizeToSourceValues ? incrementSize : 1;
                    final IntegralDataTypeHolder updateValue = value.copy().add( increment );
                    updateValue.bind( updatePS, 1 );
                    value.bind( updatePS, 2 );
                    rows = updatePS.executeUpdate();
                  }
                  catch ( SQLException e ) {
                      LOG.unableToUpdateQueryHiValue(tableName, e);
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.