最后是存储对象到后台存储模型中,用完以后别忘了关闭存储
- /** Stores the pageview object with the given key */
- ivate void storePageview(long key, Pageview pageview) throws IOException {
- dataStore.put(key, pageview);
- private void close() throws IOException {
- //It is very important to close the datastore properly, otherwise
- //some data loss might occur.
- if(dataStore != null)
- dataStore.close();
从数据库中取数据
- /** Fetches a single pageview object and prints it*/
- private void get(long key) throws IOException {
- Pageview pageview = dataStore.get(key);
- printPageview(pageview);
- }
查询对象
- /** Queries and prints pageview object that have keys between startKey and endKey*/
- private void query(long startKey, long endKey) throws IOException {
- Query<Long, Pageview> query = dataStore.newQuery();
- //set the properties of query
- query.setStartKey(startKey);
- query.setEndKey(endKey);
- Result<Long, Pageview> result = query.execute();
- printResult(result);
- }
删除对象
- /**Deletes the pageview with the given line number */
- private void delete(long lineNum) throws Exception {
- dataStore.delete(lineNum);
- dataStore.flush(); //write changes may need to be flushed before
- //they are committed
- }
- /** This method illustrates delete by query call */
- private void deleteByQuery(long startKey, long endKey) throws IOException {
- //Constructs a query from the dataStore. The matching rows to this query will be deleted
- QueryLong, Pageview> query = dataStore.newQuery();
- //set the properties of query
- query.setStartKey(startKey);
- query.setEndKey(endKey);
- dataStore.deleteByQuery(query);
- }
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
