use of com.manydesigns.portofino.model.database.SequenceGenerator in project Portofino by ManyDesigns.
the class SessionFactoryBuilder method setupNonIdentityGenerator.
protected void setupNonIdentityGenerator(Table table, AnnotationsAttribute fieldAnnotations, Generator generator, ConstPool constPool) {
String generatorName = table.getQualifiedName() + "_generator";
if (generator instanceof IncrementGenerator) {
addGeneratedValueAnnotation(GenerationType.AUTO, generatorName, fieldAnnotations, constPool);
Annotation annotation = new Annotation(GenericGenerator.class.getName(), constPool);
annotation.addMemberValue("name", new StringMemberValue(generatorName, constPool));
annotation.addMemberValue("strategy", new StringMemberValue("increment", constPool));
fieldAnnotations.addAnnotation(annotation);
} else if (generator instanceof SequenceGenerator) {
addGeneratedValueAnnotation(GenerationType.SEQUENCE, generatorName, fieldAnnotations, constPool);
Annotation annotation = new Annotation(javax.persistence.SequenceGenerator.class.getName(), constPool);
annotation.addMemberValue("name", new StringMemberValue(generatorName, constPool));
annotation.addMemberValue("sequenceName", new StringMemberValue(((SequenceGenerator) generator).getName(), constPool));
fieldAnnotations.addAnnotation(annotation);
} else if (generator instanceof TableGenerator) {
TableGenerator tableGenerator = (TableGenerator) generator;
addGeneratedValueAnnotation(GenerationType.TABLE, generatorName, fieldAnnotations, constPool);
Annotation annotation = new Annotation(javax.persistence.TableGenerator.class.getName(), constPool);
annotation.addMemberValue("name", new StringMemberValue(generatorName, constPool));
annotation.addMemberValue("schema", new StringMemberValue(table.getSchema().getActualSchemaName(), constPool));
annotation.addMemberValue("table", new StringMemberValue(tableGenerator.getTable(), constPool));
annotation.addMemberValue("pkColumnName", new StringMemberValue(tableGenerator.getKeyColumn(), constPool));
annotation.addMemberValue("pkColumnValue", new StringMemberValue(tableGenerator.getKeyValue(), constPool));
annotation.addMemberValue("valueColumnName", new StringMemberValue(tableGenerator.getValueColumn(), constPool));
// TODO support additional parameters for the generator?
fieldAnnotations.addAnnotation(annotation);
} else {
throw new IllegalArgumentException("Unsupported generator: " + generator);
}
}
Aggregations