本文整理汇总了Java中com.mongodb.DBRef类的典型用法代码示例。如果您正苦于以下问题:Java DBRef类的具体用法?Java DBRef怎么用?Java DBRef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DBRef类属于com.mongodb包,在下文中一共展示了DBRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: insertUserFans
import com.mongodb.DBRef; //导入依赖的package包/类
@Override
public boolean insertUserFans(String girlId, String boyId) {
// TODO Auto-generated method stub
DB db = MongoDBUtil.getDB();
BasicDBObject girl = new BasicDBObject();
girl.put("_id", girlId);
DBRef boyDbRef = new DBRef(db, "user", boyId);
BasicDBObject update = new BasicDBObject();
update.put("user", boyDbRef);
update.put("isPass", 0);
DBCollection users = db.getCollection(userCollection);
WriteResult res = users.update(girl, new BasicDBObject("$addToSet",
new BasicDBObject("userFans", update)), false, true);
return res.getN() > 0 ? true : false;
}
示例3: insertUserBoyMatch
import com.mongodb.DBRef; //导入依赖的package包/类
@Override
public boolean insertUserBoyMatch(String boyId, String girlId) {
// TODO Auto-generated method stub
DB db = MongoDBUtil.getDB();
BasicDBObject boy = new BasicDBObject();
boy.put("_id", boyId);
DBRef girlDbRef = new DBRef(db, "user", girlId);
BasicDBObject update = new BasicDBObject();
update.put("user", girlDbRef);
update.put("isPass", 0);
DBCollection users = db.getCollection(userCollection);
WriteResult res = users.update(boy, new BasicDBObject("$addToSet",
new BasicDBObject("userMatch", update)), false, true);
return res.getN() > 0 ? true : false;
}
示例4: 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());
}
示例5: getDBRef
import com.mongodb.DBRef; //导入依赖的package包/类
@Override
protected DBRef getDBRef(String uri) throws ResourceProcessingException {
if (uri != null) {
String rootURI = this.uri().toString();
if (uri.startsWith(rootURI + "/")) {
String resourcePath = uri.substring(rootURI.length());
String[] paths = resourcePath.split("/");
if (paths.length != 3) {
throw new ResourceProcessingException("$DBRefs must be in the format /rootContextPath/collectionName/resourceID");
} else {
String collectionName = paths[1];
String resourceID = paths[2];
return new DBRef(this.db(), collectionName, resourceID);
}
} else {
throw new ResourceProcessingException("$DBRefs are only supported under the same context root. URL specified ('" + uri + "')should start with " + rootURI
+ ".");
}
} else {
throw new ResourceProcessingException("$DBRefs must be URL, they cannot be null.");
}
}
示例6: member
import com.mongodb.DBRef; //导入依赖的package包/类
@Override
public Resource member(RequestContext ctx, String id) throws Exception {
Object object = getDBObject().get(id);
if (object == null) {
return null;
}
if (object != null) {
if (object instanceof BasicDBObject || object instanceof BasicDBList) {
return null;
} else if (object instanceof DBRef) {
// TODO In case of exception make sure it results in InvalidRequest
//try {
return getResource((DBRef) object, ctx.returnFields().child(id).isEmpty());
//} catch (ResourceProcessingException e) {
// responder.invalidRequest(e.getMessage());
//}
} else {
throw new RuntimeException("ERROR: Object type (" + object.getClass() + ") not recognized");
}
}
return null;
}
示例7: member
import com.mongodb.DBRef; //导入依赖的package包/类
@Override
public Resource member(RequestContext ctx, String id) throws Exception {
Object object = getDBObject().get(id);
if (object != null) {
if (object instanceof BasicDBObject || object instanceof BasicDBList) {
return null;
} else if (object instanceof DBRef) {
//try {
// TODO throw exception that will end up as InvalidRequest
return getResource((DBRef) object, ctx.returnFields().child(id).isEmpty());
//} catch (ResourceProcessingException e) {
// responder.invalidRequest(e.getMessage());
//}
} else {
// TODO throw exception that will end up as InternalError
//responder.internalError("ERROR: Object type (" + object.getClass() + ") not recognized");
throw new RuntimeException("ERROR: Object type (" + object.getClass() + ") not recognized");
}
}
return null;
}
示例8: properties
import com.mongodb.DBRef; //导入依赖的package包/类
@Override
public Map<String, ?> properties(RequestContext ctx) throws Exception {
// TODO: only read properties specified in the return fields and not everything
Map<String, Object> result = new HashMap<>();
Set<String> keys = getDBObject().keySet();
for (String key : keys) {
if (!key.equals(MONGO_ID_FIELD) && !key.equals(LiveOak.ID)) {
Object value = getDBObject().get(key);
if (value instanceof BasicDBObject) {
value = new MongoEmbeddedObjectResource(this, (DBObject) value);
} else if (value instanceof BasicDBList) {
value = getResourceCollection(value);
} else if (value instanceof DBRef) {
value = getResource((DBRef) value, ctx.returnFields().child(key).isEmpty());
}
if (supportedObject(value)) {
result.put(key, value);
} else {
log.warn("Unsupported Property type " + value.getClass() + " cannot encode.");
}
}
}
return result;
}
示例9: getResourceCollection
import com.mongodb.DBRef; //导入依赖的package包/类
protected Object getResourceCollection(Object object) throws Exception {
if (object instanceof BasicDBObject) {
return new MongoEmbeddedObjectResource(this, (DBObject) object);
} else if (object instanceof BasicDBList) {
BasicDBList dbList = ((BasicDBList) object);
ArrayList list = new ArrayList();
for (int i = 0; i < dbList.size(); i++) {
Object child = dbList.get(i);
list.add(getResourceCollection(child));
}
return list;
} else if (object instanceof DBRef) {
return getResource((DBRef) object, true);
} else {
return object;
}
}
示例10: matches
import com.mongodb.DBRef; //导入依赖的package包/类
private DBObject matches(StatisticsFilter request) {
BasicDBObjectBuilder b = new BasicDBObjectBuilder();
BasicDBObjectBuilder match = b.push(Ops.MATCH);
if (request.hasTrack()) {
DBRef track = mongoDB.ref(request.getTrack());
match.add(MongoMeasurement.TRACK, track);
}
if (request.hasUser()) {
DBRef user = mongoDB.ref(request.getUser());
match.add(MongoMeasurement.USER, user);
}
if (request.hasSensor()) {
MongoSensor sensor = (MongoSensor) request.getSensor();
match.add(SENSOR_ID_PATH, sensor.getId());
}
return b.get();
}
示例11: keyToDBRef
import com.mongodb.DBRef; //导入依赖的package包/类
/**
* Converts a Key to a DBRef
*
* @param key the Key to convert
* @return the DBRef
*/
public DBRef keyToDBRef(final Key key) {
if (key == null) {
return null;
}
if (key.getType() == null && key.getCollection() == null) {
throw new IllegalStateException("How can it be missing both?");
}
if (key.getCollection() == null) {
key.setCollection(getCollectionName(key.getType()));
}
Object id = key.getId();
if (isMapped(id.getClass())) {
id = toMongoObject(id, true);
}
return new DBRef(key.getCollection(), id);
}
示例12: decode
import com.mongodb.DBRef; //导入依赖的package包/类
@Override
public Object decode(final Class targetClass, final Object o, final MappedField optionalExtraInfo) {
if (o == null) {
return null;
}
if (!(o instanceof DBRef)) {
throw new ConverterException(String.format("cannot convert %s to Key because it isn't a DBRef", o.toString()));
}
DBRef ref = (DBRef) o;
MappedField actualType = getActualType(optionalExtraInfo);
final Class<?> keyType = actualType != null
? actualType.getConcreteType()
: getMapper().getClassFromCollection(ref.getCollectionName());
final Key<?> key = new Key<Object>(keyType, ref.getCollectionName(), ref.getId());
return key;
}
示例13: getDBRef
import com.mongodb.DBRef; //导入依赖的package包/类
public DBRef getDBRef(DB db, boolean push) {
if (this.id != null) {
if (this.idReference != null) {
return new DBRef(db, push?this.parentTable:this.embeddedTable, new DBRef(db, this.idReference, this.id.getValue()));
}
return new DBRef(db, push?this.parentTable:this.embeddedTable, this.id.getValue());
}
return null;
}
示例14: getEmbeddedDocument
import com.mongodb.DBRef; //导入依赖的package包/类
public DBObject getEmbeddedDocument(DB mongoDB, String docName) {
for (MergeDetails ref:this.embeddedKeys) {
if (ref.getName().equals(docName)) {
DBRef dbRef = ref.getDBRef(mongoDB, false);
if (dbRef != null) {
return mongoDB.getCollection(dbRef.getRef()).findOne(new BasicDBObject("_id", dbRef.getId())); //$NON-NLS-1$
}
}
}
return null;
}
示例15: getRowValue
import com.mongodb.DBRef; //导入依赖的package包/类
private Object getRowValue(Expression obj) throws TranslatorException {
if (!(obj instanceof ColumnReference)) {
throw new TranslatorException(MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18017));
}
ColumnReference column = (ColumnReference)obj;
Object value = null;
if (MongoDBSelectVisitor.isPartOfPrimaryKey(column.getTable().getMetadataObject(), column.getName())) {
// this is true one to many case
value = this.row.get("_id"); //$NON-NLS-1$
if (value == null) {
value = getValueFromRowInfo(column, value);
}
}
if (value == null && MongoDBSelectVisitor.isPartOfForeignKey(column.getTable().getMetadataObject(), column.getName())) {
value = getValueFromRowInfo(column, value);
}
if (value == null) {
value = this.row.get(column.getName());
}
if (value instanceof DBRef) {
value = ((DBRef)value).getId();
}
if (value instanceof DBObject) {
value = ((DBObject) value).get(column.getName());
}
return this.executionFactory.retrieveValue(value, column.getType(), this.mongoDB, column.getName(), column.getName());
}