use of org.hibernate.annotations.GenericGenerator in project hibernate-orm by hibernate.
the class AnnotationBinder method bindGenericGenerators.
private static void bindGenericGenerators(XAnnotatedElement annotatedElement, MetadataBuildingContext context) {
GenericGenerator defAnn = annotatedElement.getAnnotation(GenericGenerator.class);
GenericGenerators defsAnn = annotatedElement.getAnnotation(GenericGenerators.class);
if (defAnn != null) {
bindGenericGenerator(defAnn, context);
}
if (defsAnn != null) {
for (GenericGenerator def : defsAnn.value()) {
bindGenericGenerator(def, context);
}
}
}
use of org.hibernate.annotations.GenericGenerator 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 org.hibernate.annotations.GenericGenerator in project tephra by heisedebaise.
the class ModelTablesImpl method parse.
private void parse(Class<? extends Model> modelClass) {
Table table = modelClass.getAnnotation(Table.class);
if (table == null)
return;
ModelTable modelTable = BeanFactory.getBean(ModelTable.class);
modelTable.setModelClass(modelClass);
DataSource dataSource = modelClass.getAnnotation(DataSource.class);
if (dataSource != null)
modelTable.setDataSource(dataSource.key());
modelTable.setTableName(table.name());
Memory memory = modelClass.getAnnotation(Memory.class);
if (memory != null)
modelTable.setMemoryName(memory.name());
Method[] methods = modelClass.getMethods();
for (Method method : methods) {
String name = method.getName();
if (name.length() < 3)
continue;
if (name.equals("getId")) {
modelTable.setIdColumnName(method.getAnnotation(Column.class).name());
GenericGenerator generator = method.getAnnotation(GenericGenerator.class);
if (generator != null && generator.name().toLowerCase().startsWith("uuid"))
modelTable.setUuid(true);
continue;
}
String propertyName = converter.toFirstLowerCase(name.substring(3));
if (startsWith(name, 'g')) {
modelTable.addGetMethod(propertyName, method);
Column column = method.getAnnotation(Column.class);
if (column != null)
modelTable.addColumn(propertyName, column);
continue;
}
if (startsWith(name, 's'))
modelTable.addSetMethod(propertyName, method);
}
map.put(modelClass, modelTable);
}
use of org.hibernate.annotations.GenericGenerator 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 org.hibernate.annotations.GenericGenerator 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