All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.versioneye.persistence.mongodb.ErrorDao Maven / Gradle / Ivy

Go to download

This is the java implementation of the VersionEye core services. It contains some buisiness logic and utility classes.

There is a newer version: 1.3.7
Show newest version
package com.versioneye.persistence.mongodb;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import org.bson.types.ObjectId;
import com.versioneye.domain.Error;
import com.versioneye.persistence.IErrorDao;

/**
 * Created with IntelliJ IDEA.
 * User: robertreiz
 * Date: 4/19/13
 * Time: 4:29 PM
 *
 */
public class ErrorDao implements IErrorDao {

    private MongoDB mongoDB;

    private DBCollection getCollection(){
        return mongoDB.getDb().getCollection(Error.ERRORS);
    }

    public void create(com.versioneye.domain.Error error) {
        DBCollection errors = getCollection();
        errors.insert(error.getDBObject());
    }

    public Error getById(ObjectId id) {
        BasicDBObject match = new BasicDBObject();
        match.put(Error.ID, id);
        DBCursor cursor = getCollection().find(match);
        if (!cursor.hasNext())
            return null;
        DBObject errorObj = cursor.next();
        Error error = new Error();
        error.updateFromDBObject(errorObj);
        return error;
    }

    public void setMongoDB(MongoDB mongoDB) {
        this.mongoDB = mongoDB;

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy