use of org.jooq.meta.RoutineDefinition in project jOOQ by jOOQ.
the class JavaGenerator method generateUDT.
protected void generateUDT(UDTDefinition udt, JavaWriter out) {
final SchemaDefinition schema = udt.getSchema();
final PackageDefinition pkg = udt.getPackage();
final boolean synthetic = udt.isSynthetic();
final String className = getStrategy().getJavaClassName(udt);
final String recordType = out.ref(getStrategy().getFullJavaClassName(udt, Mode.RECORD));
final List<String> interfaces = out.ref(getStrategy().getJavaClassImplements(udt, Mode.DEFAULT));
final String schemaId = out.ref(getStrategy().getFullJavaIdentifier(schema), 2);
final String packageId = pkg == null ? null : out.ref(getStrategy().getFullJavaIdentifier(pkg), 2);
final String udtId = out.ref(getStrategy().getJavaIdentifier(udt), 2);
printPackage(out, udt);
if (scala) {
out.println("object %s {", className);
printSingletonInstance(out, udt);
for (AttributeDefinition attribute : udt.getAttributes()) {
final String attrId = out.ref(getStrategy().getJavaIdentifier(attribute), 2);
out.javadoc("The attribute <code>%s</code>.[[before= ][%s]]", attribute.getQualifiedOutputName(), list(escapeEntities(comment(attribute))));
out.println("val %s = %s.%s", attrId, udtId, attrId);
}
out.println("}");
out.println();
}
generateUDTClassJavadoc(udt, out);
printClassAnnotations(out, udt, Mode.DEFAULT);
if (scala) {
out.println("%sclass %s extends %s[%s](\"%s\", null, %s, %s)[[before= with ][separator= with ][%s]] {", visibility(), className, UDTImpl.class, recordType, escapeString(udt.getOutputName()), packageId, synthetic, interfaces);
} else if (kotlin) {
out.println("%sopen class %s : %s<%s>(\"%s\", null, %s, %s)[[before=, ][%s]] {", visibility(), className, UDTImpl.class, recordType, escapeString(udt.getOutputName()), packageId, synthetic, interfaces);
out.println();
out.println("public companion object {");
out.javadoc("The reference instance of <code>%s</code>", udt.getQualifiedOutputName());
out.println("public val %s: %s = %s()", getStrategy().getJavaIdentifier(udt), className, className);
out.println("}");
} else {
out.println("%sclass %s extends %s<%s>[[before= implements ][%s]] {", visibility(), className, UDTImpl.class, recordType, interfaces);
out.printSerial();
printSingletonInstance(out, udt);
}
printRecordTypeMethod(out, udt);
for (AttributeDefinition attribute : udt.getAttributes()) {
final String attrTypeFull = getJavaType(attribute.getType(resolver(out)), out);
final String attrType = out.ref(attrTypeFull);
final String attrTypeRef = getJavaTypeReference(attribute.getDatabase(), attribute.getType(resolver(out)), out);
final String attrId = out.ref(getStrategy().getJavaIdentifier(attribute), 2);
final String attrName = attribute.getName();
final List<String> converter = out.ref(list(attribute.getType(resolver(out)).getConverter()));
final List<String> binding = out.ref(list(attribute.getType(resolver(out)).getBinding()));
if (!printDeprecationIfUnknownType(out, attrTypeFull))
out.javadoc("The attribute <code>%s</code>.[[before= ][%s]]", attribute.getQualifiedOutputName(), list(escapeEntities(comment(attribute))));
if (scala)
out.println("private val %s: %s[%s, %s] = %s.createField(%s.name(\"%s\"), %s, this, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + ")", scalaWhitespaceSuffix(attrId), UDTField.class, recordType, attrType, UDTImpl.class, DSL.class, escapeString(attrName), attrTypeRef, escapeString(""), converter, binding);
else if (kotlin)
out.println("%sval %s: %s<%s, %s> = %s.createField(%s.name(\"%s\"), %s, this, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + ")", visibility(), attrId, UDTField.class, recordType, attrType, UDTImpl.class, DSL.class, escapeString(attrName), attrTypeRef, escapeString(""), converter, binding);
else
out.println("%sstatic final %s<%s, %s> %s = createField(%s.name(\"%s\"), %s, %s, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + ");", visibility(), UDTField.class, recordType, attrType, attrId, DSL.class, escapeString(attrName), attrTypeRef, udtId, escapeString(""), converter, binding);
}
// [#799] Oracle UDT's can have member procedures
for (RoutineDefinition routine : udt.getRoutines()) {
try {
if (!routine.isSQLUsable()) {
// Static execute() convenience method
printConvenienceMethodProcedure(out, routine, false);
} else {
// Static execute() convenience method
if (!routine.isAggregate())
printConvenienceMethodFunction(out, routine, false);
// Static asField() convenience method
printConvenienceMethodFunctionAsField(out, routine, false);
printConvenienceMethodFunctionAsField(out, routine, true);
}
} catch (Exception e) {
log.error("Error while generating routine " + routine, e);
}
}
if (scala || kotlin) {
} else {
out.javadoc(NO_FURTHER_INSTANCES_ALLOWED);
out.println("private %s() {", className);
out.println("super(\"%s\", null, %s, %s);", udt.getOutputName(), packageId, synthetic);
out.println("}");
}
if (scala) {
out.println();
out.println("%soverride def getSchema: %s = %s", visibilityPublic(), Schema.class, schemaId);
} else if (kotlin) {
out.println();
out.println("%s override fun getSchema(): %s = %s", visibilityPublic(), Schema.class, schemaId);
} else {
out.overrideInherit();
out.println("%s%s getSchema() {", visibilityPublic(), Schema.class);
out.println("return %s != null ? %s : new %s(%s.name(\"%s\"));", schemaId, schemaId, SchemaImpl.class, DSL.class, schema.getOutputName());
out.println("}");
}
generateUDTClassFooter(udt, out);
out.println("}");
closeJavaWriter(out);
}
use of org.jooq.meta.RoutineDefinition in project jOOQ by jOOQ.
the class FirebirdDatabase method getRoutines0.
@Override
protected List<RoutineDefinition> getRoutines0() throws SQLException {
Rdb$procedures p = RDB$PROCEDURES.as("p");
Rdb$functions fu = RDB$FUNCTIONS.as("fu");
Rdb$functionArguments fa = RDB$FUNCTION_ARGUMENTS.as("fa");
Rdb$fields fi = RDB$FIELDS.as("fi");
return create().select(p.RDB$PROCEDURE_NAME.trim(), inline(null, VARCHAR).as("t"), inline(null, SMALLINT).as("p"), inline(null, SMALLINT).as("s")).from(p).where(p.RDB$PROCEDURE_TYPE.eq((short) 2)).union(is30() ? select(fu.RDB$FUNCTION_NAME.trim(), FIELD_TYPE(fi).as("t"), coalesce(CHARACTER_LENGTH(fi), fi.RDB$FIELD_PRECISION).as("p"), FIELD_SCALE(fi).as("s")).from(fu).leftAntiJoin(p).on(fu.RDB$FUNCTION_NAME.eq(p.RDB$PROCEDURE_NAME)).join(fa).on(fu.RDB$FUNCTION_NAME.eq(fa.RDB$FUNCTION_NAME)).leftOuterJoin(fi).on(fa.RDB$FIELD_SOURCE.eq(fi.RDB$FIELD_NAME)).where(fa.RDB$ARGUMENT_POSITION.eq(inline((short) 0))) : select(inline(""), inline(""), inline((short) 0), inline((short) 0)).where(falseCondition())).orderBy(1).collect(mapping(r -> new FirebirdRoutineDefinition(getSchemata().get(0), r.get(0, String.class), r.get(1, String.class), r.get(2, Integer.class), r.get(3, Integer.class)), Collectors.<RoutineDefinition>toList()));
}
use of org.jooq.meta.RoutineDefinition in project jOOQ by jOOQ.
the class H2Database method getRoutines1_4.
private List<RoutineDefinition> getRoutines1_4() {
List<RoutineDefinition> result = new ArrayList<>();
Field<Boolean> overloaded = field(select(field(DSL.exists(select(one()).from(FUNCTION_ALIASES.as("a")).where(field(name("a", FUNCTION_ALIASES.ALIAS_SCHEMA.getName())).eq(FUNCTION_ALIASES.ALIAS_SCHEMA)).and(field(name("a", FUNCTION_ALIASES.ALIAS_NAME.getName())).eq(FUNCTION_ALIASES.ALIAS_NAME)).and(field(name("a", FUNCTION_ALIASES.COLUMN_COUNT.getName())).ne(FUNCTION_ALIASES.COLUMN_COUNT)))))).as("overloaded");
for (Record record : create().select(FUNCTION_ALIASES.ALIAS_SCHEMA, FUNCTION_ALIASES.ALIAS_NAME, FUNCTION_ALIASES.REMARKS, FUNCTION_ALIASES.DATA_TYPE, FUNCTION_ALIASES.RETURNS_RESULT, FUNCTION_ALIASES.COLUMN_COUNT, overloaded, TYPE_INFO.TYPE_NAME, TYPE_INFO.PRECISION, TYPE_INFO.MAXIMUM_SCALE).from(FUNCTION_ALIASES).leftOuterJoin(TYPE_INFO).on(FUNCTION_ALIASES.DATA_TYPE.equal(TYPE_INFO.DATA_TYPE)).and(TYPE_INFO.POS.equal(0)).where(FUNCTION_ALIASES.ALIAS_SCHEMA.in(getInputSchemata())).and(FUNCTION_ALIASES.RETURNS_RESULT.in((short) 1, (short) 2)).orderBy(FUNCTION_ALIASES.ALIAS_NAME).fetch()) {
SchemaDefinition schema = getSchema(record.get(FUNCTION_ALIASES.ALIAS_SCHEMA));
if (schema != null) {
String name = record.get(FUNCTION_ALIASES.ALIAS_NAME);
String comment = record.get(FUNCTION_ALIASES.REMARKS);
String typeName = record.get(TYPE_INFO.TYPE_NAME);
Integer precision = record.get(TYPE_INFO.PRECISION);
Short scale = record.get(TYPE_INFO.MAXIMUM_SCALE);
String overload = record.get(overloaded) ? record.get(FUNCTION_ALIASES.COLUMN_COUNT, String.class) : null;
result.add(new H2RoutineDefinition(schema, name, null, typeName, precision, scale, comment, overload));
}
}
return result;
}
use of org.jooq.meta.RoutineDefinition in project jOOQ by jOOQ.
the class HSQLDBDatabase method getRoutines0.
@Override
protected List<RoutineDefinition> getRoutines0() throws SQLException {
List<RoutineDefinition> result = new ArrayList<>();
for (Record record : create().select(ROUTINES.ROUTINE_SCHEMA, ROUTINES.ROUTINE_NAME, ROUTINES.SPECIFIC_NAME, nvl(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER, ROUTINES.DATA_TYPE).as("datatype"), ROUTINES.NUMERIC_PRECISION, ROUTINES.NUMERIC_SCALE, field(ROUTINES.ROUTINE_DEFINITION.likeRegex(".*(?i:(\\w+\\s+)+aggregate\\s+function).*")).as("aggregate")).from(ROUTINES).leftOuterJoin(ELEMENT_TYPES).on(ROUTINES.ROUTINE_SCHEMA.equal(ELEMENT_TYPES.OBJECT_SCHEMA)).and(ROUTINES.ROUTINE_NAME.equal(ELEMENT_TYPES.OBJECT_NAME)).and(ROUTINES.DTD_IDENTIFIER.equal(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER)).where(ROUTINES.ROUTINE_SCHEMA.in(getInputSchemata())).and(tableValuedFunctions() ? ROUTINES.DATA_TYPE.isNull().or(ROUTINES.DATA_TYPE.notLike(inline("ROW(%"))) : noCondition()).orderBy(ROUTINES.ROUTINE_SCHEMA, ROUTINES.ROUTINE_NAME).fetch()) {
String datatype = record.get("datatype", String.class);
// [#3285] We currently do not recognise HSQLDB table-valued functions as such.
if (datatype != null && datatype.toUpperCase().startsWith("ROW")) {
JooqLogger.getLogger(getClass()).info("A row : " + datatype);
datatype = "ROW";
}
result.add(new HSQLDBRoutineDefinition(getSchema(record.get(ROUTINES.ROUTINE_SCHEMA)), record.get(ROUTINES.ROUTINE_NAME), record.get(ROUTINES.SPECIFIC_NAME), datatype, record.get(ROUTINES.NUMERIC_PRECISION), record.get(ROUTINES.NUMERIC_SCALE), record.get("aggregate", boolean.class)));
}
return result;
}
use of org.jooq.meta.RoutineDefinition in project jOOQ by jOOQ.
the class PostgresDatabase method getRoutines0.
@Override
protected List<RoutineDefinition> getRoutines0() throws SQLException {
List<RoutineDefinition> result = new ArrayList<>();
if (!canUseRoutines())
return result;
Routines r1 = ROUTINES.as("r1");
// [#7785] The pg_proc.proisagg column has been replaced incompatibly in PostgreSQL 11
Field<Boolean> isAgg = (is11() ? field(PG_PROC.PROKIND.eq(inline("a"))) : field("{0}.proisagg", SQLDataType.BOOLEAN, PG_PROC)).as("is_agg");
return create().select(r1.ROUTINE_SCHEMA, r1.ROUTINE_NAME, r1.SPECIFIC_NAME, r1.ROUTINE_TYPE, when(r1.DATA_TYPE.eq(inline("USER-DEFINED")).and(r1.TYPE_UDT_NAME.eq(inline("geometry"))), inline("geometry")).else_(canCombineArrays() ? when(condition("{0} && ARRAY['o','b']::\"char\"[]", PG_PROC.PROARGMODES), inline("void")).else_(r1.DATA_TYPE) : r1.DATA_TYPE).as("data_type"), r1.CHARACTER_MAXIMUM_LENGTH, // [#12048] TODO: Maintain whether we know the precision or not
when(r1.NUMERIC_PRECISION.isNull().and(r1.DATA_TYPE.in(inline("time"), inline("timetz"), inline("time without time zone"), inline("time with time zone"), inline("timestamp"), inline("timestamptz"), inline("timestamp without time zone"), inline("timestamp with time zone"))), inline(6)).else_(r1.NUMERIC_PRECISION).as(r1.NUMERIC_PRECISION), r1.NUMERIC_SCALE, r1.TYPE_UDT_SCHEMA, r1.TYPE_UDT_NAME, // Calculate overload index if applicable
when(count().over(partitionBy(r1.ROUTINE_SCHEMA, r1.ROUTINE_NAME)).gt(one()), rowNumber().over(partitionBy(r1.ROUTINE_SCHEMA, r1.ROUTINE_NAME).orderBy(// replace(field("pg_get_function_arguments({0})", VARCHAR, PG_PROC.OID), inline('"'), inline("")),
r1.SPECIFIC_NAME))).as("overload"), isAgg).from(r1).join(PG_NAMESPACE).on(PG_NAMESPACE.NSPNAME.eq(r1.SPECIFIC_SCHEMA)).join(PG_PROC).on(PG_PROC.PRONAMESPACE.eq(PG_NAMESPACE.OID)).and(is12() ? condition("nameconcatoid({0}, {1}) = {2}", PG_PROC.PRONAME, PG_PROC.OID, r1.SPECIFIC_NAME) : PG_PROC.PRONAME.concat("_").concat(PG_PROC.OID).eq(r1.SPECIFIC_NAME)).where(r1.ROUTINE_SCHEMA.in(getInputSchemata())).and(tableValuedFunctions() ? condition(not(PG_PROC.PRORETSET)) : noCondition()).and(!getIncludeTriggerRoutines() ? r1.DATA_TYPE.isDistinctFrom(inline("trigger")) : noCondition()).orderBy(r1.ROUTINE_SCHEMA.asc(), r1.ROUTINE_NAME.asc(), field(name("overload")).asc()).collect(mapping(r -> new PostgresRoutineDefinition(this, r), Collectors.<RoutineDefinition>toList()));
}
Aggregations