示例#1
0
  private Element createStoredProcedureElement(final Document dom, final Routine sp) {
    final Schema schema = sp.getSchema();

    final Element eStoredProcedure = dom.createElement("storedprocedure");

    final boolean isFunction = sp.getRoutineType() == RoutineType.function;
    eStoredProcedure.setAttribute("type", isFunction ? "function" : "procedure");
    eStoredProcedure.setAttribute("schema", schema.getName());
    eStoredProcedure.setAttribute("catalog", sp.getSchema().getCatalogName());
    // System.out.printf ("%s> [%s] [%s]%n", sp.getName (), sp.getDefinition (),
    // sp.getRoutineBodyType ());

    final String storedProcedureName = getPhysicalName(sp.getName());
    eStoredProcedure.setAttribute("name", getLogicalName(storedProcedureName));
    eStoredProcedure.setAttribute("physicalname", storedProcedureName);

    final List<? extends RoutineColumn<? extends Routine>> parameters = sp.getColumns();
    for (final RoutineColumn<? extends Routine> parameter : parameters) {
      if (shouldIncludeParameter(sp, parameter)) {
        final Element eParameter = createParameterElement(dom, parameter);
        eStoredProcedure.appendChild(eParameter);
      }
    }

    return eStoredProcedure;
  }
  @Test
  public void routineDefinitions() throws Exception {

    final InformationSchemaViews informationSchemaViews = new InformationSchemaViews();
    informationSchemaViews.setRoutinesSql("SELECT * FROM INFORMATION_SCHEMA.ROUTINES");

    final SchemaCrawlerOptions schemaCrawlerOptions = new SchemaCrawlerOptions();
    schemaCrawlerOptions.setInformationSchemaViews(informationSchemaViews);
    schemaCrawlerOptions.setSchemaInfoLevel(SchemaInfoLevel.maximum());

    final Database database = getDatabase(schemaCrawlerOptions);
    final Schema schema = new SchemaReference("PUBLIC", "BOOKS");
    final Routine[] routines = database.getRoutines(schema).toArray(new Routine[0]);
    assertEquals("Wrong number of routines", 4, routines.length);
    for (final Routine routine : routines) {
      assertFalse(
          "Routine definition not found, for " + routine, Utility.isBlank(routine.getDefinition()));
    }
  }
示例#3
0
  private boolean shouldIncludeParameter(
      final Routine sp, final RoutineColumn<? extends Routine> parameter) {
    boolean should = true;

    if (m_options.m_ignoreReturnParameterOnProcedure) {
      final boolean isFunction = sp.getRoutineType() == RoutineType.function;

      if (!isFunction) {
        final RoutineColumnType columnType = parameter.getColumnType();
        if (columnType instanceof ProcedureColumnType
            && (ProcedureColumnType) columnType == ProcedureColumnType.returnValue) {
          should = false;
        }
      }
    }

    return should;
  }