use of com.mongodb.WriteResult in project symmetric-ds by JumpMind.
the class MongoDatabaseWriter method delete.
@Override
protected LoadStatus delete(CsvData data, boolean useConflictDetection) {
statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS);
try {
DB db = clientManager.getDB(objectMapper.mapToDatabase(this.targetTable));
DBCollection collection = db.getCollection(objectMapper.mapToCollection(this.targetTable));
String[] columnNames = sourceTable.getColumnNames();
Map<String, String> newData = data.toColumnNameValuePairs(columnNames, CsvData.ROW_DATA);
Map<String, String> oldData = data.toColumnNameValuePairs(columnNames, CsvData.OLD_DATA);
Map<String, String> pkData = data.toKeyColumnValuePairs(this.sourceTable);
DBObject query = objectMapper.mapToDBObject(sourceTable, newData, oldData, pkData, true);
WriteResult results = collection.remove(query, WriteConcern.ACKNOWLEDGED);
if (results.getN() != 1) {
log.warn("Attempted to remove a single object" + query.toString() + ". Instead removed: " + results.getN());
}
return LoadStatus.SUCCESS;
} finally {
statistics.get(batch).stopTimer(DataWriterStatisticConstants.DATABASEMILLIS);
}
}
use of com.mongodb.WriteResult in project symmetric-ds by JumpMind.
the class MongoDatabaseWriter method upsert.
protected LoadStatus upsert(CsvData data) {
statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS);
try {
DB db = clientManager.getDB(objectMapper.mapToDatabase(this.targetTable));
DBCollection collection = db.getCollection(objectMapper.mapToCollection(this.targetTable));
String[] columnNames = sourceTable.getColumnNames();
Map<String, String> newData = data.toColumnNameValuePairs(columnNames, CsvData.ROW_DATA);
Map<String, String> oldData = data.toColumnNameValuePairs(columnNames, CsvData.OLD_DATA);
Map<String, String> pkData = data.toKeyColumnValuePairs(this.sourceTable);
DBObject query = objectMapper.mapToDBObject(sourceTable, newData, oldData, pkData, true);
DBObject object = objectMapper.mapToDBObject(sourceTable, newData, oldData, pkData, false);
WriteResult results = collection.update(query, object, true, false, WriteConcern.ACKNOWLEDGED);
if (results.getN() == 1) {
return LoadStatus.SUCCESS;
} else {
throw new SymmetricException("Failed to write data: " + object.toString());
}
} finally {
statistics.get(batch).stopTimer(DataWriterStatisticConstants.DATABASEMILLIS);
}
}
Aggregations