Package org.bson.types

Examples of org.bson.types.ObjectId


* @author Dennis Oelkers <dennis@torch.sh>
*/
public class MatcherTest {
    protected StreamRule getSampleRule() {
        Map<String, Object> mongoRule = Maps.newHashMap();
        mongoRule.put("_id", new ObjectId());
        mongoRule.put("field", "something");

        return new StreamRuleMock(mongoRule);
    }
View Full Code Here


        this.bundleImporterProvider = bundleImporterProvider;
        this.bundleExporterProvider = bundleExporterProvider;
    }

    public ConfigurationBundle load(final String bundleId) throws NotFoundException {
        final ConfigurationBundle bundle = dbCollection.findOneById(new ObjectId(bundleId));

        if (bundle == null) {
            throw new NotFoundException();
        }
View Full Code Here

        return bundles;
    }

    public ConfigurationBundle update(final String bundleId, final ConfigurationBundle bundle) {
        final WriteResult<ConfigurationBundle, ObjectId> writeResult = dbCollection.updateById(new ObjectId(bundleId), bundle);
        return writeResult.getSavedObject();
    }
View Full Code Here

        final WriteResult<ConfigurationBundle, ObjectId> writeResult = dbCollection.insert(bundle);
        return writeResult.getSavedObject();
    }

    public int delete(String bundleId) {
        return dbCollection.removeById(new ObjectId(bundleId)).getN();
    }
View Full Code Here

    protected final Map<String, Object> fields;
    protected final ObjectId id;

    protected PersistedImpl(Map<String, Object> fields) {
        this(new ObjectId(), fields);
    }
View Full Code Here

                final ImmutableMap.Builder<String, Object> streamRuleData = ImmutableMap.builder();
                streamRuleData.put(StreamRuleImpl.FIELD_TYPE, streamRule.getType().toInteger());
                streamRuleData.put(StreamRuleImpl.FIELD_VALUE, streamRule.getValue());
                streamRuleData.put(StreamRuleImpl.FIELD_FIELD, streamRule.getField());
                streamRuleData.put(StreamRuleImpl.FIELD_INVERTED, streamRule.isInverted());
                streamRuleData.put(StreamRuleImpl.FIELD_STREAM_ID, new ObjectId(streamId));
                streamRuleData.put(StreamRuleImpl.FIELD_CONTENT_PACK, bundleId);

                streamRuleService.save(new StreamRuleImpl(streamRuleData.build()));
            }
        }
View Full Code Here

    protected <T extends Persisted> DBObject get(Class<T> modelClass, ObjectId id) {
        return collection(modelClass).findOne(new BasicDBObject("_id", id));
    }

    protected <T extends Persisted> DBObject get(Class<T> modelClass, String id) {
        return get(modelClass, new ObjectId(id));
    }
View Full Code Here

        return collection(modelClass).count();
    }

    @Override
    public <T extends Persisted> int destroy(T model) {
        return collection(model).remove(new BasicDBObject("_id", new ObjectId(model.getId()))).getN();
    }
View Full Code Here

        if (!errors.isEmpty()) {
            throw new ValidationException(errors);
        }

        BasicDBObject doc = new BasicDBObject(model.getFields());
        doc.put("_id", new ObjectId(model.getId())); // ID was created in constructor or taken from original doc already.

        // Do field transformations
        fieldTransformations(doc);

    /*
         * We are running an upsert. This means that the existing
     * document will be updated if the ID already exists and
     * a new document will be created if it doesn't.
     */
        BasicDBObject q = new BasicDBObject("_id", new ObjectId(model.getId()));
        collection(model).update(q, doc, true, false);

        return model.getId();
    }
View Full Code Here

        Map<String, Object> fields = Maps.newHashMap(o.getPersistedFields());
        fieldTransformations(fields);

        BasicDBObject dbo = new BasicDBObject(fields);
        collection(model).update(new BasicDBObject("_id", new ObjectId(model.getId())), new BasicDBObject("$push", new BasicDBObject(key, dbo)));
    }
View Full Code Here

TOP

Related Classes of org.bson.types.ObjectId

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.