你好,游客 登录 注册 搜索
背景:
阅读新闻

Nutch 2.0 之 Apache Gora 介绍

[日期:2012-07-21] 来源:Linux社区  作者:amuseme_lu [字体:大 中 小]

最后是存储对象到后台存储模型中,用完以后别忘了关闭存储

  1. /** Stores the pageview object with the given key */  
  2. ivate void storePageview(long key, Pageview pageview) throws IOException {  
  3. dataStore.put(key, pageview);  
  4.   
  5.   
  6.   
  7. private void close() throws IOException {  
  8. //It is very important to close the datastore properly, otherwise  
  9. //some data loss might occur.  
  10. if(dataStore != null)  
  11.   dataStore.close();  

从数据库中取数据

  1.   /** Fetches a single pageview object and prints it*/  
  2. private void get(long key) throws IOException {  
  3.   Pageview pageview = dataStore.get(key);  
  4.   printPageview(pageview);  
  5. }  

查询对象

  1.   /** Queries and prints pageview object that have keys between startKey and endKey*/  
  2. private void query(long startKey, long endKey) throws IOException {  
  3.   Query<Long, Pageview> query = dataStore.newQuery();  
  4.   //set the properties of query   
  5.   query.setStartKey(startKey);  
  6.   query.setEndKey(endKey);  
  7.     
  8.   Result<Long, Pageview> result = query.execute();  
  9.     
  10.   printResult(result);  
  11. }  

删除对象

  1.  /**Deletes the pageview with the given line number */  
  2. private void delete(long lineNum) throws Exception {  
  3.   dataStore.delete(lineNum);  
  4.   dataStore.flush(); //write changes may need to be flushed before   
  5.                      //they are committed    
  6. }  
  7.   
  8. /** This method illustrates delete by query call */  
  9. private void deleteByQuery(long startKey, long endKey) throws IOException {  
  10.   //Constructs a query from the dataStore. The matching rows to this query will be deleted   
  11.   QueryLong, Pageview> query = dataStore.newQuery();  
  12.   //set the properties of query   
  13.   query.setStartKey(startKey);  
  14.   query.setEndKey(endKey);  
  15.     
  16.   dataStore.deleteByQuery(query);  
  17. }     

5. 参考
http://gora.apache.org/docs/current/quickstart.html
http://gora.apache.org/docs/current/tutorial.html

相关阅读:Nutch 2.0 终于来了 http://www.linuxidc.com/Linux/2012-07/65967.htm

linux
相关资讯       Nutch  Apache Gora  Nutch 2.0 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款