Java 类org.hibernate.id.enhanced.TableGenerator 实例源码
项目:lams
文件:DefaultIdentifierGeneratorFactory.java
/**
* Constructs a new DefaultIdentifierGeneratorFactory.
*/
public DefaultIdentifierGeneratorFactory() {
register( "uuid2", UUIDGenerator.class );
register( "guid", GUIDGenerator.class ); // can be done with UUIDGenerator + strategy
register( "uuid", UUIDHexGenerator.class ); // "deprecated" for new use
register( "uuid.hex", UUIDHexGenerator.class ); // uuid.hex is deprecated
register( "hilo", TableHiLoGenerator.class );
register( "assigned", Assigned.class );
register( "identity", IdentityGenerator.class );
register( "select", SelectGenerator.class );
register( "sequence", SequenceGenerator.class );
register( "seqhilo", SequenceHiLoGenerator.class );
register( "increment", IncrementGenerator.class );
register( "foreign", ForeignGenerator.class );
register( "sequence-identity", SequenceIdentityGenerator.class );
register( "enhanced-sequence", SequenceStyleGenerator.class );
register( "enhanced-table", TableGenerator.class );
}
项目:Portofino
文件:HibernateConfig.java
protected void setPKColumnGenerator(Mappings mappings, RootClass clazz, Table tab, com.manydesigns.portofino.model.database.Column column, SimpleValue id, Generator generator) {
if (column.isAutoincrement()) {
manageIdentityGenerator(mappings, tab, id);
} else if (generator != null) {
if (generator instanceof SequenceGenerator) {
manageSequenceGenerator(mappings, tab, id, (SequenceGenerator) generator);
} else if (generator instanceof
com.manydesigns.portofino.model.database.TableGenerator) {
manageTableGenerator(mappings, tab, id,
(com.manydesigns.portofino.model.database.TableGenerator) generator);
} else if (generator instanceof
com.manydesigns.portofino.model.database.IncrementGenerator){
manageIncrementGenerator(mappings, tab, id, clazz.getEntityName());
}
}
}
项目:Portofino
文件:HibernateConfig.java
private void manageTableGenerator(Mappings mappings, Table tab, SimpleValue id,
com.manydesigns.portofino.model.database.TableGenerator generator) {
id.setIdentifierGeneratorStrategy("enhanced-table");
Properties params = new Properties();
params.put(TableGenerator.TABLE,
tab);
params.put(TableGenerator.TABLE_PARAM,
quoteIdentifier(generator.getTable()));
params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
mappings.getObjectNameNormalizer());
params.put(TableGenerator.SEGMENT_COLUMN_PARAM, quoteIdentifier(generator.getKeyColumn()));
params.put(TableGenerator.SEGMENT_VALUE_PARAM, generator.getKeyValue());
params.put(TableGenerator.VALUE_COLUMN_PARAM, quoteIdentifier(generator.getValueColumn()));
params.setProperty(
TableGenerator.SCHEMA, quoteIdentifier(tab.getSchema()));
id.setIdentifierGeneratorProperties(params);
id.setNullValue(null);
}
项目:manydesigns.cn
文件:HibernateConfig.java
protected void setPKColumnGenerator(Mappings mappings, RootClass clazz, Table tab, com.manydesigns.portofino.model.database.Column column, SimpleValue id, Generator generator) {
if (column.isAutoincrement()) {
manageIdentityGenerator(mappings, tab, id);
} else if (generator != null) {
if (generator instanceof SequenceGenerator) {
manageSequenceGenerator(mappings, tab, id, (SequenceGenerator) generator);
} else if (generator instanceof
com.manydesigns.portofino.model.database.TableGenerator) {
manageTableGenerator(mappings, tab, id,
(com.manydesigns.portofino.model.database.TableGenerator) generator);
} else if (generator instanceof
com.manydesigns.portofino.model.database.IncrementGenerator){
manageIncrementGenerator(mappings, tab, id, clazz.getEntityName());
}
}
}
项目:manydesigns.cn
文件:HibernateConfig.java
private void manageTableGenerator(Mappings mappings, Table tab, SimpleValue id,
com.manydesigns.portofino.model.database.TableGenerator generator) {
id.setIdentifierGeneratorStrategy("enhanced-table");
Properties params = new Properties();
params.put(TableGenerator.TABLE,
tab);
params.put(TableGenerator.TABLE_PARAM,
escapeName(generator.getTable()));
params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
mappings.getObjectNameNormalizer());
params.put(TableGenerator.SEGMENT_COLUMN_PARAM, escapeName(generator.getKeyColumn()));
params.put(TableGenerator.SEGMENT_VALUE_PARAM, generator.getKeyValue());
params.put(TableGenerator.VALUE_COLUMN_PARAM,escapeName(generator.getValueColumn()));
params.setProperty(
TableGenerator.SCHEMA,escapeName(tab.getSchema()));
id.setIdentifierGeneratorProperties(params);
id.setNullValue(null);
}
项目:cacheonix-core
文件:BasicTableTest.java
public void testNormalBoundary() {
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
assertClassAssignability( TableGenerator.class, persister.getIdentifierGenerator().getClass() );
TableGenerator generator = ( TableGenerator ) 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.getTableAccessCount() );
assertEquals( expectedId, generator.getOptimizer().getLastSourceValue() );
}
s.getTransaction().commit();
s.beginTransaction();
for ( int i = 0; i < count; i++ ) {
assertEquals( i + 1, entities[i].getId().intValue() );
s.delete( entities[i] );
}
s.getTransaction().commit();
s.close();
}
项目:cacheonix-core
文件:PooledTableTest.java
public void testNormalBoundary() {
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
assertClassAssignability( TableGenerator.class, persister.getIdentifierGenerator().getClass() );
TableGenerator generator = ( TableGenerator ) 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.getTableAccessCount() ); // initialization calls seq twice
assertEquals( increment + 1, optimizer.getLastSourceValue() ); // initialization calls seq twice
assertEquals( i + 1, optimizer.getLastValue() );
assertEquals( increment + 1, optimizer.getLastSourceValue() );
}
// now force a "clock over"
entities[ increment ] = new Entity( "" + increment );
s.save( entities[ increment ] );
assertEquals( 3, generator.getTableAccessCount() ); // initialization (2) + clock over
assertEquals( ( increment * 2 ) + 1, optimizer.getLastSourceValue() ); // initialization (2) + clock over
assertEquals( increment + 1, optimizer.getLastValue() );
s.getTransaction().commit();
s.beginTransaction();
for ( int i = 0; i < entities.length; i++ ) {
assertEquals( i + 1, entities[i].getId().intValue() );
s.delete( entities[i] );
}
s.getTransaction().commit();
s.close();
}
项目:cacheonix-core
文件:HiLoTableTest.java
public void testNormalBoundary() {
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
assertClassAssignability( TableGenerator.class, persister.getIdentifierGenerator().getClass() );
TableGenerator generator = ( TableGenerator ) 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.getTableAccessCount() ); // initialization
assertEquals( 1, optimizer.getLastSourceValue() ); // initialization
assertEquals( i + 1, optimizer.getLastValue() );
assertEquals( increment + 1, optimizer.getHiValue() );
}
// now force a "clock over"
entities[ increment ] = new Entity( "" + increment );
s.save( entities[ increment ] );
assertEquals( 2, generator.getTableAccessCount() ); // initialization
assertEquals( 2, optimizer.getLastSourceValue() ); // initialization
assertEquals( increment + 1, optimizer.getLastValue() );
assertEquals( ( increment * 2 ) + 1, optimizer.getHiValue() );
s.getTransaction().commit();
s.beginTransaction();
for ( int i = 0; i < entities.length; i++ ) {
assertEquals( i + 1, entities[i].getId().intValue() );
s.delete( entities[i] );
}
s.getTransaction().commit();
s.close();
}
项目:lams
文件:IdGeneratorBinder.java
private static void bindTableGenerator(MetadataImplementor metadata, AnnotationInstance generator) {
String name = JandexHelper.getValue( generator, "name", String.class );
Map<String, String> parameterMap = new HashMap<String, String>();
addStringParameter( generator, "catalog", parameterMap, PersistentIdentifierGenerator.CATALOG );
addStringParameter( generator, "schema", parameterMap, PersistentIdentifierGenerator.SCHEMA );
boolean useNewIdentifierGenerators = metadata.getOptions().useNewIdentifierGenerators();
String strategy = EnumConversionHelper.generationTypeToGeneratorStrategyName(
GenerationType.TABLE,
useNewIdentifierGenerators
);
if ( useNewIdentifierGenerators ) {
parameterMap.put( TableGenerator.CONFIG_PREFER_SEGMENT_PER_ENTITY, "true" );
addStringParameter( generator, "table", parameterMap, TableGenerator.TABLE_PARAM );
addStringParameter( generator, "pkColumnName", parameterMap, TableGenerator.SEGMENT_COLUMN_PARAM );
addStringParameter( generator, "pkColumnValue", parameterMap, TableGenerator.SEGMENT_VALUE_PARAM );
addStringParameter( generator, "valueColumnName", parameterMap, TableGenerator.VALUE_COLUMN_PARAM );
parameterMap.put(
TableGenerator.INCREMENT_PARAM,
String.valueOf( JandexHelper.getValue( generator, "allocationSize", String.class ) )
);
parameterMap.put(
TableGenerator.INITIAL_PARAM,
String.valueOf( JandexHelper.getValue( generator, "initialValue", String.class ) + 1 )
);
}
else {
addStringParameter( generator, "table", parameterMap, MultipleHiLoPerTableGenerator.ID_TABLE );
addStringParameter( generator, "pkColumnName", parameterMap, MultipleHiLoPerTableGenerator.PK_COLUMN_NAME );
addStringParameter( generator, "pkColumnValue", parameterMap, MultipleHiLoPerTableGenerator.PK_VALUE_NAME );
addStringParameter( generator, "valueColumnName", parameterMap, MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME );
parameterMap.put(
TableHiLoGenerator.MAX_LO,
String.valueOf( JandexHelper.getValue( generator, "allocationSize", Integer.class ) - 1 )
);
}
if ( JandexHelper.getValue( generator, "uniqueConstraints", AnnotationInstance[].class ).length > 0 ) {
LOG.ignoringTableGeneratorConstraints( name );
}
metadata.addIdGenerator( new IdGenerator( name, strategy, parameterMap ) );
LOG.tracef( "Add table generator with name: %s", name );
}