Domino毫秒级查询利器Elasticsearch(一)

     Domino的数据库查询慢,上100W大量数据之后,更是慢得让用户不能接受。从Domino 10开始又多了一种数据库查询方法,Domino Query Language(简称DQL),刚开始只支持nodejs开放,后期会支持ls、java一起。看了一些资料DQL查询比以前的方式要快不少。由于没有使用nodejs开发,一直没有测试。
     目前流行什么查询呢?能否集成到我们的Domino里面来?在我的博客已经有提到过Domino集成关系数据库,目前关系数据库如果在上亿级的记录及查询,已经不流行了。现在在一些开源的java平台,提及最多查询数据库方式使用Elasticsearch。让查询上亿级的数据到毫秒级。
     我们的Domino是否可以同步?Elasticsearch去网上下载,不具体介绍安装Elasticsearch。以下简要介绍Domino同步到Elasticsearch的过程吧。

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;

import com.alibaba.fastjson.JSONObject;

import lotus.domino.*;

public class JavaAgent extends AgentBase {

    public void NotesMain() {

      try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();


          Date d1 = new Date();     
        Database db = session.getCurrentDatabase();
        View view =db.getView("AllNames");
        ViewEntryCollection vc=view.getAllEntries();
        ViewEntry tmpentry=null;
		ViewEntry entry=vc.getFirstEntry();
		
		System.out.println(vc.getCount());
		
	
		int i=0;
	    while (entry != null) {
	    	i++;	 	    	
	    	String temp="{\"Name\":\""+entry.getColumnValues().elementAt(0).toString()
	    			+"\",\"EMail\":\""+entry.getColumnValues().elementAt(1).toString()+"\"}";
	    	temp=HttpSendSoapPost("PUT","http://localhost:9200/xpages/ext/"+entry.getUniversalID(),temp);
	    	System.out.println(i);
	    	
	        tmpentry = vc.getNextEntry();
	        entry.recycle();
	        entry = tmpentry;
	      }
		
	    Date d2 = new Date();
		System.out.println(d2.getTime() - d1.getTime());
		System.out.println("****** END ********");	
		
      } catch(Exception e) {
          e.printStackTrace();
       }
   }
    
    public static String HttpSendSoapPost(String Method,String strurl,String xml){
		HttpURLConnection connection = null;
		InputStream is = null;
		BufferedReader br = null;
		String result = null;// 返回结果字符串
		OutputStream out = null;
		
		//Date d1 = new Date();

		try {
		
			// 创建远程url连接对象
			URL url = new URL(strurl);
			// 通过远程url连接对象打开一个连接,强转成httpURLConnection类
			
			connection = (HttpURLConnection) url.openConnection();
			// 设置连接方式:GET,POST
			if(Method.equals("")){
				connection.setRequestMethod("POST");
			}else{
				connection.setRequestMethod(Method);
			}
			

			connection.setDoInput(true);
			connection.setDoOutput(true);
			
			connection.setRequestProperty("Content-Type", "application/json");
			//这里必须要写,否则出错
			//connection.setRequestProperty("SOAPAction", "");			
						
			// 设置连接主机服务器的超时时间:15000毫秒
			connection.setConnectTimeout(15000);
			// 设置读取远程返回的数据时间:60000毫秒
			connection.setReadTimeout(60000);

			// 发送请求
			connection.connect();
			out = connection.getOutputStream(); // 获取输出流对象
			connection.getOutputStream().write(xml.getBytes("UTF-8")); // 将要提交服务器的SOAP请求字符流写入输出流
			
			out.flush();
			out.close();

			//System.out.println(connection.getResponseCode());

			// 通过connection连接,获取输入流
			if (connection.getResponseCode() == 200 || connection.getResponseCode() == 201) {
				is = connection.getInputStream();
				// 封装输入流is,并指定字符
				br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
				// 存放数据
				StringBuffer sbf = new StringBuffer();
				String temp = null;
				while ((temp = br.readLine()) != null) {
					sbf.append(temp);
					sbf.append("\r\n");
				}
				result = sbf.toString();
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			// 关闭资源
			if (null != br) {
				try {
					br.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

			if (null != is) {
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

			connection.disconnect();// 关闭远程连接

		}
			
		//System.out.println();
		return result;
	}
    
}

发布了76 篇原创文章 · 获赞 17 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/weijia3624/article/details/104491993
今日推荐