Search in sources :

Example 1 with SequenceGenerators

use of javax.persistence.SequenceGenerators in project hibernate-orm by hibernate.

the class AnnotationBinder method bindPackage.

public static void bindPackage(String packageName, MetadataBuildingContext context) {
    XPackage pckg;
    try {
        pckg = context.getBootstrapContext().getReflectionManager().packageForName(packageName);
    } catch (ClassLoadingException e) {
        LOG.packageNotFound(packageName);
        return;
    } catch (ClassNotFoundException cnf) {
        LOG.packageNotFound(packageName);
        return;
    }
    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));
        }
    }
    bindGenericGenerators(pckg, context);
    bindQueries(pckg, context);
    bindFilterDefs(pckg, context);
    bindTypeDefs(pckg, context);
    bindFetchProfiles(pckg, context);
    BinderHelper.bindAnyMetaDefs(pckg, context);
}
Also used : SequenceGenerators(javax.persistence.SequenceGenerators) ClassLoadingException(org.hibernate.annotations.common.reflection.ClassLoadingException) SequenceGenerator(javax.persistence.SequenceGenerator) IdentifierGeneratorDefinition(org.hibernate.boot.model.IdentifierGeneratorDefinition) TableGenerators(javax.persistence.TableGenerators) XPackage(org.hibernate.annotations.common.reflection.XPackage) TableGenerator(javax.persistence.TableGenerator)

Example 2 with SequenceGenerators

use of javax.persistence.SequenceGenerators in project hibernate-orm by hibernate.

the class AnnotationBinder method buildGenerators.

private static HashMap<String, IdentifierGeneratorDefinition> buildGenerators(XAnnotatedElement annElt, MetadataBuildingContext context) {
    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);
        }
    }
    SequenceGenerators sequenceGenerators = annElt.getAnnotation(SequenceGenerators.class);
    if (sequenceGenerators != null) {
        for (SequenceGenerator sequenceGenerator : sequenceGenerators.value()) {
            IdentifierGeneratorDefinition idGenerator = buildIdGenerator(sequenceGenerator, context);
            generators.put(idGenerator.getName(), 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);
    }
    if (seqGen != null) {
        IdentifierGeneratorDefinition idGen = buildIdGenerator(seqGen, context);
        generators.put(idGen.getName(), idGen);
    }
    if (genGen != null) {
        IdentifierGeneratorDefinition idGen = buildIdGenerator(genGen, context);
        generators.put(idGen.getName(), idGen);
    }
    generators.forEach((name, idGenerator) -> {
        context.getMetadataCollector().addIdentifierGenerator(idGenerator);
    });
    return generators;
}
Also used : SequenceGenerators(javax.persistence.SequenceGenerators) HashMap(java.util.HashMap) SequenceGenerator(javax.persistence.SequenceGenerator) IdentifierGeneratorDefinition(org.hibernate.boot.model.IdentifierGeneratorDefinition) TableGenerators(javax.persistence.TableGenerators) TableGenerator(javax.persistence.TableGenerator) GenericGenerator(org.hibernate.annotations.GenericGenerator)

Aggregations

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