Package com.mongodb

Examples of com.mongodb.DBRef


        } else if (value instanceof Calendar) {
            writeDateTime(((Calendar) value).getTime());
        } else if (value instanceof ObjectId) {
            writeObjectId(ObjectIdConvertor.convert((ObjectId) value));
        } else if (value instanceof DBRef) {
            DBRef dbRef = (DBRef) value;
            writeStartObject();
            writeFieldName("$ref");
            writeString(dbRef.getRef());
            writeFieldName("$id");
            writeObject(dbRef.getId());
            if (dbRef.getDB() != null) {
                writeFieldName("$db");
                writeString(dbRef.getDB().getName());
            }
            writeEndObject();
        } else {
            super._writeSimpleObject(value);
        }
View Full Code Here


        }
        String ns = getStringFieldValue(Item.namespace);
        if (ns.trim().isEmpty()) {
            return id;
        }
        return new DBRef(null, ns, id);
    }
View Full Code Here

        } else if (value instanceof Calendar) {
            writeDateTime(((Calendar) value).getTime());
        } else if (value instanceof ObjectId) {
            writeObjectId(ObjectIdConvertor.convert((ObjectId) value));
        } else if (value instanceof DBRef) {
            DBRef dbRef = (DBRef) value;
            writeStartObject();
            writeFieldName("$ref");
            writeString(dbRef.getRef());
            writeFieldName("$id");
            writeObject(dbRef.getId());
            if (dbRef.getDB() != null) {
                writeFieldName("$db");
                writeString(dbRef.getDB().getName());
            }
            writeEndObject();
        } else {
            super._writeSimpleObject(value);
        }
View Full Code Here

     * @return
     */
    public <T, V> DBRef createRef(Class<T> clazz, V id) {
        if (id == null)
            throw new MappingException("Could not get id for " + clazz.getName());
        return new DBRef(getDB(), getCollection(clazz).getName(), id);
    }
View Full Code Here

    private void writeSingle(DBObject dbObject, String name, Object fieldValue, Mapper mapr) {
        if (fieldValue == null)
            if (mapr.getOptions().storeNulls)
                dbObject.put(name, null);

        DBRef dbrefFromKey = mapr.keyToRef(getKey(fieldValue, mapr));
        dbObject.put(name, dbrefFromKey);
    }
View Full Code Here

    private void readSingle(final DBObject dbObject, final MappedField mf, final Object entity, Class fieldType,
                            Reference refAnn, EntityCache cache, Mapper mapr) {
        Class referenceObjClass = fieldType;

        DBRef dbRef = (DBRef) mf.getDbObjectValue(dbObject);
        if (dbRef != null) {
            Object resolvedObject = null;
            if (refAnn.lazy() && LazyFeatureDependencies.assertDependencyFullFilled()) {
                if (exists(referenceObjClass, dbRef, cache, mapr)) {
                    resolvedObject = createOrReuseProxy(referenceObjClass, dbRef, cache, mapr);
                } else {
                    if (!refAnn.ignoreMissing()) {
                        throw new MappingException("The reference(" + dbRef.toString() + ") could not be fetched for "
                                + mf.getFullName());
                    }
                }
            } else {
                resolvedObject = resolveObject(dbRef, mf, cache, mapr);
View Full Code Here

                            log.warning(msg);
                    }

                    referencesAsProxy.__addAll(keys);
                } else {
                    DBRef dbRef = (DBRef) dbVal;
                    if (!exists(mf.getSubClass(), dbRef, cache, mapr)) {
                        String msg = "The reference(" + dbRef.toString() + ") could not be fetched for "
                                + mf.getFullName();
                        if (!refAnn.ignoreMissing())
                            throw new MappingException(msg);
                        else
                            log.warning(msg);
                    } else {
                        referencesAsProxy.__add(mapr.refToKey(dbRef));
                    }
                }
            }
        } else {
            Object dbVal = mf.getDbObjectValue(dbObject);
            final Collection refs = references;
            new IterHelper<String, Object>().loopOrSingle((Object) dbVal, new IterCallback<Object>() {
                @Override
                public void eval(Object val) {
                    DBRef dbRef = (DBRef) val;
                    Object ent = resolveObject(dbRef, mf, cache, mapr);
                    if (ent == null)
                        log.warning("Null reference found when retrieving value for " + mf.getFullName());
                    else
                        refs.add(ent);
View Full Code Here

            final Map map = m;
            new IterHelper<Object, Object>().loopMap(dbVal, new MapIterCallback<Object, Object>() {
                @Override
                public void eval(Object key, Object val) {
                    DBRef dbRef = (DBRef) val;

                    Object objKey = mapr.getConverters().decode(mf.getMapKeyClass(), key);

                    if (refAnn.lazy() && LazyFeatureDependencies.assertDependencyFullFilled()) {
                        ProxiedEntityReferenceMap proxiedMap = (ProxiedEntityReferenceMap) map;
View Full Code Here

        if (key.getKindClass() == null && key.getKind() == null)
            throw new IllegalStateException("How can it be missing both?");
        if (key.getKind() == null)
            key.setKind(getCollectionName(key.getKindClass()));

        return new DBRef(null, key.getKind(), toMongoObject(key.getId(), false));
    }
View Full Code Here

      MongoPersistentEntity<?> entity, Object id) {

    DB db = mongoDbFactory.getDb();
    db = annotation != null && StringUtils.hasText(annotation.db()) ? mongoDbFactory.getDb(annotation.db()) : db;

    return new DBRef(db, entity.getCollection(), id);
  }
View Full Code Here

TOP

Related Classes of com.mongodb.DBRef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.