コード例 #1
0
 private static void generateSingle(Table table, Proc proc, PrintWriter outData) {
   String dataStruct;
   if (proc.isStd || proc.isStdExtended()) dataStruct = table.useName();
   else dataStruct = table.useName() + proc.upperFirst();
   String parameters = "";
   boolean hasInput = (proc.inputs.size() > 0 || proc.dynamics.size() > 0);
   outData.println("    def " + proc.name + "(self):");
   outData.println("        ''' Single returns boolean and record");
   if (hasInput == true) {
     outData.println("        Input:");
     for (int f = 0; f < proc.inputs.size(); f++) {
       Field field = (Field) proc.inputs.elementAt(f);
       outData.println("            " + field.useName());
       parameters += ", " + field.useName() + "=" + defValue(field);
     }
     for (int f = 0; f < proc.dynamics.size(); f++) {
       String field = (String) proc.dynamics.elementAt(f);
       outData.println("            " + field);
       parameters += ", " + field + "=''";
     }
   }
   outData.println("        Output:");
   for (int f = 0; f < proc.outputs.size(); f++) {
     Field field = (Field) proc.outputs.elementAt(f);
     outData.println("            " + field.useName());
   }
   outData.println("        '''");
   outData.println(
       "        return " + pymodFront + table.useName() + proc.upperFirst() + "(self)");
   if (hasInput == true)
     generateInput(table.useName(), dataStruct, proc.name, parameters, outData);
   else generateCover(table.useName(), dataStruct, proc.name, outData);
 }
コード例 #2
0
 private static void generateAction(Table table, Proc proc, PrintWriter outData) {
   String dataStruct;
   if (proc.isStd || proc.isStdExtended()) dataStruct = table.useName();
   else dataStruct = table.useName() + proc.upperFirst();
   String parameters = "";
   outData.println("    def " + proc.name + "(self):");
   outData.println("        ''' Action");
   outData.println("        Input:");
   for (int f = 0; f < proc.inputs.size(); f++) {
     Field field = (Field) proc.inputs.elementAt(f);
     outData.println("            " + field.useName());
     parameters += ", " + field.useName() + "=" + defValue(field);
   }
   for (int f = 0; f < proc.dynamics.size(); f++) {
     String field = (String) proc.dynamics.elementAt(f);
     outData.println("            " + field);
     parameters += ", " + field + "=''";
   }
   outData.println("        '''");
   outData.println(
       "        return " + pymodFront + table.useName() + proc.upperFirst() + "(self)");
   generateInput(table.useName(), dataStruct, proc.name, parameters, outData);
 }
コード例 #3
0
 private static void generateBulkAction(Table table, Proc proc, PrintWriter outData) {
   outData.println("    def " + proc.name + "(self, recs):");
   outData.println("        ''' Bulk Action");
   outData.println("        Input:");
   for (int f = 0; f < proc.inputs.size(); f++) {
     Field field = (Field) proc.inputs.elementAt(f);
     outData.println("            " + field.useName());
   }
   for (int f = 0; f < proc.dynamics.size(); f++) {
     String field = (String) proc.dynamics.elementAt(f);
     outData.println("            " + field);
   }
   outData.println("        '''");
   outData.println(
       "        " + pymodFront + table.useName() + proc.upperFirst() + "(len(recs), recs)");
 }
コード例 #4
0
ファイル: IdlObjCCode.java プロジェクト: VincentRisi/jportal
 private static void generateInterfaceStructs(Table table, PrintWriter outData) {
   if (table.fields.size() > 0) {
     if (table.comments.size() > 0) {
       for (int i = 0; i < table.comments.size(); i++) {
         String s = (String) table.comments.elementAt(i);
         outData.println("// " + s);
       }
     }
     generateInterfaceTableStructs(table.fields, table.useName(), outData);
     generateEnumOrdinals(table, outData);
   }
   for (int i = 0; i < table.procs.size(); i++) {
     Proc proc = (Proc) table.procs.elementAt(i);
     if (proc.isData || proc.isStd || proc.isStdExtended() || proc.hasNoData()) continue;
     if (proc.comments.size() > 0) {
       for (int j = 0; j < proc.comments.size(); j++) {
         String s = (String) proc.comments.elementAt(j);
         outData.println("// " + s);
       }
     }
     generateInterfaceStructPairs(proc, table.useName() + proc.upperFirst(), outData);
   }
 }
コード例 #5
0
ファイル: AdoVBCode.java プロジェクト: VincentRisi/jportal
 /** Emits functions for processing the database activity */
 static void emitCode(
     Proc proc, PrintWriter outData, String tableName, String optIndex, String optUseIndex) {
   if (proc.outputs.size() == 0) {
     outData.println("Public Sub " + proc.upperFirst() + "(Connect as TConnect" + optIndex + ")");
   } else if (proc.isSingle)
     outData.println(
         "Public Function "
             + proc.upperFirst()
             + "(Connect as TConnect"
             + optIndex
             + ") as Boolean");
   else {
     outData.println("Public Sub " + proc.upperFirst() + "(Connect as TConnect)");
     if (optUseIndex != "") optUseIndex = "(0)";
   }
   if (proc.comments.size() > 0) {
     for (int i = 0; i < proc.comments.size(); i++) {
       String comment = (String) proc.comments.elementAt(i);
       outData.println("'" + comment);
     }
   }
   if (proc.outputs.size() == 0) {
     outData.println("' Returns no output.");
   } else if (proc.isSingle) {
     outData.println("  Dim RS as RecordSet");
     outData.println("  " + proc.upperFirst() + " = False");
   } else {
     outData.println("  Set " + proc.upperFirst() + "Cursor = new TCursor");
   }
   outData.println("  Connect.RoutineName = \"" + proc.upperFirst() + "\"");
   outData.println("  Dim QD as QueryDef");
   for (int index = 0; index < proc.inputs.size(); index++) {
     Field field = (Field) proc.inputs.elementAt(index);
     if (proc.isInsert) {
       if (field.isSequence)
         outData.println(
             "  Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + " = getSequence(\""
                 + tableName
                 + "\") ' User supplied Function for Sequences");
     }
     if (field.type == Field.TIMESTAMP)
       outData.println(
           "  Rec"
               + optUseIndex
               + "."
               + field.useName()
               + " = getTimeStamp ' User supplied Function for Time Stamp");
     if (field.type == Field.USERSTAMP)
       outData.println(
           "  Rec"
               + optUseIndex
               + "."
               + field.useName()
               + " = getUserStamp ' User supplied Function for User Stamp");
   }
   outData.print("  Set QD = Connect.DB.CreateQueryDef(\"\", ");
   String vbline = "";
   for (int i = 0; i < proc.lines.size(); i++) {
     String x = "";
     if (i + 1 < proc.lines.size()) x = " & ";
     Line l = (Line) proc.lines.elementAt(i);
     if (l.isVar) vbline = vbline + l.line + x;
     else vbline = vbline + "\"" + l.line + "\"" + x;
   }
   int p;
   while ((p = vbline.indexOf("\" & \"")) > -1)
     vbline = vbline.substring(0, p) + vbline.substring(p + 5);
   if (proc.placeHolders.size() > 0) {
     for (int i = 0; i < proc.placeHolders.size(); i++) {
       String placeHolder = ":" + (String) proc.placeHolders.elementAt(i);
       String work = "";
       int n = vbline.indexOf(placeHolder);
       if (n == -1) {
         outData.println("Error with placeholders " + placeHolder);
         break;
       }
       if (n > 0) work = vbline.substring(0, n);
       work = work + "?";
       n += placeHolder.length();
       if (n < vbline.length()) ;
       work = work + vbline.substring(n);
       vbline = work;
     }
     outData.println(vbline + ")");
     for (int i = 0, pos = 0; i < proc.placeHolders.size(); i++) {
       String placeHolder = (String) proc.placeHolders.elementAt(i);
       int index = proc.indexOf(placeHolder);
       pos = emitInputCode(proc, index, pos, outData, optUseIndex);
     }
   } else {
     outData.println(vbline + ")");
     for (int index = 0, pos = 0; index < proc.inputs.size(); index++)
       pos = emitInputCode(proc, index, pos, outData, optUseIndex);
   }
   if (proc.outputs.size() == 0) {
     outData.println("  QD.execute");
     outData.println("  QD.Close");
   } else if (proc.isSingle) {
     outData.println("  Set RS = QD.OpenRecordSet(dbOpenSnapShot, dbForwardOnly and dbReadOnly)");
     outData.println("  If Not RS.eof Then");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       if (field.isNull && notString(field)) {
         outData.println(
             "    Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + "IsNull = isNull(RS!"
                 + field.name
                 + ")");
         outData.println(
             "    If Not Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + "IsNull Then Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + " = RS!"
                 + field.name);
       } else
         outData.println("    Rec" + optUseIndex + "." + field.useName() + " =  RS!" + field.name);
     }
     outData.println("    " + proc.upperFirst() + " = True");
     outData.println("  End If");
     outData.println("  RS.Close");
     outData.println("  QD.Close");
   } else {
     outData.println("  Set " + proc.upperFirst() + "Cursor.Connect = Connect");
     outData.println("  Set " + proc.upperFirst() + "Cursor.QD = QD");
     outData.println(
         "  Set "
             + proc.upperFirst()
             + "Cursor.RS = "
             + proc.upperFirst()
             + "Cursor.QD.openRecordSet(dbOpenSnapShot, dbForwardOnly and dbReadOnly)");
   }
   if (proc.isSingle) outData.println("End Function");
   else outData.println("End Sub");
   outData.println();
   if (proc.outputs.size() > 0 && !proc.isSingle) {
     outData.println("Public Function next" + proc.upperFirst() + "() as Boolean");
     outData.println(
         "  If "
             + proc.upperFirst()
             + "Cursor Is Nothing Then Err.Raise 1998, \""
             + proc.upperFirst()
             + "\"");
     outData.println(
         "  "
             + proc.upperFirst()
             + "Cursor.Connect.RoutineName = \"next"
             + proc.upperFirst()
             + "\"");
     outData.println("  next" + proc.upperFirst() + " = False");
     outData.println("  If Not " + proc.upperFirst() + "Cursor.RS.eof Then");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       if (field.isNull && notString(field)) {
         outData.println(
             "    Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + "IsNull = isNull("
                 + proc.upperFirst()
                 + "Cursor.RS!"
                 + field.name
                 + ")");
         outData.println(
             "    If Not Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + "IsNull Then Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + " = "
                 + proc.upperFirst()
                 + "Cursor.RS!"
                 + field.name);
       } else
         outData.println(
             "    Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + " = "
                 + proc.upperFirst()
                 + "Cursor.RS!"
                 + field.name);
     }
     outData.println("    next" + proc.upperFirst() + " = True");
     outData.println("    " + proc.upperFirst() + "Cursor.RS.MoveNext");
     outData.println("  Else");
     outData.println("    " + proc.upperFirst() + "Cursor.RS.Close");
     outData.println("  End If");
     outData.println("End Function");
     outData.println();
     outData.println("Public Sub cancel" + proc.upperFirst() + "()");
     outData.println(
         "  if " + proc.upperFirst() + "Cursor.isOpen then " + proc.upperFirst() + "Cursor.Done");
     outData.println("End Sub");
     outData.println();
     outData.println(
         "Public Sub load" + proc.upperFirst() + "(Connect as TConnect, Optional Max As Long)");
     outData.println("  Dim AllocCount As Long");
     outData.println("  AllocCount = 64");
     outData.println("  ReDim Rec(0 to AllocCount)");
     outData.println("  " + proc.upperFirst() + " Connect");
     outData.println("  Do While next" + proc.upperFirst() + "()");
     outData.println("    RecCount = RecCount + 1");
     outData.println("    If RecCount > AllocCount Then");
     outData.println("      AllocCount = AllocCount * 2");
     outData.println("      ReDim Preserve Rec(0 to AllocCount)");
     outData.println("    End If");
     outData.println("    Rec(RecCount) = Rec(0)");
     outData.println("    If RecCount = Max Then");
     outData.println("      cancel" + proc.upperFirst() + "");
     outData.println("      Exit Do");
     outData.println("    End If");
     outData.println("  Loop");
     outData.println("  ReDim Preserve Rec(0 to RecCount)");
     outData.println("End Sub");
     outData.println();
   }
 }
コード例 #6
0
ファイル: AdoVBCode.java プロジェクト: VincentRisi/jportal
 /** Build of all required standard procedures */
 static void generateOther(Table table, String output, PrintWriter outLog) {
   for (int i = 0; i < table.procs.size(); i++) {
     Proc proc = (Proc) table.procs.elementAt(i);
     if (proc.isData || proc.isStd || proc.hasNoData()) continue;
     try {
       outLog.println("Code: " + output + table.useName() + proc.upperFirst() + ".cls");
       OutputStream outFile =
           new FileOutputStream(output + table.useName() + proc.upperFirst() + ".cls");
       try {
         PrintWriter outData = new PrintWriter(outFile);
         outData.println("VERSION 1.0 CLASS");
         outData.println("BEGIN");
         outData.println("  MultiUse = -1");
         outData.println("END");
         outData.println("ATTRIBUTE VB_NAME=\"t" + table.useName() + proc.upperFirst() + "\"");
         outData.println("Option explicit");
         outData.println(
             "' This code was generated, do not modify it, modify it at source and regenerate it.");
         for (int j = 0; j < proc.comments.size(); j++) {
           String comment = (String) proc.comments.elementAt(j);
           outData.println("'" + comment);
         }
         boolean hasMulti = true;
         if (proc.inputs.size() > 0) {}
         if (proc.outputs.size() == 0 || proc.isSingle == true) hasMulti = false;
         outData.println();
         outData.println("Private Type TRec");
         for (int j = 0; j < proc.inputs.size(); j++) {
           Field field = (Field) proc.inputs.elementAt(j);
           String io;
           if (!proc.hasOutput(field.name)) io = "input";
           else io = "input-output";
           outData.println("  " + varType(field) + " '" + io);
           for (int c = 0; c < field.comments.size(); c++) {
             String s = (String) field.comments.elementAt(c);
             outData.println("'" + s);
           }
           if (field.isNull && notString(field))
             outData.println("  " + field.useName() + "IsNull as Boolean");
         }
         for (int j = 0; j < proc.outputs.size(); j++) {
           Field field = (Field) proc.outputs.elementAt(j);
           if (!proc.hasInput(field.name)) {
             outData.println("  " + varType(field) + " 'output");
             for (int c = 0; c < field.comments.size(); c++) {
               String s = (String) field.comments.elementAt(c);
               outData.println("'" + s);
             }
             if (field.isNull && notString(field))
               outData.println("  " + field.useName() + "IsNull as Boolean");
           }
         }
         for (int j = 0; j < proc.dynamics.size(); j++) {
           String s = (String) proc.dynamics.elementAt(j);
           outData.println("  " + s + " As String 'dynamic");
         }
         outData.println("End Type");
         outData.println();
         if (hasMulti) {
           outData.println("Private Rec() as TRec");
           outData.println("Public RecCount as Long");
           outData.println("Private " + proc.name + "Cursor As TCursor");
         } else outData.println("Private Rec as TRec");
         outData.println();
         generateCopy(table.useName() + proc.upperFirst(), outData, hasMulti);
         String optZero = hasMulti ? "(0)" : "";
         String optIndex = hasMulti ? "Optional aIndex as Long" : "";
         String optIndex1 = hasMulti ? ", Optional aIndex as Long" : "";
         String optIndex2 = hasMulti ? "Optional aIndex as Long, " : "";
         String optUseIndex = hasMulti ? "(aIndex)" : "";
         outData.println("Private Sub Class_Initialize()");
         if (hasMulti) outData.println("  RecClear");
         for (int j = 0; j < proc.inputs.size(); j++) {
           Field field = (Field) proc.inputs.elementAt(j);
           outData.println("  Rec" + optZero + "." + initVBVar(field));
           if (field.isNull && notString(field))
             outData.println("  Rec" + optZero + "." + field.useName() + "IsNull = false");
         }
         for (int j = 0; j < proc.outputs.size(); j++) {
           Field field = (Field) proc.outputs.elementAt(j);
           if (proc.hasInput(field.name)) continue;
           outData.println("  Rec" + optZero + "." + initVBVar(field));
           if (field.isNull && notString(field))
             outData.println("  Rec" + optZero + "." + field.useName() + "IsNull = false");
         }
         for (int j = 0; j < proc.dynamics.size(); j++) {
           String s = (String) proc.dynamics.elementAt(j);
           outData.println("  Rec" + optZero + "." + s + " = \"\"");
         }
         outData.println("End Sub");
         outData.println();
         if (ioRoutines) {
           outData.println("Public Sub Class_PutFile(OutFile as Long" + optIndex1 + ")");
           outData.println("  Put OutFile,, Rec" + optUseIndex);
           outData.println("End Sub");
           outData.println();
           outData.println("Public Sub Class_GetFile(InFile as Long" + optIndex1 + ")");
           outData.println("  Get InFile,, Rec" + optUseIndex);
           outData.println("End Sub");
           outData.println();
         }
         for (int j = 0; j < proc.inputs.size(); j++) {
           Field field = (Field) proc.inputs.elementAt(j);
           generateProperties(field, outData, optIndex, optIndex2, optUseIndex);
         }
         for (int j = 0; j < proc.outputs.size(); j++) {
           Field field = (Field) proc.outputs.elementAt(j);
           if (proc.hasInput(field.name)) continue;
           generateProperties(field, outData, optIndex, optIndex2, optUseIndex);
         }
         for (int j = 0; j < proc.dynamics.size(); j++) {
           String s = (String) proc.dynamics.elementAt(j);
           outData.println("Public Property Get " + s + "(" + optIndex + ") as String");
           outData.println("  " + s + " = Rec" + optUseIndex + "." + s);
           outData.println("End Property");
           outData.println();
           outData.println("Public Property Let " + s + "(" + optIndex2 + "aValue as String)");
           outData.println("  Rec" + optUseIndex + "." + s + " = aValue");
           outData.println("End Property");
           outData.println();
         }
         emitCode(proc, outData, table.useName(), optIndex1, optUseIndex);
         outData.flush();
       } finally {
         outFile.close();
       }
     } catch (IOException e1) {
       outLog.println("Generate Procs IO Error");
     }
   }
 }
コード例 #7
0
  /** Build of output data rec for user procedures */
  static void generateUserOutputRecs(Table table, PrintWriter outData) {
    for (int i = 0; i < table.procs.size(); i++) {
      Proc proc = (Proc) table.procs.elementAt(i);
      if (proc.isData || proc.isStd || proc.hasNoData()) continue;
      if (proc.isStdExtended()) continue;
      String work = "(object)";
      String superName = "";
      if (proc.outputs.size() > 0) {
        for (int j = 0; j < proc.comments.size(); j++)
          outData.println("##" + (String) proc.comments.elementAt(j));
        String typeChar = "D";
        if (proc.hasDiscreteInput()) typeChar = "O";
        work = "(" + typeChar + table.useName() + proc.upperFirst() + ")";
        superName = typeChar + table.useName() + proc.upperFirst();
        outData.println("## \\class " + typeChar + table.useName() + proc.upperFirst());
        outData.println("class " + typeChar + table.useName() + proc.upperFirst() + "(object):");
        outData.println(
            "    def _make(self): return " + typeChar + table.useName() + proc.upperFirst() + "()");
        if (proc.hasDiscreteInput())
          outData.println(
              "    def _name(self): return ('"
                  + typeChar
                  + table.useName()
                  + proc.upperFirst()
                  + "')");
        else
          outData.println(
              "    def _name(self): return ('D"
                  + table.useName()
                  + proc.upperFirst()
                  + "', 'O"
                  + table.useName()
                  + proc.upperFirst()
                  + "')");
        generateDataFields(
            proc.outputs,
            "",
            typeChar + table.useName() + proc.upperFirst(),
            table.useName(),
            outData);
        outData.println();
      }
      if (proc.hasDiscreteInput()) {
        outData.println("## \\class D" + table.useName() + proc.upperFirst());
        outData.println("class D" + table.useName() + proc.upperFirst() + work + ":");
        outData.println(
            "    def _make(self): return D" + table.useName() + proc.upperFirst() + "()");
        outData.println(
            "    def _name(self): return ('D" + table.useName() + proc.upperFirst() + "')");
        Vector<Field> discreteInputs = new Vector<Field>();
        for (int j = 0; j < proc.inputs.size(); j++) {
          Field field = (Field) proc.inputs.elementAt(j);
          if (!proc.hasOutput(field.name)) discreteInputs.addElement(field);
        }

        for (int j = 0; j < proc.dynamics.size(); j++) {
          Field f = new Field();
          Integer length = (Integer) proc.dynamicSizes.elementAt(j);
          f.name = (String) proc.dynamics.elementAt(j);
          f.type = Field.CHAR;
          f.length = length.intValue();
          discreteInputs.addElement(f);
        }
        generateDataFields(
            discreteInputs,
            superName,
            "D" + table.useName() + proc.upperFirst(),
            table.useName(),
            outData);
        outData.println();
      } else if (proc.outputs.size() > 0) {
        outData.println("## \\class O" + table.useName() + proc.upperFirst());
        outData.println("## \\field see:O" + table.useName() + proc.upperFirst());
        outData.println(
            "O"
                + table.useName()
                + proc.upperFirst()
                + " = D"
                + table.useName()
                + proc.upperFirst());
        outData.println();
      }
      if (pymodName.length() > 0) {
        coverFunctions = new Vector<String>();
        outData.println(
            "class "
                + table.useName()
                + proc.upperFirst()
                + "(D"
                + table.useName()
                + proc.upperFirst()
                + "):");
        outData.println(
            "    def __init__(self): D" + table.useName() + proc.upperFirst() + ".__init__(self)");
        if (proc.isMultipleInput) generateBulkAction(table, proc, outData);
        else if (proc.isInsert && proc.hasReturning) generateAction(table, proc, outData);
        else if (proc.outputs.size() > 0)
          if (proc.isSingle) generateSingle(table, proc, outData);
          else generateMultiple(table, proc, outData);
        else generateAction(table, proc, outData);
        outData.println();
        for (int j = 0; j < coverFunctions.size(); j++)
          outData.println((String) coverFunctions.elementAt(j));
      }
    }
  }