Ejemplo n.º 1
0
  private void visit(Procedure procedure) {
    if (this.filter != null && !filter.matcher(procedure.getName()).matches()) {
      return;
    }

    append(CREATE).append(SPACE);
    if (procedure.isVirtual()) {
      append(VIRTUAL);
    } else {
      append(FOREIGN);
    }
    append(SPACE)
        .append(procedure.isFunction() ? FUNCTION : PROCEDURE)
        .append(SPACE)
        .append(SQLStringVisitor.escapeSinglePart(procedure.getName()));
    append(LPAREN);

    boolean first = true;
    for (ProcedureParameter pp : procedure.getParameters()) {
      if (first) {
        first = false;
      } else {
        append(COMMA).append(SPACE);
      }
      visit(pp);
    }
    append(RPAREN);

    if (procedure.getResultSet() != null) {
      append(SPACE).append(RETURNS);
      appendOptions(procedure.getResultSet());
      append(SPACE).append(TABLE).append(SPACE);
      addColumns(procedure.getResultSet().getColumns(), true);
    }
    /* The parser treats the RETURN clause as optional for a procedure if using the RESULT param
      for (ProcedureParameter pp: procedure.getParameters()) {
    	if (pp.getType().equals(Type.ReturnValue)) {
    		append(SPACE).append(RETURNS).append(SPACE);
    		appendColumn(buffer, pp, false, true);
    		break;
    	}
    }*/

    // options
    String options = buildProcedureOptions(procedure);
    if (!options.isEmpty()) {
      append(NEWLINE).append(OPTIONS).append(SPACE).append(LPAREN).append(options).append(RPAREN);
    }
    // block
    if (procedure.isVirtual()) {
      append(NEWLINE).append(SQLConstants.Reserved.AS).append(NEWLINE);
      String plan = procedure.getQueryPlan();
      append(plan);
    }

    append(SEMICOLON);
  }
Ejemplo n.º 2
0
 public WrongType(Procedure proc, int n, Object argValue, Type expectedType) {
   this.proc = proc;
   this.procname = proc.getName();
   this.number = n;
   this.argValue = argValue;
   this.expectedType = expectedType;
 }
Ejemplo n.º 3
0
 protected Statement getStatement(Database catalog_db, Procedure catalog_proc, String stmt_name) {
   assertNotNull(catalog_db);
   assertNotNull(catalog_proc);
   Statement catalog_stmt = catalog_proc.getStatements().get(stmt_name);
   assert (catalog_stmt != null)
       : "Failed to retrieve Statement '"
           + stmt_name
           + "' from Procedure '"
           + catalog_proc.getName()
           + "'";
   return (catalog_stmt);
 }
Ejemplo n.º 4
0
 @Override
 public String getCreateStatement() {
   return ""
       + "CREATE TRIGGER "
       + this.name
       + " "
       + "AFTER INSERT OR UPDATE OR DELETE ON "
       + table
       + " "
       + "FOR EACH ROW EXECUTE PROCEDURE "
       + procedure.getName()
       + "();"
       + "";
 }
Ejemplo n.º 5
0
 @Override
 public void create(boolean ignoreAlreadyExists) throws SQLException {
   super.create(ignoreAlreadyExists);
   PreparedStatement ps =
       yordifier
           .getConnection()
           .prepareStatement(
               "INSERT INTO "
                   + Yordifier.TRIGGERS
                   + " (NAME, FUNCTION_NAME, TABLE_NAME) VALUES (?, ?, ?)");
   ps.setString(1, name);
   ps.setString(2, procedure.getName());
   ps.setString(3, table);
   ps.execute();
 }
Ejemplo n.º 6
0
 public FcudaStreamData(
     Procedure kernel,
     ForLoop streamLoop,
     IDExpression streamLoopVar,
     IDExpression streamLoopBound,
     IDExpression streamLoopUpdate) {
   loops = new LinkedList<ForLoop>();
   loops.add(streamLoop);
   // loopVar = streamLoopVar;
   loopVars = new LinkedList<IDExpression>();
   loopVars.add(streamLoopVar);
   loopBounds = new LinkedList<IDExpression>();
   loopBounds.add(streamLoopBound);
   // loopUpdate = streamLoopUpdate;
   loopUpdates = new LinkedList<IDExpression>();
   loopUpdates.add(streamLoopUpdate);
   kernelName = kernel.getName();
   mConstMemIDs = new HashSet<IDExpression>();
   mConstMemIDs.clear();
 }
Ejemplo n.º 7
0
  /**
   * Holt sich alle Triggers zu der übergebenen Procedure aus der Datenbank, die über die Yordifier
   * Connection angebunden ist.
   *
   * @param yordifier Yordifier für die Connection
   * @param procedure Procedure für die die Trigger geholt werden sollen
   * @return Liste von Triggers
   * @throws SQLException Falls etaws schief geht :-)
   */
  public static List<Trigger> getAllByProcedure(Yordifier yordifier, Procedure procedure)
      throws SQLException {
    PreparedStatement ps =
        yordifier
            .getConnection()
            .prepareStatement(
                "SELECT NAME, TABLE_NAME FROM "
                    + Yordifier.TRIGGERS.getName()
                    + " WHERE FUNCTION_NAME = ?");
    ps.setString(1, procedure.getName());
    ResultSet rs = ps.executeQuery();

    List<Trigger> triggers = new ArrayList<Trigger>();
    while (rs.next()) {
      Trigger t = new Trigger(yordifier);
      t.created = true;
      t.procedure = procedure;
      t.name = rs.getString(1);
      t.table = rs.getString(2);
      triggers.add(t);
    }

    return triggers;
  }
Ejemplo n.º 8
0
 /**
  * Add a procedure to this session.
  *
  * @param procedure the procedure to add
  */
 public void addProcedure(Procedure procedure) {
   if (procedures == null) {
     procedures = database.newStringMap();
   }
   procedures.put(procedure.getName(), procedure);
 }
  private static void buildFunctionImports(MetadataStore metadataStore, List<Builder> edmSchemas) {
    for (Schema schema : metadataStore.getSchemaList()) {

      EdmSchema.Builder odataSchema = findSchema(edmSchemas, schema.getName());
      EdmEntityContainer.Builder entityContainer =
          findEntityContainer(edmSchemas, schema.getName());

      // procedures
      for (Procedure proc : schema.getProcedures().values()) {
        EdmFunctionImport.Builder edmProcedure = EdmFunctionImport.newBuilder();
        edmProcedure.setName(proc.getName());
        String httpMethod = "POST";

        for (ProcedureParameter pp : proc.getParameters()) {
          if (pp.getName().equals("return")) {
            httpMethod = "GET";
            edmProcedure.setReturnType(
                ODataTypeManager.odataType(pp.getDatatype().getRuntimeTypeName()));
            continue;
          }

          EdmFunctionParameter.Builder param = EdmFunctionParameter.newBuilder();
          param.setName(pp.getName());
          param.setType(ODataTypeManager.odataType(pp.getDatatype().getRuntimeTypeName()));

          if (pp.getType() == ProcedureParameter.Type.In) {
            param.setMode(Mode.In);
          } else if (pp.getType() == ProcedureParameter.Type.InOut) {
            param.setMode(Mode.InOut);
          } else if (pp.getType() == ProcedureParameter.Type.Out) {
            param.setMode(Mode.Out);
          }

          param.setNullable(pp.getNullType() == NullType.Nullable);
          edmProcedure.addParameters(param);
        }

        // add a complex type for return resultset.
        ColumnSet<Procedure> returnColumns = proc.getResultSet();
        if (returnColumns != null) {
          httpMethod = "GET";
          EdmComplexType.Builder complexType = EdmComplexType.newBuilder();
          complexType.setName(proc.getName() + "_" + returnColumns.getName());
          complexType.setNamespace(schema.getName());
          for (Column c : returnColumns.getColumns()) {
            EdmProperty.Builder property =
                EdmProperty.newBuilder(c.getName())
                    .setType(ODataTypeManager.odataType(c.getDatatype().getRuntimeTypeName()))
                    .setNullable(c.getNullType() == NullType.Nullable);
            if (c.getDatatype()
                .getRuntimeTypeName()
                .equals(DataTypeManager.DefaultDataTypes.STRING)) {
              property
                  .setFixedLength(c.isFixedLength())
                  .setMaxLength(c.getLength())
                  .setUnicode(true);
            }
            complexType.addProperties(property);
          }
          odataSchema.addComplexTypes(complexType);
          edmProcedure.setIsCollection(true);
          edmProcedure.setReturnType(
              EdmCollectionType.newBuilder()
                  .setCollectionType(complexType)
                  .setKind(CollectionKind.Collection));
        }
        edmProcedure.setHttpMethod(httpMethod);
        entityContainer.addFunctionImports(edmProcedure);
      }
    }
  }
Ejemplo n.º 10
0
 public WrongType(Procedure proc, int n, Object argValue, String expectedType) {
   this(proc.getName(), n, argValue, expectedType);
   this.proc = proc;
 }
Ejemplo n.º 11
0
 public WrongType(Procedure proc, int n, ClassCastException ex) {
   super(ex);
   this.proc = proc;
   this.procname = proc.getName();
   this.number = n;
 }