设为首页 加入收藏

TOP

MongoDBJava连接(二)
2014-11-24 00:59:49 来源: 作者: 【 】 浏览:12
Tags:MongoDBJava 连接
long id = obj.getLong("_id"); ArrayList tagList = (ArrayList) obj.get("tag"); // tag ArrayList keywordList = (ArrayList)obj.get("keyword"); // keyword ArrayList copyrightList = (ArrayList)obj.get("copyright"); // copyright MediaEntity mediaEntity = new MediaEntity(); mediaEntity.setId(id); // tag for(int j=0; j actorsObjList = (ArrayList)obj.get("actors"); // actors for(int j=0; j directorObjList = (ArrayList)obj.get("director"); // director for(int j=0; j 100) { break; } System.out.println(index + " --- mediaEntity : " + mediaEntity.toString()); } long costTime = System.currentTimeMillis() - startTime; System.out.println("load data costTime = " + index + "; costTime = " + costTime/1000f); } catch (Exception e) { e.printStackTrace(); } } public static int getTagInt(String tag) { int tagIntId = -1; try { MongoClient mongo = new MongoClient(CosineCluster.gMongo_HOST, CosineCluster.gMongo_PORT); DB db = mongo.getDB(CosineCluster.gMongo_DB); DBCollection tagmapCollection = db.getCollection("recommend_tag_map"); DBCursor cursor = tagmapCollection.find(new BasicDBObject("name", tag)); if(cursor == null || cursor.toArray().size() <= 0) { // 处理小于2或n的映射关键字,下同 return tagIntId; } DBObject obj = cursor.toArray().get(0); String name = tag; tagIntId = (Integer) obj.get("id"); int num = (Integer) obj.get("num"); mongo.close(); } catch (UnknownHostException e) { e.printStackTrace(); } return tagIntId; } public static int getActorInt(String actor) { int actorIntId = -1; try { MongoClient mongo = new MongoClient(CosineCluster.gMongo_HOST, CosineCluster.gMongo_PORT); DB db = mongo.getDB(CosineCluster.gMongo_DB); DBCollection tagmapCollection = db.getCollection("recommend_actor_map"); DBCursor cursor = tagmapCollection.find(new BasicDBObject("name", actor)); if(cursor == null || cursor.toArray().size() <= 0) { return actorIntId; } DBObject obj = cursor.toArray().get(0); String name = actor; actorIntId = (Integer) obj.get("id"); int num = (Integer) obj.get("num"); mongo.close(); } catch (UnknownHostException e) { e.printStackTrace(); } return actorIntId; }
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇bbed修改undo段状态(ORA-01578) 下一篇PostgreSQL启动过程中的那些事六..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: