MAX_SPLIT_NUM);
bulkInsertLine = param.getIntValue(ParamKey.bulkInsertLine,
this.bulkInsertLine);
dropCollectionBeforeInsertionSwitch = param.getBooleanValue(ParamKey.dropCollectionBeforeInsertionSwitch, false);
MongoURI uri = new MongoURI(outputUri);
Mongo mongo = null;
try {
mongo = new Mongo(uri);
} catch (UnknownHostException e) {
throw new IllegalStateException(
" Unable to connect to MongoDB at '" + uri + "'", e);
}
DB db = mongo.getDB(uri.getDatabase());
// if there's a username and password
if (uri.getUsername() != null && uri.getPassword() != null
&& !db.isAuthenticated()) {
boolean auth = db
.authenticate(uri.getUsername(), uri.getPassword());
if (auth) {
log.info("Sucessfully authenticated with collection.");
} else {
throw new IllegalArgumentException(
"Unable to connect to collection. You have to check your username and password");
}
}
if (dropCollectionBeforeInsertionSwitch){
log.info("start to drop collection " + uri.getCollection());
DBCollection coll = MongoUtils.getCollection(uri);
coll.drop();
log.info("drop collection " + uri.getCollection() + " before insert data successfully");
}
param.putValue(ParamKey.outputUri, this.outputUri);
param.putValue(ParamKey.outputFields, this.outputFields);
param.putValue(ParamKey.concurrency, String.valueOf(this.concurrency));