Example usage for com.mongodb BasicDBObjectBuilder start

List of usage examples for com.mongodb BasicDBObjectBuilder start

Introduction

In this page you can find the example usage for com.mongodb BasicDBObjectBuilder start.

Prototype

public static BasicDBObjectBuilder start() 

Source Link

Document

Creates a builder intialized with an empty document.

Usage

From source file:org.apache.rya.mongodb.instance.MongoDetailsAdapter.java

License:Apache License

static DBObject toDBObject(final PCJDetails pcjDetails) {
    requireNonNull(pcjDetails);/*from w w w. j a va2s . co m*/

    final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();

    // PCJ ID
    builder.add(PCJ_ID_KEY, pcjDetails.getId());

    // PCJ Update Strategy if present.
    if (pcjDetails.getUpdateStrategy().isPresent()) {
        builder.add(PCJ_UPDATE_STRAT_KEY, pcjDetails.getUpdateStrategy().get().name());
    }

    // Last Update Time if present.
    if (pcjDetails.getLastUpdateTime().isPresent()) {
        builder.add(PCJ_LAST_UPDATE_KEY, pcjDetails.getLastUpdateTime().get());
    }

    return builder.get();
}

From source file:org.apache.whirr.service.mongodb.MongoDBReplSetMemberClusterActionHandler.java

License:Apache License

/** 
 * Returns a BasicDBObject containing a replica set config object, usable as param to rs.initiate().
 * //from  www . java 2 s  . c  om
 * @param memberInstances   A set containing instances to be included in config object.
 * @throws IOException      Thrown if the private IP of any instance is unavailable
 *
 */
private BasicDBObject generateReplicaSetConfig(Set<Cluster.Instance> memberInstances) throws IOException {
    BasicDBObject returnVal = new BasicDBObject();

    if (this.replicaSetName != null) {
        returnVal.put("_id", this.replicaSetName);
    } else {
        returnVal.put("_id", "whirr");
    }
    int counter = 0;

    ArrayList replicaSetMembers = new ArrayList();
    for (Cluster.Instance member : memberInstances) {
        BasicDBObjectBuilder hostObj = BasicDBObjectBuilder.start().add("_id", counter);
        if (member.getRoles().contains(MongoDBArbiterClusterActionHandler.ROLE)) {
            //it's an arbiter, use port from config file
            hostObj.add("host", member.getPrivateAddress().getHostAddress() + ":" + this.arbiterPort);
            hostObj.add("arbiterOnly", true);
        } else {
            // it's a data member
            hostObj.add("host", member.getPrivateAddress().getHostAddress() + ":" + this.port); // throws an IOExc
        }

        replicaSetMembers.add(hostObj.get());
        counter++;
    }

    returnVal.put("members", replicaSetMembers);
    return returnVal;
}

From source file:org.axonframework.eventhandling.saga.repository.mongo.SagaEntry.java

License:Apache License

/**
 * Returns the Mongo Query to find a Saga based on its identifier.
 *
 * @param identifier The identifier of the saga to find
 * @return the Query (as DBObject) to find a Saga in a Mongo Database
 *///  w  ww  . j a v a  2s  .  c om
public static DBObject queryByIdentifier(String identifier) {
    return BasicDBObjectBuilder.start().add(SAGA_IDENTIFIER, identifier).get();
}

From source file:org.axonframework.eventsourcing.eventstore.mongo.AbstractEventStorageStrategy.java

License:Apache License

@Override
public void deleteSnapshots(DBCollection snapshotCollection, String aggregateIdentifier) {
    DBObject mongoEntry = BasicDBObjectBuilder.start()
            .add(eventConfiguration.aggregateIdentifierProperty(), aggregateIdentifier).get();
    snapshotCollection.find(mongoEntry).forEach(snapshotCollection::remove);
}

From source file:org.axonframework.eventsourcing.eventstore.mongo.AbstractEventStorageStrategy.java

License:Apache License

@Override
public List<? extends DomainEventData<?>> findDomainEvents(DBCollection eventCollection,
        String aggregateIdentifier, long firstSequenceNumber, int batchSize) {
    DBCursor cursor = eventCollection/*from w  w w. j  a v  a 2s . co  m*/
            .find(BasicDBObjectBuilder.start()
                    .add(eventConfiguration().aggregateIdentifierProperty(), aggregateIdentifier)
                    .add(eventConfiguration().sequenceNumberProperty(),
                            new BasicDBObject("$gte", firstSequenceNumber))
                    .get())
            .sort(new BasicDBObject(eventConfiguration().sequenceNumberProperty(), ORDER_ASC));
    cursor = applyBatchSize(cursor, batchSize);
    try {
        return stream(cursor.spliterator(), false).flatMap(this::extractDomainEvents)
                .filter(event -> event.getSequenceNumber() >= firstSequenceNumber).limit(batchSize)
                .collect(Collectors.toList());
    } finally {
        cursor.close();
    }
}

From source file:org.axonframework.eventsourcing.eventstore.mongo.AbstractEventStorageStrategy.java

License:Apache License

@Override
public List<? extends TrackedEventData<?>> findTrackedEvents(DBCollection eventCollection,
        TrackingToken lastToken, int batchSize) {
    DBCursor cursor;/*from  w w  w .  j  ava2s. c  o m*/
    if (lastToken == null) {
        cursor = eventCollection.find(BasicDBObjectBuilder.start().get());
    } else {
        Assert.isTrue(lastToken instanceof LegacyTrackingToken,
                String.format("Token %s is of the wrong type", lastToken));
        LegacyTrackingToken legacyTrackingToken = (LegacyTrackingToken) lastToken;
        cursor = eventCollection.find(BasicDBObjectBuilder.start()
                .add(eventConfiguration.timestampProperty(),
                        new BasicDBObject("$gte", legacyTrackingToken.getTimestamp().toString()))
                .add(eventConfiguration.sequenceNumberProperty(),
                        new BasicDBObject("$gte", legacyTrackingToken.getSequenceNumber()))
                .get());
    }
    cursor = cursor.sort(new BasicDBObject(eventConfiguration().timestampProperty(), ORDER_ASC)
            .append(eventConfiguration().sequenceNumberProperty(), ORDER_ASC));
    cursor = applyBatchSize(cursor, batchSize);
    try {
        return stream(cursor.spliterator(), false).flatMap(this::extractTrackedEvents)
                .filter(event -> event.trackingToken().isAfter(lastToken)).limit(batchSize)
                .collect(Collectors.toList());
    } finally {
        cursor.close();
    }
}

From source file:org.axonframework.eventsourcing.eventstore.mongo.AbstractEventStorageStrategy.java

License:Apache License

@Override
public Optional<? extends DomainEventData<?>> findLastSnapshot(DBCollection snapshotCollection,
        String aggregateIdentifier) {
    DBObject mongoEntry = BasicDBObjectBuilder.start()
            .add(eventConfiguration.aggregateIdentifierProperty(), aggregateIdentifier).get();
    try (DBCursor cursor = snapshotCollection.find(mongoEntry)
            .sort(new BasicDBObject(eventConfiguration.sequenceNumberProperty(), ORDER_DESC)).limit(1)) {
        return stream(cursor.spliterator(), false).findFirst().map(this::extractSnapshot);
    }//ww w  . ja v  a2  s .c  om
}

From source file:org.axonframework.eventsourcing.eventstore.mongo.documentpercommit.CommitEntry.java

License:Apache License

/**
 * Returns the current CommitEntry as a mongo DBObject.
 *
 * @return DBObject representing the CommitEntry
 *//*from   ww  w  .ja  v a  2s. com*/
public DBObject asDBObject(CommitEntryConfiguration commitConfiguration,
        EventEntryConfiguration eventConfiguration) {
    final BasicDBList events = new BasicDBList();
    BasicDBObjectBuilder commitBuilder = BasicDBObjectBuilder.start()
            .add(eventConfiguration.aggregateIdentifierProperty(), aggregateIdentifier)
            .add(eventConfiguration.sequenceNumberProperty(), lastSequenceNumber)
            .add(commitConfiguration.firstSequenceNumberProperty(), firstSequenceNumber)
            .add(commitConfiguration.lastSequenceNumberProperty(), lastSequenceNumber)
            .add(eventConfiguration.timestampProperty(), lastTimestamp)
            .add(commitConfiguration.firstTimestampProperty(), firstTimestamp)
            .add(commitConfiguration.lastTimestampProperty(), lastTimestamp)
            .add(eventConfiguration.typeProperty(), aggregateType)
            .add(commitConfiguration.eventsProperty(), events);
    for (EventEntry eventEntry : eventEntries) {
        events.add(eventEntry.asDBObject(eventConfiguration));
    }
    return commitBuilder.get();
}

From source file:org.axonframework.eventsourcing.eventstore.mongo.documentperevent.EventEntry.java

License:Apache License

/**
 * Returns the current entry as a mongo DBObject.
 *
 * @return DBObject representing the entry
 *///from  w  w  w.j  a v  a  2  s. co m
public DBObject asDBObject(EventEntryConfiguration configuration) {
    return BasicDBObjectBuilder.start().add(configuration.aggregateIdentifierProperty(), aggregateIdentifier)
            .add(configuration.typeProperty(), aggregateType)
            .add(configuration.sequenceNumberProperty(), sequenceNumber)
            .add(configuration.payloadProperty(), serializedPayload)
            .add(configuration.timestampProperty(), timestamp)
            .add(configuration.payloadTypeProperty(), payloadType)
            .add(configuration.payloadRevisionProperty(), payloadRevision)
            .add(configuration.metaDataProperty(), serializedMetaData)
            .add(configuration.eventIdentifierProperty(), eventIdentifier).get();
}

From source file:org.axonframework.eventstore.mongo.DocumentPerCommitStorageStrategy.java

License:Apache License

@Override
public DBCursor findEvents(DBCollection collection, MongoCriteria criteria) {
    DBObject filter = criteria == null ? null : criteria.asMongoObject();
    DBObject sort = BasicDBObjectBuilder.start().add(CommitEntry.TIME_STAMP_PROPERTY, ORDER_ASC)
            .add(CommitEntry.SEQUENCE_NUMBER_PROPERTY, ORDER_ASC).get();
    return collection.find(filter).sort(sort);
}