Search in sources :

Example 41 with StopWatch

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);
    }
}
Also used : BsonDocument(org.bson.BsonDocument) DeleteResult(com.mongodb.client.result.DeleteResult) StopWatch(core.framework.util.StopWatch)

Example 42 with StopWatch

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);
    }
}
Also used : StopWatch(core.framework.util.StopWatch)

Example 43 with StopWatch

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);
    }
}
Also used : UpdateOptions(com.mongodb.client.model.UpdateOptions) StopWatch(core.framework.util.StopWatch)

Example 44 with StopWatch

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);
    }
}
Also used : StopWatch(core.framework.util.StopWatch)

Example 45 with StopWatch

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);
    }
}
Also used : StopWatch(core.framework.util.StopWatch)

Aggregations

StopWatch (core.framework.util.StopWatch)79 IOException (java.io.IOException)21 UncheckedIOException (java.io.UncheckedIOException)21 SearchException (core.framework.search.SearchException)10 ElasticsearchException (org.elasticsearch.ElasticsearchException)10 ArrayList (java.util.ArrayList)6 HTMLTemplate (core.framework.impl.template.HTMLTemplate)4 BytesParam (core.framework.impl.log.filter.BytesParam)3 Map (java.util.Map)3 BsonDocument (org.bson.BsonDocument)3 BulkWriteOptions (com.mongodb.client.model.BulkWriteOptions)2 UpdateOptions (com.mongodb.client.model.UpdateOptions)2 DeleteResult (com.mongodb.client.result.DeleteResult)2 TemplateContext (core.framework.impl.template.TemplateContext)2 Headers (org.apache.kafka.common.header.Headers)2 Bson (org.bson.conversions.Bson)2 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)2 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)2 Settings (org.elasticsearch.common.settings.Settings)2 MongoClient (com.mongodb.MongoClient)1