Search in sources :

Example 21 with StopWatch

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

the class RepositoryImpl method fetch.

List<T> fetch(String sql, Object... params) {
    StopWatch watch = new StopWatch();
    int returnedRows = 0;
    try {
        List<T> results = database.operation.select(sql, rowMapper, params);
        returnedRows = results.size();
        checkTooManyRowsReturned(returnedRows);
        return results;
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("db", elapsedTime, returnedRows, 0);
        logger.debug("fetch, sql={}, params={}, returnedRows={}, elapsedTime={}", sql, params, returnedRows, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : StopWatch(core.framework.util.StopWatch)

Example 22 with StopWatch

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

the class RepositoryImpl method batchInsert.

@Override
public void batchInsert(List<T> entities) {
    StopWatch watch = new StopWatch();
    entities.forEach(validator::validate);
    String sql = insertQuery.sql;
    List<Object[]> params = entities.stream().map(insertQuery::params).collect(Collectors.toList());
    try {
        database.operation.batchUpdate(sql, params);
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("db", elapsedTime, 0, entities.size());
        logger.debug("batch insert, sql={}, size={}, elapsedTime={}", sql, entities.size(), elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : StopWatch(core.framework.util.StopWatch)

Example 23 with StopWatch

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

the class RepositoryImpl method update.

@Override
public void update(T entity) {
    StopWatch watch = new StopWatch();
    validator.partialValidate(entity);
    UpdateQuery.Statement query = updateQuery.update(entity);
    int updatedRows = 0;
    try {
        updatedRows = database.operation.update(query.sql, query.params);
        if (updatedRows != 1)
            logger.warn(Markers.errorCode("UNEXPECTED_UPDATE_RESULT"), "updated rows is not 1, rows={}", updatedRows);
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("db", elapsedTime, 0, updatedRows);
        logger.debug("update, sql={}, params={}, elapsedTime={}", query.sql, query.params, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : StopWatch(core.framework.util.StopWatch)

Example 24 with StopWatch

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

the class RepositoryImpl method delete.

@Override
public void delete(Object... primaryKeys) {
    StopWatch watch = new StopWatch();
    int deletedRows = 0;
    try {
        deletedRows = database.operation.update(deleteSQL, primaryKeys);
        if (deletedRows != 1)
            logger.warn(Markers.errorCode("UNEXPECTED_UPDATE_RESULT"), "deleted rows is not 1, rows={}", deletedRows);
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("db", elapsedTime, 0, deletedRows);
        logger.debug("delete, sql={}, params={}, elapsedTime={}", deleteSQL, primaryKeys, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : StopWatch(core.framework.util.StopWatch)

Example 25 with StopWatch

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

the class EntitySchemaGenerator method generate.

public void generate() {
    StopWatch watch = new StopWatch();
    List<String> statements = schemeStatements();
    try {
        for (String statement : statements) {
            database.execute(statement);
        }
    } finally {
        logger.info("create schema, entityClass={}, sql={}, elapsedTime={}", entityClass.getCanonicalName(), statements, watch.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