Package org.hibernate.id.enhanced

Examples of org.hibernate.id.enhanced.Optimizer


  }

  public void testBasicNoOptimizerUsage() {
    // test historic sequence behavior, where the initial values start at 1...
    SourceMock sequence = new SourceMock( 1 );
    Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.NONE, Long.class, 1 );
    for ( int i = 1; i < 11; i++ ) {
      final Long next = ( Long ) optimizer.generate( sequence );
      assertEquals( i, next.intValue() );
    }
    assertEquals( 10, sequence.getTimesCalled() );
    assertEquals( 10, sequence.getCurrentValue() );

    // test historic table behavior, where the initial values started at 0 (we now force 1 to be the first used id value)
    sequence = new SourceMock( 0 );
    optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.NONE, Long.class, 1 );
    for ( int i = 1; i < 11; i++ ) {
      final Long next = ( Long ) optimizer.generate( sequence );
      assertEquals( i, next.intValue() );
    }
    assertEquals( 11, sequence.getTimesCalled() ); // an extra time to get to 1 initially
    assertEquals( 10, sequence.getCurrentValue() );
  }
View Full Code Here


    int increment = 10;
    Long next;

    // test historic sequence behavior, where the initial values start at 1...
    SourceMock sequence = new SourceMock( 1 );
    Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.HILO, Long.class, increment );
    for ( int i = 1; i <= increment; i++ ) {
      next = ( Long ) optimizer.generate( sequence );
      assertEquals( i, next.intValue() );
    }
    assertEquals( 1, sequence.getTimesCalled() ); // once to initialze state
    assertEquals( 1, sequence.getCurrentValue() );
    // force a "clock over"
    next = ( Long ) optimizer.generate( sequence );
    assertEquals( 11, next.intValue() );
    assertEquals( 2, sequence.getTimesCalled() );
    assertEquals( 2, sequence.getCurrentValue() );

    // test historic table behavior, where the initial values started at 0 (we now force 1 to be the first used id value)
    sequence = new SourceMock( 0 );
    optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.HILO, Long.class, increment );
    for ( int i = 1; i <= increment; i++ ) {
      next = ( Long ) optimizer.generate( sequence );
      assertEquals( i, next.intValue() );
    }
    assertEquals( 2, sequence.getTimesCalled() ); // here have have an extra call to get to 1 initially
    assertEquals( 1, sequence.getCurrentValue() );
    // force a "clock over"
    next = ( Long ) optimizer.generate( sequence );
    assertEquals( 11, next.intValue() );
    assertEquals( 3, sequence.getTimesCalled() );
    assertEquals( 2, sequence.getCurrentValue() );
  }
View Full Code Here

  public void testBasicPooledOptimizerUsage() {
    Long next;
    // test historic sequence behavior, where the initial values start at 1...
    SourceMock sequence = new SourceMock( 1, 10 );
    Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 10 );
    for ( int i = 1; i < 11; i++ ) {
      next = ( Long ) optimizer.generate( sequence );
      assertEquals( i, next.intValue() );
    }
    assertEquals( 2, sequence.getTimesCalled() ); // twice to initialize state
    assertEquals( 11, sequence.getCurrentValue() );
    // force a "clock over"
    next = ( Long ) optimizer.generate( sequence );
    assertEquals( 11, next.intValue() );
    assertEquals( 3, sequence.getTimesCalled() );
    assertEquals( 21, sequence.getCurrentValue() );
  }
View Full Code Here

  public void testSubsequentPooledOptimizerUsage() {
    // test the pooled optimizer in situation where the sequence is already beyond its initial value on init.
    //    cheat by telling the sequence to start with 1000
    final SourceMock sequence = new SourceMock( 1001, 3, 5 );
    //    but tell the optimizer the start-with is 1
    final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 3, 1 );

    assertEquals( 5, sequence.getTimesCalled() );
    assertEquals( 1001, sequence.getCurrentValue() );

    Long next = (Long) optimizer.generate( sequence );
    assertEquals( 1001, next.intValue() );
    assertEquals( (5+1), sequence.getTimesCalled() );
    assertEquals( (1001+3), sequence.getCurrentValue() );

    next = (Long) optimizer.generate( sequence );
    assertEquals( (1001+1), next.intValue() );
    assertEquals( (5+1), sequence.getTimesCalled() );
    assertEquals( (1001+3), sequence.getCurrentValue() );

    next = (Long) optimizer.generate( sequence );
    assertEquals( (1001+2), next.intValue() );
    assertEquals( (5+1), sequence.getTimesCalled() );
    assertEquals( (1001+3), sequence.getCurrentValue() );

    // force a "clock over"
    next = (Long) optimizer.generate( sequence );
    assertEquals( (1001+3), next.intValue() );
    assertEquals( (5+2), sequence.getTimesCalled() );
    assertEquals( (1001+6), sequence.getCurrentValue() );
  }
View Full Code Here

  public void testSubsequentPooledLoOptimizerUsage() {
    // test the pooled optimizer in situation where the sequence is already beyond its initial value on init.
    //    cheat by telling the sequence to start with 1000
    final SourceMock sequence = new SourceMock( 1001, 3, 5 );
    //    but tell the optimizer the start-with is 1
    final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 3, 1 );

    assertEquals( 5, sequence.getTimesCalled() );
    assertEquals( 1001, sequence.getCurrentValue() );

    Long next = ( Long ) optimizer.generate( sequence );
    assertEquals( (1001), next.intValue() );
    assertEquals( (5+1), sequence.getTimesCalled() );
    assertEquals( (1001+3), sequence.getCurrentValue() );

    next = ( Long ) optimizer.generate( sequence );
    assertEquals( (1001+1), next.intValue() );
    assertEquals( (5+1), sequence.getTimesCalled() );
    assertEquals( (1001+3), sequence.getCurrentValue() );

    next = ( Long ) optimizer.generate( sequence );
    assertEquals( (1001+2), next.intValue() );
    assertEquals( (5+1), sequence.getTimesCalled() );
    assertEquals( (1001+3), sequence.getCurrentValue() );

//    // force a "clock over"
    next = ( Long ) optimizer.generate( sequence );
    assertEquals( (1001+3), next.intValue() );
    assertEquals( (5+2), sequence.getTimesCalled() );
    assertEquals( (1001+6), sequence.getCurrentValue() );
  }
View Full Code Here

    assertEquals( (1001+6), sequence.getCurrentValue() );
  }

  public void testRecoveredPooledOptimizerUsage() {
    final SourceMock sequence = new SourceMock( 1, 3 );
    final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 3, 1 );

    assertEquals( 0, sequence.getTimesCalled() );
    assertEquals( -1, sequence.getCurrentValue() );

    Long next = ( Long ) optimizer.generate( sequence );
    assertEquals( 1, next.intValue() );
    assertEquals( 2, sequence.getTimesCalled() );
    assertEquals( 4, sequence.getCurrentValue() );

    // app ends, and starts back up (we should "lose" only 2 and 3 as id values)
    final Optimizer optimizer2 = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 3, 1 );
    next = ( Long ) optimizer2.generate( sequence );
    assertEquals( 4, next.intValue() );
    assertEquals( 3, sequence.getTimesCalled() );
    assertEquals( 7, sequence.getCurrentValue() );
  }
View Full Code Here

  }

  public void testBasicNoOptimizerUsage() {
    // test historic sequence behavior, where the initial values start at 1...
    SourceMock sequence = new SourceMock( 1 );
    Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.NONE, Long.class, 1 );
    for ( int i = 1; i < 11; i++ ) {
      final Long next = ( Long ) optimizer.generate( sequence );
      assertEquals( i, next.intValue() );
    }
    assertEquals( 10, sequence.getTimesCalled() );
    assertEquals( 10, sequence.getCurrentValue() );

    // test historic table behavior, where the initial values started at 0 (we now force 1 to be the first used id value)
    sequence = new SourceMock( 0 );
    optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.NONE, Long.class, 1 );
    for ( int i = 1; i < 11; i++ ) {
      final Long next = ( Long ) optimizer.generate( sequence );
      assertEquals( i, next.intValue() );
    }
    assertEquals( 11, sequence.getTimesCalled() ); // an extra time to get to 1 initially
    assertEquals( 10, sequence.getCurrentValue() );
  }
View Full Code Here

    int increment = 10;
    Long next;

    // test historic sequence behavior, where the initial values start at 1...
    SourceMock sequence = new SourceMock( 1 );
    Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.HILO, Long.class, increment );
    for ( int i = 1; i <= increment; i++ ) {
      next = ( Long ) optimizer.generate( sequence );
      assertEquals( i, next.intValue() );
    }
    assertEquals( 1, sequence.getTimesCalled() ); // once to initialze state
    assertEquals( 1, sequence.getCurrentValue() );
    // force a "clock over"
    next = ( Long ) optimizer.generate( sequence );
    assertEquals( 11, next.intValue() );
    assertEquals( 2, sequence.getTimesCalled() );
    assertEquals( 2, sequence.getCurrentValue() );

    // test historic table behavior, where the initial values started at 0 (we now force 1 to be the first used id value)
    sequence = new SourceMock( 0 );
    optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.HILO, Long.class, increment );
    for ( int i = 1; i <= increment; i++ ) {
      next = ( Long ) optimizer.generate( sequence );
      assertEquals( i, next.intValue() );
    }
    assertEquals( 2, sequence.getTimesCalled() ); // here have have an extra call to get to 1 initially
    assertEquals( 1, sequence.getCurrentValue() );
    // force a "clock over"
    next = ( Long ) optimizer.generate( sequence );
    assertEquals( 11, next.intValue() );
    assertEquals( 3, sequence.getTimesCalled() );
    assertEquals( 2, sequence.getCurrentValue() );
  }
View Full Code Here

  public void testBasicPooledOptimizerUsage() {
    Long next;
    // test historic sequence behavior, where the initial values start at 1...
    SourceMock sequence = new SourceMock( 1, 10 );
    Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 10 );
    for ( int i = 1; i < 11; i++ ) {
      next = ( Long ) optimizer.generate( sequence );
      assertEquals( i, next.intValue() );
    }
    assertEquals( 2, sequence.getTimesCalled() ); // twice to initialze state
    assertEquals( 11, sequence.getCurrentValue() );
    // force a "clock over"
    next = ( Long ) optimizer.generate( sequence );
    assertEquals( 11, next.intValue() );
    assertEquals( 3, sequence.getTimesCalled() );
    assertEquals( 21, sequence.getCurrentValue() );
  }
View Full Code Here

            optimizer = new Callable<Optimizer>() {
                private volatile Optimizer optimizer;
               
                @Override
                public Optimizer call() throws Exception {
                    Optimizer o = optimizer;
                    if (o != null) {
                        return o;
                    }
                   
                    synchronized (this) {
View Full Code Here

TOP

Related Classes of org.hibernate.id.enhanced.Optimizer

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.