org.databene.platform.db
Class OfflineSequenceGenerator

java.lang.Object
  extended by org.databene.benerator.util.AbstractGenerator<E>
      extended by org.databene.benerator.util.ThreadSafeGenerator<java.lang.Long>
          extended by org.databene.platform.db.OfflineSequenceGenerator
All Implemented Interfaces:
java.io.Closeable, Generator<java.lang.Long>, org.databene.commons.Resettable, org.databene.commons.ThreadAware

public class OfflineSequenceGenerator
extends ThreadSafeGenerator<java.lang.Long>

Reads the current value of a sequence on first invocation, increases the value locally on subsequent calls and finally (on close()) updates the DB sequence with the local value. This saves database round trips but limits execution to a single client.

Created: 11.11.2009 18:35:26

Since:
0.6.0
Author:
Volker Bergmann

Field Summary
 
Fields inherited from class org.databene.benerator.util.AbstractGenerator
context, state
 
Constructor Summary
OfflineSequenceGenerator()
           
OfflineSequenceGenerator(DBSystem target, java.lang.String sequenceName)
           
 
Method Summary
 void close()
          Closes the generator.
 java.lang.Long generate()
          Returns an instance of the generic type E.
 java.lang.Class<java.lang.Long> getGeneratedType()
          Declares the type of the objects returned by the generate() method.
 java.lang.String getSequenceName()
           
 DBSystem getTarget()
           
 void init(GeneratorContext context)
           
 void setSequenceName(java.lang.String sequenceName)
           
 void setTarget(DBSystem target)
           
 
Methods inherited from class org.databene.benerator.util.ThreadSafeGenerator
isParallelizable, isThreadSafe
 
Methods inherited from class org.databene.benerator.util.AbstractGenerator
assertInitialized, assertNotInitialized, reset, toString, wasInitialized
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OfflineSequenceGenerator

public OfflineSequenceGenerator()

OfflineSequenceGenerator

public OfflineSequenceGenerator(DBSystem target,
                                java.lang.String sequenceName)
Method Detail

getTarget

public DBSystem getTarget()

setTarget

public void setTarget(DBSystem target)

getSequenceName

public java.lang.String getSequenceName()

setSequenceName

public void setSequenceName(java.lang.String sequenceName)

init

public void init(GeneratorContext context)
Specified by:
init in interface Generator<java.lang.Long>
Overrides:
init in class AbstractGenerator<java.lang.Long>

getGeneratedType

public java.lang.Class<java.lang.Long> getGeneratedType()
Description copied from interface: Generator
Declares the type of the objects returned by the generate() method.


generate

public java.lang.Long generate()
Description copied from interface: Generator
Returns an instance of the generic type E.


close

public void close()
Description copied from interface: Generator
Closes the generator. After invocation the state is unavailable.

Specified by:
close in interface java.io.Closeable
Specified by:
close in interface Generator<java.lang.Long>
Overrides:
close in class AbstractGenerator<java.lang.Long>


Copyright © 2011. All Rights Reserved.