Package org.hibernate.id

Examples of org.hibernate.id.IntegralDataTypeHolder


     * {@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


          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

    @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

                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

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

          PreparedStatement st = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql );
          try {
            ResultSet rs = st.executeQuery();
            try {
              rs.next();
              IntegralDataTypeHolder value = IdentifierGeneratorHelper.getIntegralDataTypeHolder( numberType );
              value.initialize( rs, 1 );
                            LOG.debugf("Sequence value obtained: %s", value.makeValue());
              return value;
            }
            finally {
              try {
                rs.close();
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

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.