use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class MongoCollectionImpl method delete.
@Override
public long delete(Bson filter) {
StopWatch watch = new StopWatch();
long deletedRows = 0;
try {
DeleteResult result = collection().deleteMany(filter == null ? new BsonDocument() : filter);
deletedRows = result.getDeletedCount();
return deletedRows;
} finally {
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("mongoDB", elapsedTime, 0, (int) deletedRows);
logger.debug("delete, collection={}, filter={}, deletedRows={}, elapsedTime={}", collectionName, new BsonParam(filter, mongo.registry), deletedRows, elapsedTime);
checkSlowOperation(elapsedTime);
}
}
use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class MongoCollectionImpl method insert.
@Override
public void insert(T entity) {
StopWatch watch = new StopWatch();
validator.validate(entity);
try {
collection().insertOne(entity);
} finally {
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("mongoDB", elapsedTime, 0, 1);
logger.debug("insert, collection={}, elapsedTime={}", collectionName, elapsedTime);
checkSlowOperation(elapsedTime);
}
}
use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class MongoCollectionImpl method replace.
@Override
public void replace(T entity) {
StopWatch watch = new StopWatch();
Object id = null;
validator.validate(entity);
try {
id = mongo.codecs.id(entity);
if (id == null)
throw Exceptions.error("entity must have id, entityClass={}", entityClass.getCanonicalName());
collection().replaceOne(Filters.eq("_id", id), entity, new UpdateOptions().upsert(true));
} finally {
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("mongoDB", elapsedTime, 0, 1);
logger.debug("replace, collection={}, id={}, elapsedTime={}", collectionName, id, elapsedTime);
checkSlowOperation(elapsedTime);
}
}
use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class MongoCollectionImpl method mapReduce.
@Override
public <V> List<V> mapReduce(MapReduce<V> mapReduce) {
if (Strings.isEmpty(mapReduce.mapFunction))
throw new Error("mapReduce.mapFunction must not be empty");
if (Strings.isEmpty(mapReduce.reduceFunction))
throw new Error("mapReduce.reduceFunction must not be empty");
if (mapReduce.resultClass == null)
throw new Error("mapReduce.resultClass must not be null");
StopWatch watch = new StopWatch();
List<V> results = Lists.newArrayList();
try {
MapReduceIterable<V> query = collection(mapReduce.readPreference).mapReduce(mapReduce.mapFunction, mapReduce.reduceFunction, mapReduce.resultClass).maxTime(mongo.timeoutInMs, TimeUnit.MILLISECONDS);
if (mapReduce.filter != null)
query.filter(mapReduce.filter);
fetch(query, results);
checkTooManyRowsReturned(results.size());
return results;
} finally {
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("mongoDB", elapsedTime, results.size(), 0);
logger.debug("mapReduce, collection={}, map={}, reduce={}, filter={}, readPref={}, returnedRows={}, elapsedTime={}", collectionName, mapReduce.mapFunction, mapReduce.reduceFunction, new BsonParam(mapReduce.filter, mongo.registry), mapReduce.readPreference == null ? null : mapReduce.readPreference.getName(), results.size(), elapsedTime);
}
}
use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class DatabaseImpl method execute.
@Override
public int execute(String sql, Object... params) {
StopWatch watch = new StopWatch();
int updatedRows = 0;
try {
updatedRows = operation.update(sql, params);
return updatedRows;
} finally {
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("db", elapsedTime, 0, updatedRows);
logger.debug("execute, sql={}, params={}, updatedRows={}, elapsedTime={}", sql, params, updatedRows, elapsedTime);
checkSlowOperation(elapsedTime);
}
}
Aggregations