javax.persistence.UniqueConstraint#org.hibernate.id.IdentifierGenerator源码实例Demo

下面列出了javax.persistence.UniqueConstraint#org.hibernate.id.IdentifierGenerator 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: lams   文件: Component.java
@Override
public IdentifierGenerator createIdentifierGenerator(
		IdentifierGeneratorFactory identifierGeneratorFactory,
		Dialect dialect,
		String defaultCatalog,
		String defaultSchema,
		RootClass rootClass) throws MappingException {
	if ( builtIdentifierGenerator == null ) {
		builtIdentifierGenerator = buildIdentifierGenerator(
				identifierGeneratorFactory,
				dialect,
				defaultCatalog,
				defaultSchema,
				rootClass
		);
	}
	return builtIdentifierGenerator;
}
 
源代码2 项目: cacheonix-core   文件: IdentifierProperty.java
/**
 * Construct a non-virtual identifier property.
 *
 * @param name The name of the property representing the identifier within
 * its owning entity.
 * @param node The node name to use for XML-based representation of this
 * property.
 * @param type The Hibernate Type for the identifier property.
 * @param embedded Is this an embedded identifier.
 * @param unsavedValue The value which, if found as the value on the identifier
 * property, represents new (i.e., un-saved) instances of the owning entity.
 * @param identifierGenerator The generator to use for id value generation.
 */
public IdentifierProperty(
		String name,
		String node,
		Type type,
		boolean embedded,
		IdentifierValue unsavedValue,
		IdentifierGenerator identifierGenerator) {
	super(name, node, type);
	this.virtual = false;
	this.embedded = embedded;
	this.hasIdentifierMapper = false;
	this.unsavedValue = unsavedValue;
	this.identifierGenerator = identifierGenerator;
	this.identifierAssignedByInsert = identifierGenerator instanceof PostInsertIdentifierGenerator;
}
 
源代码3 项目: hibernate-reactive   文件: IdentifierGeneration.java
/**
 * Determine the name of the sequence (or table if this resolves to a physical table)
 * to use.
 *
 * @param params The params supplied in the generator config (plus some standard useful extras).
 * @return The sequence name
 */
static QualifiedName determineSequenceName(Properties params, ServiceRegistry serviceRegistry) {
	final String sequencePerEntitySuffix = ConfigurationHelper.getString( SequenceStyleGenerator.CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, params, SequenceStyleGenerator.DEF_SEQUENCE_SUFFIX );

	String fallbackSequenceName = SequenceStyleGenerator.DEF_SEQUENCE_NAME;
	final Boolean preferGeneratorNameAsDefaultName = serviceRegistry.getService( ConfigurationService.class )
			.getSetting( Settings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, StandardConverters.BOOLEAN, true );
	if ( preferGeneratorNameAsDefaultName ) {
		final String generatorName = params.getProperty( IdentifierGenerator.GENERATOR_NAME );
		if ( StringHelper.isNotEmpty( generatorName ) ) {
			fallbackSequenceName = generatorName;
		}
	}

	// JPA_ENTITY_NAME value honors <class ... entity-name="..."> (HBM) and @Entity#name (JPA) overrides.
	final String defaultSequenceName = ConfigurationHelper.getBoolean( SequenceStyleGenerator.CONFIG_PREFER_SEQUENCE_PER_ENTITY, params, false )
			? params.getProperty( SequenceStyleGenerator.JPA_ENTITY_NAME ) + sequencePerEntitySuffix
			: fallbackSequenceName;

	final String sequenceName = ConfigurationHelper.getString( SequenceStyleGenerator.SEQUENCE_PARAM, params, defaultSequenceName );
	if ( sequenceName.contains( "." ) ) {
		return QualifiedNameParser.INSTANCE.parse( sequenceName );
	}
	else {
		JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );
		// todo : need to incorporate implicit catalog and schema names
		final Identifier catalog = jdbcEnvironment.getIdentifierHelper().toIdentifier(
				ConfigurationHelper.getString( CATALOG, params )
		);
		final Identifier schema =  jdbcEnvironment.getIdentifierHelper().toIdentifier(
				ConfigurationHelper.getString( SCHEMA, params )
		);
		return new QualifiedNameParser.NameParts(
				catalog,
				schema,
				jdbcEnvironment.getIdentifierHelper().toIdentifier( sequenceName )
		);
	}
}
 
源代码4 项目: hibernate-reactive   文件: IdentifierGeneration.java
static QualifiedName determineTableName(Properties params, ServiceRegistry serviceRegistry) {
	String fallbackTableName = TableGenerator.DEF_TABLE;
	final Boolean preferGeneratorNameAsDefaultName = serviceRegistry.getService( ConfigurationService.class )
			.getSetting( Settings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, StandardConverters.BOOLEAN, true );
	if ( preferGeneratorNameAsDefaultName ) {
		final String generatorName = params.getProperty( IdentifierGenerator.GENERATOR_NAME );
		if ( StringHelper.isNotEmpty( generatorName ) ) {
			fallbackTableName = generatorName;
		}
	}

	String tableName = ConfigurationHelper.getString( TableGenerator.TABLE_PARAM, params, fallbackTableName );

	QualifiedNameParser.NameParts qualifiedTableName;
	if ( tableName.contains( "." ) ) {
		qualifiedTableName = QualifiedNameParser.INSTANCE.parse( tableName );
	}
	else {
		JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );
		// todo : need to incorporate implicit catalog and schema names
		final Identifier catalog = jdbcEnvironment.getIdentifierHelper().toIdentifier(
				ConfigurationHelper.getString( CATALOG, params )
		);
		final Identifier schema = jdbcEnvironment.getIdentifierHelper().toIdentifier(
				ConfigurationHelper.getString( SCHEMA, params )
		);
		qualifiedTableName = new QualifiedNameParser.NameParts(
				catalog,
				schema,
				jdbcEnvironment.getIdentifierHelper().toIdentifier( tableName )
		);
	}
	return qualifiedTableName;
}
 
private static IdentifierGenerator augmentWithReactiveGenerator(IdentifierGenerator generator, Type type, Properties params, ServiceRegistryImplementor serviceRegistry) {
	ReactiveIdentifierGenerator<?> reactiveGenerator;
	if (generator instanceof SequenceStyleGenerator) {
		DatabaseStructure structure = ((SequenceStyleGenerator) generator).getDatabaseStructure();
		if (structure instanceof TableStructure) {
			reactiveGenerator = new TableReactiveIdentifierGenerator(true);
		}
		else if (structure instanceof SequenceStructure) {
			reactiveGenerator = new SequenceReactiveIdentifierGenerator();
		}
		else {
			throw new IllegalStateException("unknown structure type");
		}
	}
	else if (generator instanceof TableGenerator) {
		reactiveGenerator = new TableReactiveIdentifierGenerator(false);
	}
	else if (generator instanceof SequenceGenerator) {
		reactiveGenerator = new SequenceReactiveIdentifierGenerator();
	}
	else if (generator instanceof SelectGenerator) {
		//TODO: this is easy to fix!
		throw new HibernateException("SelectGenerator is not yet supported in Hibernate Reactive");
	}
	else {
		//nothing to do
		return generator;
	}

	((Configurable) reactiveGenerator).configure( type, params, serviceRegistry );

	return new ReactiveGeneratorWrapper<>( reactiveGenerator, generator );
}
 
private void storeCache(final String strategy, final Class<? extends IdentifierGenerator> generatorClass) {
    if (strategy == null || generatorClass == null)
        return;
    final String className = generatorClass.getName();
    //Store for access both via short and long names:
    typeCache.put(strategy, generatorClass);
    if (!className.equals(strategy)) {
        typeCache.put(className, generatorClass);
    }
}
 
@Override
public Class getIdentifierGeneratorClass(final String strategy) {
    Class<? extends IdentifierGenerator> aClass = typeCache.get(strategy);
    if (aClass != null)
        return aClass;
    aClass = original.getIdentifierGeneratorClass(strategy);
    storeCache(strategy, aClass);
    return aClass;
}
 
源代码8 项目: lams   文件: IdentifierProperty.java
/**
 * Construct a non-virtual identifier property.
 *
 * @param name The name of the property representing the identifier within
 * its owning entity.
 * @param node The node name to use for XML-based representation of this
 * property.
 * @param type The Hibernate Type for the identifier property.
 * @param embedded Is this an embedded identifier.
 * @param unsavedValue The value which, if found as the value on the identifier
 * property, represents new (i.e., un-saved) instances of the owning entity.
 * @param identifierGenerator The generator to use for id value generation.
 */
public IdentifierProperty(
		String name,
		Type type,
		boolean embedded,
		IdentifierValue unsavedValue,
		IdentifierGenerator identifierGenerator) {
	super( name, type );
	this.virtual = false;
	this.embedded = embedded;
	this.hasIdentifierMapper = false;
	this.unsavedValue = unsavedValue;
	this.identifierGenerator = identifierGenerator;
	this.identifierAssignedByInsert = identifierGenerator instanceof PostInsertIdentifierGenerator;
}
 
源代码9 项目: lams   文件: IdentifierProperty.java
/**
 * Construct a virtual IdentifierProperty.
 *
 * @param type The Hibernate Type for the identifier property.
 * @param embedded Is this an embedded identifier.
 * @param unsavedValue The value which, if found as the value on the identifier
 * property, represents new (i.e., un-saved) instances of the owning entity.
 * @param identifierGenerator The generator to use for id value generation.
 */
public IdentifierProperty(
		Type type,
		boolean embedded,
		boolean hasIdentifierMapper,
		IdentifierValue unsavedValue,
		IdentifierGenerator identifierGenerator) {
	super( null, type );
	this.virtual = true;
	this.embedded = embedded;
	this.hasIdentifierMapper = hasIdentifierMapper;
	this.unsavedValue = unsavedValue;
	this.identifierGenerator = identifierGenerator;
	this.identifierAssignedByInsert = identifierGenerator instanceof PostInsertIdentifierGenerator;
}
 
源代码10 项目: lams   文件: PropertyFactory.java
/**
 * Generates the attribute representation of the identifier for a given entity mapping.
 *
 * @param mappedEntity The mapping definition of the entity.
 * @param generator The identifier value generator to use for this identifier.
 *
 * @return The appropriate IdentifierProperty definition.
 */
public static IdentifierProperty buildIdentifierAttribute(
		PersistentClass mappedEntity,
		IdentifierGenerator generator) {
	String mappedUnsavedValue = mappedEntity.getIdentifier().getNullValue();
	Type type = mappedEntity.getIdentifier().getType();
	Property property = mappedEntity.getIdentifierProperty();

	IdentifierValue unsavedValue = UnsavedValueFactory.getUnsavedIdentifierValue(
			mappedUnsavedValue,
			getGetter( property ),
			type,
			getConstructor( mappedEntity )
	);

	if ( property == null ) {
		// this is a virtual id property...
		return new IdentifierProperty(
				type,
				mappedEntity.hasEmbeddedIdentifier(),
				mappedEntity.hasIdentifierMapper(),
				unsavedValue,
				generator
		);
	}
	else {
		return new IdentifierProperty(
				property.getName(),
				type,
				mappedEntity.hasEmbeddedIdentifier(),
				unsavedValue,
				generator
		);
	}
}
 
源代码11 项目: lams   文件: TableGenerator.java
/**
 * Determine the table name to use for the generator values.
 * <p/>
 * Called during {@link #configure configuration}.
 *
 * @see #getTableName()
 * @param params The params supplied in the generator config (plus some standard useful extras).
 * @param jdbcEnvironment The JDBC environment
 * @return The table name to use.
 */
@SuppressWarnings({"UnusedParameters", "WeakerAccess"})
protected QualifiedName determineGeneratorTableName(Properties params, JdbcEnvironment jdbcEnvironment, ServiceRegistry serviceRegistry) {

	String fallbackTableName = DEF_TABLE;

	final Boolean preferGeneratorNameAsDefaultName = serviceRegistry.getService( ConfigurationService.class )
			.getSetting( AvailableSettings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, StandardConverters.BOOLEAN, true );
	if ( preferGeneratorNameAsDefaultName ) {
		final String generatorName = params.getProperty( IdentifierGenerator.GENERATOR_NAME );
		if ( StringHelper.isNotEmpty( generatorName ) ) {
			fallbackTableName = generatorName;
		}
	}


	String tableName = ConfigurationHelper.getString( TABLE_PARAM, params, fallbackTableName );

	if ( tableName.contains( "." ) ) {
		return QualifiedNameParser.INSTANCE.parse( tableName );
	}
	else {
		// todo : need to incorporate implicit catalog and schema names
		final Identifier catalog = jdbcEnvironment.getIdentifierHelper().toIdentifier(
				ConfigurationHelper.getString( CATALOG, params )
		);
		final Identifier schema = jdbcEnvironment.getIdentifierHelper().toIdentifier(
				ConfigurationHelper.getString( SCHEMA, params )
		);
		return new QualifiedNameParser.NameParts(
				catalog,
				schema,
				jdbcEnvironment.getIdentifierHelper().toIdentifier( tableName )
		);
	}
}
 
源代码12 项目: lams   文件: DefaultIdentifierGeneratorFactory.java
@Override
public IdentifierGenerator createIdentifierGenerator(String strategy, Type type, Properties config) {
	try {
		Class clazz = getIdentifierGeneratorClass( strategy );
		IdentifierGenerator identifierGenerator = ( IdentifierGenerator ) clazz.newInstance();
		if ( identifierGenerator instanceof Configurable ) {
			( ( Configurable ) identifierGenerator ).configure( type, config, serviceRegistry );
		}
		return identifierGenerator;
	}
	catch ( Exception e ) {
		final String entityName = config.getProperty( IdentifierGenerator.ENTITY_NAME );
		throw new MappingException( String.format( "Could not instantiate id generator [entity-name=%s]", entityName ), e );
	}
}
 
源代码13 项目: lams   文件: InFlightMetadataCollectorImpl.java
private void handleIdentifierValueBinding(
		KeyValue identifierValueBinding,
		Dialect dialect,
		String defaultCatalog,
		String defaultSchema,
		RootClass entityBinding) {
	// todo : store this result (back into the entity or into the KeyValue, maybe?)
	// 		This process of instantiating the id-generator is called multiple times.
	//		It was done this way in the old code too, so no "regression" here; but
	//		it could be done better
	try {
		final IdentifierGenerator ig = identifierValueBinding.createIdentifierGenerator(
				getIdentifierGeneratorFactory(),
				dialect,
				defaultCatalog,
				defaultSchema,
				entityBinding
		);

		if ( ig instanceof ExportableProducer ) {
			( (ExportableProducer) ig ).registerExportables( getDatabase() );
		}
	}
	catch (MappingException e) {
		// ignore this for now.  The reasoning being "non-reflective" binding as needed
		// by tools.  We want to hold off requiring classes being present until we
		// try to build a SF.  Here, just building the Metadata, it is "ok" for an
		// exception to occur, the same exception will happen later as we build the SF.
		log.debugf( "Ignoring exception thrown when trying to build IdentifierGenerator as part of Metadata building", e );
	}
}
 
源代码14 项目: lams   文件: FileUtil.java
public static String generateUniqueContentFolderID() {
	IdentifierGenerator uuidGen = new UUIDGenerator();
	((Configurable) uuidGen).configure(StringType.INSTANCE, new Properties(), null);

//	Serializable generate(SharedSessionContractImplementor session, Object object)
	
	// lowercase to resolve OS issues
	return ((String) uuidGen.generate(null, null)).toLowerCase();
    }
 
源代码15 项目: lams   文件: ForgotPasswordServlet.java
/**
    * Generates the unique key used for the forgot password request
    *
    * @return a unique key
    * @throws HibernateException
    * @throws FileUtilException
    * @throws IOException
    */
   public static String generateUniqueKey() throws HibernateException {
Properties props = new Properties();

IdentifierGenerator uuidGen = new UUIDGenerator();
((Configurable) uuidGen).configure(StringType.INSTANCE, props, null);

return ((String) uuidGen.generate(null, null)).toLowerCase();
   }
 
源代码16 项目: cacheonix-core   文件: IdentifierProperty.java
/**
 * Construct a virtual IdentifierProperty.
 *
 * @param type The Hibernate Type for the identifier property.
 * @param embedded Is this an embedded identifier.
 * @param unsavedValue The value which, if found as the value on the identifier
 * property, represents new (i.e., un-saved) instances of the owning entity.
 * @param identifierGenerator The generator to use for id value generation.
 */
public IdentifierProperty(
        Type type,
        boolean embedded,
		boolean hasIdentifierMapper,
		IdentifierValue unsavedValue,
        IdentifierGenerator identifierGenerator) {
	super(null, null, type);
	this.virtual = true;
	this.embedded = embedded;
	this.hasIdentifierMapper = hasIdentifierMapper;
	this.unsavedValue = unsavedValue;
	this.identifierGenerator = identifierGenerator;
	this.identifierAssignedByInsert = identifierGenerator instanceof PostInsertIdentifierGenerator;
}
 
源代码17 项目: cacheonix-core   文件: PropertyFactory.java
/**
 * Generates an IdentifierProperty representation of the for a given entity mapping.
 *
 * @param mappedEntity The mapping definition of the entity.
 * @param generator The identifier value generator to use for this identifier.
 * @return The appropriate IdentifierProperty definition.
 */
public static IdentifierProperty buildIdentifierProperty(PersistentClass mappedEntity, IdentifierGenerator generator) {

	String mappedUnsavedValue = mappedEntity.getIdentifier().getNullValue();
	Type type = mappedEntity.getIdentifier().getType();
	Property property = mappedEntity.getIdentifierProperty();
	
	IdentifierValue unsavedValue = UnsavedValueFactory.getUnsavedIdentifierValue(
			mappedUnsavedValue,
			getGetter( property ),
			type,
			getConstructor(mappedEntity)
		);

	if ( property == null ) {
		// this is a virtual id property...
		return new IdentifierProperty(
		        type,
				mappedEntity.hasEmbeddedIdentifier(),
				mappedEntity.hasIdentifierMapper(),
				unsavedValue,
				generator
			);
	}
	else {
		return new IdentifierProperty(
				property.getName(),
				property.getNodeName(),
				type,
				mappedEntity.hasEmbeddedIdentifier(),
				unsavedValue,
				generator
			);
	}
}
 
public ReactiveGeneratorWrapper(ReactiveIdentifierGenerator<T> reactiveGenerator, IdentifierGenerator generator) {
	this.reactiveGenerator = reactiveGenerator;
	this.generator = generator;
}
 
private static CompletionStage<?> generateId(Object entity, EventSource source, EntityPersister persister) {
	IdentifierGenerator generator = persister.getIdentifierGenerator();
	return generator instanceof ReactiveIdentifierGenerator
			? ( (ReactiveIdentifierGenerator<?>) generator ).generate( (ReactiveSession) source, entity )
			: CompletionStages.completedFuture( generator.generate( source.getSession(), entity ) );
}
 
@Override
public IdentifierGenerator createIdentifierGenerator(final String strategy, final Type type, final Properties config) {
    final IdentifierGenerator identifierGenerator = original.createIdentifierGenerator(strategy, type, config);
    storeCache(strategy, identifierGenerator.getClass());
    return identifierGenerator;
}
 
源代码21 项目: lams   文件: BinderHelper.java
/**
 * apply an id generator to a SimpleValue
 */
public static void makeIdGenerator(
		SimpleValue id,
		XProperty idXProperty,
		String generatorType,
		String generatorName,
		MetadataBuildingContext buildingContext,
		Map<String, IdentifierGeneratorDefinition> localGenerators) {
	log.debugf( "#makeIdGenerator(%s, %s, %s, %s, ...)", id, idXProperty, generatorType, generatorName );

	Table table = id.getTable();
	table.setIdentifierValue( id );
	//generator settings
	id.setIdentifierGeneratorStrategy( generatorType );

	Properties params = new Properties();

	//always settable
	params.setProperty(
			PersistentIdentifierGenerator.TABLE, table.getName()
	);

	final String implicitCatalogName = buildingContext.getBuildingOptions().getMappingDefaults().getImplicitCatalogName();
	if ( implicitCatalogName != null ) {
		params.put( PersistentIdentifierGenerator.CATALOG, implicitCatalogName );
	}
	final String implicitSchemaName = buildingContext.getBuildingOptions().getMappingDefaults().getImplicitSchemaName();
	if ( implicitSchemaName != null ) {
		params.put( PersistentIdentifierGenerator.SCHEMA, implicitSchemaName );
	}

	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, buildingContext.getObjectNameNormalizer() );
	params.put( IdentifierGenerator.GENERATOR_NAME, generatorName );

	if ( !isEmptyAnnotationValue( generatorName ) ) {
		//we have a named generator
		IdentifierGeneratorDefinition gen = getIdentifierGenerator(
				generatorName,
				idXProperty,
				localGenerators,
				buildingContext
		);
		if ( gen == null ) {
			throw new AnnotationException( "Unknown named generator (@GeneratedValue#generatorName): " + generatorName );
		}
		//This is quite vague in the spec but a generator could override the generate choice
		String identifierGeneratorStrategy = gen.getStrategy();
		//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);
		for ( Object o : gen.getParameters().entrySet() ) {
			Map.Entry elt = (Map.Entry) o;
			if ( elt.getKey() == null ) {
				continue;
			}
			params.setProperty( (String) elt.getKey(), (String) elt.getValue() );
		}
	}
	if ( "assigned".equals( generatorType ) ) {
		id.setNullValue( "undefined" );
	}
	id.setIdentifierGeneratorProperties( params );
}
 
源代码22 项目: lams   文件: KeyValue.java
public IdentifierGenerator createIdentifierGenerator(
IdentifierGeneratorFactory identifierGeneratorFactory,
Dialect dialect,
String defaultCatalog,
String defaultSchema,
RootClass rootClass) throws MappingException;
 
源代码23 项目: lams   文件: Component.java
private IdentifierGenerator buildIdentifierGenerator(
		IdentifierGeneratorFactory identifierGeneratorFactory,
		Dialect dialect,
		String defaultCatalog,
		String defaultSchema,
		RootClass rootClass) throws MappingException {
	final boolean hasCustomGenerator = ! DEFAULT_ID_GEN_STRATEGY.equals( getIdentifierGeneratorStrategy() );
	if ( hasCustomGenerator ) {
		return super.createIdentifierGenerator(
				identifierGeneratorFactory, dialect, defaultCatalog, defaultSchema, rootClass
		);
	}

	final Class entityClass = rootClass.getMappedClass();
	final Class attributeDeclarer; // what class is the declarer of the composite pk attributes
	CompositeNestedGeneratedValueGenerator.GenerationContextLocator locator;

	// IMPL NOTE : See the javadoc discussion on CompositeNestedGeneratedValueGenerator wrt the
	//		various scenarios for which we need to account here
	if ( rootClass.getIdentifierMapper() != null ) {
		// we have the @IdClass / <composite-id mapped="true"/> case
		attributeDeclarer = resolveComponentClass();
	}
	else if ( rootClass.getIdentifierProperty() != null ) {
		// we have the "@EmbeddedId" / <composite-id name="idName"/> case
		attributeDeclarer = resolveComponentClass();
	}
	else {
		// we have the "straight up" embedded (again the hibernate term) component identifier
		attributeDeclarer = entityClass;
	}

	locator = new StandardGenerationContextLocator( rootClass.getEntityName() );
	final CompositeNestedGeneratedValueGenerator generator = new CompositeNestedGeneratedValueGenerator( locator );

	Iterator itr = getPropertyIterator();
	while ( itr.hasNext() ) {
		final Property property = (Property) itr.next();
		if ( property.getValue().isSimpleValue() ) {
			final SimpleValue value = (SimpleValue) property.getValue();

			if ( DEFAULT_ID_GEN_STRATEGY.equals( value.getIdentifierGeneratorStrategy() ) ) {
				// skip any 'assigned' generators, they would have been handled by
				// the StandardGenerationContextLocator
				continue;
			}

			final IdentifierGenerator valueGenerator = value.createIdentifierGenerator(
					identifierGeneratorFactory,
					dialect,
					defaultCatalog,
					defaultSchema,
					rootClass
			);
			generator.addGeneratedValuePlan(
					new ValueGenerationPlan(
							valueGenerator,
							injector( property, attributeDeclarer )
					)
			);
		}
	}
	return generator;
}
 
源代码24 项目: lams   文件: Component.java
public ValueGenerationPlan(
		IdentifierGenerator subGenerator,
		Setter injector) {
	this.subGenerator = subGenerator;
	this.injector = injector;
}
 
源代码25 项目: lams   文件: SimpleValue.java
@Override
public IdentifierGenerator createIdentifierGenerator(
		IdentifierGeneratorFactory identifierGeneratorFactory,
		Dialect dialect, 
		String defaultCatalog, 
		String defaultSchema, 
		RootClass rootClass) throws MappingException {

	if ( identifierGenerator != null ) {
		return identifierGenerator;
	}

	Properties params = new Properties();
	
	//if the hibernate-mapping did not specify a schema/catalog, use the defaults
	//specified by properties - but note that if the schema/catalog were specified
	//in hibernate-mapping, or as params, they will already be initialized and
	//will override the values set here (they are in identifierGeneratorProperties)
	if ( defaultSchema!=null ) {
		params.setProperty(PersistentIdentifierGenerator.SCHEMA, defaultSchema);
	}
	if ( defaultCatalog!=null ) {
		params.setProperty(PersistentIdentifierGenerator.CATALOG, defaultCatalog);
	}
	
	//pass the entity-name, if not a collection-id
	if (rootClass!=null) {
		params.setProperty( IdentifierGenerator.ENTITY_NAME, rootClass.getEntityName() );
		params.setProperty( IdentifierGenerator.JPA_ENTITY_NAME, rootClass.getJpaEntityName() );
	}
	
	//init the table here instead of earlier, so that we can get a quoted table name
	//TODO: would it be better to simply pass the qualified table name, instead of
	//      splitting it up into schema/catalog/table names
	String tableName = getTable().getQuotedName(dialect);
	params.setProperty( PersistentIdentifierGenerator.TABLE, tableName );
	
	//pass the column name (a generated id almost always has a single column)
	String columnName = ( (Column) getColumnIterator().next() ).getQuotedName(dialect);
	params.setProperty( PersistentIdentifierGenerator.PK, columnName );
	
	if (rootClass!=null) {
		StringBuilder tables = new StringBuilder();
		Iterator iter = rootClass.getIdentityTables().iterator();
		while ( iter.hasNext() ) {
			Table table= (Table) iter.next();
			tables.append( table.getQuotedName(dialect) );
			if ( iter.hasNext() ) {
				tables.append(", ");
			}
		}
		params.setProperty( PersistentIdentifierGenerator.TABLES, tables.toString() );
	}
	else {
		params.setProperty( PersistentIdentifierGenerator.TABLES, tableName );
	}

	if (identifierGeneratorProperties!=null) {
		params.putAll(identifierGeneratorProperties);
	}

	// TODO : we should pass along all settings once "config lifecycle" is hashed out...
	final ConfigurationService cs = metadata.getMetadataBuildingOptions().getServiceRegistry()
			.getService( ConfigurationService.class );

	params.put(
			AvailableSettings.PREFER_POOLED_VALUES_LO,
			cs.getSetting( AvailableSettings.PREFER_POOLED_VALUES_LO, StandardConverters.BOOLEAN, false )
	);
	if ( cs.getSettings().get( AvailableSettings.PREFERRED_POOLED_OPTIMIZER ) != null ) {
		params.put(
				AvailableSettings.PREFERRED_POOLED_OPTIMIZER,
				cs.getSettings().get( AvailableSettings.PREFERRED_POOLED_OPTIMIZER )
		);
	}

	identifierGeneratorFactory.setDialect( dialect );
	identifierGenerator = identifierGeneratorFactory.createIdentifierGenerator( identifierGeneratorStrategy, getType(), params );

	return identifierGenerator;
}
 
源代码26 项目: lams   文件: AbstractEntityPersister.java
public IdentifierGenerator getIdentifierGenerator() throws HibernateException {
	return entityMetamodel.getIdentifierProperty().getIdentifierGenerator();
}
 
源代码27 项目: lams   文件: AbstractCollectionPersister.java
@Override
public IdentifierGenerator getIdentifierGenerator() {
	return identifierGenerator;
}
 
源代码28 项目: lams   文件: IdentifierProperty.java
@Override
public IdentifierGenerator getIdentifierGenerator() {
	return identifierGenerator;
}
 
源代码29 项目: lams   文件: SessionFactoryDelegatingImpl.java
@Override
public IdentifierGenerator getIdentifierGenerator(String rootEntityName) {
	return delegate.getIdentifierGenerator( rootEntityName );
}
 
源代码30 项目: lams   文件: SequenceStyleGenerator.java
/**
 * Determine the name of the sequence (or table if this resolves to a physical table)
 * to use.
 * <p/>
 * Called during {@link #configure configuration}.
 *
 * @param params The params supplied in the generator config (plus some standard useful extras).
 * @param dialect The dialect in effect
 * @param jdbcEnv The JdbcEnvironment
 * @return The sequence name
 */
@SuppressWarnings({"UnusedParameters", "WeakerAccess"})
protected QualifiedName determineSequenceName(
		Properties params,
		Dialect dialect,
		JdbcEnvironment jdbcEnv,
		ServiceRegistry serviceRegistry) {
	final String sequencePerEntitySuffix = ConfigurationHelper.getString( CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, params, DEF_SEQUENCE_SUFFIX );

	String fallbackSequenceName = DEF_SEQUENCE_NAME;
	final Boolean preferGeneratorNameAsDefaultName = serviceRegistry.getService( ConfigurationService.class )
			.getSetting( AvailableSettings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, StandardConverters.BOOLEAN, true );
	if ( preferGeneratorNameAsDefaultName ) {
		final String generatorName = params.getProperty( IdentifierGenerator.GENERATOR_NAME );
		if ( StringHelper.isNotEmpty( generatorName ) ) {
			fallbackSequenceName = generatorName;
		}
	}

	// JPA_ENTITY_NAME value honors <class ... entity-name="..."> (HBM) and @Entity#name (JPA) overrides.
	final String defaultSequenceName = ConfigurationHelper.getBoolean( CONFIG_PREFER_SEQUENCE_PER_ENTITY, params, false )
			? params.getProperty( JPA_ENTITY_NAME ) + sequencePerEntitySuffix
			: fallbackSequenceName;

	final String sequenceName = ConfigurationHelper.getString( SEQUENCE_PARAM, params, defaultSequenceName );
	if ( sequenceName.contains( "." ) ) {
		return QualifiedNameParser.INSTANCE.parse( sequenceName );
	}
	else {
		// 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( sequenceName )
		);
	}
}