本文整理汇总了Java中org.hibernate.id.PersistentIdentifierGenerator类的典型用法代码示例。如果您正苦于以下问题:Java PersistentIdentifierGenerator类的具体用法?Java PersistentIdentifierGenerator怎么用?Java PersistentIdentifierGenerator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PersistentIdentifierGenerator类属于org.hibernate.id包,在下文中一共展示了PersistentIdentifierGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConfiguration
import org.hibernate.id.PersistentIdentifierGenerator; //导入依赖的package包/类
/**
* Check strategy configuration.
*/
@Test
public void testConfiguration() {
final Properties params = new Properties();
params.put("identity_tables", "summy.seg");
params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, new ObjectNameNormalizer() {
@Override
protected MetadataBuildingContext getBuildingContext() {
return null;
}
});
OptimizedSequenceStyleGenerator optimizedSequenceStyleGenerator = newStyleGenerator();
optimizedSequenceStyleGenerator.configure(StringType.INSTANCE, params, newServiceRegistry());
}
示例2: manageIdentityGenerator
import org.hibernate.id.PersistentIdentifierGenerator; //导入依赖的package包/类
private void manageIdentityGenerator(Mappings mappings, Table tab, SimpleValue id) {
id.setIdentifierGeneratorStrategy(PortofinoIdentityGenerator.class.getName()); //"identity");
Properties params = new Properties();
params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer());
if (mappings.getSchemaName() != null) {
params.setProperty(
PersistentIdentifierGenerator.SCHEMA,
mappings.getObjectNameNormalizer().normalizeIdentifierQuoting(mappings.getSchemaName()));
}
if (mappings.getCatalogName() != null) {
params.setProperty(
PersistentIdentifierGenerator.CATALOG,
mappings.getObjectNameNormalizer().normalizeIdentifierQuoting(mappings.getCatalogName()));
}
id.setIdentifierGeneratorProperties(params);
id.setNullValue(null);
}
示例3: manageTableGenerator
import org.hibernate.id.PersistentIdentifierGenerator; //导入依赖的package包/类
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);
}
示例4: manageTableGenerator
import org.hibernate.id.PersistentIdentifierGenerator; //导入依赖的package包/类
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);
}
示例5: validateSchema
import org.hibernate.id.PersistentIdentifierGenerator; //导入依赖的package包/类
public void validateSchema(Dialect dialect, DatabaseMetadata databaseMetadata)throws HibernateException {
secondPassCompile();
String defaultCatalog = properties.getProperty( Environment.DEFAULT_CATALOG );
String defaultSchema = properties.getProperty( Environment.DEFAULT_SCHEMA );
Iterator iter = getTableMappings();
while ( iter.hasNext() ) {
Table table = (Table) iter.next();
if ( table.isPhysicalTable() ) {
TableMetadata tableInfo = databaseMetadata.getTableMetadata(
table.getName(),
( table.getSchema() == null ) ? defaultSchema : table.getSchema(),
( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog(),
table.isQuoted());
if ( tableInfo == null ) {
throw new HibernateException( "Missing table: " + table.getName() );
}
else {
table.validateColumns( dialect, mapping, tableInfo );
}
}
}
iter = iterateGenerators( dialect );
while ( iter.hasNext() ) {
PersistentIdentifierGenerator generator = (PersistentIdentifierGenerator) iter.next();
Object key = generator.generatorKey();
if (key instanceof String) {
key = normalizer.normalizeIdentifierQuoting( (String) key );
}
if ( !databaseMetadata.isSequence( key ) && !databaseMetadata.isTable( key ) ) {
throw new HibernateException( "Missing sequence or table: " + key );
}
}
}
示例6: resolve
import org.hibernate.id.PersistentIdentifierGenerator; //导入依赖的package包/类
@SuppressWarnings( {"unchecked"} )
void resolve() {
for ( EntityBinding entityBinding : metadata.getEntityBindings() ) {
if ( entityBinding.isRoot() ) {
Properties properties = new Properties( );
properties.putAll(
metadata.getServiceRegistry()
.getService( ConfigurationService.class )
.getSettings()
);
//TODO: where should these be added???
if ( ! properties.contains( AvailableSettings.PREFER_POOLED_VALUES_LO ) ) {
properties.put( AvailableSettings.PREFER_POOLED_VALUES_LO, "false" );
}
if ( ! properties.contains( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER ) ) {
properties.put(
PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
new ObjectNameNormalizerImpl( metadata )
);
}
entityBinding.getHierarchyDetails().getEntityIdentifier().createIdentifierGenerator(
metadata.getIdentifierGeneratorFactory(),
properties
);
}
}
}
示例7: validateSchema
import org.hibernate.id.PersistentIdentifierGenerator; //导入依赖的package包/类
public void validateSchema(Dialect dialect, DatabaseMetadata databaseMetadata)
throws HibernateException {
secondPassCompile();
String defaultCatalog = properties.getProperty( Environment.DEFAULT_CATALOG );
String defaultSchema = properties.getProperty( Environment.DEFAULT_SCHEMA );
Iterator iter = getTableMappings();
while ( iter.hasNext() ) {
Table table = (Table) iter.next();
if ( table.isPhysicalTable() ) {
TableMetadata tableInfo = databaseMetadata.getTableMetadata(
table.getName(),
( table.getSchema() == null ) ? defaultSchema : table.getSchema(),
( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog(),
table.isQuoted());
if ( tableInfo == null ) {
throw new HibernateException( "Missing table: " + table.getName() );
}
else {
table.validateColumns( dialect, mapping, tableInfo );
}
}
}
iter = iterateGenerators( dialect );
while ( iter.hasNext() ) {
PersistentIdentifierGenerator generator = (PersistentIdentifierGenerator) iter.next();
Object key = generator.generatorKey();
if ( !databaseMetadata.isSequence( key ) && !databaseMetadata.isTable( key ) ) {
throw new HibernateException( "Missing sequence or table: " + key );
}
}
}
示例8: determineSequenceName
import org.hibernate.id.PersistentIdentifierGenerator; //导入依赖的package包/类
@Override
protected QualifiedName determineSequenceName(Properties params, Dialect dialect, JdbcEnvironment jdbcEnv) {
String tableName = params.getProperty(PersistentIdentifierGenerator.TABLE);
String columnName = params.getProperty(PersistentIdentifierGenerator.PK);
if (tableName != null && columnName != null) {
StringBuilder sequenceNameBuilder = new StringBuilder();
sequenceNameBuilder.append(tableName);
sequenceNameBuilder.append(SEQUENCE_NAME_SEPARATOR);
sequenceNameBuilder.append(columnName);
sequenceNameBuilder.append(SEQUENCE_NAME_SEPARATOR);
sequenceNameBuilder.append(SEQUENCE_NAME_SUFFIX);
// todo : need to incorporate implicit catalog and schema names
final Identifier catalog = jdbcEnv.getIdentifierHelper().toIdentifier(
ConfigurationHelper.getString( CATALOG, params )
);
final Identifier schema = jdbcEnv.getIdentifierHelper().toIdentifier(
ConfigurationHelper.getString( SCHEMA, params )
);
return new QualifiedNameParser.NameParts(
catalog,
schema,
jdbcEnv.getIdentifierHelper().toIdentifier( sequenceNameBuilder.toString() )
);
}
throw new IllegalStateException("Unable to build the sequence name");
}
示例9: manageIncrementGenerator
import org.hibernate.id.PersistentIdentifierGenerator; //导入依赖的package包/类
private void manageIncrementGenerator(Mappings mappings, Table tab, SimpleValue id, String entityName) {
id.setIdentifierGeneratorStrategy("increment");
Properties params = new Properties();
params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
mappings.getObjectNameNormalizer());
params.setProperty(PersistentIdentifierGenerator.SCHEMA, quoteIdentifier(tab.getSchema()));
params.put(IncrementGenerator.ENTITY_NAME,
entityName);
id.setIdentifierGeneratorProperties(params);
id.setNullValue(null);
}
示例10: configure
import org.hibernate.id.PersistentIdentifierGenerator; //导入依赖的package包/类
public void configure(Type type, Properties params, Dialect d) throws MappingException {
table = params.getProperty("table");
if (table == null)
table = params.getProperty(PersistentIdentifierGenerator.TABLE);
column = params.getProperty("column");
if (column == null)
column = params.getProperty(PersistentIdentifierGenerator.PK);
String schema = params.getProperty(PersistentIdentifierGenerator.SCHEMA);
String minIdParam = params.getProperty("minId");
if(null != minIdParam)
minId = Long.parseLong(minIdParam);
selectsql = "select max(" + column + ") from " + (schema == null ? table : schema + "." + table);
returnClass = type.getReturnedClass();
}
示例11: manageIdentityGenerator
import org.hibernate.id.PersistentIdentifierGenerator; //导入依赖的package包/类
private void manageIdentityGenerator(Mappings mappings, Table tab,
SimpleValue id) {
id.setIdentifierGeneratorStrategy("identity");
Properties params = new Properties();
params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
mappings.getObjectNameNormalizer());
params.setProperty(
PersistentIdentifierGenerator.SCHEMA,
escapeName(tab.getSchema()));
id.setIdentifierGeneratorProperties(params);
id.setNullValue(null);
}
示例12: manageIncrementGenerator
import org.hibernate.id.PersistentIdentifierGenerator; //导入依赖的package包/类
private void manageIncrementGenerator(Mappings mappings, Table tab, SimpleValue id, String entityName) {
id.setIdentifierGeneratorStrategy("increment");
Properties params = new Properties();
params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
mappings.getObjectNameNormalizer());
params.setProperty(PersistentIdentifierGenerator.SCHEMA, escapeName(tab.getSchema()));
params.put(IncrementGenerator.ENTITY_NAME,
entityName);
id.setIdentifierGeneratorProperties(params);
id.setNullValue(null);
}
示例13: includeGenerator
import org.hibernate.id.PersistentIdentifierGenerator; //导入依赖的package包/类
@Override
public boolean includeGenerator(PersistentIdentifierGenerator pig)
{
return includeGenerators;
}
示例14: makeIdentifier
import org.hibernate.id.PersistentIdentifierGenerator; //导入依赖的package包/类
private static void makeIdentifier(Element node, SimpleValue model, Mappings mappings) {
// GENERATOR
Element subnode = node.element( "generator" );
if ( subnode != null ) {
final String generatorClass = subnode.attributeValue( "class" );
model.setIdentifierGeneratorStrategy( generatorClass );
Properties params = new Properties();
// YUCK! but cannot think of a clean way to do this given the string-config based scheme
params.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer() );
if ( mappings.getSchemaName() != null ) {
params.setProperty(
PersistentIdentifierGenerator.SCHEMA,
mappings.getObjectNameNormalizer().normalizeIdentifierQuoting( mappings.getSchemaName() )
);
}
if ( mappings.getCatalogName() != null ) {
params.setProperty(
PersistentIdentifierGenerator.CATALOG,
mappings.getObjectNameNormalizer().normalizeIdentifierQuoting( mappings.getCatalogName() )
);
}
Iterator iter = subnode.elementIterator( "param" );
while ( iter.hasNext() ) {
Element childNode = (Element) iter.next();
params.setProperty( childNode.attributeValue( "name" ), childNode.getTextTrim() );
}
model.setIdentifierGeneratorProperties( params );
}
model.getTable().setIdentifierValue( model );
// ID UNSAVED-VALUE
Attribute nullValueNode = node.attribute( "unsaved-value" );
if ( nullValueNode != null ) {
model.setNullValue( nullValueNode.getValue() );
}
else {
if ( "assigned".equals( model.getIdentifierGeneratorStrategy() ) ) {
model.setNullValue( "undefined" );
}
else {
model.setNullValue( null );
}
}
}
示例15: makeIdGenerator
import org.hibernate.id.PersistentIdentifierGenerator; //导入依赖的package包/类
/**
* apply an id generator to a SimpleValue
*/
public static void makeIdGenerator(
SimpleValue id,
String generatorType,
String generatorName,
Mappings mappings,
Map<String, IdGenerator> localGenerators) {
Table table = id.getTable();
table.setIdentifierValue( id );
//generator settings
id.setIdentifierGeneratorStrategy( generatorType );
Properties params = new Properties();
//always settable
params.setProperty(
PersistentIdentifierGenerator.TABLE, table.getName()
);
if ( id.getColumnSpan() == 1 ) {
params.setProperty(
PersistentIdentifierGenerator.PK,
( (org.hibernate.mapping.Column) id.getColumnIterator().next() ).getName()
);
}
// YUCK! but cannot think of a clean way to do this given the string-config based scheme
params.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer() );
if ( !isEmptyAnnotationValue( generatorName ) ) {
//we have a named generator
IdGenerator gen = mappings.getGenerator( generatorName, localGenerators );
if ( gen == null ) {
throw new AnnotationException( "Unknown Id.generator: " + generatorName );
}
//This is quite vague in the spec but a generator could override the generate choice
String identifierGeneratorStrategy = gen.getIdentifierGeneratorStrategy();
//yuk! this is a hack not to override 'AUTO' even if generator is set
final boolean avoidOverriding =
identifierGeneratorStrategy.equals( "identity" )
|| identifierGeneratorStrategy.equals( "seqhilo" )
|| identifierGeneratorStrategy.equals( MultipleHiLoPerTableGenerator.class.getName() );
if ( generatorType == null || !avoidOverriding ) {
id.setIdentifierGeneratorStrategy( identifierGeneratorStrategy );
}
//checkIfMatchingGenerator(gen, generatorType, generatorName);
Iterator genParams = gen.getParams().entrySet().iterator();
while ( genParams.hasNext() ) {
Map.Entry elt = (Map.Entry) genParams.next();
params.setProperty( (String) elt.getKey(), (String) elt.getValue() );
}
}
if ( "assigned".equals( generatorType ) ) id.setNullValue( "undefined" );
id.setIdentifierGeneratorProperties( params );
}