当前位置: 首页>>代码示例>>Java>>正文


Java SequenceStyleGenerator类代码示例

本文整理汇总了Java中org.hibernate.id.enhanced.SequenceStyleGenerator的典型用法代码示例。如果您正苦于以下问题:Java SequenceStyleGenerator类的具体用法?Java SequenceStyleGenerator怎么用?Java SequenceStyleGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SequenceStyleGenerator类属于org.hibernate.id.enhanced包,在下文中一共展示了SequenceStyleGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testForceTableUse

import org.hibernate.id.enhanced.SequenceStyleGenerator; //导入依赖的package包/类
/**
 * Test forcing of table as backing strucuture with dialect supporting sequences
 */
public void testForceTableUse() {
	Dialect dialect = new SequenceDialect();
	Properties props = new Properties();
	props.setProperty( SequenceStyleGenerator.FORCE_TBL_PARAM, "true" );
	SequenceStyleGenerator generator = new SequenceStyleGenerator();
	generator.configure( Hibernate.LONG, props, dialect );
	assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
	assertClassAssignability( OptimizerFactory.NoopOptimizer.class, generator.getOptimizer().getClass() );
	assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:14,代码来源:SequenceStyleConfigUnitTest.java

示例2: bindSimpleValue

import org.hibernate.id.enhanced.SequenceStyleGenerator; //导入依赖的package包/类
protected void bindSimpleValue(PersistentProperty grailsProp,
                               PersistentProperty parentProperty, SimpleValue simpleValue,
                               String path, PropertyConfig propertyConfig, String sessionFactoryBeanName) {
    setTypeForPropertyConfig(grailsProp, simpleValue, propertyConfig);
    final PropertyConfig mappedForm = (PropertyConfig) grailsProp.getMapping().getMappedForm();
    if (mappedForm.isDerived() && !(grailsProp instanceof TenantId)) {
        Formula formula = new Formula();
        formula.setFormula(propertyConfig.getFormula());
        simpleValue.addFormula(formula);
    } else {
        Table table = simpleValue.getTable();
        boolean hasConfig = propertyConfig != null;

        String generator = hasConfig ? propertyConfig.getGenerator() : null;
        if(generator != null) {
            simpleValue.setIdentifierGeneratorStrategy(generator);
            Properties params = propertyConfig.getTypeParams();
            if(params != null) {
                Properties generatorProps = new Properties();
                generatorProps.putAll(params);

                if(generatorProps.containsKey(SEQUENCE_KEY)) {
                    generatorProps.put(SequenceStyleGenerator.SEQUENCE_PARAM,  generatorProps.getProperty(SEQUENCE_KEY));
                }
                simpleValue.setIdentifierGeneratorProperties( generatorProps );
            }
        }

        // Add the column definitions for this value/property. Note that
        // not all custom mapped properties will have column definitions,
        // in which case we still need to create a Hibernate column for
        // this value.
        List<?> columnDefinitions = hasConfig ? propertyConfig.getColumns()
                : Arrays.asList(new Object[] { null });
        if (columnDefinitions.isEmpty()) {
            columnDefinitions = Arrays.asList(new Object[] { null });
        }

        for (Object columnDefinition : columnDefinitions) {
            ColumnConfig cc = (ColumnConfig) columnDefinition;
            Column column = new Column();

            // Check for explicitly mapped column name and SQL type.
            if (cc != null) {
                if (cc.getName() != null) {
                    column.setName(cc.getName());
                }
                if (cc.getSqlType() != null) {
                    column.setSqlType(cc.getSqlType());
                }
            }

            column.setValue(simpleValue);


            if (cc != null) {
                if (cc.getLength() != -1) {
                    column.setLength(cc.getLength());
                }
                if (cc.getPrecision() != -1) {
                    column.setPrecision(cc.getPrecision());
                }
                if (cc.getScale() != -1) {
                    column.setScale(cc.getScale());
                }
                if(!mappedForm.isUniqueWithinGroup()) {
                    column.setUnique(cc.isUnique());
                }
            }

            bindColumn(grailsProp, parentProperty, column, cc, path, table, sessionFactoryBeanName);

            if (table != null) {
                table.addColumn(column);
            }

            simpleValue.addColumn(column);
        }
    }
}
 
开发者ID:grails,项目名称:gorm-hibernate5,代码行数:81,代码来源:GrailsDomainBinder.java

示例3: testNormalBoundary

import org.hibernate.id.enhanced.SequenceStyleGenerator; //导入依赖的package包/类
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, 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.getDatabaseStructure().getTimesAccessed() ); // 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();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:36,代码来源:PooledSequenceTest.java

示例4: testNormalBoundary

import org.hibernate.id.enhanced.SequenceStyleGenerator; //导入依赖的package包/类
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, 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();

}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:29,代码来源:BasicSequenceTest.java

示例5: testNormalBoundary

import org.hibernate.id.enhanced.SequenceStyleGenerator; //导入依赖的package包/类
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, 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.getDatabaseStructure().getTimesAccessed() ); // 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();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:38,代码来源:HiLoSequenceTest.java

示例6: testDefaultedSequenceBackedConfiguration

import org.hibernate.id.enhanced.SequenceStyleGenerator; //导入依赖的package包/类
/**
 * Test all params defaulted with a dialect supporting sequences
 */
public void testDefaultedSequenceBackedConfiguration() {
	Dialect dialect = new SequenceDialect();
	Properties props = new Properties();
	SequenceStyleGenerator generator = new SequenceStyleGenerator();
	generator.configure( Hibernate.LONG, props, dialect );

	assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
	assertClassAssignability( OptimizerFactory.NoopOptimizer.class, generator.getOptimizer().getClass() );
	assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:14,代码来源:SequenceStyleConfigUnitTest.java

示例7: testDefaultedTableBackedConfiguration

import org.hibernate.id.enhanced.SequenceStyleGenerator; //导入依赖的package包/类
/**
 * Test all params defaulted with a dialect which does not support sequences
 */
public void testDefaultedTableBackedConfiguration() {
	Dialect dialect = new TableDialect();
	Properties props = new Properties();
	SequenceStyleGenerator generator = new SequenceStyleGenerator();
	generator.configure( Hibernate.LONG, props, dialect );

	assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
	assertClassAssignability( OptimizerFactory.NoopOptimizer.class, generator.getOptimizer().getClass() );
	assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:14,代码来源:SequenceStyleConfigUnitTest.java

示例8: testDefaultOptimizerBasedOnIncrementBackedByTable

import org.hibernate.id.enhanced.SequenceStyleGenerator; //导入依赖的package包/类
/**
 * Test default optimizer selection for table backed generators
 * based on the configured increment size.  Here we always prefer
 * pooled.
 */
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() );
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:16,代码来源:SequenceStyleConfigUnitTest.java

示例9: getStrategies

import org.hibernate.id.enhanced.SequenceStyleGenerator; //导入依赖的package包/类
@Override
public Map<String, Class<?>> getStrategies() {
	return ImmutableMap.<String, Class<?>> builder()
			// overriding default SequenceStyleGenerator; our SequenceStyleGenerator is configured to
			// always generate a sequence by table
			.put(SequenceStyleGenerator.class.getName(), PerTableSequenceStyleGenerator.class).build();
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:8,代码来源:PerTableSequenceStrategyProvider.java

示例10: manageSequenceGenerator

import org.hibernate.id.enhanced.SequenceStyleGenerator; //导入依赖的package包/类
private void manageSequenceGenerator(Mappings mappings, Table tab,
                                      SimpleValue id, SequenceGenerator generator) {
    id.setIdentifierGeneratorStrategy
            ("enhanced-sequence");
    Properties params = new Properties();
    params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
                mappings.getObjectNameNormalizer());
    params.put(SequenceStyleGenerator.SEQUENCE_PARAM,
                quoteIdentifier(generator.getName()));
    params.setProperty(
            SequenceStyleGenerator.SCHEMA,
            quoteIdentifier(tab.getSchema()));
    id.setIdentifierGeneratorProperties(params);
    id.setNullValue(null);
}
 
开发者ID:ManyDesigns,项目名称:Portofino,代码行数:16,代码来源:HibernateConfig.java

示例11: configure

import org.hibernate.id.enhanced.SequenceStyleGenerator; //导入依赖的package包/类
@Override
public void configure(
        Type type, Properties params, ServiceRegistry serviceRegistry)
        throws MappingException {
    final JdbcEnvironment jdbcEnvironment =
            serviceRegistry.getService(JdbcEnvironment.class);
    final Dialect dialect = jdbcEnvironment.getDialect();

    final ConfigurationService configurationService =
            serviceRegistry.getService(ConfigurationService.class);
    String globalEntityIdentifierPrefix =
        configurationService.getSetting( "entity.identifier.prefix", String.class, "SEQ_" );

    sequencePrefix = ConfigurationHelper.getString(
            SEQUENCE_PREFIX,
            params,
            globalEntityIdentifierPrefix);

    final String sequencePerEntitySuffix = ConfigurationHelper.getString(
            SequenceStyleGenerator.CONFIG_SEQUENCE_PER_ENTITY_SUFFIX,
            params,
            SequenceStyleGenerator.DEF_SEQUENCE_SUFFIX);

    final String defaultSequenceName = ConfigurationHelper.getBoolean(
            SequenceStyleGenerator.CONFIG_PREFER_SEQUENCE_PER_ENTITY,
            params,
            false)
            ? params.getProperty(JPA_ENTITY_NAME) + sequencePerEntitySuffix
            : SequenceStyleGenerator.DEF_SEQUENCE_NAME;

    sequenceCallSyntax = dialect.getSequenceNextValString(
            ConfigurationHelper.getString(
                    SequenceStyleGenerator.SEQUENCE_PARAM,
                    params,
                    defaultSequenceName));
}
 
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:37,代码来源:StringSequenceIdentifier.java

示例12: manageSequenceGenerator

import org.hibernate.id.enhanced.SequenceStyleGenerator; //导入依赖的package包/类
private void manageSequenceGenerator(Mappings mappings, Table tab,
                                      SimpleValue id, SequenceGenerator generator) {
    id.setIdentifierGeneratorStrategy
            ("enhanced-sequence");
    Properties params = new Properties();
    params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
                mappings.getObjectNameNormalizer());
    params.put(SequenceStyleGenerator.SEQUENCE_PARAM,
                escapeName(generator.getName()));
    params.setProperty(
            SequenceStyleGenerator.SCHEMA,
            escapeName(tab.getSchema()));
    id.setIdentifierGeneratorProperties(params);
    id.setNullValue(null);
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:16,代码来源:HibernateConfig.java

示例13: generatorType

import org.hibernate.id.enhanced.SequenceStyleGenerator; //导入依赖的package包/类
private static String generatorType(GenerationType generatorEnum, Mappings mappings) {
	boolean useNewGeneratorMappings = mappings.useNewGeneratorMappings();
	switch ( generatorEnum ) {
		case IDENTITY:
			return "identity";
		case AUTO:
			return useNewGeneratorMappings
					? org.hibernate.id.enhanced.SequenceStyleGenerator.class.getName()
					: "native";
		case TABLE:
			return useNewGeneratorMappings
					? org.hibernate.id.enhanced.TableGenerator.class.getName()
					: MultipleHiLoPerTableGenerator.class.getName();
		case SEQUENCE:
			return useNewGeneratorMappings
					? org.hibernate.id.enhanced.SequenceStyleGenerator.class.getName()
					: "seqhilo";
	}
	throw new AssertionFailure( "Unknown GeneratorType: " + generatorEnum );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:AnnotationBinder.java

示例14: bindSequenceGenerator

import org.hibernate.id.enhanced.SequenceStyleGenerator; //导入依赖的package包/类
private static void bindSequenceGenerator(MetadataImplementor metadata, AnnotationInstance generator) {
	String name = JandexHelper.getValue( generator, "name", String.class );
	Map<String, String> parameterMap = new HashMap<String, String>();
	addStringParameter( generator, "sequenceName", parameterMap, SequenceStyleGenerator.SEQUENCE_PARAM );
	boolean useNewIdentifierGenerators = metadata.getOptions().useNewIdentifierGenerators();
	String strategy = EnumConversionHelper.generationTypeToGeneratorStrategyName(
			GenerationType.SEQUENCE,
			useNewIdentifierGenerators
	);
	if ( useNewIdentifierGenerators ) {
		addStringParameter( generator, "catalog", parameterMap, PersistentIdentifierGenerator.CATALOG );
		addStringParameter( generator, "schema", parameterMap, PersistentIdentifierGenerator.SCHEMA );
		parameterMap.put(
				SequenceStyleGenerator.INCREMENT_PARAM,
				String.valueOf( JandexHelper.getValue( generator, "allocationSize", Integer.class ) )
		);
		parameterMap.put(
				SequenceStyleGenerator.INITIAL_PARAM,
				String.valueOf( JandexHelper.getValue( generator, "initialValue", Integer.class ) )
		);
	}
	else {
		if ( JandexHelper.getValue( generator, "initialValue", Integer.class ) != 1 ) {
			LOG.unsupportedInitialValue( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS );
		}
		parameterMap.put(
				SequenceHiLoGenerator.MAX_LO,
				String.valueOf( JandexHelper.getValue( generator, "allocationSize", Integer.class ) - 1 )
		);
	}
	metadata.addIdGenerator( new IdGenerator( name, strategy, parameterMap ) );
	LOG.tracef( "Add sequence generator with name: %s", name );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:IdGeneratorBinder.java

示例15: DefaultIdentifierGeneratorFactory

import org.hibernate.id.enhanced.SequenceStyleGenerator; //导入依赖的package包/类
/**
 * 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 );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:DefaultIdentifierGeneratorFactory.java


注:本文中的org.hibernate.id.enhanced.SequenceStyleGenerator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。