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

com.versioneye.persistence.mongodb.GlobalSettingDao 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 com.versioneye.domain.GlobalSetting;
import com.versioneye.persistence.IGlobalSettingDao;


public class GlobalSettingDao implements IGlobalSettingDao {

    private MongoDB mongoDB;

    public DBCollection getCollection(){
        return mongoDB.getDb().getCollection(GlobalSetting.GLOBAL_SETTINGS);
    }

    public GlobalSetting getBy(String environment, String key) throws Exception {
        if (environment == null || key == null){
            return null;
        }
        DBCollection licenses = getCollection();
        BasicDBObject match = new BasicDBObject();
        match.put(GlobalSetting.ENVIRONMENT, environment);
        match.put(GlobalSetting.KEY, key.toUpperCase());
        DBCursor cursor = licenses.find(match);
        while (cursor.hasNext()){
            DBObject gsObj = cursor.next();
            GlobalSetting gs = new GlobalSetting();
            gs.updateFromDbObject(gsObj);
            return gs;
        }
        return null;
    }

    public boolean setValue(String environment, String key, String value) throws Exception {
        GlobalSetting gs = new GlobalSetting();
        gs.setEnvironment(environment);
        gs.setKey(key.toUpperCase());
        gs.setValue(value);
        DBCollection globalSettings = getCollection();
        globalSettings.insert(gs.getDBObject());
        return true;
    }

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy