package util.sqlparse.visitor.mongo.test;

import bean.DataBase;
import bean.Schema;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import util.JdbcUtil;
import util.SqlUtil;
import util.getdata.DatabaseCache;

public class EncoderTest {
   public static void main(String[] args) throws SQLException, InterruptedException, IOException {
      String content = "{\n      \"ip_port\": \"192.168.2.109:27017\",\n      \"url\": \"jdbc:mongodb://192.168.2.109:27017/test\",\n      \"username\": \"\",\n      \"isIgnorecase\":\"0\",\n      \"password\": \"\",\n      \"dbType\": \"mongodb\",\n      \"servername\": \"test\",\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);
      EncoderTest myTest = new EncoderTest();
      myTest.test();
   }

   public void test() throws InterruptedException {
      DataBase dataBase = (DataBase)JdbcUtil.dataBaseList.get(0);
      DatabaseCache simpleCache = dataBase.simpleCache;
      Schema ry = simpleCache.getSchema("ry");
      System.out.println(ry == null ? "" : ry.getName());
      Map<String, String> params = new HashMap();
      params.put("dbType", "mongodb");
      params.put("schema", "test");
      params.put("url", "jdbc:mongodb://192.168.2.109:27017/test");
      params.put("replaceSchema", ".*");
      params.put("replaceNewTable", "people_bk");
      params.put("replaceTable", ".*");
      params.put("replaceColumn", ".*");
      params.put("expression", "concat(substr(${value},1,1),'**')");
      params.put("limit", "3");
      String api = "db.student.find({},{\"_id\": 0.0, \"name\": 1.0}).sort({ name: 1 })";
      api = "db.runCommand(   {     find: \"myColl\",     filter: { category: \"cafe\", status: \"a\" },    sort: { category: 1 },     collation: { locale: \"fr\", strength: 1 }   })";
      SqlUtil sqlUtil = new SqlUtil();
      params.put("sh-sql", api);
      Map<String, Object> result = sqlUtil.parseMongoShellApi2BsonString(params);
      System.out.println(result.get("bsonString"));
   }
}
