当前位置: 首页>>代码示例>>Java>>正文


Java DBRef.fetch方法代码示例

本文整理汇总了Java中com.mongodb.DBRef.fetch方法的典型用法代码示例。如果您正苦于以下问题:Java DBRef.fetch方法的具体用法?Java DBRef.fetch怎么用?Java DBRef.fetch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.DBRef的用法示例。


在下文中一共展示了DBRef.fetch方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: queryUserFriendList

import com.mongodb.DBRef; //导入方法依赖的package包/类
@Override
public List<Map<String, Object>> queryUserFriendList(String userId) {
	// TODO Auto-generated method stub
	BasicDBObject column = new BasicDBObject("userFriend", 1);
	Map<String, Object> user = super.findOneById(userId, column);
	BasicDBList friendList = (BasicDBList) user.get("userFriend");
	List<Map<String, Object>> friends = new ArrayList<Map<String, Object>>();
	for (int i = 0; i < friendList.size(); i++) {
		DBRef friend = (DBRef) friendList.get(i);
		DBObject friendObj = friend.fetch();
		Map<String, Object> fre = new HashMap<String, Object>();
		fre.put("_id", friendObj.get("_id"));
		fre.put("userNickName", friendObj.get("userNickName"));
		fre.put("userPhoto", friendObj.get("userPhoto"));
		fre.put("userSignature", friendObj.get("userSignature"));
		// System.out.println(fre);
		friends.add(fre);
	}

	return friends;
}
 
开发者ID:hongdong,项目名称:FindMe_Server,代码行数:22,代码来源:UserDaoImpl2Mongo.java

示例2: query

import com.mongodb.DBRef; //导入方法依赖的package包/类
public void query() {
	DB db = MongoDBUtil.getDB();
	DBCollection connection = db.getCollection("user");
	BasicDBObject user = new BasicDBObject();
	// ReadPreference preference = ReadPreference.valueOf("$ref");
	user.put("_id", "2014062710281828268456656");
	DBObject obj = connection.findOne(user);
	// DBRefBase base = new DBRefBase(db, "post",
	// "2014062509521826635294167");
	// DBObject a = base.fetch();
	DBRef b = (DBRef) obj.get("post");
	DBObject a = b.fetch();
	// Object b = obj.get("post");
	System.out.println(a);
	System.out.println(obj.toMap());
}
 
开发者ID:hongdong,项目名称:FindMe_Server,代码行数:17,代码来源:TestMain.java

示例3: queryUserFansList

import com.mongodb.DBRef; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<Map<String, Object>> queryUserFansList(String userId) {
	// TODO Auto-generated method stub

	Map<String, Object> user = super.findOneById(userId, null);
	List<Map<String, Object>> fans = new ArrayList<Map<String, Object>>();
	if (user != null && user.isEmpty() == false) {
		BasicDBList userFans = (BasicDBList) user.get("userFans");
		for (int i = 0; i < userFans.size(); i++) {
			BasicDBObject _obj = (BasicDBObject) userFans.get(i);
			DBRef dbRef = (DBRef) _obj.get("user");
			BasicDBObject obj = (BasicDBObject) dbRef.fetch();
			obj.remove("userEquipment");
			obj.remove("userOpenId");
			obj.remove("userLastLoginIpAddress");
			obj.remove("userLoginLog");
			obj.remove("userMatch");
			obj.remove("userFans");
			obj.remove("userLike");
			obj.remove("userFriend");
			fans.add(obj.toMap());
		}
	}

	return fans;
}
 
开发者ID:hongdong,项目名称:FindMe_Server,代码行数:28,代码来源:UserDaoImpl2Mongo.java

示例4: queryPushUser

import com.mongodb.DBRef; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Map<String, Object> queryPushUser(String sort) {
	// TODO Auto-generated method stub
	DB db = MongoDBUtil.getDB();
	DBCollection users = db.getCollection("puser");

	BasicDBObject user = new BasicDBObject("sort", Integer.parseInt(sort));

	DBObject u = users.findOne(user);
	DBRef puser = (DBRef) u.get("user");
	BasicDBObject obj = (BasicDBObject) puser.fetch();
	obj.remove("userLoginLog");
	obj.remove("userAuthType");
	obj.remove("userEquipment");
	obj.remove("userLastLoginIpAddress");
	obj.remove("userLastLoginTime");
	if (obj != null && obj.isEmpty() == false) {
		return obj.toMap();
	}
	return null;
}
 
开发者ID:hongdong,项目名称:FindMe_Server,代码行数:23,代码来源:UserDaoImpl2Mongo.java

示例5: queryNewsListByRefresh

import com.mongodb.DBRef; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<Map<String, Object>> queryNewsListByRefresh(String userId) {

	List<Map<String, Object>> postList = new ArrayList<Map<String, Object>>();
	BasicDBObject query = new BasicDBObject();
	query.put("users._id", userId);
	query.put("users.isDel", 0);
	BasicDBObject sort = new BasicDBObject();
	sort.put("updateTime", -1);
	List<Map<String, Object>> m = super.findByParams(query, sort,
			CommonVariables.PAGE_SIZE, null);
	for (Map<String, Object> map : m) {

		DBRef dbRef = (DBRef) map.get("post");
		BasicDBObject post = (BasicDBObject) dbRef.fetch();
		post.remove("postMessage");
		Map<String, Object> postMap = post.toMap();
		postMap.put("updateTime", map.get("updateTime"));

		BasicDBList users = (BasicDBList) map.get("users");
		for (int i = 0; i < users.size(); i++) {
			BasicDBObject user = (BasicDBObject) users.get(i);
			String _id = user.getString("_id");
			if (_id.equals(userId)) {
				postMap.put("isRead", user.getString("isRead"));
				break;
			}
		}
		postList.add(postMap);
	}
	return postList;
}
 
开发者ID:hongdong,项目名称:FindMe_Server,代码行数:34,代码来源:NewsDaoImpl2Mongo.java

示例6: queryNewsListByLoadMore

import com.mongodb.DBRef; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<Map<String, Object>> queryNewsListByLoadMore(String userId,
		String newsId) {
	List<Map<String, Object>> postList = new ArrayList<Map<String, Object>>();
	BasicDBObject query = new BasicDBObject();
	query.put("users._id", userId);
	query.put("users.isDel", 0);
	query.put("_id", new BasicDBObject("$lt",newsId));
	
	BasicDBObject sort = new BasicDBObject();
	sort.put("updateTime", -1);
	List<Map<String, Object>> m = super.findByParams(query, sort,
			CommonVariables.PAGE_SIZE, null);
	for (Map<String, Object> map : m) {

		DBRef dbRef = (DBRef) map.get("post");
		BasicDBObject post = (BasicDBObject) dbRef.fetch();
		post.remove("postMessage");
		Map<String, Object> postMap = post.toMap();
		postMap.put("updateTime", map.get("updateTime"));

		BasicDBList users = (BasicDBList) map.get("users");
		for (int i = 0; i < users.size(); i++) {
			BasicDBObject user = (BasicDBObject) users.get(i);
			String _id = user.getString("_id");
			if (_id.equals(userId)) {
				postMap.put("isRead", user.getString("isRead"));
				break;
			}
		}
		postList.add(postMap);
	}
	return postList;
}
 
开发者ID:hongdong,项目名称:FindMe_Server,代码行数:36,代码来源:NewsDaoImpl2Mongo.java

示例7: getResource

import com.mongodb.DBRef; //导入方法依赖的package包/类
@Override
protected MongoObjectResource getResource(DBRef dbRef, boolean byReference) throws ResourceProcessingException {
    if (dbRef != null) {
        if (dbRef.getDB() == null) {
            throw new ResourceProcessingException("Invalid Reference. Reference Database is null.");
        }
        if (dbRef.getDB().getName() != db().getName()) {
            throw new ResourceProcessingException("LiveOak only supports MongoResource objects within the same database.");
        }

        String collectionName = dbRef.getRef();
        if (!db().collectionExists(collectionName)) {
            throw new ResourceProcessingException("Cannot find collection specified in a reference. No collection named '" + collectionName + "' found");
        }

        MongoCollectionResource mongoCollectionResource = new MongoCollectionResource(this, collectionName);

        if (byReference) {

            MongoObjectResource mongoObjectResource = new MongoBaseObjectResource(mongoCollectionResource, dbRef.getId());

            return mongoObjectResource;
        } else {
            DBObject referencedObject = dbRef.fetch();
            if (referencedObject == null) {
                throw new ResourceProcessingException("Cannot find referenced resource. No resource in collection '" + collectionName + "' with id '" + dbRef.getId()
                        + "'");
            }
            return new MongoBaseObjectResource(mongoCollectionResource, referencedObject);
        }
    } else {
        throw new ResourceProcessingException("Invalid Reference. Reference cannot be null.");
    }
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:35,代码来源:RootMongoResource.java

示例8: userMatchInfo

import com.mongodb.DBRef; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Map<String, Object> userMatchInfo(String userMatchId, String userId,
		String type) {
	// TODO Auto-generated method stub
	Map<String, Object> userMap = new HashMap<String, Object>();

	if (type != null && type.equals("2")) {
		// 删除userFans中的用户
		boolean isflag = this.userDao.deleteUserFans(userId, userMatchId);
		userMap.put("fansPass", isflag);

	} else if (type != null && type.equals("1")) {

		// 如果是第一次请求则badge减一
		Integer requestCount = this.userDao
				.updateAddUserRequestCountAndFind(userId);
		if (requestCount == 0) {
			this.userDao.minusUserBadge(userId);
		}

		boolean flag = true;
		if (userMatchId != null && !userMatchId.equals("")) {
			flag = this.userDao.updateUserMatchPass(userId, userMatchId);
			userMap.put("success", flag);
		}
		if (flag) {
			// 查询匹配的用户
			Map<String, Object> user_Map = this.userDao.findOneById(userId);
			Integer userIsLike = 0;
			if (user_Map != null && user_Map.isEmpty() == false) {
				userIsLike = (Integer) user_Map.get("userIsLike");
			}
			if (userIsLike == 0) {
				BasicDBList userMatchs = new BasicDBList();
				Map<String, Object> uMap = this.userDao.findOneById(userId);

				if (uMap != null && uMap.isEmpty() == false) {
					userMatchs = (BasicDBList) uMap.get("userMatch");
				}

				for (int i = 0; i < userMatchs.size(); i++) {
					BasicDBObject userMatch = (BasicDBObject) userMatchs
							.get(i);
					Integer isPass = userMatch.getInt("isPass");
					if (isPass == 1)
						continue;
					else {
						DBRef userDBRef = (DBRef) userMatch.get("user");
						DBObject user = userDBRef.fetch();
						user.removeField("userLoginLog");
						userMap = user.toMap();
						if (userMap != null && userMap.isEmpty() == false) {
							userMap.put("likeToday", uMap.get("userIsLike"));
							userMap.remove("userEquipment");
							userMap.remove("userOpenId");
							userMap.remove("userLastLoginIpAddress");
							userMap.remove("userLoginLog");
							userMap.remove("userMatch");
							userMap.remove("userFans");
							userMap.remove("userLike");
							userMap.remove("userFriend");
						}
						break;
					}
				}
			}
		}
	}

	return userMap;
}
 
开发者ID:hongdong,项目名称:FindMe_Server,代码行数:73,代码来源:UserServiceImpl2Mongo.java


注:本文中的com.mongodb.DBRef.fetch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。