Sequoiadb操作

简介:
Java代码   收藏代码
  1. package com.iminido.nosql;  
  2.   
  3. import com.google.gson.Gson;  
  4. import com.iminido.constant.Const;  
  5. import com.iminido.instruction.core.IstRequ;  
  6. import com.iminido.log.Log;  
  7. import com.iminido.util.SU;  
  8. import static com.iminido.util.SU.parseJSON2Map;  
  9. import com.iminido.util.TL;  
  10. import com.sequoiadb.base.CollectionSpace;  
  11. import com.sequoiadb.base.DBCollection;  
  12. import com.sequoiadb.base.DBCursor;  
  13. import com.sequoiadb.base.Sequoiadb;  
  14. import com.sequoiadb.base.SequoiadbDatasource;  
  15. import com.sequoiadb.base.SequoiadbOption;  
  16. import com.sequoiadb.exception.BaseException;  
  17. import com.sequoiadb.net.ConfigOptions;  
  18. import java.util.ArrayList;  
  19. import java.util.List;  
  20. import java.util.concurrent.Semaphore;  
  21. import java.util.concurrent.TimeUnit;  
  22. import java.util.logging.Level;  
  23. import java.util.logging.Logger;  
  24.   
  25. import org.bson.BSONObject;  
  26. import org.bson.BasicBSONObject;  
  27. import org.bson.util.JSON;  
  28.   
  29. /** 
  30.  * 
  31.  * @author JadeLuo 
  32.  */  
  33. public class NoSQLDb {  
  34.   
  35.     private static SequoiadbDatasource sequoiadbDatasource;  
  36.     private static final Log log = Log.init(NoSQLDb.class);  
  37.     private static Semaphore semaphore = new Semaphore(1);  
  38.   
  39.     static {  
  40.         initSequoiadbDatasource();  
  41.     }  
  42.   
  43.     public static void initSequoiadbDatasource() {  
  44.         ArrayList<String> urls = new ArrayList<>();  
  45.         ConfigOptions nwOpt = new ConfigOptions();          // 定义连接选项  
  46.         SequoiadbOption dsOpt = new SequoiadbOption();      // 定义连接池选项  
  47.   
  48.         urls.add(Const.SEQUOIADB_HOST + ":" + Const.SEQUOIADB_PORT);  
  49. //        urls.add("ubuntu-dev2:11810");  
  50. //        urls.add("ubuntu-dev3:11810");  
  51.   
  52.         nwOpt.setConnectTimeout(500);                       // 设置若连接失败,超时时间(ms)  
  53.         nwOpt.setMaxAutoConnectRetryTime(0);                // 设置若连接失败,重试次数  
  54.   
  55. // 以下设置的都是 SequoiadbOption 的默认值  
  56.         dsOpt.setMaxConnectionNum(500);                     // 设置连接池最大连接数  
  57.         dsOpt.setInitConnectionNum(10);                     // 初始化连接池时,创建连接的数量  
  58.         dsOpt.setDeltaIncCount(10);                        // 当池中没有可用连接时,增加连接的数量  
  59.         dsOpt.setMaxIdeNum(10);                             // 周期清理多余的空闲连接时,应保留连接的数量  
  60.         dsOpt.setTimeout(5 * 1000);                         // 当已使用的连接数到达设置的最大连接数时(500),请求连接的等待时间。  
  61.         dsOpt.setAbandonTime(10 * 60 * 1000);               // 连接存活时间,当连接空闲时间超过连接存活时间,将被连接池丢弃  
  62.         dsOpt.setRecheckCyclePeriod(1 * 60 * 1000);         // 清除多余空闲连接的周期  
  63.         dsOpt.setRecaptureConnPeriod(10 * 60 * 1000);       // 检测并取回异常地址的周期  
  64.   
  65.         sequoiadbDatasource = new SequoiadbDatasource(urls, Const.SEQUOIADB_USERNAME, Const.SEQUOIADB_PASSWORD, nwOpt, dsOpt); // 创建连接池  
  66.     }  
  67.   
  68.     public static synchronized Sequoiadb getSequoiadb() {  
  69.         Sequoiadb sdb = null;  
  70.         try {  
  71.             sdb = sequoiadbDatasource.getConnection();  
  72.         } catch (BaseException ex) {  
  73.             System.out.println("getIdleConnNum1  " + sequoiadbDatasource.getIdleConnNum());  
  74.             System.out.println("getUsedConnNum" + sequoiadbDatasource.getUsedConnNum());  
  75.             Logger.getLogger(NoSQLDb.class.getName()).log(Level.SEVERE, null, ex);  
  76.         } catch (InterruptedException ex) {  
  77.             System.out.println("getIdleConnNum2  " + sequoiadbDatasource.getIdleConnNum());  
  78.             System.out.println("getUsedConnNum" + sequoiadbDatasource.getUsedConnNum());  
  79.             Logger.getLogger(NoSQLDb.class.getName()).log(Level.SEVERE, null, ex);  
  80.         }  
  81.   
  82.         if (sdb == null) {  
  83.             while (sdb == null) {  
  84.                 try {  
  85.                     semaphore.tryAcquire(12, TimeUnit.SECONDS);  
  86.                 } catch (InterruptedException ex) {  
  87.                     System.out.println("getIdleConnNum3  " + sequoiadbDatasource.getIdleConnNum());  
  88.                     System.out.println("getUsedConnNum" + sequoiadbDatasource.getUsedConnNum());  
  89.                     Logger.getLogger(NoSQLDb.class.getName()).log(Level.SEVERE, null, ex);  
  90.                 }  
  91.                 try {  
  92.                     sdb = sequoiadbDatasource.getConnection();  
  93.                 } catch (BaseException | InterruptedException ex) {  
  94.                     System.out.println("getIdleConnNum4  " + sequoiadbDatasource.getIdleConnNum());  
  95.                     System.out.println("getUsedConnNum" + sequoiadbDatasource.getUsedConnNum());  
  96.                     Logger.getLogger(NoSQLDb.class.getName()).log(Level.SEVERE, null, ex);  
  97.                 }  
  98.             }  
  99.             semaphore.release();  
  100.             return sdb;  
  101.         }  
  102.         return sdb;  
  103.     }  
  104.   
  105.     public static CollectionSpace initCollectionSpace(String csName) {  
  106.         try {  
  107.             Sequoiadb sdb = getSequoiadb();  
  108.             CollectionSpace cs;  
  109.             if (sdb.isCollectionSpaceExist(csName)) {  
  110.                 cs = sdb.getCollectionSpace(csName);  
  111.             } else {  
  112.                 cs = sdb.createCollectionSpace(csName);  
  113.             }  
  114.             return cs;  
  115.         } catch (BaseException ex) {  
  116.             Logger.getLogger(NoSQLDb.class.getName()).log(Level.SEVERE, null, ex);  
  117.             log.debug("D:\\working\\workspace\\LF_S_SignalProc\\src\\com\\iminido\\nosql\\NoSQLDb.java initCollectionSpace 方法获取 Sequoiadb 为空");  
  118.             return null;  
  119.         }  
  120.     }  
  121.   
  122.     public static DBCollection initCollection(String collectionName) {  
  123.         CollectionSpace cs = initCollectionSpace(Const.SEQUOIADB_DATABASE);  
  124.         DBCollection cl;  
  125.         if (cs.isCollectionExist(collectionName)) {  
  126.             cl = cs.getCollection(collectionName);  
  127.         } else {  
  128.             cl = cs.createCollection(collectionName);  
  129.         }  
  130.         return cl;  
  131.     }  
  132.   
  133.     public static void removeAll(String collectionName) {  
  134.         DBCollection cl = initCollection(collectionName);  
  135.         cl.delete(new BasicBSONObject());  
  136.         sequoiadbDatasource.close(cl.getSequoiadb());  
  137.     }  
  138.   
  139.     public static void remove(String collectionName) {  
  140.         DBCollection cl = initCollection(collectionName);  
  141.         cl.delete(new BasicBSONObject());  
  142.         sequoiadbDatasource.close(cl.getSequoiadb());  
  143.     }  
  144.   
  145.     public static boolean delete(String cl, String matcher) {  
  146.         try {  
  147.             DBCollection dbc = initCollection(cl);  
  148.             dbc.delete(matcher);  
  149.             sequoiadbDatasource.close(dbc.getSequoiadb());  
  150.             return true;  
  151.         } catch (Exception e) {  
  152.             log.error("delete " + cl + "matcher=>" + matcher + "失败", e);  
  153.             return false;  
  154.         }  
  155.     }  
  156.   
  157.     public static void delete(String cl, String matcher, String hint) {  
  158.         DBCollection dbc = initCollection(cl);  
  159.         dbc.delete(matcher, hint);  
  160.         sequoiadbDatasource.close(dbc.getSequoiadb());  
  161.     }  
  162.   
  163.     public static boolean insert(String collectionName, String... key_val) {  
  164.         String strJson = strs2json(key_val);  
  165.         log.debug("D:\\working\\workspace\\LF_S_SignalProc\\src\\com\\iminido\\nosql\\NoSQLDb.java save=>" + strJson);  
  166.         if (strJson != null) {  
  167.             BSONObject dbo;  
  168.             try {  
  169.                 dbo = (BasicBSONObject) JSON.parse(strJson); //添加异常处理   
  170.             } catch (Exception e) {  
  171.                 log.error("解析json字符串异常,传入的字符串为:" + strJson, e);  
  172.                 return false;  
  173.             }  
  174.   
  175.             try {  
  176.                 DBCollection dbc = initCollection(collectionName);  
  177.                 dbc.insert(dbo);  
  178.                 sequoiadbDatasource.close(dbc.getSequoiadb());  
  179.                 return true;  
  180.             } catch (Exception e) {  
  181.                 return false;  
  182.             }  
  183.         }  
  184.         return false;  
  185.     }  
  186.   
  187.     public static boolean insert(String collectionName, String strJson) {  
  188.         BSONObject dbo = null;  
  189.         try {  
  190.             dbo = (BasicBSONObject) JSON.parse(strJson); //添加异常处理   
  191.         } catch (Exception e) {  
  192.             log.error("解析json字符串异常,传入的字符串为:" + strJson, e);  
  193.             return false;  
  194.         }  
  195.   
  196.         DBCollection dBCollection = initCollection(collectionName);  
  197.         Object object = dBCollection.insert(dbo);  
  198.         sequoiadbDatasource.close(dBCollection.getSequoiadb());  
  199.         return true;  
  200.     }  
  201.   
  202.     public static boolean insertNestJson(String collectionName, String strJson, String strJson2, String nameOfNest) {  
  203.         BSONObject dbo = null;  
  204.         try {  
  205.             dbo = (BasicBSONObject) JSON.parse(strJson); //添加异常处理   
  206.         } catch (Exception e) {  
  207.             log.error("解析json字符串异常,传入的字符串为:" + strJson, e);  
  208.             return false;  
  209.         }  
  210.   
  211.         BSONObject dbo2 = null;  
  212.         try {  
  213.             dbo2 = (BasicBSONObject) JSON.parse(strJson2); //添加异常处理   
  214.         } catch (Exception e) {  
  215.             log.error("解析json字符串异常,传入的字符串为:" + strJson, e);  
  216.             return false;  
  217.         }  
  218.   
  219.         dbo.put(nameOfNest, dbo2);  
  220.   
  221.         DBCollection dBCollection = initCollection(collectionName);  
  222.         Object object = dBCollection.insert(dbo);  
  223.         sequoiadbDatasource.close(dBCollection.getSequoiadb());  
  224.         return true;  
  225.     }  
  226.   
  227.     public static boolean insert(String collectionName, IstRequ requ) {  
  228.         String strJson = TL.requ2json(requ);  
  229.         BSONObject dbo = null;  
  230.         try {  
  231.             dbo = (BasicBSONObject) JSON.parse(strJson); //添加异常处理   
  232.         } catch (Exception e) {  
  233.             log.error("解析json字符串异常,传入的字符串为:" + strJson, e);  
  234.             return false;  
  235.         }  
  236.   
  237.         DBCollection dBCollection = initCollection(collectionName);  
  238.         dBCollection.insert(dbo);  
  239.         sequoiadbDatasource.close(dBCollection.getSequoiadb());  
  240.         return true ;  
  241.     }  
  242.   
  243.     public static Object insert(String collectionName, IstRequ requ, String args) {  
  244.         String strJson = TL.requ2json(requ, args);  
  245.         BSONObject dbo = null;  
  246.         try {  
  247.             dbo = (BasicBSONObject) JSON.parse(strJson); //添加异常处理   
  248.         } catch (Exception e) {  
  249.             log.error("解析json字符串异常,传入的字符串为:" + strJson, e);  
  250.         }  
  251.   
  252.         DBCollection dBCollection = initCollection(collectionName);  
  253.         Object object = dBCollection.insert(dbo);  
  254.         sequoiadbDatasource.close(dBCollection.getSequoiadb());  
  255.         return object;  
  256.     }  
  257.   
  258. //    public static void savej(String collectionName, IstRequ req) {  
  259. //        String strJson = req.get("j");  
  260. //        strJson = strJson.replaceAll("\'", "\""); //把单引号替换成双引号,不用这句也可以执行成功。加这句是为了让我记住json应用中存在单双引号问题,在jquery中,如果json是用单引号的话,就会出错,在php中json用单引号也会出错。  
  261. //        insert(collectionName, strJson);  
  262. //    }  
  263.     public static boolean isExist(String collectionName, String matcher) {  
  264.         if (null == queryOne(collectionName, matcher, matcher, matcher, null)) {  
  265.             return false;  
  266.         } else {  
  267.             return true;  
  268.         }  
  269.     }  
  270.   
  271.     public static BSONObject queryOne(String collectionName, String matcher, String selector, String orderBy, String hint) {  
  272.         DBCollection dBCollection = initCollection(collectionName);  
  273.         BSONObject bSONObject = dBCollection.queryOne(str2BSONObject(matcher), str2BSONObject(selector), str2BSONObject(orderBy), str2BSONObject(hint), 0);  
  274.         sequoiadbDatasource.close(dBCollection.getSequoiadb());  
  275.         return bSONObject;  
  276.     }  
  277.   
  278.     public static DBCursor findandclose(String collectionName, String... key_val) {  
  279.         DBCollection dBCollection = initCollection(collectionName);  
  280.         DBCursor dBCursor = dBCollection.query();  
  281.         sequoiadbDatasource.close(dBCollection.getSequoiadb());  
  282.         return dBCursor;  
  283.     }  
  284.   
  285.     public static DBCursor query(String collectionName, String... key_val) {  
  286.         return initCollection(collectionName).query();  
  287.     }  
  288.   
  289.     public static DBCursor query(String collectionName) {  
  290.         return initCollection(collectionName).query();  
  291.     }  
  292.   
  293.     public static DBCursor query(String collectionName, String matcher, String selector, String orderBy, String hint, int limitNum) {  
  294.         return initCollection(collectionName).query(matcher, selector, orderBy, hint);  
  295.     }  
  296.   
  297.     public static BasicBSONObject str2BSONObject(String jsonString) {  
  298.         return (BasicBSONObject) JSON.parse(jsonString);  
  299.     }  
  300.   
  301.     public static List exec(String sql) {  
  302.         DBCursor c = null;  
  303.         Sequoiadb seq = null;  
  304.         try {  
  305.             seq = sequoiadbDatasource.getConnection();  
  306.             c = seq.exec(sql);  
  307.         } catch (BaseException e) {  
  308.             e.printStackTrace();  
  309.         } catch (InterruptedException ex) {  
  310.             Logger.getLogger(NoSQLDb.class.getName()).log(Level.SEVERE, null, ex);  
  311.         }  
  312.   
  313.         if (c != null && c.hasNext()) {  
  314.             List list = new ArrayList();  
  315.             while (c.hasNext()) {  
  316.                 list.add(c.getNext());  
  317.             }  
  318.             if (seq != null) {  
  319.                 sequoiadbDatasource.close(seq);  
  320.             }  
  321.             return list;  
  322.         } else {  
  323.             if (seq != null) {  
  324.                 sequoiadbDatasource.close(seq);  
  325.             }  
  326.             return null;  
  327.         }  
  328.     }  
  329.   
  330.     public static String exeSql(String sql) {  
  331.         return list2String(exec(sql));  
  332.     }  
  333.   
  334.     public static String exe(String sql) {  
  335.         return list2String(exec(sql));  
  336.     }  
  337.   
  338.     public static boolean execUpdate(String sql) {  
  339.         try {  
  340.             Sequoiadb seq = sequoiadbDatasource.getConnection();  
  341.             seq.execUpdate(sql);  
  342.             sequoiadbDatasource.close(seq);  
  343.             return true;  
  344.         } catch (BaseException e) {  
  345.             e.printStackTrace();  
  346.             log.warn(sql, e);  
  347.             return false;  
  348.         } catch (InterruptedException ex) {  
  349.             Logger.getLogger(NoSQLDb.class.getName()).log(Level.SEVERE, null, ex);  
  350.             return false;  
  351.         }  
  352.     }  
  353.   
  354.     //matcher test  
  355.     public static List query(String cl, String matcher) {  
  356.         DBCollection dbc = initCollection(cl);  
  357.         DBCursor c = dbc.query(matcher, nullnullnull, 0L, 100L);  
  358.         List<String> list = null;//new ArrayList<>();  
  359.         if (c != null && c.hasNext()) {  
  360.             list = cur2list(c);  
  361.         } else {  
  362.             sequoiadbDatasource.close(dbc.getSequoiadb());  
  363.             return list;  
  364.         }  
  365.         sequoiadbDatasource.close(dbc.getSequoiadb());  
  366.         return list;  
  367.   
  368.     }  
  369.       
  370.     //matcher test  
  371.     public static List query(String cl, String matcher,String selector) {  
  372.         DBCollection dbc = initCollection(cl);  
  373.         DBCursor c = dbc.query(matcher, selector, nullnull, 0L, 100L);  
  374.         List<String> list = null;//new ArrayList<>();  
  375.         if (c != null && c.hasNext()) {  
  376.             list = cur2list(c);  
  377.         } else {  
  378.             sequoiadbDatasource.close(dbc.getSequoiadb());  
  379.             return list;  
  380.         }  
  381.         sequoiadbDatasource.close(dbc.getSequoiadb());  
  382.         return list;  
  383.   
  384.     }  
  385.   
  386.     //returnRows test  
  387.     public static DBCursor query(String cl, String matcher, long returnRows) {  
  388.         return initCollection(cl).query(matcher, nullnullnull, 0L, returnRows);  
  389.     }  
  390.   
  391.     // selector {filed:1}  
  392.     public static DBCursor query(String cl, String matcher, String selector, long returnRows) {  
  393.         return initCollection(cl).query(matcher, selector, nullnull, 0L, returnRows);  
  394.     }  
  395.   
  396.     //orderBy {filed:1/-1}  
  397.     public static DBCursor query(String cl, String matcher, String selector, String orderBy, long returnRows) {  
  398.         return initCollection(cl).query(matcher, selector, orderBy, null, 0L, returnRows);  
  399.     }  
  400.   
  401.     //hint (index) {}  
  402.     public static DBCursor query(String cl, String matcher, String selector, String orderBy, String hint, long returnRows) {  
  403.         DBCollection dbc = initCollection(cl);  
  404.         DBCursor dbcu = dbc.query(matcher, selector, orderBy, hint, 0L, returnRows);  
  405.         sequoiadbDatasource.close(dbc.getSequoiadb());  
  406.         return dbcu;  
  407.     }  
  408.   
  409.     public static List query2(String cl, String matcher, String selector, String orderBy, String hint, long returnRows,List<String> list ) {  
  410.         DBCollection dbc = initCollection(cl);  
  411.         DBCursor c = dbc.query(matcher, selector, orderBy, hint, 0L, returnRows);  
  412.         
  413.         if (c != null && c.hasNext()) {  
  414.             while (c.hasNext()) {  
  415.                 String str1 = (String) c.getNext().get("acc");  
  416.                 for (int j = 0; j < list.size(); j++) {  
  417.                     String str2 = list.get(j);  
  418.                     if (str2.equals(str1)) {  
  419.                         list.remove(str1);  
  420.                     }  
  421.                 }  
  422.             }  
  423.         } else {  
  424.             sequoiadbDatasource.close(dbc.getSequoiadb());  
  425.             return list;//直接返回生成的推荐号  
  426.         }  
  427.         sequoiadbDatasource.close(dbc.getSequoiadb());  
  428.         return list;  
  429.     }  
  430.   
  431.     public static DBCursor query(String cl, String matcher, long returnRows, long skipRows) {  
  432.         return initCollection(cl).query(matcher, nullnullnull, skipRows, returnRows);  
  433.     }  
  434.   
  435.     public static String query(String cl, String matcher, String selector, String orderBy, String hint, long skipRows, long returnRows) {  
  436.         DBCollection dbc = initCollection(cl);  
  437.         String jsonString = cur2jsonstr(dbc.query(matcher, selector, orderBy, hint, skipRows, returnRows));  
  438.         sequoiadbDatasource.close(dbc.getSequoiadb());  
  439.         return jsonString;  
  440.     }  
  441.   
  442.     public static void update(String cl, String matcher, String modifier, String hint) {  
  443.         DBCollection dbc = initCollection(cl);  
  444.         dbc.update(matcher, modifier, hint);  
  445.         sequoiadbDatasource.close(dbc.getSequoiadb());  
  446.     }  
  447.   
  448.     public static void update$unsetAll(String cl, String matcher, String field, String hint) {  
  449.         DBCollection dbc = initCollection(cl);  
  450.         dbc.update(matcher, "{$unset:" + field + ":[]}", hint); // NoSQLDb.update("friend", "{}", "{$unset:{label:[]}}", "{}");  
  451.         sequoiadbDatasource.close(dbc.getSequoiadb());  
  452.     }  
  453.   
  454.     public static void update$unset(String cl, String matcher, String modifier, String hint) {  
  455.         DBCollection dbc = initCollection(cl);  
  456.         dbc.update(matcher, "{$unset:" + modifier + "}", hint); //  NoSQLDb.update("friend", "{}", "{$unset:{label:[33,44,55]}}", "{}");  
  457.         sequoiadbDatasource.close(dbc.getSequoiadb());  
  458.   
  459.     }  
  460.   
  461.     public static void update$addtoset(String cl, String matcher, String modifier, String hint) {  
  462.         DBCollection dbc = initCollection(cl);  
  463.         dbc.update(matcher, "{$addtoset:" + modifier + "}", hint); //    NoSQLDb.upsert("friend", "{}", "{$addtoset:{label:[33,44,55]}}", "{}");  
  464.         sequoiadbDatasource.close(dbc.getSequoiadb());  
  465.     }  
  466.   
  467.     /** 
  468.      * 不存在会自动插入新记录 
  469.      * 
  470.      * @param cl 
  471.      * @param matcher 
  472.      * @param modifier 
  473.      * @param hint 
  474.      */  
  475.     public static void upsert(String cl, String matcher, String modifier, String hint) {  
  476.         DBCollection dbc = initCollection(cl);  
  477.         BSONObject ma = null;  
  478.         BSONObject mo = null;  
  479.         BSONObject hi = null;  
  480.         if (matcher != null) {  
  481.             ma = (BSONObject) JSON.parse(matcher);  
  482.         }  
  483.         if (modifier != null) {  
  484.             mo = (BSONObject) JSON.parse(modifier);  
  485.         }  
  486.         if (hint != null) {  
  487.             hi = (BSONObject) JSON.parse(hint);  
  488.         }  
  489.         dbc.upsert(ma, mo, hi);  
  490.         sequoiadbDatasource.close(dbc.getSequoiadb());  
  491.   
  492.     }  
  493.   
  494.     public static String strs2json(String... key_val) {  
  495.         String strJson = null;  
  496.         if (key_val != null) {  
  497.             StringBuilder sb = new StringBuilder();  
  498.             sb.append("{");  
  499.             int i = 0;  
  500.             while (key_val[i] != null) {  
  501.                 sb.append(key_val[i]).append(":'").append(key_val[++i]).append("'");  
  502.                 if (i < key_val.length - 1) {  
  503.                     sb.append(",");  
  504.                     i++;  
  505.                 } else {  
  506.                     key_val[i] = null;  
  507.                 }  
  508.             }  
  509.             sb.append("}");  
  510.             strJson = sb.toString();  
  511.   
  512.         }  
  513.         return strJson;  
  514.     }  
  515.   
  516.     public static List cur2list(DBCursor c) {  
  517.         if (c != null && c.hasNext()) {  
  518.             List list = new ArrayList();  
  519.             while (c.hasNext()) {  
  520.                 list.add(c.getNext());  
  521.             }  
  522.   
  523.             return list;  
  524.         }  
  525.         return null;  
  526.     }  
  527.   
  528.     public static String cur2jsonstr(DBCursor c) {  
  529.         String jsonString = "";  
  530.         if (c != null && c.hasNext()) {  
  531.             while (c.hasNext()) {  
  532.                 jsonString = jsonString + (c.getNext().toString());  
  533.             }  
  534.             c.close();  
  535.             return jsonString;  
  536.         }  
  537.         return "{}";  
  538.     }  
  539.   
  540.     private static String list2String(List list) {  
  541.         if (list != null) {  
  542.             StringBuilder sb = new StringBuilder();  
  543.             list.stream().forEach((Object s) -> {  
  544.                 sb.append(s).append(",");  
  545.             });  
  546.             return sb.toString();  
  547.         } else {  
  548.             return null;  
  549.         }  
  550.   
  551.     }  
  552.   
  553.     public static void main(String[] args) {  
  554. //        NoSQLDb.insertNestJson(Const.TEST, "{a:'a'}","{cc:'dd'}","nestJson");  
  555.   
  556.         String s = "{ \"_id\": { \"$oid\": \"544634608e849c2f20465015\" }, \"a\": \"a\", \"nestJson\": { \"cc\": \"dd\" } }";  
  557.         s = s.replace("\\", "");  
  558.         SU.parseJSON2Map(s);  
  559.   
  560.     }  
  561. }  
相关文章
|
SQL Oracle 关系型数据库
国产化人大金仓数据库转库工具:oracle12c数据库转kingbase8.6人大金仓数据库实例演示
国产化人大金仓数据库转库工具:oracle12c数据库转kingbase8.6人大金仓数据库实例演示
847 0
国产化人大金仓数据库转库工具:oracle12c数据库转kingbase8.6人大金仓数据库实例演示
|
8月前
|
SQL Kubernetes 安全
国产数据库-技术特性-CloudberryDB
Cloudberrydb基于gpdb,支持PG14内核,有很多GP目前不支持的优秀特性
241 0
|
11月前
|
存储 NoSQL 关系型数据库
「数据库选型」抛弃MongoDB,拥抱PostgreSQL,工作更轻松
「数据库选型」抛弃MongoDB,拥抱PostgreSQL,工作更轻松
|
11月前
|
Oracle 关系型数据库 数据库连接
Kingbase国产化数据库数据迁移:oracle11g数据库转库人大金仓数据库实例演示
Kingbase国产化数据库数据迁移:oracle11g数据库转库人大金仓数据库实例演示
220 0
|
存储 关系型数据库 OLAP
在MySQL和PostgreSQL之外,为什么阿里要研发HybridDB数据库?
好好用MySQL和PostgreSQL不就行了?为啥阿里要劳神费力地又基于Greenplum的开源版本研发HybridDB方案?HybridDB方案深究之下,有什么技术细节与故事?本文将向您分享阿里与HybridDB的故事。
13843 0
|
数据库
达梦数据库DM8飞腾版本、芯版本获取地址,最新达梦数据库各国产化版本获取方法,达梦数据库DM8使用手册、产品文档获取
达梦数据库DM8飞腾版本、芯版本获取地址,最新达梦数据库各国产化版本获取方法,达梦数据库DM8使用手册、产品文档获取
466 0
达梦数据库DM8飞腾版本、芯版本获取地址,最新达梦数据库各国产化版本获取方法,达梦数据库DM8使用手册、产品文档获取
|
监控 Oracle 关系型数据库
实战篇:AutoUpgrade 便捷高效的升级 Oracle 数据库
实战篇:AutoUpgrade 便捷高效的升级 Oracle 数据库
实战篇:AutoUpgrade 便捷高效的升级 Oracle 数据库
|
网络协议 Java 数据库连接
Dremio对国产数据库的支持使用
一.国产数据库调研 Ⅰ).达梦数据库 达梦数据库管理系统是达梦公司推出的具有完全自主知识产权的高性能数据库管理系统,简称DM。达梦数据库管理系统的最新版本是8.1.0版本,简称DM8。 DM8吸收借鉴当前先进新技术思想与主流数据库产品的优点,融合了分布式、弹性计算与云计算的优势,对灵活性、易用性、可靠性、高安全性等方面进行了大规模改进,多样化架构充分满足不同场景需求,支持超大规模并发事务处理和事务-分析混合型业务处理,动态分配计算资源,实现更精细化的资源利用、更低成本的投入。
2784 0
|
NoSQL 关系型数据库 数据库
SequoiaDB - 企业级NoSQL分布式大数据库
SequoiaDB 巨杉数据库是一款开源的金融级分布式关系型数据库,主要面对高并发联机交易型场景提供高性能、可靠稳定以及无限水平扩展的数据库服务。 用户可以在 SequoiaDB 巨杉数据库中创建多种类型的数据库实例,以满足上层不同应用程序各自的需求。
1097 0