Search in sources :

Example 1 with Routine

use of org.jooq.util.xml.jaxb.Routine in project jOOQ by jOOQ.

the class XMLRoutineDefinition method overload.

private static String overload(InformationSchema info, Routine routine) {
    Name routineName = name(routine.getRoutineCatalog(), routine.getRoutineSchema(), routine.getRoutinePackage(), routine.getRoutineName());
    String result = null;
    int count = 0;
    // TODO: Better algorithm by pre-calculating
    for (Routine r : info.getRoutines()) {
        Name rName = name(r.getRoutineCatalog(), r.getRoutineSchema(), r.getRoutinePackage(), r.getRoutineName());
        if (routineName.equals(rName)) {
            count++;
            if (routine == r) {
                result = "" + count;
            }
            if (count > 1 && result != null)
                break;
        }
    }
    return count > 1 ? result : null;
}
Also used : Routine(org.jooq.util.xml.jaxb.Routine) Name(org.jooq.Name)

Example 2 with Routine

use of org.jooq.util.xml.jaxb.Routine in project jOOQ by jOOQ.

the class XMLGenerator method exportRoutine.

private void exportRoutine(InformationSchema is, RoutineDefinition r, String catalogName, String schemaName) {
    String specificName = r.getName() + (isBlank(r.getOverload()) ? "" : "_" + r.getOverload());
    Routine routine = new Routine();
    routine.setRoutineCatalog(catalogName);
    routine.setSpecificCatalog(catalogName);
    routine.setRoutineSchema(schemaName);
    routine.setSpecificSchema(schemaName);
    if (r.getPackage() != null) {
        routine.setRoutinePackage(r.getPackage().getName());
        routine.setSpecificPackage(r.getPackage().getName());
    }
    routine.setRoutineName(r.getName());
    routine.setSpecificName(specificName);
    if (r.getReturnValue() == null) {
        routine.setRoutineType(RoutineType.PROCEDURE);
    } else {
        routine.setRoutineType(RoutineType.FUNCTION);
        routine.setDataType(r.getReturnType().getType());
        routine.setCharacterMaximumLength(r.getReturnType().getLength());
        routine.setNumericPrecision(r.getReturnType().getPrecision());
        routine.setNumericScale(r.getReturnType().getScale());
    }
    is.getRoutines().add(routine);
    int i = 1;
    for (ParameterDefinition p : r.getAllParameters()) {
        if (p != r.getReturnValue()) {
            Parameter parameter = new Parameter();
            parameter.setSpecificCatalog(catalogName);
            parameter.setSpecificSchema(schemaName);
            if (r.getPackage() != null)
                parameter.setSpecificPackage(r.getPackage().getName());
            parameter.setSpecificName(specificName);
            parameter.setOrdinalPosition(i++);
            parameter.setParameterName(p.getName());
            boolean in = r.getInParameters().contains(p);
            boolean out = r.getOutParameters().contains(p);
            if (in && out)
                parameter.setParameterMode(ParameterMode.INOUT);
            else if (in)
                parameter.setParameterMode(ParameterMode.IN);
            else if (out)
                parameter.setParameterMode(ParameterMode.OUT);
            parameter.setDataType(p.getType().getType());
            parameter.setCharacterMaximumLength(p.getType().getLength());
            parameter.setNumericPrecision(p.getType().getPrecision());
            parameter.setNumericScale(p.getType().getScale());
            parameter.setParameterDefault(p.getType().getDefaultValue());
            is.getParameters().add(parameter);
        }
    }
}
Also used : Parameter(org.jooq.util.xml.jaxb.Parameter) Routine(org.jooq.util.xml.jaxb.Routine) ReferentialConstraint(org.jooq.util.xml.jaxb.ReferentialConstraint) TableConstraint(org.jooq.util.xml.jaxb.TableConstraint)

Example 3 with Routine

use of org.jooq.util.xml.jaxb.Routine in project jOOQ by jOOQ.

the class XMLDatabase method getPackages0.

@Override
protected List<PackageDefinition> getPackages0() {
    List<PackageDefinition> result = new ArrayList<PackageDefinition>();
    Set<String> packages = new HashSet<String>();
    for (Routine routine : info().getRoutines()) {
        String schemaName = defaultIfBlank(routine.getSpecificSchema(), routine.getRoutineSchema());
        if (getInputSchemata().contains(schemaName)) {
            SchemaDefinition schema = getSchema(schemaName);
            String packageName = defaultIfBlank(routine.getSpecificPackage(), routine.getRoutinePackage());
            if (!isBlank(packageName) && packages.add(packageName)) {
                result.add(new XMLPackageDefinition(schema, info(), packageName));
            }
        }
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) PackageDefinition(org.jooq.util.PackageDefinition) ArrayList(java.util.ArrayList) Routine(org.jooq.util.xml.jaxb.Routine) HashSet(java.util.HashSet)

Example 4 with Routine

use of org.jooq.util.xml.jaxb.Routine in project jOOQ by jOOQ.

the class XMLDatabase method getRoutines0.

@Override
protected List<RoutineDefinition> getRoutines0() {
    List<RoutineDefinition> result = new ArrayList<RoutineDefinition>();
    for (Routine routine : info().getRoutines()) {
        if (isBlank(routine.getSpecificPackage()) && isBlank(routine.getRoutinePackage())) {
            String schemaName = defaultIfBlank(routine.getSpecificSchema(), routine.getRoutineSchema());
            if (getInputSchemata().contains(schemaName)) {
                SchemaDefinition schema = getSchema(schemaName);
                result.add(new XMLRoutineDefinition(schema, null, info(), routine));
            }
        }
    }
    return result;
}
Also used : RoutineDefinition(org.jooq.util.RoutineDefinition) SchemaDefinition(org.jooq.util.SchemaDefinition) ArrayList(java.util.ArrayList) Routine(org.jooq.util.xml.jaxb.Routine)

Aggregations

Routine (org.jooq.util.xml.jaxb.Routine)4 ArrayList (java.util.ArrayList)2 SchemaDefinition (org.jooq.util.SchemaDefinition)2 HashSet (java.util.HashSet)1 Name (org.jooq.Name)1 PackageDefinition (org.jooq.util.PackageDefinition)1 RoutineDefinition (org.jooq.util.RoutineDefinition)1 Parameter (org.jooq.util.xml.jaxb.Parameter)1 ReferentialConstraint (org.jooq.util.xml.jaxb.ReferentialConstraint)1 TableConstraint (org.jooq.util.xml.jaxb.TableConstraint)1