Example usage for com.mongodb BasicDBList BasicDBList

List of usage examples for com.mongodb BasicDBList BasicDBList

Introduction

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

Prototype

BasicDBList

Source Link

Usage

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
 *///  w  w  w .  j a  va  2 s  .  c o m
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.eventstore.mongo.criteria.And.java

License:Apache License

@Override
public DBObject asMongoObject() {
    BasicDBList value = new BasicDBList();
    value.add(criteria1.asMongoObject());
    value.add(criteria2.asMongoObject());
    return new BasicDBObject("$and", value);
}

From source file:org.axonframework.mongo.serialization.BSONNode.java

License:Apache License

/**
 * Returns the current BSON structure as DBObject.
 *
 * @return the current BSON structure as DBObject
 *///from  w  w  w  .ja  v a  2 s  . c  o m
public DBObject asDBObject() {
    if (childNodes.isEmpty() && value != null) {
        // only a value
        return new BasicDBObject(encodedName, value);
    } else if (childNodes.size() == 1 && value == null) {
        return new BasicDBObject(encodedName, childNodes.get(0).asDBObject());
    } else {
        BasicDBList subNodes = new BasicDBList();
        BasicDBObject thisNode = new BasicDBObject(encodedName, subNodes);
        if (value != null) {
            subNodes.add(new BasicDBObject(VALUE_KEY, value));
        }
        subNodes.addAll(childNodes.stream().map(BSONNode::asDBObject).collect(Collectors.toList()));
        return thisNode;
    }
}

From source file:org.axonframework.serialization.bson.BSONNode.java

License:Apache License

/**
 * Returns the current BSON structure as DBObject.
 *
 * @return the current BSON structure as DBObject
 *///from  w w w  . ja va 2s .  c  o  m
public DBObject asDBObject() {
    if (childNodes.isEmpty() && value != null) {
        // only a value
        return new BasicDBObject(encodedName, value);
    } else if (childNodes.size() == 1 && value == null) {
        return new BasicDBObject(encodedName, childNodes.get(0).asDBObject());
    } else {
        BasicDBList subNodes = new BasicDBList();
        BasicDBObject thisNode = new BasicDBObject(encodedName, subNodes);
        if (value != null) {
            subNodes.add(new BasicDBObject(VALUE_KEY, value));
        }
        for (BSONNode childNode : childNodes) {
            subNodes.add(childNode.asDBObject());
        }
        return thisNode;
    }
}

From source file:org.bigmouth.nvwa.log4mongo.LoggingEventBsonifierImpl.java

License:Apache License

/**
 * Adds the ThrowableInformation object to an existing BSON object.
 * /*from w w  w .jav  a2s.  c o m*/
 * @param bson
 *            The BSON object to add the throwable info to <i>(must not be null)</i>.
 * @param throwableInfo
 *            The ThrowableInformation object to add to the BSON object <i>(may be null)</i>.
 */
@SuppressWarnings(value = "unchecked")
protected void addThrowableInformation(DBObject bson, final ThrowableInformation throwableInfo) {
    if (throwableInfo != null) {
        Throwable currentThrowable = throwableInfo.getThrowable();
        List throwables = new BasicDBList();

        while (currentThrowable != null) {
            DBObject throwableBson = bsonifyThrowable(currentThrowable);

            if (throwableBson != null) {
                throwables.add(throwableBson);
            }

            currentThrowable = currentThrowable.getCause();
        }

        if (throwables.size() > 0) {
            bson.put(KEY_THROWABLES, throwables);
        }
    }
}

From source file:org.bigmouth.nvwa.log4mongo.LoggingEventBsonifierImpl.java

License:Apache License

/**
 * BSONifies the given stack trace.//from  ww w  . j  a v  a2  s . co m
 * 
 * @param stackTrace
 *            The stack trace object to BSONify <i>(may be null)</i>.
 * @return The BSONified equivalent of the stack trace object <i>(may be null)</i>.
 */
protected DBObject bsonifyStackTrace(final StackTraceElement[] stackTrace) {
    BasicDBList result = null;

    if (stackTrace != null && stackTrace.length > 0) {
        result = new BasicDBList();

        for (StackTraceElement element : stackTrace) {
            DBObject bson = bsonifyStackTraceElement(element);

            if (bson != null) {
                result.add(bson);
            }
        }
    }

    return (result);
}

From source file:org.bigmouth.nvwa.log4mongo.LoggingEventBsonifierImpl.java

License:Apache License

/**
 * BSONifies the given class name./*from   ww w.  j a v  a 2 s.c  o m*/
 * 
 * @param className
 *            The class name to BSONify <i>(may be null)</i>.
 * @return The BSONified equivalent of the class name <i>(may be null)</i>.
 */
@SuppressWarnings(value = "unchecked")
protected DBObject bsonifyClassName(final String className) {
    DBObject result = null;

    if (className != null && className.trim().length() > 0) {
        result = new BasicDBObject();

        result.put(KEY_FQCN, className);

        List packageComponents = new BasicDBList();
        String[] packageAndClassName = className.split("\\.");

        packageComponents.addAll(Arrays.asList(packageAndClassName));
        // Requires Java 6
        // packageComponents.addAll(Arrays.asList(Arrays.copyOf(packageAndClassName,
        // packageAndClassName.length - 1)));

        // TODO Allen
        //            if (packageComponents.size() > 0) {
        //                result.put(KEY_PACKAGE, packageComponents);
        //            }

        result.put(KEY_CLASS_NAME, packageAndClassName[packageAndClassName.length - 1]);
    }

    return (result);
}

From source file:org.breizhbeans.thrift.tools.thriftmongobridge.protocol.TBSONUnstackedProtocol.java

License:Apache License

@Override
public void writeListBegin(TList tList) throws TException {
    //System.out.println("writeListBegin");
    // Replace the BasicDbObject by a DBList
    threadSafeSIOStack.get().push(new ThriftIO(null, new BasicDBList(), null, false, true));
}

From source file:org.breizhbeans.thrift.tools.thriftmongobridge.protocol.TBSONUnstackedProtocol.java

License:Apache License

@Override
public void writeSetBegin(TSet tSet) throws TException {
    //System.out.println("writeSetBegin");
    // Replace the BasicDbObject by a DBList
    threadSafeSIOStack.get().push(new ThriftIO(null, new BasicDBList(), null, false, true));
}

From source file:org.codinjutsu.tools.mongo.view.model.JsonTreeModel.java

License:Apache License

private static DBObject buildDBList(JsonTreeNode parentNode) {
    BasicDBList basicDBList = new BasicDBList();
    Enumeration children = parentNode.children();
    while (children.hasMoreElements()) {
        JsonTreeNode node = (JsonTreeNode) children.nextElement();
        MongoValueDescriptor descriptor = (MongoValueDescriptor) node.getDescriptor();
        Object value = descriptor.getValue();
        if (value instanceof DBObject) {
            if (value instanceof BasicDBList) {
                basicDBList.add(buildDBList(node));
            } else {
                basicDBList.add(buildDBObject(node));
            }//from www.  j  a  va  2s .com
        } else {
            basicDBList.add(value);
        }
    }
    return basicDBList;
}