//package test;
//
//import bean.Column;
//import bean.DataBase;
//import bean.Schema;
//import java.io.IOException;
//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.getdata.DatabaseCache;
//
//public class MSSQLSERVERTestCache {
//   public static void main(String[] args) throws SQLException, InterruptedException, IOException, ClassNotFoundException {
//      Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//      String content = "{\n      \"ip_port\": \"192.168.2.118:1433\",\n      \"url\": \"jdbc:sqlserver://192.168.2.118:1433;DatabaseName=ezoffice\",\n      \"username\": \"sa\",\n      \"isIgnorecase\":\"0\",\n      \"password\": \"123456\",\n      \"dbType\": \"sql server\",\n      \"excludeSchema\": [\"encryption_test2\",\"ghca_static_develop\",\"ghca_static_develop_test\",\"pg_catalog\",\"information_schema\",\"sysaudit\",\"sysmac\",\"sys\",\"sysmac\",\"sysmac\",\"sysmac\",\"ry\"]\n    }";
//      JdbcUtil.initData(content);
//      Thread.sleep(3000L);
//      MSSQLSERVERTestCache myTest = new MSSQLSERVERTestCache();
//      myTest.testCache();
//   }
//
//   public void testCache() throws InterruptedException {
//      DataBase dataBase = (DataBase)JdbcUtil.dataBaseList.get(0);
//      DatabaseCache simpleCache = dataBase.simpleCache;
//      Schema ry = simpleCache.getSchema("Test");
//      System.out.println(ry == null ? "" : ry.getName());
//      SqlUtil util = new SqlUtil();
//      Map<String, String> p = new HashMap();
//      p.put("ip_port", "192.168.2.118:1433");
//      p.put("url", "jdbc:sqlserver://192.168.2.118:1433/ezoffice");
//      p.put("dbType", "sqlserver");
//      p.put("schema", "ezoffice");
//      String sql = "select userpo0_.USERISACTIVE as x0_0_, userpo0_.USERISSUPER as x1_0_, userpo0_.USERPASSWORD as x2_0_, userpo0_.EMP_ID as x3_0_, userpo0_.EMPNAME as x4_0_, userpo0_.BROWSERANGE as x5_0_, organizati2_.ORG_ID as x6_0_, organizati2_.ORGIDSTRING as x7_0_, userpo0_.KEYVALIDATE as x8_0_, userpo0_.KEYSERIAL as x9_0_, userpo0_.USERSUPERBEGIN as x10_0_, userpo0_.USERSUPEREND as x11_0_, userpo0_.USERSIMPLENAME as x12_0_, organizati2_.ORGSERIAL as x13_0_, organizati2_.ORGSIMPLENAME as x14_0_, userpo0_.SKIN as x15_0_, userpo0_.EMPDUTY as x16_0_, userpo0_.EMPENGLISHNAME as x17_0_, userpo0_.user_is_sleep as x18_0_, organizati2_.ORG_ENGLISH_NAME as x19_0_, userpo0_.EMPNUMBER as x20_0_, userpo0_.EMPBUSINESSPHONE as x21_0_, organizati2_.ORGNAME as x22_0_, userpo0_.EMPPOSITION as x23_0_, userpo0_.mobile_user_flag as x24_0_, userpo0_.EMPIDCARD as x25_0_, userpo0_.USERACCOUNTS as x26_0_, userpo0_.USER_PAGESIZE as x27_0_, userpo0_.ISCHANGEPWD as x28_0_, userpo0_.is_password_rule as x29_0_, organizati2_.ORGNAMESTRING as x30_0_, userpo0_.IMID as x31_0_, userpo0_.EMPDUTYLEVEL as x32_0_, userpo0_.SIDELINEORG as x33_0_, userpo0_.SIDELINEORGNAME as x34_0_, userpo0_.EMPLIVINGPHOTO as x35_0_, userpo0_.page_fontsize as x36_0_, userpo0_.oa_enterprise_number as x37_0_, userpo0_.dingTalk as x38_0_, userpo0_.cloudHub as x39_0_, userpo0_.evoPortal as x40_0_ from EZOFFICE.ORG_EMPLOYEE userpo0_ inner join EZOFFICE.ORG_ORGANIZATION_USER organizati1_ on userpo0_.EMP_ID=organizati1_.Emp_id inner join EZOFFICE.ORG_ORGANIZATION organizati2_ on organizati1_.Org_Id=organizati2_.ORG_ID where (upper(userpo0_.USERACCOUNTS)=? COLLATE Chinese_PRC_CS_AS )and(userpo0_.USERISDELETED=0 )and(userpo0_.DOMAIN_ID=? )";
//      sql = "\nselect top 45 userpo0_.emp_id as x0_0_, userpo0_.empname as x1_0_, userpo0_.empenglishname as x2_0_, \nuserpo0_.empsex as x3_0_, userpo0_.useraccounts as x4_0_, userpo0_.userissuper as x5_0_, organizati2_.orgnamestring as x6_0_, \nuserpo0_.empduty as x7_0_, userpo0_.usersimplename as x8_0_, userpo0_.empleadername as x9_0_, userpo0_.cansendmail as x10_0_,\nuserpo0_.empleaderid as x11_0_, userpo0_.latest_logon_time as x12_0_, userpo0_.user_sleep_reasons as x13_0_, userpo0_.empnumber as x14_0_, \nuserpo0_.mobile_securitypolicy as x15_0_, userpo0_.mobile_user_flag as x16_0_, userpo0_.oa_enterprise_number as x17_0_, userpo0_.accountapply as x18_0_ \nfrom ezoffice.org_employee userpo0_ \ninner join ezoffice.org_organization_user organizati1_ on userpo0_.emp_id=organizati1_.emp_id \ninner join ezoffice.org_organization organizati2_ on organizati1_.org_id=organizati2_.org_id \nwhere (userpo0_.domain_id=0 )and(userpo0_.userisactive=1 )and(userpo0_.userisdeleted=0 )and(userpo0_.user_is_sleep=0 )\nand(userpo0_.useraccounts is not null )and(userpo0_.userisformaluser=1 )and((1=1 )) \norder by  organizati2_.orgidstring , userpo0_.empdutylevel , userpo0_.userordercode , userpo0_.empname , userpo0_.emp_id";
//      p.put("sql", sql);
//      Map<String, Object> s2 = util.parseSqlStructure(p);
//      System.out.println(s2.get("sql"));
//      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 = max(fields, columnList);
//      StringBuilder columnTable = new StringBuilder("            ");
//
//      for(int j = 0; j < fields.length; ++j) {
//         fields[j] = String.format("%" + size[j] + "s", fields[j]).trim();
//         columnTable.append(fields[j]).append("  ");
//      }
//
//      System.out.println(columnTable);
//
//      for(Column item : columnList) {
//         StringBuilder output = new StringBuilder();
//         printColumn(item, output, size);
//         System.out.println(output);
//      }
//
//      System.out.println("\n\n====output-cols====");
//      ArrayList<Column> outputCols = (ArrayList)s2.get("output-cols");
//      fields = new String[]{"columnName", "seq", "columnAlisa", "fullName", "nowName", "dataType", "schema", "table", "value", "expr"};
//      size = max(fields, columnList);
//      columnTable = new StringBuilder("            ");
//
//      for(int j = 0; j < fields.length; ++j) {
//         fields[j] = String.format("%" + size[j] + "s", fields[j]).trim();
//         columnTable.append(fields[j]).append("  ");
//      }
//
//      System.out.println(columnTable);
//
//      for(Column item : columnList) {
//         StringBuilder output = new StringBuilder();
//         printColumn1(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------------------------------------------------");
//   }
//
//   static void printColumn(Column col, StringBuilder s, int[] size) {
//      s.append(format(col.getColumnName(), size[0])).append("  ").append(format(col.getColumnAlisa(), size[1])).append("  ").append(format(col.getFullName(), size[2])).append("  ").append(format(col.getNowName(), size[3])).append("  ").append(format(col.getDataType(), size[4])).append("  ").append(format(col.getSchema(), size[5])).append("  ").append(format(col.getTable(), size[6])).append("  ").append(format(col.getValue(), size[7])).append("  ").append(format(col.getExpr(), size[8]));
//   }
//
//   static void printColumn1(Column col, StringBuilder s, int[] size) {
//      s.append(format(col.getColumnName(), size[0])).append("  ").append(format(col.seq + "", size[1])).append("  ").append(format(col.getColumnAlisa(), size[2])).append("  ").append(format(col.getFullName(), size[3])).append("  ").append(format(col.getNowName(), size[4])).append("  ").append(format(col.getDataType(), size[5])).append("  ").append(format(col.getSchema(), size[6])).append("  ").append(format(col.getTable(), size[7])).append("  ").append(format(col.getValue(), size[8])).append("  ").append(format(col.getExpr(), size[9]));
//   }
//
//   static String format(Object value, int size) {
//      return String.format("%" + size + "s", value);
//   }
//
//   static 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;
//   }
//}
