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);
}
}
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());
}
Aggregations