use of javax.persistence.SequenceGenerator 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);
}
use of javax.persistence.SequenceGenerator 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;
}
use of javax.persistence.SequenceGenerator in project hibernate-orm by hibernate.
the class AnnotationBinder method buildLocalGenerators.
private static HashMap<String, IdentifierGeneratorDefinition> buildLocalGenerators(XAnnotatedElement annElt, MetadataBuildingContext context) {
HashMap<String, IdentifierGeneratorDefinition> generators = new HashMap<String, IdentifierGeneratorDefinition>();
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);
}
return generators;
}
use of javax.persistence.SequenceGenerator in project hibernate-orm by hibernate.
the class JPAMetadataProvider method getDefaults.
@Override
public Map<Object, Object> getDefaults() {
if (defaults == null) {
defaults = new HashMap<>();
XMLContext.Default xmlDefaults = xmlContext.getDefault(null);
defaults.put("schema", xmlDefaults.getSchema());
defaults.put("catalog", xmlDefaults.getCatalog());
defaults.put("delimited-identifier", xmlDefaults.getDelimitedIdentifier());
defaults.put("cascade-persist", xmlDefaults.getCascadePersist());
List<Class> entityListeners = new ArrayList<Class>();
for (String className : xmlContext.getDefaultEntityListeners()) {
try {
entityListeners.add(classLoaderAccess.classForName(className));
} catch (ClassLoadingException e) {
throw new IllegalStateException("Default entity listener class not found: " + className);
}
}
defaults.put(EntityListeners.class, entityListeners);
for (Element element : xmlContext.getAllDocuments()) {
@SuppressWarnings("unchecked") List<Element> elements = element.elements("sequence-generator");
List<SequenceGenerator> sequenceGenerators = (List<SequenceGenerator>) defaults.get(SequenceGenerator.class);
if (sequenceGenerators == null) {
sequenceGenerators = new ArrayList<>();
defaults.put(SequenceGenerator.class, sequenceGenerators);
}
for (Element subelement : elements) {
sequenceGenerators.add(JPAOverriddenAnnotationReader.buildSequenceGeneratorAnnotation(subelement));
}
elements = element.elements("table-generator");
List<TableGenerator> tableGenerators = (List<TableGenerator>) defaults.get(TableGenerator.class);
if (tableGenerators == null) {
tableGenerators = new ArrayList<>();
defaults.put(TableGenerator.class, tableGenerators);
}
for (Element subelement : elements) {
tableGenerators.add(JPAOverriddenAnnotationReader.buildTableGeneratorAnnotation(subelement, xmlDefaults));
}
List<NamedQuery> namedQueries = (List<NamedQuery>) defaults.get(NamedQuery.class);
if (namedQueries == null) {
namedQueries = new ArrayList<>();
defaults.put(NamedQuery.class, namedQueries);
}
List<NamedQuery> currentNamedQueries = JPAOverriddenAnnotationReader.buildNamedQueries(element, false, xmlDefaults, classLoaderAccess);
namedQueries.addAll(currentNamedQueries);
List<NamedNativeQuery> namedNativeQueries = (List<NamedNativeQuery>) defaults.get(NamedNativeQuery.class);
if (namedNativeQueries == null) {
namedNativeQueries = new ArrayList<>();
defaults.put(NamedNativeQuery.class, namedNativeQueries);
}
List<NamedNativeQuery> currentNamedNativeQueries = JPAOverriddenAnnotationReader.buildNamedQueries(element, true, xmlDefaults, classLoaderAccess);
namedNativeQueries.addAll(currentNamedNativeQueries);
List<SqlResultSetMapping> sqlResultSetMappings = (List<SqlResultSetMapping>) defaults.get(SqlResultSetMapping.class);
if (sqlResultSetMappings == null) {
sqlResultSetMappings = new ArrayList<>();
defaults.put(SqlResultSetMapping.class, sqlResultSetMappings);
}
List<SqlResultSetMapping> currentSqlResultSetMappings = JPAOverriddenAnnotationReader.buildSqlResultsetMappings(element, xmlDefaults, classLoaderAccess);
sqlResultSetMappings.addAll(currentSqlResultSetMappings);
List<NamedStoredProcedureQuery> namedStoredProcedureQueries = (List<NamedStoredProcedureQuery>) defaults.get(NamedStoredProcedureQuery.class);
if (namedStoredProcedureQueries == null) {
namedStoredProcedureQueries = new ArrayList<>();
defaults.put(NamedStoredProcedureQuery.class, namedStoredProcedureQueries);
}
List<NamedStoredProcedureQuery> currentNamedStoredProcedureQueries = JPAOverriddenAnnotationReader.buildNamedStoreProcedureQueries(element, xmlDefaults, classLoaderAccess);
namedStoredProcedureQueries.addAll(currentNamedStoredProcedureQueries);
}
}
return defaults;
}
use of javax.persistence.SequenceGenerator in project hibernate-orm by hibernate.
the class AnnotationBinder method buildIdGenerator.
private static IdentifierGeneratorDefinition buildIdGenerator(java.lang.annotation.Annotation generatorAnn, MetadataBuildingContext context) {
if (generatorAnn == null) {
return null;
}
IdentifierGeneratorDefinition.Builder definitionBuilder = new IdentifierGeneratorDefinition.Builder();
if (context.getMappingDefaults().getImplicitSchemaName() != null) {
definitionBuilder.addParam(PersistentIdentifierGenerator.SCHEMA, context.getMappingDefaults().getImplicitSchemaName());
}
if (context.getMappingDefaults().getImplicitCatalogName() != null) {
definitionBuilder.addParam(PersistentIdentifierGenerator.CATALOG, context.getMappingDefaults().getImplicitCatalogName());
}
if (generatorAnn instanceof TableGenerator) {
context.getBuildingOptions().getIdGenerationTypeInterpreter().interpretTableGenerator((TableGenerator) generatorAnn, definitionBuilder);
if (LOG.isTraceEnabled()) {
LOG.tracev("Add table generator with name: {0}", definitionBuilder.getName());
}
} else if (generatorAnn instanceof SequenceGenerator) {
context.getBuildingOptions().getIdGenerationTypeInterpreter().interpretSequenceGenerator((SequenceGenerator) generatorAnn, definitionBuilder);
if (LOG.isTraceEnabled()) {
LOG.tracev("Add sequence generator with name: {0}", definitionBuilder.getName());
}
} else if (generatorAnn instanceof GenericGenerator) {
GenericGenerator genGen = (GenericGenerator) generatorAnn;
definitionBuilder.setName(genGen.name());
definitionBuilder.setStrategy(genGen.strategy());
Parameter[] params = genGen.parameters();
for (Parameter parameter : params) {
definitionBuilder.addParam(parameter.name(), parameter.value());
}
if (LOG.isTraceEnabled()) {
LOG.tracev("Add generic generator with name: {0}", definitionBuilder.getName());
}
} else {
throw new AssertionFailure("Unknown Generator annotation: " + generatorAnn);
}
return definitionBuilder.build();
}
Aggregations