Package org.hibernate.id.enhanced

Examples of org.hibernate.id.enhanced.SequenceStyleGenerator


  }

  public void testNormalBoundary() {
    EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
    assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
    SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
    assertClassAssignability( OptimizerFactory.PooledOptimizer.class, generator.getOptimizer().getClass() );
    OptimizerFactory.PooledOptimizer optimizer = ( OptimizerFactory.PooledOptimizer ) generator.getOptimizer();

    int increment = optimizer.getIncrementSize();
    Entity[] entities = new Entity[ increment + 1 ];
    Session s = openSession();
    s.beginTransaction();
    for ( int i = 0; i < increment; i++ ) {
      entities[i] = new Entity( "" + ( i + 1 ) );
      s.save( entities[i] );
      assertEquals( 2, generator.getDatabaseStructure().getTimesAccessed() ); // initialization calls seq twice
      assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization calls seq twice
      assertEquals( i + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
      assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
    }
    // now force a "clock over"
    entities[ increment ] = new Entity( "" + increment );
    s.save( entities[ increment ] );
    assertEquals( 3, generator.getDatabaseStructure().getTimesAccessed() ); // initialization (2) + clock over
    assertEquals( ( increment * 2 ) + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization (2) + clock over
    assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
    s.getTransaction().commit();

    s.beginTransaction();
View Full Code Here


  }

  public void testNormalBoundary() {
    EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
    assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
    SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();

    int count = 5;
    Entity[] entities = new Entity[count];
    Session s = openSession();
    s.beginTransaction();
    for ( int i = 0; i < count; i++ ) {
      entities[i] = new Entity( "" + ( i + 1 ) );
      s.save( entities[i] );
      long expectedId = i + 1;
      assertEquals( expectedId, entities[i].getId().longValue() );
      assertEquals( expectedId, generator.getDatabaseStructure().getTimesAccessed() );
      assertEquals( expectedId, ( (BasicHolder) generator.getOptimizer().getLastSourceValue() ).getActualLongValue() );
    }
    s.getTransaction().commit();

    s.beginTransaction();
    for ( int i = 0; i < count; i++ ) {
View Full Code Here

  }

  public void testNormalBoundary() {
    EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
    assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
    SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
    assertClassAssignability( OptimizerFactory.HiLoOptimizer.class, generator.getOptimizer().getClass() );
    OptimizerFactory.HiLoOptimizer optimizer = ( OptimizerFactory.HiLoOptimizer ) generator.getOptimizer();

    int increment = optimizer.getIncrementSize();
    Entity[] entities = new Entity[ increment + 1 ];
    Session s = openSession();
    s.beginTransaction();
    for ( int i = 0; i < increment; i++ ) {
      entities[i] = new Entity( "" + ( i + 1 ) );
      s.save( entities[i] );
      assertEquals( 1, generator.getDatabaseStructure().getTimesAccessed() ); // initialization
      assertEquals( 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization
      assertEquals( i + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
      assertEquals( increment + 1, ( (BasicHolder) optimizer.getHiValue() ).getActualLongValue() );
    }
    // now force a "clock over"
    entities[ increment ] = new Entity( "" + increment );
    s.save( entities[ increment ] );
    assertEquals( 2, generator.getDatabaseStructure().getTimesAccessed() ); // initialization
    assertEquals( 2, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization
    assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
    assertEquals( ( increment * 2 ) + 1, ( (BasicHolder) optimizer.getHiValue() ).getActualLongValue() );

    s.getTransaction().commit();
View Full Code Here

  public void testMinimalSequenceEntity() {
    final EntityPersister persister = sfi().getEntityPersister( MinimalSequenceEntity.class.getName() );
    IdentifierGenerator generator = persister.getIdentifierGenerator();
    assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
    SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
    assertEquals( MinimalSequenceEntity.SEQ_NAME, seqGenerator.getDatabaseStructure().getName() );
    // 1 is the annotation default
    assertEquals( 1, seqGenerator.getDatabaseStructure().getInitialValue() );
    // 50 is the annotation default
    assertEquals( 50, seqGenerator.getDatabaseStructure().getIncrementSize() );
    assertFalse( OptimizerFactory.NoopOptimizer.class.isInstance( seqGenerator.getOptimizer() ) );
  }
View Full Code Here

  public void testCompleteSequenceEntity() {
    final EntityPersister persister = sfi().getEntityPersister( CompleteSequenceEntity.class.getName() );
    IdentifierGenerator generator = persister.getIdentifierGenerator();
    assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
    SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
    assertEquals( "my_catalog.my_schema."+CompleteSequenceEntity.SEQ_NAME, seqGenerator.getDatabaseStructure().getName() );
    assertEquals( 1000, seqGenerator.getDatabaseStructure().getInitialValue() );
    assertEquals( 52, seqGenerator.getDatabaseStructure().getIncrementSize() );
    assertFalse( OptimizerFactory.NoopOptimizer.class.isInstance( seqGenerator.getOptimizer() ) );
  }
View Full Code Here

  public void testAutoEntity() {
    final EntityPersister persister = sfi().getEntityPersister( AutoEntity.class.getName() );
    IdentifierGenerator generator = persister.getIdentifierGenerator();
    assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
    SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
    assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, seqGenerator.getDatabaseStructure().getName() );
    assertEquals( SequenceStyleGenerator.DEFAULT_INITIAL_VALUE, seqGenerator.getDatabaseStructure().getInitialValue() );
    assertEquals( SequenceStyleGenerator.DEFAULT_INCREMENT_SIZE, seqGenerator.getDatabaseStructure().getIncrementSize() );
  }
View Full Code Here

    EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
    assertTrue(
        "sequence style generator was not used",
        SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
    );
    SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
    assertTrue(
        "table structure was not used",
        TableStructure.class.isInstance( generator.getDatabaseStructure() )
    );
    assertTrue(
        "no-op optimizer was not used",
        OptimizerFactory.NoopOptimizer.class.isInstance( generator.getOptimizer() )
    );

    int count = 5;
    Entity[] entities = new Entity[count];
    Session s = openSession();
    s.beginTransaction();
    for ( int i = 0; i < count; i++ ) {
      entities[i] = new Entity( "" + ( i + 1 ) );
      s.save( entities[i] );
      long expectedId = i + 1;
      assertEquals( expectedId, entities[i].getId().longValue() );
      assertEquals( expectedId, generator.getDatabaseStructure().getTimesAccessed() );
      assertEquals( expectedId, ( (BasicHolder) generator.getOptimizer().getLastSourceValue() ).getActualLongValue() );
    }
    s.getTransaction().commit();

    s.beginTransaction();
    for ( int i = 0; i < count; i++ ) {
View Full Code Here

    EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
    assertTrue(
        "sequence style generator was not used",
        SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
    );
    SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
    assertTrue(
        "table structure was not used",
        TableStructure.class.isInstance( generator.getDatabaseStructure() )
    );
    assertTrue(
        "pooled optimizer was not used",
        OptimizerFactory.PooledOptimizer.class.isInstance( generator.getOptimizer() )
    );
    OptimizerFactory.PooledOptimizer optimizer = ( OptimizerFactory.PooledOptimizer ) generator.getOptimizer();

    int increment = optimizer.getIncrementSize();
    Entity[] entities = new Entity[ increment + 1 ];
    Session s = openSession();
    s.beginTransaction();
    for ( int i = 0; i < increment; i++ ) {
      entities[i] = new Entity( "" + ( i + 1 ) );
      s.save( entities[i] );
      long expectedId = i + 1;
      assertEquals( expectedId, entities[i].getId().longValue() );
      // NOTE : initialization calls table twice
      assertEquals( 2, generator.getDatabaseStructure().getTimesAccessed() );
      assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
      assertEquals( i + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
      assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
    }
    // now force a "clock over"
    entities[ increment ] = new Entity( "" + increment );
    s.save( entities[ increment ] );
    long expectedId = optimizer.getIncrementSize() + 1;
    assertEquals( expectedId, entities[ optimizer.getIncrementSize() ].getId().longValue() );
    // initialization (2) + clock over
    assertEquals( 3, generator.getDatabaseStructure().getTimesAccessed() );
    assertEquals( ( increment * 2 ) + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
    assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
    s.getTransaction().commit();

    s.beginTransaction();
View Full Code Here

    EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
    assertTrue(
        "sequence style generator was not used",
        SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
    );
    SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
    assertTrue(
        "table structure was not used",
        TableStructure.class.isInstance( generator.getDatabaseStructure() )
    );
    assertTrue(
        "hilo optimizer was not used",
        OptimizerFactory.HiLoOptimizer.class.isInstance( generator.getOptimizer() )
    );
    OptimizerFactory.HiLoOptimizer optimizer = ( OptimizerFactory.HiLoOptimizer ) generator.getOptimizer();

    int increment = optimizer.getIncrementSize();
    Entity[] entities = new Entity[ increment + 1 ];
    Session s = openSession();
    s.beginTransaction();
View Full Code Here

   */
  public void testDefaultOptimizerBasedOnIncrementBackedByTable() {
    Properties props = new Properties();
    props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" );
    Dialect dialect = new TableDialect();
    SequenceStyleGenerator generator = new SequenceStyleGenerator();
    generator.configure( Hibernate.LONG, props, dialect );
    assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
    assertClassAssignability( OptimizerFactory.PooledOptimizer.class, generator.getOptimizer().getClass() );
    assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
  }
View Full Code Here

TOP

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

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.