Search in sources :

Example 1 with Jongo

use of org.jongo.Jongo in project wso2-dss-connectors by wso2-attic.

the class MongoDBDataSource method init.

@Override
public void init(Map<String, String> params) throws DataServiceFault {
    String serversParam = params.get(MongoDBDSConstants.SERVERS);
    if (DBUtils.isEmptyString(serversParam)) {
        throw new DataServiceFault("The data source param '" + MongoDBDSConstants.SERVERS + "' is required");
    }
    String[] servers = serversParam.split(",");
    String database = params.get(MongoDBDSConstants.DATABASE);
    if (DBUtils.isEmptyString(database)) {
        throw new DataServiceFault("The data source param '" + MongoDBDSConstants.DATABASE + "' is required");
    }
    try {
        this.mongo = new Mongo(this.createServerAddresses(servers), this.extractMongoOptions(params));
        String writeConcern = params.get(MongoDBDSConstants.WRITE_CONCERN);
        if (!DBUtils.isEmptyString(writeConcern)) {
            this.getMongo().setWriteConcern(WriteConcern.valueOf(writeConcern));
        }
        String readPref = params.get(MongoDBDSConstants.READ_PREFERENCE);
        if (!DBUtils.isEmptyString(readPref)) {
            this.getMongo().setReadPreference(ReadPreference.valueOf(readPref));
        }
        this.jongo = new Jongo(this.getMongo().getDB(database));
    } catch (Exception e) {
        throw new DataServiceFault(e);
    }
}
Also used : Mongo(com.mongodb.Mongo) Jongo(org.jongo.Jongo) DataServiceFault(org.wso2.carbon.dataservices.core.DataServiceFault)

Example 2 with Jongo

use of org.jongo.Jongo in project commons by craftercms.

the class JongoFactoryBean method createInstance.

@Override
protected Jongo createInstance() throws Exception {
    DB db = mongo.getDB(dbName);
    JacksonMapper.Builder builder = new JacksonMapper.Builder();
    builder.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
    if (CollectionUtils.isNotEmpty(serializers) || MapUtils.isNotEmpty(deserializers)) {
        builder.registerModule(JacksonUtils.createModule(serializers, deserializers));
    }
    return new Jongo(db, builder.build());
}
Also used : JacksonMapper(org.jongo.marshall.jackson.JacksonMapper) Jongo(org.jongo.Jongo) DB(com.mongodb.DB)

Aggregations

Jongo (org.jongo.Jongo)2 DB (com.mongodb.DB)1 Mongo (com.mongodb.Mongo)1 JacksonMapper (org.jongo.marshall.jackson.JacksonMapper)1 DataServiceFault (org.wso2.carbon.dataservices.core.DataServiceFault)1