Search in sources :

Example 46 with StopWatch

use of core.framework.util.StopWatch in project core-ng-project by neowu.

the class DatabaseImpl method selectOne.

@Override
public <T> Optional<T> selectOne(String sql, Class<T> viewClass, Object... params) {
    StopWatch watch = new StopWatch();
    try {
        return operation.selectOne(sql, rowMapper(viewClass), params);
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("db", elapsedTime, 1, 0);
        logger.debug("selectOne, sql={}, params={}, elapsedTime={}", sql, params, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : StopWatch(core.framework.util.StopWatch)

Example 47 with StopWatch

use of core.framework.util.StopWatch in project core-ng-project by neowu.

the class DatabaseImpl method view.

public <T> void view(Class<T> viewClass) {
    StopWatch watch = new StopWatch();
    try {
        new DatabaseClassValidator(viewClass).validateViewClass();
        registerViewClass(viewClass);
    } finally {
        logger.info("register db view, viewClass={}, elapsedTime={}", viewClass.getCanonicalName(), watch.elapsedTime());
    }
}
Also used : StopWatch(core.framework.util.StopWatch)

Example 48 with StopWatch

use of core.framework.util.StopWatch in project core-ng-project by neowu.

the class RepositoryImpl method count.

@Override
public int count(String where, Object... params) {
    StopWatch watch = new StopWatch();
    String sql = selectQuery.countSQL(where);
    try {
        return database.operation.selectOne(sql, DatabaseImpl.ROW_MAPPER_INTEGER, params).orElseThrow(() -> new Error("unexpected result"));
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("db", elapsedTime, 1, 0);
        logger.debug("count, sql={}, params={}, elapsedTime={}", sql, params, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : StopWatch(core.framework.util.StopWatch)

Example 49 with StopWatch

use of core.framework.util.StopWatch in project core-ng-project by neowu.

the class RepositoryImpl method insert.

@Override
public Optional<Long> insert(T entity) {
    StopWatch watch = new StopWatch();
    validator.validate(entity);
    String sql = insertQuery.sql;
    Object[] params = insertQuery.params(entity);
    try {
        return database.operation.insert(sql, params, insertQuery.generatedColumn);
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("db", elapsedTime, 0, 1);
        logger.debug("insert, sql={}, params={}, elapsedTime={}", sql, params, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : StopWatch(core.framework.util.StopWatch)

Example 50 with StopWatch

use of core.framework.util.StopWatch in project core-ng-project by neowu.

the class RepositoryImpl method batchDelete.

@Override
public void batchDelete(List<?> primaryKeys) {
    StopWatch watch = new StopWatch();
    List<Object[]> params = Lists.newArrayList();
    for (Object primaryKey : primaryKeys) {
        if (primaryKey instanceof Object[]) {
            params.add((Object[]) primaryKey);
        } else {
            params.add(new Object[] { primaryKey });
        }
    }
    int deletedRows = 0;
    try {
        int[] results = database.operation.batchUpdate(deleteSQL, params);
        deletedRows = Arrays.stream(results).sum();
        for (int result : results) {
            if (result != 1) {
                logger.warn(Markers.errorCode("UNEXPECTED_UPDATE_RESULT"), "deleted rows is not 1, rows={}", Arrays.toString(results));
                break;
            }
        }
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("db", elapsedTime, 0, deletedRows);
        logger.debug("delete, sql={}, size={}, elapsedTime={}", deleteSQL, primaryKeys.size(), 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