Examples of BasicDBObjectBuilder


Examples of com.mongodb.BasicDBObjectBuilder

    public void ensureCaps() {
        for (MappedClass mc : mapr.getMappedClasses()) {
            CappedAt cap = mc.getCappedAt();
            if (cap != null && cap.value() > 0) {
                String collName = mapr.getCollectionName(mc.getClazz());
                BasicDBObjectBuilder dbCapOpts = BasicDBObjectBuilder.start("capped", true);
                if (cap.value() > 0)
                    dbCapOpts.add("size", cap.value());
                if (cap.count() > 0)
                    dbCapOpts.add("max", cap.count());
                DB db = getDB();
                if (db.getCollectionNames().contains(collName)) {
                    DBObject dbResult = db.command(BasicDBObjectBuilder.start("collstats", collName).get());
                    if (dbResult.containsField("capped")) {
                        // TODO: check the cap options.
                        log.warning("DBCollection already exists is cap'd already; doing nothing. " + dbResult);
                    } else {
                        log.warning("DBCollection already exists with same name(" + collName
                                + ") and is not cap'd; not creating cap'd version!");
                    }
                } else {
                    getDB().createCollection(collName, dbCapOpts.get());
                    log.debug("Created cap'd DBCollection (" + collName + ") with opts " + dbCapOpts);
                }
            }
        }
    }
View Full Code Here

Examples of com.mongodb.BasicDBObjectBuilder

    public void setCoveringFields(Map<String, IndexDirection> coveringFields) {
        this.coveringFields = coveringFields;
    }

    public DBObject getKeys() {
        BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(super.getKeys().toMap());

        for (Map.Entry<String, IndexDirection> entry : coveringFields.entrySet()) {
            builder.add(entry.getKey(), entry.getValue().toIndexValue());
        }

        return builder.get();
    }
View Full Code Here

Examples of com.mongodb.BasicDBObjectBuilder

    public void setFilteredFields(Map<String, IndexDirection> filteredFields) {
        this.filteredFields = filteredFields;
    }

    public DBObject getKeys() {
        BasicDBObjectBuilder keys = new BasicDBObjectBuilder();
        for (Map.Entry<String, IndexDirection> entry : filteredFields.entrySet()) {
            keys.add(entry.getKey(), entry.getValue().toIndexValue());
        }

        DBObject compoundFields = keys.get();

        compoundFields.putAll(super.getKeys());
        return compoundFields;
    }
View Full Code Here

Examples of com.mongodb.BasicDBObjectBuilder

    public void setIndexSpecificFields() {
        this.indexAllFields = false;
    }

    public DBObject getKeys() {
        BasicDBObjectBuilder builder = new BasicDBObjectBuilder();

        if (indexAllFields) {
            builder.add(WILDCARD, CMD);
        } else {
            addFieldsTo(builder);
        }

        return builder.get();
    }
View Full Code Here

Examples of com.mongodb.BasicDBObjectBuilder

        return builder.get();
    }

    public DBObject getOptions() {
        BasicDBObjectBuilder builder = new BasicDBObjectBuilder();

        if (name != null && !name.isEmpty()) {
            builder.add(INDEX_NAME, name);
        }

        if (defaultLanguage != null && !defaultLanguage.isEmpty()) {
            builder.add(DEFAULT_LANGUAGE, defaultLanguage);
        }

        if (languageOverride != null && !languageOverride.isEmpty()) {
            builder.add(LANGUAGE_OVERRIDE, languageOverride);
        }
        if (weights !=  null && !weights.isEmpty()) {
            builder.add(WEIGHTS, weights);
        }

        return builder.get();
    }
View Full Code Here

Examples of com.mongodb.BasicDBObjectBuilder

         *
         * @return DBObject representing the CommitEntry
         */
        public DBObject asDBObject() {
            final BasicDBList events = new BasicDBList();
            BasicDBObjectBuilder commitBuilder = BasicDBObjectBuilder.start()
                                                                     .add(AGGREGATE_IDENTIFIER_PROPERTY,
                                                                          aggregateIdentifier)
                                                                     .add(SEQUENCE_NUMBER_PROPERTY, firstSequenceNumber)
                                                                     .add(LAST_SEQUENCE_NUMBER_PROPERTY,
                                                                          lastSequenceNumber)
                                                                     .add(FIRST_SEQUENCE_NUMBER_PROPERTY,
                                                                          firstSequenceNumber)
                                                                     .add(TIME_STAMP_PROPERTY, firstTimestamp)
                                                                     .add(FIRST_TIME_STAMP_PROPERTY, firstTimestamp)
                                                                     .add(LAST_TIME_STAMP_PROPERTY, lastTimestamp)
                                                                     .add(AGGREGATE_TYPE_PROPERTY, aggregateType)
                                                                     .add(EVENTS_PROPERTY, events);

            for (EventEntry eventEntry : eventEntries) {
                events.add(eventEntry.asDBObject());
            }
            return commitBuilder.get();
        }
View Full Code Here

Examples of com.mongodb.BasicDBObjectBuilder

        public DateTime getTimestamp() {
            return new DateTime(timestamp);
        }

        public DBObject asDBObject() {
            final BasicDBObjectBuilder entryBuilder = BasicDBObjectBuilder.start();
            return entryBuilder.add(SERIALIZED_PAYLOAD_PROPERTY, serializedPayload)
                               .add(PAYLOAD_TYPE_PROPERTY, payloadType)
                               .add(PAYLOAD_REVISION_PROPERTY, payloadRevision)
                               .add(EVENT_TIMESTAMP_PROPERTY, timestamp)
                               .add(EVENT_SEQUENCE_NUMBER_PROPERTY, sequenceNumber)
                               .add(META_DATA_PROPERTY, serializedMetaData)
View Full Code Here

Examples of com.mongodb.BasicDBObjectBuilder

         * e.g. Not double converting the timestamp, and skipping string
         * encoding/decoding the message body
         */
        // Would it work to use Timestamp + Nanos + Hostname as the ID or is
        // there still a collision chance?
        BasicDBObjectBuilder b = BasicDBObjectBuilder.start("timestamp", new Date(e.getTimestamp()));
        b.append("nanoseconds", e.getNanos());
        b.append("hostname", e.getHost());
        b.append("priority", e.getPriority().name());
        b.append("message", new String(e.getBody()));
        b.append("metadata", new BasicDBObject(e.getAttrs()));
        collection.insert(b.get());
    }
View Full Code Here

Examples of com.mongodb.BasicDBObjectBuilder

        } catch (Exception e) {
            throw new IllegalArgumentException("Invalid Schema Format");
        }

        // Make Tuple t into BSONObject using schema provided and store result in pObj
        final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
        for (int i = 0; i < fields.length; i++) {
            writeField(builder, fields[i], t.get(i));
        }
        // BSONObject that represents Pig Tuple input using Pig Schema
        BasicBSONObject pObj = (BasicBSONObject) builder.get();

        // fill map of replacement strings to corresponding objects to replace these strings with
        fillReplacementMap(pObj);

        // Now, replace replacement strings (of form $elem) with corresponding objects in pObj     
View Full Code Here

Examples of com.mongodb.BasicDBObjectBuilder

    }

    @Override
    public void putNext(final Tuple tuple) throws IOException {
        try {
            final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
            ResourceFieldSchema[] fields = null;
            if (schema != null) {
                fields = schema.getFields();
            }
            if (fields != null) {
                for (int i = 0; i < fields.length; i++) {
                    writeField(builder, fields[i], tuple.get(i));
                }
            } else {
                for (int i = 0; i < tuple.size(); i++) {
                    writeField(builder, null, tuple.get(i));
                }
            }

            out.write(null, builder.get());
        } catch (Exception e) {
            throw new IOException("Couldn't convert tuple to bson: ", e);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.