コード例 #1
0
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();

    String previous_node = "";
    String start_node = "";

    boolean inMain = true;
    boolean isExecutedThroughWebHCat = false;

    String previousOutputConnectionName = "";

    if (node.getIncomingConnections() != null && node.getIncomingConnections().size() > 0) {
      IConnection connection = node.getIncomingConnections().get(0);
      previous_node = connection.getSource().getUniqueName();
      INode loadNode = node.getDesignSubjobStartNode();
      start_node = loadNode.getUniqueName();

      boolean isLocal = "true".equals(ElementParameterParser.getValue(loadNode, "__LOCAL__"));
      isExecutedThroughWebHCat =
          !isLocal
              && "MICROSOFT_HD_INSIGHT"
                  .equals(ElementParameterParser.getValue(loadNode, "__DISTRIBUTION__"));

      inMain = loadNode.isSubtreeStart();
      previousOutputConnectionName = connection.getName();
    }

    String outputConnectionName = "";
    List<IConnection> outputConnections = (List<IConnection>) node.getOutgoingConnections();
    if (outputConnections != null && outputConnections.size() > 0) {
      outputConnectionName = outputConnections.get(0).getName();
    }

    List<Map<String, String>> configs =
        (List<Map<String, String>>)
            ElementParameterParser.getObjectValue(node, "__FILTER_CONFIG__");
    boolean useAdvancedFilter =
        "true".equals(ElementParameterParser.getValue(node, "__USE_ADVANCED_FILTER__"));
    String advancedFilter = ElementParameterParser.getValue(node, "__ADVANCED_FILTER__");

    stringBuffer.append(TEXT_2);
    stringBuffer.append(TEXT_3);

    // this util class use by set log4j debug paramters
    class DefaultLog4jFileUtil {

      INode node = null;
      String cid = null;
      boolean isLog4jEnabled = false;
      String label = null;

      public DefaultLog4jFileUtil() {}

      public DefaultLog4jFileUtil(INode node) {
        this.node = node;
        this.cid = node.getUniqueName();
        this.label = cid;
        this.isLog4jEnabled =
            ("true")
                .equals(
                    org.talend.core.model.process.ElementParameterParser.getValue(
                        node.getProcess(), "__LOG4J_ACTIVATE__"));
      }

      public void setCid(String cid) {
        this.cid = cid;
      }

      // for all tFileinput* components
      public void startRetriveDataInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_4);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_5);
        }
      }

      public void retrievedDataNumberInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_6);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_7);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_8);
        }
      }

      public void retrievedDataNumberInfoFromGlobalMap(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_9);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_10);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_11);
        }
      }

      // for all tFileinput* components
      public void retrievedDataNumberInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_12);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_13);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_14);
        }
      }

      public void writeDataFinishInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_15);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_16);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_17);
        }
      }

      // TODO delete it and remove all log4jSb parameter from components
      public void componentStartInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_18);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_19);
        }
      }

      // TODO rename or delete it
      public void debugRetriveData(INode node, boolean hasIncreased) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_20);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_21);
          stringBuffer.append(cid);
          stringBuffer.append(hasIncreased ? "" : "+1");
          stringBuffer.append(TEXT_22);
        }
      }

      // TODO rename or delete it
      public void debugRetriveData(INode node) {
        debugRetriveData(node, true);
      }

      // TODO rename or delete it
      public void debugWriteData(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_23);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_24);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_25);
        }
      }

      public void logCurrentRowNumberInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_26);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_27);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_28);
        }
      }

      public void logDataCountInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_29);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_30);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_31);
        }
      }
    }

    final DefaultLog4jFileUtil log4jFileUtil =
        new DefaultLog4jFileUtil(
            (INode)
                (((org.talend.designer.codegen.config.CodeGeneratorArgument) argument)
                    .getArgument()));

    log4jFileUtil.componentStartInfo(node);
    final boolean isLog4jEnabled =
        ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));

    stringBuffer.append(TEXT_32);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_33);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_34);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_35);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_36);
    stringBuffer.append(outputConnectionName);
    stringBuffer.append(TEXT_37);
    stringBuffer.append(previous_node);
    stringBuffer.append(TEXT_38);
    stringBuffer.append(previousOutputConnectionName);
    stringBuffer.append(TEXT_39);

    if (!useAdvancedFilter) {
      boolean isFirst = true;
      String operator = "";
      for (Map<String, String> configMap : configs) {
        if (!isFirst) {

          stringBuffer.append(TEXT_40);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_41);
          stringBuffer.append(configMap.get("LOGICAL"));
          stringBuffer.append(TEXT_42);
        }
        isFirst = false;

        if ("EQUAL".equals(configMap.get("OPERATOR"))) {
          operator = "==";
        } else if ("NEQUAL".equals(configMap.get("OPERATOR"))) {
          operator = "!=";
        } else if ("GREATER".equals(configMap.get("OPERATOR"))) {
          operator = ">";
        } else if ("GREATER_EQUAL".equals(configMap.get("OPERATOR"))) {
          operator = ">=";
        } else if ("LESS".equals(configMap.get("OPERATOR"))) {
          operator = "<";
        } else if ("LESS_EQUAL".equals(configMap.get("OPERATOR"))) {
          operator = "<=";
        } else if ("MATCH".equals(configMap.get("OPERATOR"))) {
          operator = "matches";
        }

        stringBuffer.append(TEXT_43);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_44);
        stringBuffer.append("true".equals(configMap.get("NOT")) ? "NOT " : "");
        stringBuffer.append(TEXT_45);
        stringBuffer.append(configMap.get("COLUMN_NAME"));
        stringBuffer.append(TEXT_46);
        stringBuffer.append(operator);
        stringBuffer.append(TEXT_47);
        stringBuffer.append(configMap.get("VALUE"));
        stringBuffer.append(TEXT_48);
      }
    } else {

      stringBuffer.append(TEXT_49);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_50);
      stringBuffer.append(advancedFilter);
      stringBuffer.append(TEXT_51);
    }

    stringBuffer.append(TEXT_52);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_53);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_54);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_55);
    stringBuffer.append(TEXT_56);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_57);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_58);

    if (inMain) {

      stringBuffer.append(TEXT_59);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_60);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_61);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_62);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_63);
      if (isLog4jEnabled) {
        stringBuffer.append(TEXT_64);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_65);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_66);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_67);
      }
      stringBuffer.append(TEXT_68);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_69);

      if (isExecutedThroughWebHCat) {

        stringBuffer.append(TEXT_70);
        stringBuffer.append(start_node);
        stringBuffer.append(TEXT_71);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_72);

      } else {

        stringBuffer.append(TEXT_73);
        stringBuffer.append(start_node);
        stringBuffer.append(TEXT_74);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_75);
      }

      stringBuffer.append(TEXT_76);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_77);

      if (isExecutedThroughWebHCat) {

        stringBuffer.append(TEXT_78);
        stringBuffer.append(start_node);
        stringBuffer.append(TEXT_79);
        stringBuffer.append(start_node);
        stringBuffer.append(TEXT_80);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_81);
        stringBuffer.append(start_node);
        stringBuffer.append(TEXT_82);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_83);

      } else {

        stringBuffer.append(TEXT_84);
        stringBuffer.append(start_node);
        stringBuffer.append(TEXT_85);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_86);
      }

      stringBuffer.append(TEXT_87);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_88);

      if (isExecutedThroughWebHCat) {

        stringBuffer.append(TEXT_89);
        stringBuffer.append(start_node);
        stringBuffer.append(TEXT_90);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_91);

      } else {

        stringBuffer.append(TEXT_92);
        stringBuffer.append(start_node);
        stringBuffer.append(TEXT_93);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_94);
      }

      stringBuffer.append(TEXT_95);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_96);

      if (isExecutedThroughWebHCat) {

        stringBuffer.append(TEXT_97);
        stringBuffer.append(start_node);
        stringBuffer.append(TEXT_98);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_99);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_100);

      } else {

        stringBuffer.append(TEXT_101);
        stringBuffer.append(start_node);
        stringBuffer.append(TEXT_102);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_103);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_104);
      }

      stringBuffer.append(TEXT_105);

    } else {

      stringBuffer.append(TEXT_106);
      stringBuffer.append(start_node);
      stringBuffer.append(TEXT_107);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_108);
    }

    stringBuffer.append(TEXT_109);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_110);
    stringBuffer.append(TEXT_111);
    return stringBuffer.toString();
  }
コード例 #2
0
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    // this util class use by set log4j debug paramters
    class DefaultLog4jFileUtil {

      INode node = null;
      String cid = null;
      boolean isLog4jEnabled = false;
      String label = null;

      public DefaultLog4jFileUtil() {}

      public DefaultLog4jFileUtil(INode node) {
        this.node = node;
        this.cid = node.getUniqueName();
        this.label = cid;
        this.isLog4jEnabled =
            ("true")
                .equals(
                    org.talend.core.model.process.ElementParameterParser.getValue(
                        node.getProcess(), "__LOG4J_ACTIVATE__"));
      }

      public void setCid(String cid) {
        this.cid = cid;
      }

      // for all tFileinput* components
      public void startRetriveDataInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_2);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_3);
        }
      }

      public void retrievedDataNumberInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_4);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_5);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_6);
        }
      }

      public void retrievedDataNumberInfoFromGlobalMap(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_7);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_8);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_9);
        }
      }

      // for all tFileinput* components
      public void retrievedDataNumberInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_10);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_11);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_12);
        }
      }

      public void writeDataFinishInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_13);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_14);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_15);
        }
      }

      // TODO delete it and remove all log4jSb parameter from components
      public void componentStartInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_16);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_17);
        }
      }

      // TODO rename or delete it
      public void debugRetriveData(INode node, boolean hasIncreased) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_18);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_19);
          stringBuffer.append(cid);
          stringBuffer.append(hasIncreased ? "" : "+1");
          stringBuffer.append(TEXT_20);
        }
      }

      // TODO rename or delete it
      public void debugRetriveData(INode node) {
        debugRetriveData(node, true);
      }

      // TODO rename or delete it
      public void debugWriteData(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_21);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_22);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_23);
        }
      }

      public void logCurrentRowNumberInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_24);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_25);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_26);
        }
      }

      public void logDataCountInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_27);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_28);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_29);
        }
      }
    }

    final DefaultLog4jFileUtil log4jFileUtil =
        new DefaultLog4jFileUtil(
            (INode)
                (((org.talend.designer.codegen.config.CodeGeneratorArgument) argument)
                    .getArgument()));

    stringBuffer.append(TEXT_30);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();

    boolean customEncoding =
        "true".equals(ElementParameterParser.getValue(node, "__CUSTOM_ENCODING__"));
    String encoding = ElementParameterParser.getValue(node, "__ENCODING__");

    List<? extends IConnection> conns = node.getOutgoingSortedConnections();
    String firstConnName = "";
    if (conns != null) {
      if (conns.size() > 0) {
        IConnection conn = conns.get(0);
        if (conn != null && conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
          firstConnName = conn.getName();

          stringBuffer.append(TEXT_31);
          stringBuffer.append(firstConnName);
          stringBuffer.append(TEXT_32);
          stringBuffer.append(conn.getName());
          stringBuffer.append(TEXT_33);
        }
      }
    }

    List<IMetadataTable> metadatas = node.getMetadataList();
    if ((metadatas != null) && (metadatas.size() > 0) && firstConnName.length() > 0) {
      IMetadataTable metadata = metadatas.get(0);

      String typeFile = ElementParameterParser.getValue(node, "__TYPEFILE__");
      if (typeFile.equals("SEQUENCE")) {

        String keyColumn = ElementParameterParser.getValue(node, "__KEYCOLUMN__");
        String valueColumn = ElementParameterParser.getValue(node, "__VALUECOLUMN__");

        List<IMetadataColumn> listColumns = metadata.getListColumns();
        String talendKeyClass = "";
        String talendValueClass = "";
        for (IMetadataColumn column : listColumns) {
          if (column.getLabel().equals(keyColumn)) {
            talendKeyClass = column.getTalendType();
          }
          if (column.getLabel().equals(valueColumn)) {
            talendValueClass = column.getTalendType();
          }
        }

        String hadoopVersion = null;
        String distribution = null;
        boolean useExistingConnection =
            "true".equals(ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__"));
        if (!useExistingConnection) {
          distribution = ElementParameterParser.getValue(node, "__DISTRIBUTION__");
          hadoopVersion = ElementParameterParser.getValue(node, "__DB_VERSION__");
        } else {
          String connectionSid = ElementParameterParser.getValue(node, "__CONNECTION__");
          List<? extends INode> nodes = node.getProcess().getGeneratingNodes();
          for (INode targetNode : nodes) {
            if (targetNode.getUniqueName().equals(connectionSid)) {
              hadoopVersion = ElementParameterParser.getValue(targetNode, "__DB_VERSION__");
              distribution = ElementParameterParser.getValue(targetNode, "__DISTRIBUTION__");
              break;
            }
          }
        }

        org.talend.hadoop.distribution.component.HDFSComponent hdfsDistrib = null;
        try {
          hdfsDistrib =
              (org.talend.hadoop.distribution.component.HDFSComponent)
                  org.talend.hadoop.distribution.DistributionFactory.buildDistribution(
                      distribution, hadoopVersion);
        } catch (java.lang.Exception e) {
          e.printStackTrace();
          return "";
        }
        boolean isCustom =
            hdfsDistrib instanceof org.talend.hadoop.distribution.custom.CustomDistribution;

        stringBuffer.append(TEXT_34);

        String keyClass = "org.apache.hadoop.io.Text";
        if (talendKeyClass.equals("id_Boolean")) keyClass = "org.apache.hadoop.io.BooleanWritable";
        if (talendKeyClass.equals("id_Byte")) keyClass = "org.apache.hadoop.io.ByteWritable";
        if (talendKeyClass.equals("id_byte[]")) keyClass = "org.apache.hadoop.io.BytesWritable";
        if (talendKeyClass.equals("id_Double")) keyClass = "org.apache.hadoop.io.DoubleWritable";
        if (talendKeyClass.equals("id_Float")) keyClass = "org.apache.hadoop.io.FloatWritable";
        if (talendKeyClass.equals("id_Integer")) keyClass = "org.apache.hadoop.io.IntWritable";
        if (talendKeyClass.equals("id_Long")) keyClass = "org.apache.hadoop.io.LongWritable";
        if (talendKeyClass.equals("id_String")) keyClass = "org.apache.hadoop.io.Text";
        if (talendKeyClass.equals("id_Short")) {
          if (isCustom || hdfsDistrib.doSupportSequenceFileShortType()) {
            keyClass = "org.apache.hadoop.io.ShortWritable";
          } else {
            keyClass = "org.apache.hadoop.io.IntWritable";
          }
        }

        String valueClass = "org.apache.hadoop.io.Text";
        if (talendValueClass.equals("id_Boolean"))
          valueClass = "org.apache.hadoop.io.BooleanWritable";
        if (talendValueClass.equals("id_Byte")) valueClass = "org.apache.hadoop.io.ByteWritable";
        if (talendValueClass.equals("id_byte[]")) valueClass = "org.apache.hadoop.io.BytesWritable";
        if (talendValueClass.equals("id_Double"))
          valueClass = "org.apache.hadoop.io.DoubleWritable";
        if (talendValueClass.equals("id_Float")) valueClass = "org.apache.hadoop.io.FloatWritable";
        if (talendValueClass.equals("id_Integer")) valueClass = "org.apache.hadoop.io.IntWritable";
        if (talendValueClass.equals("id_Long")) valueClass = "org.apache.hadoop.io.LongWritable";
        if (talendValueClass.equals("id_String")) valueClass = "org.apache.hadoop.io.Text";
        if (talendValueClass.equals("id_Short")) {
          if (isCustom || hdfsDistrib.doSupportSequenceFileShortType()) {
            valueClass = "org.apache.hadoop.io.ShortWritable";
          } else {
            valueClass = "org.apache.hadoop.io.IntWritable";
          }
        }

        stringBuffer.append(TEXT_35);
        stringBuffer.append(firstConnName);
        stringBuffer.append(TEXT_36);
        stringBuffer.append(keyColumn);
        stringBuffer.append(TEXT_37);
        stringBuffer.append(talendKeyClass.equals("id_Short") ? "(short)" : "");
        stringBuffer.append(TEXT_38);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_39);
        stringBuffer.append(
            ((keyClass.equals("org.apache.hadoop.io.Text")) ? "toString()" : "get()"));
        stringBuffer.append(TEXT_40);
        stringBuffer.append(firstConnName);
        stringBuffer.append(TEXT_41);
        stringBuffer.append(valueColumn);
        stringBuffer.append(TEXT_42);
        stringBuffer.append(talendValueClass.equals("id_Short") ? "(short)" : "");
        stringBuffer.append(TEXT_43);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_44);
        stringBuffer.append(
            ((valueClass.equals("org.apache.hadoop.io.Text")) ? "toString()" : "get()"));
        stringBuffer.append(TEXT_45);

      } else {
        if (metadata != null) {
          List<IMetadataColumn> listColumns = metadata.getListColumns();
          for (int valueN = 0; valueN < listColumns.size(); valueN++) {
            IMetadataColumn column = listColumns.get(valueN);

            String typeToGenerate =
                JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable());
            JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getTalendType());
            String patternValue =
                column.getPattern() == null || column.getPattern().trim().length() == 0
                    ? null
                    : column.getPattern();
            if (javaType == JavaTypesManager.STRING || javaType == JavaTypesManager.OBJECT) {

              stringBuffer.append(TEXT_46);
              stringBuffer.append(firstConnName);
              stringBuffer.append(TEXT_47);
              stringBuffer.append(column.getLabel());
              stringBuffer.append(TEXT_48);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_49);
              stringBuffer.append(valueN);
              stringBuffer.append(TEXT_50);

            } else {

              stringBuffer.append(TEXT_51);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_52);
              stringBuffer.append(valueN);
              stringBuffer.append(TEXT_53);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_54);
              stringBuffer.append(valueN);
              stringBuffer.append(TEXT_55);

              if (javaType == JavaTypesManager.DATE) {

                stringBuffer.append(TEXT_56);
                stringBuffer.append(firstConnName);
                stringBuffer.append(TEXT_57);
                stringBuffer.append(column.getLabel());
                stringBuffer.append(TEXT_58);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_59);
                stringBuffer.append(valueN);
                stringBuffer.append(TEXT_60);
                stringBuffer.append(patternValue);
                stringBuffer.append(TEXT_61);

              } else if (javaType == JavaTypesManager.BYTE_ARRAY) {

                stringBuffer.append(TEXT_62);
                stringBuffer.append(firstConnName);
                stringBuffer.append(TEXT_63);
                stringBuffer.append(column.getLabel());
                stringBuffer.append(TEXT_64);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_65);
                stringBuffer.append(valueN);
                stringBuffer.append(TEXT_66);
                stringBuffer.append((customEncoding ? encoding : "utf8Charset"));
                stringBuffer.append(TEXT_67);

              } else {

                stringBuffer.append(TEXT_68);
                stringBuffer.append(firstConnName);
                stringBuffer.append(TEXT_69);
                stringBuffer.append(column.getLabel());
                stringBuffer.append(TEXT_70);
                stringBuffer.append(typeToGenerate);
                stringBuffer.append(TEXT_71);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_72);
                stringBuffer.append(valueN);
                stringBuffer.append(TEXT_73);
              }

              stringBuffer.append(TEXT_74);
              stringBuffer.append(firstConnName);
              stringBuffer.append(TEXT_75);
              stringBuffer.append(column.getLabel());
              stringBuffer.append(TEXT_76);
              stringBuffer.append(JavaTypesManager.getDefaultValueFromJavaType(typeToGenerate));
              stringBuffer.append(TEXT_77);
            }
          } // for
        }
      }

      stringBuffer.append(TEXT_78);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_79);

      log4jFileUtil.debugRetriveData(node);
    }

    stringBuffer.append(TEXT_80);
    return stringBuffer.toString();
  }
コード例 #3
0
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    // this util class use by set log4j debug paramters
    class DefaultLog4jFileUtil {

      INode node = null;
      String cid = null;
      boolean isLog4jEnabled = false;
      String label = null;

      public DefaultLog4jFileUtil() {}

      public DefaultLog4jFileUtil(INode node) {
        this.node = node;
        this.cid = node.getUniqueName();
        this.label = cid;
        this.isLog4jEnabled =
            ("true")
                .equals(
                    org.talend.core.model.process.ElementParameterParser.getValue(
                        node.getProcess(), "__LOG4J_ACTIVATE__"));
      }

      public void setCid(String cid) {
        this.cid = cid;
      }

      // for all tFileinput* components
      public void startRetriveDataInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_2);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_3);
        }
      }

      public void retrievedDataNumberInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_4);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_5);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_6);
        }
      }

      public void retrievedDataNumberInfoFromGlobalMap(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_7);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_8);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_9);
        }
      }

      // for all tFileinput* components
      public void retrievedDataNumberInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_10);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_11);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_12);
        }
      }

      public void writeDataFinishInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_13);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_14);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_15);
        }
      }

      // TODO delete it and remove all log4jSb parameter from components
      public void componentStartInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_16);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_17);
        }
      }

      // TODO rename or delete it
      public void debugRetriveData(INode node, boolean hasIncreased) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_18);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_19);
          stringBuffer.append(cid);
          stringBuffer.append(hasIncreased ? "" : "+1");
          stringBuffer.append(TEXT_20);
        }
      }

      // TODO rename or delete it
      public void debugRetriveData(INode node) {
        debugRetriveData(node, true);
      }

      // TODO rename or delete it
      public void debugWriteData(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_21);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_22);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_23);
        }
      }

      public void logCurrentRowNumberInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_24);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_25);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_26);
        }
      }

      public void logDataCountInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_27);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_28);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_29);
        }
      }
    }

    final DefaultLog4jFileUtil log4jFileUtil =
        new DefaultLog4jFileUtil(
            (INode)
                (((org.talend.designer.codegen.config.CodeGeneratorArgument) argument)
                    .getArgument()));

    stringBuffer.append(TEXT_30);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;

    INode node = (INode) codeGenArgument.getArgument();

    String cid = node.getUniqueName();

    String clientId = ElementParameterParser.getValue(node, "__CLIENT_ID__");
    String clientSecret = ElementParameterParser.getValue(node, "__CLIENT_SECRET__");
    String projectId = ElementParameterParser.getValue(node, "__PROJECT_ID__");
    String authorizationCode = ElementParameterParser.getValue(node, "__AUTHORIZATION_CODE__");
    String query = ElementParameterParser.getValue(node, "__QUERY__");
    query = query.replaceAll("\n", " ");
    query = query.replaceAll("\r", " ");

    String tokenFile = ElementParameterParser.getValue(node, "__TOKEN_NAME__");
    boolean isLog4jEnabled =
        ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));

    stringBuffer.append(TEXT_31);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_32);
    stringBuffer.append(clientId);
    stringBuffer.append(TEXT_33);

    String passwordFieldName = "__CLIENT_SECRET__";

    stringBuffer.append(TEXT_34);
    if (ElementParameterParser.canEncrypt(node, passwordFieldName)) {
      stringBuffer.append(TEXT_35);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_36);
      stringBuffer.append(ElementParameterParser.getEncryptedValue(node, passwordFieldName));
      stringBuffer.append(TEXT_37);
    } else {
      stringBuffer.append(TEXT_38);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_39);
      stringBuffer.append(ElementParameterParser.getValue(node, passwordFieldName));
      stringBuffer.append(TEXT_40);
    }
    stringBuffer.append(TEXT_41);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_42);
    stringBuffer.append(clientId);
    stringBuffer.append(TEXT_43);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_44);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_45);
    stringBuffer.append(projectId);
    stringBuffer.append(TEXT_46);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_47);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_48);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_49);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_50);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_51);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_52);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_53);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_54);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_55);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_56);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_57);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_58);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_59);
    }

    stringBuffer.append(TEXT_60);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_61);
    stringBuffer.append(tokenFile);
    stringBuffer.append(TEXT_62);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_63);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_64);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_65);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_66);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_67);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_68);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_69);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_70);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_71);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_72);
    }

    stringBuffer.append(TEXT_73);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_74);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_75);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_76);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_77);
    }

    stringBuffer.append(TEXT_78);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_79);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_80);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_81);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_82);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_83);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_84);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_85);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_86);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_87);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_88);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_89);
    }

    stringBuffer.append(TEXT_90);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_91);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_92);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_93);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_94);
    }
    if (authorizationCode == null
        || "".equals(authorizationCode)
        || "\"\"".equals(authorizationCode)) {

      stringBuffer.append(TEXT_95);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_96);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_97);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_98);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_99);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_100);

      if (isLog4jEnabled) {

        stringBuffer.append(TEXT_101);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_102);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_103);
      }

      stringBuffer.append(TEXT_104);

    } else {

      stringBuffer.append(TEXT_105);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_106);
      stringBuffer.append(authorizationCode);
      stringBuffer.append(TEXT_107);

      if (isLog4jEnabled) {

        stringBuffer.append(TEXT_108);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_109);
      }

      stringBuffer.append(TEXT_110);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_111);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_112);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_113);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_114);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_115);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_116);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_117);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_118);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_119);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_120);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_121);

      if (isLog4jEnabled) {

        stringBuffer.append(TEXT_122);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_123);
      }

      stringBuffer.append(TEXT_124);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_125);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_126);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_127);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_128);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_129);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_130);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_131);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_132);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_133);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_134);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_135);
    }

    stringBuffer.append(TEXT_136);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_137);
    stringBuffer.append(query);
    stringBuffer.append(TEXT_138);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_139);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_140);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_141);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_142);
    }

    stringBuffer.append(TEXT_143);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_144);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_145);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_146);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_147);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_148);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_149);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_150);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_151);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_152);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_153);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_154);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_155);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_156);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_157);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_158);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_159);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_160);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_161);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_162);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_163);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_164);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_165);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_166);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_167);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_168);
    }

    stringBuffer.append(TEXT_169);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_170);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_171);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_172);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_173);
    }

    stringBuffer.append(TEXT_174);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_175);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_176);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_177);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_178);
    }

    stringBuffer.append(TEXT_179);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_180);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_181);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_182);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_183);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_184);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_185);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_186);
    }

    stringBuffer.append(TEXT_187);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_188);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_189);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_190);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_191);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_192);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_193);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_194);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_195);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_196);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_197);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_198);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_199);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_200);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_201);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_202);

    List<? extends IConnection> conns = node.getOutgoingSortedConnections();
    if (conns != null) {
      if (conns.size() > 0) {
        IConnection conn = conns.get(0);
        String connName = conn.getName();
        if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
          List<IMetadataTable> metadatas = node.getMetadataList();
          if ((metadatas != null) && (metadatas.size() > 0)) {
            IMetadataTable metadata = metadatas.get(0);
            if (metadata != null) {
              String encoding = ElementParameterParser.getValue(node, "__ENCODING__");
              String advancedSeparatorStr =
                  ElementParameterParser.getValue(node, "__ADVANCED_SEPARATOR__");
              boolean advancedSeparator =
                  (advancedSeparatorStr != null && !("").equals(advancedSeparatorStr))
                      ? ("true").equals(advancedSeparatorStr)
                      : false;
              String thousandsSeparator =
                  ElementParameterParser.getValueWithJavaType(
                      node, "__THOUSANDS_SEPARATOR__", JavaTypesManager.CHARACTER);
              String decimalSeparator =
                  ElementParameterParser.getValueWithJavaType(
                      node, "__DECIMAL_SEPARATOR__", JavaTypesManager.CHARACTER);

              List<IMetadataColumn> columns = metadata.getListColumns();
              int nbColumns = columns.size();
              for (int i = 0; i < nbColumns; i++) {
                IMetadataColumn column = columns.get(i);
                String columnName = column.getLabel();

                String typeToGenerate =
                    JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable());
                JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getTalendType());
                String patternValue =
                    column.getPattern() == null || column.getPattern().trim().length() == 0
                        ? null
                        : column.getPattern();

                stringBuffer.append(TEXT_203);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_204);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_205);
                stringBuffer.append(i);
                stringBuffer.append(TEXT_206);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_207);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_208);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_209);

                if (javaType == JavaTypesManager.STRING) {

                  stringBuffer.append(TEXT_210);
                  stringBuffer.append(connName);
                  stringBuffer.append(TEXT_211);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_212);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_213);

                } else if (javaType == JavaTypesManager.OBJECT) {

                  stringBuffer.append(TEXT_214);
                  stringBuffer.append(connName);
                  stringBuffer.append(TEXT_215);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_216);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_217);

                } else if (javaType == JavaTypesManager.DATE) {

                  stringBuffer.append(TEXT_218);
                  stringBuffer.append(connName);
                  stringBuffer.append(TEXT_219);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_220);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_221);
                  stringBuffer.append(patternValue);
                  stringBuffer.append(TEXT_222);

                } else if (advancedSeparator && JavaTypesManager.isNumberType(javaType)) {

                  stringBuffer.append(TEXT_223);
                  stringBuffer.append(connName);
                  stringBuffer.append(TEXT_224);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_225);
                  stringBuffer.append(typeToGenerate);
                  stringBuffer.append(TEXT_226);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_227);
                  stringBuffer.append(thousandsSeparator);
                  stringBuffer.append(TEXT_228);
                  stringBuffer.append(decimalSeparator);
                  stringBuffer.append(TEXT_229);

                } else if (javaType == JavaTypesManager.BYTE_ARRAY) {

                  stringBuffer.append(TEXT_230);
                  stringBuffer.append(connName);
                  stringBuffer.append(TEXT_231);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_232);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_233);
                  stringBuffer.append(encoding);
                  stringBuffer.append(TEXT_234);

                } else {

                  stringBuffer.append(TEXT_235);
                  stringBuffer.append(connName);
                  stringBuffer.append(TEXT_236);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_237);
                  stringBuffer.append(typeToGenerate);
                  stringBuffer.append(TEXT_238);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_239);
                }

                stringBuffer.append(TEXT_240);
                stringBuffer.append(connName);
                stringBuffer.append(TEXT_241);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_242);
                stringBuffer.append(
                    JavaTypesManager.getDefaultValueFromJavaType(
                        typeToGenerate, column.getDefault()));
                stringBuffer.append(TEXT_243);
              }
              log4jFileUtil.debugRetriveData(node);
            }
          }
        }
      }
    }

    stringBuffer.append(TEXT_244);
    return stringBuffer.toString();
  }
コード例 #4
0
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    // this util class use by set log4j debug paramters
    class DefaultLog4jFileUtil {

      INode node = null;
      String cid = null;
      boolean isLog4jEnabled = false;
      String label = null;

      public DefaultLog4jFileUtil() {}

      public DefaultLog4jFileUtil(INode node) {
        this.node = node;
        this.cid = node.getUniqueName();
        this.label = cid;
        this.isLog4jEnabled =
            ("true")
                .equals(
                    org.talend.core.model.process.ElementParameterParser.getValue(
                        node.getProcess(), "__LOG4J_ACTIVATE__"));
      }

      public void setCid(String cid) {
        this.cid = cid;
      }

      // for all tFileinput* components
      public void startRetriveDataInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_2);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_3);
        }
      }

      public void retrievedDataNumberInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_4);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_5);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_6);
        }
      }

      public void retrievedDataNumberInfoFromGlobalMap(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_7);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_8);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_9);
        }
      }

      // for all tFileinput* components
      public void retrievedDataNumberInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_10);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_11);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_12);
        }
      }

      public void writeDataFinishInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_13);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_14);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_15);
        }
      }

      // TODO delete it and remove all log4jSb parameter from components
      public void componentStartInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_16);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_17);
        }
      }

      // TODO rename or delete it
      public void debugRetriveData(INode node, boolean hasIncreased) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_18);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_19);
          stringBuffer.append(cid);
          stringBuffer.append(hasIncreased ? "" : "+1");
          stringBuffer.append(TEXT_20);
        }
      }

      // TODO rename or delete it
      public void debugRetriveData(INode node) {
        debugRetriveData(node, true);
      }

      // TODO rename or delete it
      public void debugWriteData(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_21);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_22);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_23);
        }
      }

      public void logCurrentRowNumberInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_24);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_25);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_26);
        }
      }

      public void logDataCountInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_27);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_28);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_29);
        }
      }
    }

    final DefaultLog4jFileUtil log4jFileUtil =
        new DefaultLog4jFileUtil(
            (INode)
                (((org.talend.designer.codegen.config.CodeGeneratorArgument) argument)
                    .getArgument()));

    stringBuffer.append(TEXT_30);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();
    String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
    List<IMetadataTable> metadatas = node.getMetadataList();
    if ((metadatas != null) && (metadatas.size() > 0)) {
      IMetadataTable metadata = metadatas.get(0);
      if (metadata != null) {
        List<? extends IConnection> conns = node.getOutgoingSortedConnections();
        if (conns != null) {
          if (conns.size() > 0) {

            stringBuffer.append(TEXT_31);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_32);
          }
        }
      }
    }

    stringBuffer.append(TEXT_33);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_34);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_35);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_36);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_37);

    // use local connection
    if (!"true".equals(useExistingConn)) {
      String distribution = ElementParameterParser.getValue(node, "__DISTRIBUTION__");
      String hbaseVersion = ElementParameterParser.getValue(node, "__HBASE_VERSION__");
      boolean isHadoop2 =
          "HADOOP_2".equals(ElementParameterParser.getValue(node, "__HADOOP_CUSTOM_VERSION__"));
      org.talend.hadoop.distribution.component.HBaseComponent hbaseDistrib = null;
      try {
        hbaseDistrib =
            (org.talend.hadoop.distribution.component.HBaseComponent)
                org.talend.hadoop.distribution.DistributionFactory.buildDistribution(
                    distribution, hbaseVersion);
      } catch (java.lang.Exception e) {
        e.printStackTrace();
        return "";
      }
      boolean isCustom =
          hbaseDistrib instanceof org.talend.hadoop.distribution.custom.CustomDistribution;

      stringBuffer.append(TEXT_38);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_39);
      stringBuffer.append(TEXT_40);

      if ((isCustom && isHadoop2) || (!isCustom && hbaseDistrib.doSupportNewHBaseAPI())) {
        stringBuffer.append(TEXT_41);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_42);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_43);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_44);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_45);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_46);
      } else {
        stringBuffer.append(TEXT_47);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_48);
      }
      stringBuffer.append(TEXT_49);
    }

    stringBuffer.append(TEXT_50);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_51);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_52);

    log4jFileUtil.retrievedDataNumberInfo(node);

    return stringBuffer.toString();
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    // this util class use by set log4j debug paramters
    class DefaultLog4jFileUtil {

      INode node = null;
      String cid = null;
      boolean isLog4jEnabled = false;
      String label = null;

      public DefaultLog4jFileUtil() {}

      public DefaultLog4jFileUtil(INode node) {
        this.node = node;
        this.cid = node.getUniqueName();
        this.label = cid;
        this.isLog4jEnabled =
            ("true")
                .equals(
                    org.talend.core.model.process.ElementParameterParser.getValue(
                        node.getProcess(), "__LOG4J_ACTIVATE__"));
      }

      public void setCid(String cid) {
        this.cid = cid;
      }

      // for all tFileinput* components
      public void startRetriveDataInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_2);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_3);
        }
      }

      public void retrievedDataNumberInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_4);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_5);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_6);
        }
      }

      public void retrievedDataNumberInfoFromGlobalMap(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_7);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_8);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_9);
        }
      }

      // for all tFileinput* components
      public void retrievedDataNumberInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_10);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_11);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_12);
        }
      }

      public void writeDataFinishInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_13);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_14);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_15);
        }
      }

      // TODO delete it and remove all log4jSb parameter from components
      public void componentStartInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_16);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_17);
        }
      }

      // TODO rename or delete it
      public void debugRetriveData(INode node, boolean hasIncreased) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_18);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_19);
          stringBuffer.append(cid);
          stringBuffer.append(hasIncreased ? "" : "+1");
          stringBuffer.append(TEXT_20);
        }
      }

      // TODO rename or delete it
      public void debugRetriveData(INode node) {
        debugRetriveData(node, true);
      }

      // TODO rename or delete it
      public void debugWriteData(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_21);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_22);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_23);
        }
      }

      public void logCurrentRowNumberInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_24);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_25);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_26);
        }
      }

      public void logDataCountInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_27);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_28);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_29);
        }
      }
    }

    final DefaultLog4jFileUtil log4jFileUtil =
        new DefaultLog4jFileUtil(
            (INode)
                (((org.talend.designer.codegen.config.CodeGeneratorArgument) argument)
                    .getArgument()));

    stringBuffer.append(TEXT_30);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();

    stringBuffer.append(TEXT_31);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_32);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_33);
    log4jFileUtil.logDataCountInfo();
    return stringBuffer.toString();
  }