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);
}
}
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());
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations