Example usage for com.mongodb DBObject toMap

List of usage examples for com.mongodb DBObject toMap

Introduction

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

Prototype

Map toMap();

Source Link

Document

Returns a map representing this BSONObject.

Usage

From source file:org.iternine.jeppetto.dao.mongodb.MongoDBSessionCache.java

License:Apache License

public void put(DBObject key, Object object) {
    //noinspection unchecked
    objectCache.put(flatten(key.toMap()), new WeakReference(object));
}

From source file:org.iternine.jeppetto.dao.mongodb.MongoDBSessionCache.java

License:Apache License

public Object get(DBObject key) {
    //noinspection unchecked
    Map<String, String> flattenedKey = flatten(key.toMap());
    WeakReference reference = objectCache.get(flattenedKey);

    if (reference == null) {
        return null;
    }//from   ww  w  . j  a  v  a  2s.co m

    if (reference.get() == null) {
        objectCache.remove(flattenedKey);

        return null;
    }

    return reference.get();
}

From source file:org.iternine.jeppetto.dao.mongodb.projections.CountCommand.java

License:Apache License

private static DBObject addFieldExistsCriterion(DBObject query, String field) {
    return new BasicDBObject(query.toMap()).append(field, new BasicDBObject("$exists", true));
}

From source file:org.jwebsocket.jms.mongodb.MongoDBConsumerAdviceTempStorage.java

License:Apache License

@Override
public Map<String, String> getData(String aCorrelationId) throws Exception {
    DBObject lRecord = mCollection
            .findOne(new BasicDBObject().append(Attributes.CORRELATION_ID, aCorrelationId));
    if (null == lRecord) {
        return null;
    }//  w ww .  j a  va2  s  .  c  om
    mCollection.remove(lRecord);

    return lRecord.toMap();
}

From source file:org.jwebsocket.plugins.monitoring.MonitoringPlugIn.java

License:Apache License

/**
 *
 * @param aConnector/*  ww  w  .  j a  v a2s  .com*/
 */
public void broadcastServerXchgInfo(WebSocketConnector aConnector) {
    Token lToken = TokenFactory.createToken(getNamespace(), TT_SERVER_XCHG_INFO);

    //Getting server exchanges
    try {
        String lToday = mFormat.format(new Date());
        DBObject lRecord = mDBExchanges.findOne(new BasicDBObject().append(DATE, lToday));
        lToken.setMap(EXCHANGES, lRecord.toMap());

    } catch (Exception ex) {
        mLog.error(ex.getMessage());
    }

    getServer().sendToken(aConnector, lToken);
}

From source file:org.jwebsocket.plugins.monitoring.MonitoringPlugIn.java

License:Apache License

/**
 *
 * @param aConnector//from   w  ww  .j  a va2 s  .  co m
 * @param aDay
 * @param aMonth
 * @param aYear
 */
public void broadcastServerXchgInfoPreviousDate(WebSocketConnector aConnector, String aDay, String aMonth,
        String aYear) {
    Token token = TokenFactory.createToken(getNamespace(), TT_SERVER_XCHG_INFO);
    //Getting server exchanges
    try {
        String lToday = aMonth + "/" + aDay + "/" + aYear;

        DBObject lRecord = mDBExchanges.findOne(new BasicDBObject().append(DATE, lToday));

        token.setMap(EXCHANGES, lRecord.toMap());

    } catch (Exception ex) {
        mLog.error(ex.getMessage());
    }

    getServer().sendToken(aConnector, token);

}

From source file:org.jwebsocket.plugins.quota.storage.StorageQuotaMongo.java

License:Apache License

/**
 *
 * @param aUuid/*w  w w. j a v a  2s .  com*/
 * @param aInstance
 * @return
 */
@Override
public Map<String, Object> getRawQuota(String aUuid, String aInstance) {

    BasicDBObject lObject = new BasicDBObject();
    BasicDBObject lObjectInstance = new BasicDBObject();
    lObject.put("uuid", aUuid);
    lObjectInstance.put("uuidquota", aUuid);
    lObjectInstance.put("instance", aInstance);
    DBObject lQuery = mCollection.findOne(lObject);

    DBObject lQueryInstance = mCollectionInstance.findOne(lObjectInstance);
    Map<String, Object> lMap = lQuery.toMap();
    lMap.put("instance", lQueryInstance.get("instance"));
    lMap.put("instanceType", lQueryInstance.get("instanceType"));
    return lMap;
}

From source file:org.log4mongo.MongoDbPatternLayoutAppender.java

License:Apache License

/**
 * Inserts a BSON representation of a LoggingEvent into a MongoDB collection. A PatternLayout is
 * used to format a JSON document containing data available in the LoggingEvent and, optionally,
 * additional data returned by custom PatternConverters.
 * <p>/*w  w  w.java  2  s .  c o m*/
 * The format of the JSON document is specified in the .layout.ConversionPattern property.
 *
 * @param loggingEvent
 *            The LoggingEvent that will be formatted and stored in MongoDB
 */
@Override
protected void append(final LoggingEvent loggingEvent) {
    if (isInitialized()) {
        DBObject bson = null;
        String json = layout.format(loggingEvent);

        if (json.length() > 0) {
            Object obj = JSON.parse(json);
            if (obj instanceof DBObject) {
                bson = (DBObject) obj;
            }
        }

        if (bson != null) {
            try {
                getCollection().insertOne(new Document(bson.toMap()));
            } catch (MongoException e) {
                errorHandler.error("Failed to insert document to MongoDB", e, ErrorCode.WRITE_FAILURE);
            }
        }
    }
}

From source file:org.mandar.analysis.recsys2014.models.NeoMongoDBDataModel.java

License:Apache License

/**
 * <p>/*from w  w w.  j ava2s . c  o m*/
 * Translates the MongoDB identifier to Mahout/MongoDBDataModel's internal
 * identifier, if required.
 * </p>
 * <p>
 * If MongoDB identifiers are long datatypes, it returns the id.
 * </p>
 * <p>
 * This conversion is needed since Mahout uses the long datatype to feed the
 * recommender, and MongoDB uses 12 bytes to create its identifiers.
 * </p>
 *
 * @param id     MongoDB identifier
 * @param isUser
 * @return String containing the translation of the external MongoDB ID to
 *         internal long ID (mapping).
 * @see #fromLongToId(long)
 * @see <a href="http://www.mongodb.org/display/DOCS/Object%20IDs">
 *      Mongo Object IDs</a>
 */
public String fromIdToLong(String id, boolean isUser) {
    DBObject objectIdLong = collectionMap.findOne(new BasicDBObject("element_id", id));
    if (objectIdLong != null) {
        Map<String, Object> idLong = (Map<String, Object>) objectIdLong.toMap();
        Object value = idLong.get("long_value");
        return value == null ? null : value.toString();
    } else {
        objectIdLong = new BasicDBObject();
        String longValue = Long.toString(idCounter++);
        objectIdLong.put("element_id", id);
        objectIdLong.put("long_value", longValue);
        collectionMap.insert(objectIdLong);
        log.info("Collection: {} Adding Translation {}: {} long_value: {}", collectionMap.getName(),
                isUser ? "User ID" : "Item ID", id, longValue);
        return longValue;
    }
}

From source file:org.mongoj.samples.service.persistence.CarPersistenceImpl.java

License:Open Source License

protected Car getDocument(DBObject dbObject) throws SystemException {
    if (dbObject == null) {
        return null;
    }/*from   w  w  w. j  a  v a2  s  .c  om*/

    Car car = new CarImpl(dbObject.toMap());

    return car;
}