本文整理汇总了Java中org.hibernate.id.IdentifierGenerator类的典型用法代码示例。如果您正苦于以下问题:Java IdentifierGenerator类的具体用法?Java IdentifierGenerator怎么用?Java IdentifierGenerator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IdentifierGenerator类属于org.hibernate.id包,在下文中一共展示了IdentifierGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIdentifierGenerator
import org.hibernate.id.IdentifierGenerator; //导入依赖的package包/类
@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: IdentifierProperty
import org.hibernate.id.IdentifierGenerator; //导入依赖的package包/类
/**
* 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, type );
this.virtual = false;
this.embedded = embedded;
this.hasIdentifierMapper = false;
this.unsavedValue = unsavedValue;
this.identifierGenerator = identifierGenerator;
this.identifierAssignedByInsert = identifierGenerator instanceof PostInsertIdentifierGenerator;
}
示例3: IdentifierProperty
import org.hibernate.id.IdentifierGenerator; //导入依赖的package包/类
/**
* 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;
}
示例4: main
import org.hibernate.id.IdentifierGenerator; //导入依赖的package包/类
/**
* The main method.
*
* @param args
* the arguments
* @throws Exception
* the exception
*/
public static void main(String[] args) throws Exception {
Properties props = new Properties();
props.setProperty("separator", "");
IdentifierGenerator gen = new UIDGenerator();
((Configurable) gen).configure(Hibernate.STRING, props, null);
IdentifierGenerator gen2 = new UIDGenerator();
((Configurable) gen2).configure(Hibernate.STRING, props, null);
for (int i = 0; i < 10; i++) {
String id = (String) gen.generate(null, gen);
System.out.println(id);
String id2 = (String) gen2.generate(null, gen2);
System.out.println(id2);
}
}
示例5: getGeneratorType
import org.hibernate.id.IdentifierGenerator; //导入依赖的package包/类
private String getGeneratorType(AbstractEntityPersister entityPersister) {
String generatorType = null;
IdentifierGenerator generator = entityPersister != null ? entityPersister.getIdentifierGenerator() : null;
if (generator != null) {
if (generator instanceof IdentityGenerator)
generatorType = "Identity";
else if (generator instanceof Assigned)
generatorType = "None";
else
generatorType = "KeyGenerator";
}
return generatorType;
}
示例6: ValueGenerationPlan
import org.hibernate.id.IdentifierGenerator; //导入依赖的package包/类
public ValueGenerationPlan(
String propertyName,
IdentifierGenerator subGenerator,
Setter injector) {
this.propertyName = propertyName;
this.subGenerator = subGenerator;
this.injector = injector;
}
示例7: bindSimpleIdentifier
import org.hibernate.id.IdentifierGenerator; //导入依赖的package包/类
private void bindSimpleIdentifier(SimpleIdentifierSource identifierSource, EntityBinding entityBinding) {
final BasicAttributeBinding idAttributeBinding = doBasicSingularAttributeBindingCreation(
identifierSource.getIdentifierAttributeSource(), entityBinding
);
entityBinding.getHierarchyDetails().getEntityIdentifier().setValueBinding( idAttributeBinding );
IdGenerator generator = identifierSource.getIdentifierGeneratorDescriptor();
if ( generator == null ) {
Map<String, String> params = new HashMap<String, String>();
params.put( IdentifierGenerator.ENTITY_NAME, entityBinding.getEntity().getName() );
generator = new IdGenerator( "default_assign_identity_generator", "assigned", params );
}
entityBinding.getHierarchyDetails()
.getEntityIdentifier()
.setIdGenerator( generator );
final org.hibernate.metamodel.relational.Value relationalValue = idAttributeBinding.getValue();
if ( SimpleValue.class.isInstance( relationalValue ) ) {
if ( !Column.class.isInstance( relationalValue ) ) {
// this should never ever happen..
throw new AssertionFailure( "Simple-id was not a column." );
}
entityBinding.getPrimaryTable().getPrimaryKey().addColumn( Column.class.cast( relationalValue ) );
}
else {
for ( SimpleValue subValue : ( (Tuple) relationalValue ).values() ) {
if ( Column.class.isInstance( subValue ) ) {
entityBinding.getPrimaryTable().getPrimaryKey().addColumn( Column.class.cast( subValue ) );
}
}
}
}
示例8: buildIdentifierAttribute
import org.hibernate.id.IdentifierGenerator; //导入依赖的package包/类
/**
* 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(),
property.getNodeName(),
type,
mappedEntity.hasEmbeddedIdentifier(),
unsavedValue,
generator
);
}
}
示例9: createIdentifierGenerator
import org.hibernate.id.IdentifierGenerator; //导入依赖的package包/类
@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, dialect );
}
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 );
}
}
示例10: generateUniqueContentFolderID
import org.hibernate.id.IdentifierGenerator; //导入依赖的package包/类
public static String generateUniqueContentFolderID() {
IdentifierGenerator uuidGen = new UUIDGenerator();
((Configurable) uuidGen).configure(StringType.INSTANCE, new Properties(), null);
// lowercase to resolve OS issues
return ((String) uuidGen.generate(null, null)).toLowerCase();
}
示例11: generateUniqueKey
import org.hibernate.id.IdentifierGenerator; //导入依赖的package包/类
/**
* Generates the unique key used for the forgot password request
*
* @return a unique key
* @throws FileUtilException
* @throws IOException
*/
public static String generateUniqueKey() {
Properties props = new Properties();
IdentifierGenerator uuidGen = new UUIDGenerator();
((Configurable) uuidGen).configure(StringType.INSTANCE, props, null);
return ((String) uuidGen.generate(null, null)).toLowerCase();
}
示例12: buildIdentifierProperty
import org.hibernate.id.IdentifierGenerator; //导入依赖的package包/类
/**
* 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
);
}
}
示例13: getIdentifierGenerator
import org.hibernate.id.IdentifierGenerator; //导入依赖的package包/类
public IdentifierGenerator getIdentifierGenerator(String rootEntityName) {
return sessionFactoryImplementor.getIdentifierGenerator(rootEntityName);
}
示例14: createIdentifierGenerator
import org.hibernate.id.IdentifierGenerator; //导入依赖的package包/类
public IdentifierGenerator createIdentifierGenerator(
IdentifierGeneratorFactory identifierGeneratorFactory,
Dialect dialect,
String defaultCatalog,
String defaultSchema,
RootClass rootClass) throws MappingException;
示例15: buildIdentifierGenerator
import org.hibernate.id.IdentifierGenerator; //导入依赖的package包/类
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(
property.getName(),
valueGenerator,
injector( property, attributeDeclarer )
)
);
}
}
return generator;
}