//package test;
//
//import bean.Column;
//import com.alibaba.druid.DbType;
//import com.alibaba.druid.sql.SQLUtils;
//import java.lang.reflect.Method;
//import java.sql.SQLException;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import util.JdbcUtil;
//import util.SqlUtil;
//import util.StringJoin;
//
//public class OracleTest {
//   public static void main(String[] args) throws SQLException {
//      String content = "{\n      \"ip_port\": \"192.168.2.250:1522\",\n      \"url\": \"jdbc:oracle:thin:@192.168.2.250:1522/lhrsdb\",\n      \"username\": \"system\",\n      \"password\": \"system\",\n      \"dbType\": \"oracle\",\n      \"isIgnorecase\":\"1\",\n      \"excludeSchema\": [\"SYS\",\"ANONYMOUS\",\"APPQOSSYS\",\"AUDSYS\",\"CSM\",\"DBSFWUSER\",\"DIP\",\"DVF\",\"DVSYS\",\"DW_XNDRC_ERPDATAXN\",\"DW_XNSYGC\",\"FOOXR\",\"GGSYS\",\"GSMADMIN_INTERNAL\",\"GSMCATUSER\",\"GSMUSER\",\"INFA_DOMAIN\",\"INFA_REP\",\"INFA_REP_DEV\",\"INFA_WORKFLOW\",\"INFA_XN\",\"LBACSYS\",\"LONGDA\",\"MDL_REP\",\"MM_USER\",\"MODEL_USER\",\"OJVMSYS\",\"ORACAPTL1\",\"PWX_ORACLE_CDC_CONTINUOUS209\",\"REMOTE_SCHEDULER_AGENT\",\"SPATIAL_CSW_ADMIN_USR\",\"SYS$UMF\",\"SYSBACKUP\",\"SYSDG\",\"SYSKM\",\"SYSRAC\",\"TEST\",\"TEST1\",\"TEST2\",\"XN_DM\",\"XS$NULL\",\"XN_XNBS_CRTJSBS\",\"TEST1\",\"XN_XNBS_SYGCETL\",\"XN_XNDRC_EPBWXN\",\"XN_XNDRC_ERPDATAXN\",\"XN_XNDRC_SSSJ\",\"TEST1\",\"TEST1\",\"TEST1\"\n    ]}";
//      JdbcUtil.initData(content);
//      OracleTest myTest = new OracleTest();
//      myTest.testOracle();
//   }
//
//   public void testOracle() {
//      String[] sqls = new String[0];
//
//      for(int i = 0; i < 1; ++i) {
//         Map<String, String> params = new HashMap();
//         String sql = "SELECT * FROM V_QTSC_JCXX_JLDXX";
//         sql = "\nSELECT  max(rownum) rn,json_arrayagg\n(\n\tjson_object(\n\t\tKEY 'table_name' value table_name format json\n\t)  returning clob\n) AS json_doc\nFROM dba_tables;\n";
//         sql = "SELECT JLDXXBS, JLDBH, JLDMC, SSZKDM, SSZKMC, ZKSSDWDM, ZKSSDWMC, ZKSSEJDWDM, ZKSSEJDWMC, ZKSSGLQDM, ZKSSGLQMC, JLLXDM, JLLXMC, KHMC, CJR, CJSJ FROM V_QTSC_JCXX_JLDXX";
//         sql = "SELECT JHDM AS JHDM,\n                    WJ AS WJ,\n                    LISTAGG(GJA, ',') WITHIN GROUP(ORDER BY GJA) AS GJMC\n               FROM (SELECT DISTINCT JHDM, WJ,  C.BMDXDMYY GJA\n                       FROM CLBM_GJDM C\n                       LEFT JOIN ZJJTG_TG Z\n                         ON Z.GJA = C.BMDXDM\n                      WHERE TGZJMCDM = '10')\n              GROUP BY JHDM, WJ";
//         sql = "select * from TEST1.tests";
//         sql = "select * from \"user_name\".\"NEWTABLE\"";
//         sql = "SELECT x.*,x.ROWID FROM TEST.AATEST17 x\n";
//         sql = "insert all into sys_user_role(user_id, role_id) values (99,99) SELECT 1 FROM DUAL";
//         sql = "MERGE INTO products as p   \nUSING newproducts np   \nON (p.product_id = np.product_id)   \nWHEN MATCHED THEN  \n  UPDATE SET p.product_name = np.product_name, p.category = np.category WHERE p.product_name != 'play gym'  \nWHEN NOT MATCHED THEN  \n  INSERT VALUES (np.product_id, np.product_name, np.category) WHERE np.category = 'books'; ";
//         sql = "SELECT *\n          from (SELECT *\n                  FROM ELE_PERIDE f\n                  where\n                    f.start_date <= to_date(?, 'yyyy-mm-dd') and f.end_date >= to_date(?, 'yyyy-mm-dd')\n                   \n                   \n                      and ELE_CODE in\n                       (  \n                          ?\n                       , \n                          ?\n                       , \n                          ?\n                       , \n                          ?\n                       , \n                          ?\n                       ) \n                      union\n                      SELECT *\n                      FROM ELE_PERIDE f\n                      WHERE PARENT_ID in\n                       (  \n                          ?\n                       , \n                          ?\n                       , \n                          ?\n                       , \n                          ?\n                       , \n                          ?\n                       ) \n                      and f.start_date <= to_date(?, 'yyyy-mm-dd') and f.end_date >= to_date(?, 'yyyy-mm-dd')\n                   \n                )\n         START WITH parent_id IS NULL\n        CONNECT BY PRIOR ele_code = parent_id -- appUsername=";
//         params.put("sql", sql);
//         params.put("dbType", "oracle");
//         params.put("schema", "WYM");
//         params.put("url", "jdbc:oracle:thin:@192.168.2.250:1522/lhrsdb");
//         params.put("replaceSchema", "wym");
//         params.put("replaceNewTable", "people_bk");
//         params.put("replaceTable", ".*test.*");
//         params.put("replaceColumn", "table_name");
//         params.put("expression", "concat(substr(${value},1,1),'**')");
//         params.put("configPath", "D:/masking-mysql.properties");
//         Map<String, String> map = new HashMap();
//         map.put("ghca31.AT_TEST.name", "替1");
//         map.put("ghca31.AT_TEST2.name", "替2");
//         map.put("ghca31.AT_TEST3.name", "替3");
//         map.put("ghca31.AT_TEST.name", "替4");
//         map.put("ghca31.AT_TEST2.name", "替5");
//         map.put("ghca31.AT_TEST3.name", "替6");
//         map.put("ghca_classify_encrytest.T_CONSOLE_DICTIONARY.value", "替7");
//         params.put("limit", "10");
//         SqlUtil sqlUtil = new SqlUtil();
//         System.out.println("\n\n[0]********************************************************************************");
//         System.out.println("--------------------- source sql    ------------------------------------------------");
//         System.out.println(sql);
//         System.out.println("---------------------/source sql    ------------------------------------------------");
//         System.out.println("..............row visit.....................................");
//         Map<String, List<String>> modifyTable = new HashMap();
//         List<String> vals = new ArrayList();
//         vals.add("張三");
//         modifyTable.put("tB1", vals);
//         Map<String, String> tableKeyWord = new HashMap();
//         Map<String, Object> param = new HashMap(params);
//         param.put("modifyTable", modifyTable);
//         param.put("tableKeyWord", tableKeyWord);
//         tableKeyWord.put("tB1", "\"fD\"");
//         param.put("operateType", "select");
//         param.put("limit", "10");
//         HashMap h = new HashMap(params);
//         h.putAll(params);
//         h.putAll(param);
//         System.out.println("---------------------parse structure------------------------------------------------");
//         params.put("sql", sql);
//         Map<String, Object> s2 = sqlUtil.parseSqlStructure(params);
//         System.out.println("\n\n====schemaMap====");
//         Map<String, Object> schemaMap = (Map)s2.get("schemaMap");
//
//         for(Map.Entry<String, Object> item : schemaMap.entrySet()) {
//            System.out.println((String)item.getKey() + "\t" + item.getValue());
//         }
//
//         System.out.println("\n\n====tableMap====");
//         Map<String, Object> tableMap = (Map)s2.get("tableMap");
//
//         for(Map.Entry<String, Object> item : tableMap.entrySet()) {
//            System.out.println((String)item.getKey() + "\t" + item.getValue());
//         }
//
//         System.out.println("\n\n====whereMap====");
//         Map<String, Object> whereMap = (Map)s2.get("whereMap");
//
//         for(Map.Entry<String, Object> item : whereMap.entrySet()) {
//            System.out.println((String)item.getKey() + "\t" + item.getValue());
//         }
//
//         System.out.println("\n\n====whereList====");
//
//         for(Map<String, Object> where : (ArrayList)s2.get("whereList")) {
//            for(Map.Entry<String, Object> item : where.entrySet()) {
//               System.out.println((String)item.getKey() + "\t" + item.getValue());
//            }
//         }
//
//         System.out.println("\n\n====columnList====");
//         ArrayList<Column> columnList = (ArrayList)s2.get("columnList");
//         String[] fields = new String[]{"columnName", "columnAlisa", "fullName", "nowName", "dataType", "schema", "table", "value", "expr"};
//         int[] size = this.max(fields, columnList);
//
//         for(int j = 0; j < fields.length; ++j) {
//            fields[j] = String.format("%" + size[j] + "s", fields[j]);
//         }
//
//         System.out.println(StringJoin.join(fields, "  "));
//
//         for(Column item : columnList) {
//            StringBuilder output = new StringBuilder();
//            this.printColumn(item, output, size);
//            System.out.println(output);
//         }
//
//         System.out.println("\n\n====SQL====");
//         System.out.println(s2.get("sql"));
//         System.out.println("\n\n====/SQL====");
//         System.out.println("---------------------/parse structure------------------------------------------------");
//      }
//
//   }
//
//   private double invoke(String sql) {
//      try {
//         long c = System.nanoTime();
//         SQLUtils.parseStatements(sql, DbType.mysql);
//         long c1 = System.nanoTime();
//         double c2 = (double)(c1 - c) / (double)1000000.0F;
//         return c2;
//      } catch (Exception e) {
//         e.printStackTrace();
//         return (double)0.0F;
//      }
//   }
//
//   private void printColumn(Column col, StringBuilder s, int[] size) {
//      s.append(this.format(col.getColumnName(), size[0])).append("  ").append(this.format(col.getColumnAlisa(), size[1])).append("  ").append(this.format(col.getFullName(), size[2])).append("  ").append(this.format(col.getNowName(), size[3])).append("  ").append(this.format(col.getDataType(), size[4])).append("  ").append(this.format(col.getSchema(), size[5])).append("  ").append(this.format(col.getTable(), size[6])).append("  ").append(this.format(col.getValue(), size[7])).append("  ").append(this.format(col.getExpr(), size[8]));
//   }
//
//   private String format(Object value, int size) {
//      return String.format("%" + size + "s", value);
//   }
//
//   private int[] max(String[] fields, List<Column> columns) {
//      int[] size = new int[fields.length];
//
//      try {
//         for(int i = 0; i < fields.length; ++i) {
//            String name = fields[i];
//            name = (name.charAt(0) + "").toUpperCase() + name.substring(1);
//            String method = "get" + name;
//            Method m = Column.class.getDeclaredMethod(method);
//            int max = name.length();
//            if (columns != null) {
//               for(Column column : columns) {
//                  Object value = m.invoke(column);
//                  if (value != null) {
//                     int s = value.toString().length();
//                     max = max < s ? s : max;
//                  }
//               }
//            }
//
//            size[i] = max;
//         }
//      } catch (Exception e) {
//         e.printStackTrace();
//      }
//
//      return size;
//   }
//
//   class A implements Runnable {
//      String sql;
//
//      public A(String sql) {
//         this.sql = sql;
//      }
//
//      public void run() {
//         OracleTest.this.invoke(this.sql);
//      }
//   }
//}
