[#4146] Generate PL/SQL constants
This commit is contained in:
parent
539fb703b9
commit
73e5405dde
@ -1842,6 +1842,31 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
watch.splitInfo("Routines generated");
|
||||
}
|
||||
|
||||
protected void printConstant(JavaWriter out, AttributeDefinition constant) {
|
||||
final String constantType = out.ref(getJavaType(constant.getType()));
|
||||
final String constantId = out.ref(getStrategy().getJavaIdentifier(constant));
|
||||
|
||||
out.tab(1).javadoc("The constant <code>%s</code>.", constant.getQualifiedOutputName());
|
||||
|
||||
if (scala) {
|
||||
out.tab(1).println("val %s = %s.field(%s.name(\"%s\", \"%s\", \"%s\"), classOf[%s]);",
|
||||
constantId, DSL.class, DSL.class,
|
||||
constant.getSchema().getOutputName().replace("\"", "\\\""),
|
||||
constant.getContainer().getOutputName().replace("\"", "\\\""),
|
||||
constant.getOutputName().replace("\"", "\\\""),
|
||||
constantType);
|
||||
}
|
||||
else {
|
||||
out.tab(1).println("public static final %s<%s> %s = %s.field(%s.name(\"%s\", \"%s\", \"%s\"), %s.class);",
|
||||
Field.class, constantType, constantId,
|
||||
DSL.class, DSL.class,
|
||||
constant.getSchema().getOutputName().replace("\"", "\\\""),
|
||||
constant.getContainer().getOutputName().replace("\"", "\\\""),
|
||||
constant.getOutputName().replace("\"", "\\\""),
|
||||
constantType);
|
||||
}
|
||||
}
|
||||
|
||||
protected void printRoutine(JavaWriter out, RoutineDefinition routine) {
|
||||
if (!routine.isSQLUsable()) {
|
||||
|
||||
@ -1914,6 +1939,10 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
printSingletonInstance(out, pkg);
|
||||
}
|
||||
|
||||
for (AttributeDefinition constant : pkg.getConstants()) {
|
||||
printConstant(out, constant);
|
||||
}
|
||||
|
||||
for (RoutineDefinition routine : pkg.getRoutines()) {
|
||||
printRoutine(out, routine);
|
||||
|
||||
|
||||
@ -52,9 +52,10 @@ import org.jooq.tools.JooqLogger;
|
||||
*/
|
||||
public abstract class AbstractPackageDefinition extends AbstractDefinition implements PackageDefinition {
|
||||
|
||||
private static final JooqLogger log = JooqLogger.getLogger(AbstractPackageDefinition.class);
|
||||
private static final JooqLogger log = JooqLogger.getLogger(AbstractPackageDefinition.class);
|
||||
|
||||
private List<RoutineDefinition> routines;
|
||||
private List<RoutineDefinition> routines;
|
||||
private List<AttributeDefinition> constants;
|
||||
|
||||
public AbstractPackageDefinition(SchemaDefinition schema, String name, String comment) {
|
||||
super(schema.getDatabase(), schema, name, comment);
|
||||
@ -82,4 +83,22 @@ public abstract class AbstractPackageDefinition extends AbstractDefinition imple
|
||||
}
|
||||
|
||||
protected abstract List<RoutineDefinition> getRoutines0() throws SQLException;
|
||||
|
||||
@Override
|
||||
public final List<AttributeDefinition> getConstants() {
|
||||
if (constants == null) {
|
||||
constants = new ArrayList<AttributeDefinition>();
|
||||
|
||||
try {
|
||||
constants = getConstants0();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
log.error("Error while initialising package", e);
|
||||
}
|
||||
}
|
||||
|
||||
return constants;
|
||||
}
|
||||
|
||||
protected abstract List<AttributeDefinition> getConstants0() throws SQLException;
|
||||
}
|
||||
|
||||
@ -40,6 +40,7 @@
|
||||
*/
|
||||
package org.jooq.util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -84,4 +85,9 @@ implements
|
||||
}
|
||||
|
||||
protected abstract List<RoutineDefinition> getRoutines0();
|
||||
|
||||
@Override
|
||||
public List<AttributeDefinition> getConstants() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,7 +50,12 @@ import java.util.List;
|
||||
public interface PackageDefinition extends Definition {
|
||||
|
||||
/**
|
||||
* Fetch all routines from the package
|
||||
* Fetch all routines from the package.
|
||||
*/
|
||||
List<RoutineDefinition> getRoutines();
|
||||
|
||||
/**
|
||||
* Fetch all constants from the package.
|
||||
*/
|
||||
List<AttributeDefinition> getConstants();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user