use of org.hibernate.id.IdentifierGenerator in project hibernate-orm by hibernate.
the class GeneratedValueTests method testImplicitIncrementGenerator.
@Test
public void testImplicitIncrementGenerator() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
final Metadata bootModel = new MetadataSources(ssr).addAnnotatedClass(ImplicitIncrementGeneratorEntity.class).buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding(ImplicitIncrementGeneratorEntity.class.getName());
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(bootModel.getIdentifierGeneratorFactory(), ssr.getService(JdbcEnvironment.class).getDialect(), null, null, (RootClass) entityMapping);
assertTyping(IncrementGenerator.class, generator);
}
use of org.hibernate.id.IdentifierGenerator in project hibernate-orm by hibernate.
the class Component method buildIdentifierGenerator.
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();
// what class is the declarer of the composite pk attributes
final Class attributeDeclarer;
CompositeNestedGeneratedValueGenerator.GenerationContextLocator locator;
// 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())) {
// the StandardGenerationContextLocator
continue;
}
final IdentifierGenerator valueGenerator = value.createIdentifierGenerator(identifierGeneratorFactory, dialect, defaultCatalog, defaultSchema, rootClass);
generator.addGeneratedValuePlan(new ValueGenerationPlan(valueGenerator, injector(property, attributeDeclarer)));
}
}
return generator;
}
Aggregations