Search in sources :

Example 1 with TableGenerators

use of jakarta.persistence.TableGenerators in project hibernate-orm by hibernate.

the class AnnotationBinder method bindPackage.

public static void bindPackage(ClassLoaderService cls, String packageName, MetadataBuildingContext context) {
    final Package packaze = cls.packageForNameOrNull(packageName);
    if (packaze == null) {
        return;
    }
    final XPackage pckg = context.getBootstrapContext().getReflectionManager().toXPackage(packaze);
    if (pckg.isAnnotationPresent(SequenceGenerator.class)) {
        SequenceGenerator ann = pckg.getAnnotation(SequenceGenerator.class);
        IdentifierGeneratorDefinition idGen = buildIdGenerator(ann, context);
        context.getMetadataCollector().addIdentifierGenerator(idGen);
        if (LOG.isTraceEnabled()) {
            LOG.tracev("Add sequence generator with name: {0}", idGen.getName());
        }
    }
    if (pckg.isAnnotationPresent(SequenceGenerators.class)) {
        SequenceGenerators ann = pckg.getAnnotation(SequenceGenerators.class);
        for (SequenceGenerator tableGenerator : ann.value()) {
            context.getMetadataCollector().addIdentifierGenerator(buildIdGenerator(tableGenerator, context));
        }
    }
    if (pckg.isAnnotationPresent(TableGenerator.class)) {
        TableGenerator ann = pckg.getAnnotation(TableGenerator.class);
        IdentifierGeneratorDefinition idGen = buildIdGenerator(ann, context);
        context.getMetadataCollector().addIdentifierGenerator(idGen);
    }
    if (pckg.isAnnotationPresent(TableGenerators.class)) {
        TableGenerators ann = pckg.getAnnotation(TableGenerators.class);
        for (TableGenerator tableGenerator : ann.value()) {
            context.getMetadataCollector().addIdentifierGenerator(buildIdGenerator(tableGenerator, context));
        }
    }
    handleTypeDescriptorRegistrations(pckg, context);
    bindEmbeddableInstantiatorRegistrations(pckg, context);
    bindCompositeUserTypeRegistrations(pckg, context);
    bindGenericGenerators(pckg, context);
    bindQueries(pckg, context);
    bindFilterDefs(pckg, context);
}
Also used : SequenceGenerators(jakarta.persistence.SequenceGenerators) SequenceGenerator(jakarta.persistence.SequenceGenerator) IdentifierGeneratorDefinition(org.hibernate.boot.model.IdentifierGeneratorDefinition) TableGenerators(jakarta.persistence.TableGenerators) XPackage(org.hibernate.annotations.common.reflection.XPackage) XPackage(org.hibernate.annotations.common.reflection.XPackage) TableGenerator(jakarta.persistence.TableGenerator)

Example 2 with TableGenerators

use of jakarta.persistence.TableGenerators in project hibernate-orm by hibernate.

the class AnnotationBinder method buildGenerators.

private static HashMap<String, IdentifierGeneratorDefinition> buildGenerators(XAnnotatedElement annElt, MetadataBuildingContext context) {
    InFlightMetadataCollector metadataCollector = context.getMetadataCollector();
    HashMap<String, IdentifierGeneratorDefinition> generators = new HashMap<>();
    TableGenerators tableGenerators = annElt.getAnnotation(TableGenerators.class);
    if (tableGenerators != null) {
        for (TableGenerator tableGenerator : tableGenerators.value()) {
            IdentifierGeneratorDefinition idGenerator = buildIdGenerator(tableGenerator, context);
            generators.put(idGenerator.getName(), idGenerator);
            metadataCollector.addIdentifierGenerator(idGenerator);
        }
    }
    SequenceGenerators sequenceGenerators = annElt.getAnnotation(SequenceGenerators.class);
    if (sequenceGenerators != null) {
        for (SequenceGenerator sequenceGenerator : sequenceGenerators.value()) {
            IdentifierGeneratorDefinition idGenerator = buildIdGenerator(sequenceGenerator, context);
            generators.put(idGenerator.getName(), idGenerator);
            metadataCollector.addIdentifierGenerator(idGenerator);
        }
    }
    TableGenerator tabGen = annElt.getAnnotation(TableGenerator.class);
    SequenceGenerator seqGen = annElt.getAnnotation(SequenceGenerator.class);
    GenericGenerator genGen = annElt.getAnnotation(GenericGenerator.class);
    if (tabGen != null) {
        IdentifierGeneratorDefinition idGen = buildIdGenerator(tabGen, context);
        generators.put(idGen.getName(), idGen);
        metadataCollector.addIdentifierGenerator(idGen);
    }
    if (seqGen != null) {
        IdentifierGeneratorDefinition idGen = buildIdGenerator(seqGen, context);
        generators.put(idGen.getName(), idGen);
        metadataCollector.addIdentifierGenerator(idGen);
    }
    if (genGen != null) {
        IdentifierGeneratorDefinition idGen = buildIdGenerator(genGen, context);
        generators.put(idGen.getName(), idGen);
        metadataCollector.addIdentifierGenerator(idGen);
    }
    return generators;
}
Also used : SequenceGenerators(jakarta.persistence.SequenceGenerators) InFlightMetadataCollector(org.hibernate.boot.spi.InFlightMetadataCollector) HashMap(java.util.HashMap) SequenceGenerator(jakarta.persistence.SequenceGenerator) IdentifierGeneratorDefinition(org.hibernate.boot.model.IdentifierGeneratorDefinition) TableGenerators(jakarta.persistence.TableGenerators) TableGenerator(jakarta.persistence.TableGenerator) GenericGenerator(org.hibernate.annotations.GenericGenerator)

Aggregations

SequenceGenerator (jakarta.persistence.SequenceGenerator)2 SequenceGenerators (jakarta.persistence.SequenceGenerators)2 TableGenerator (jakarta.persistence.TableGenerator)2 TableGenerators (jakarta.persistence.TableGenerators)2 IdentifierGeneratorDefinition (org.hibernate.boot.model.IdentifierGeneratorDefinition)2 HashMap (java.util.HashMap)1 GenericGenerator (org.hibernate.annotations.GenericGenerator)1 XPackage (org.hibernate.annotations.common.reflection.XPackage)1 InFlightMetadataCollector (org.hibernate.boot.spi.InFlightMetadataCollector)1