Skip to content

Commit

Permalink
- v0.x系の不具合対応の追いつき
Browse files Browse the repository at this point in the history
- ログ出力の整理
  • Loading branch information
HidekiSugimoto189 committed Jan 8, 2024
1 parent 8a7fca0 commit b8e24d4
Show file tree
Hide file tree
Showing 38 changed files with 2,160 additions and 202 deletions.
56 changes: 55 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,62 @@
{
"cSpell.words": [
"autocommit",
"Autoincrement",
"batyz",
"batyzyzy",
"batzz",
"Choi",
"chrono",
"classpath",
"Cobertura",
"crypted",
"cstmt",
"datasources",
"Decryptor",
"hamcrest",
"Hmmss",
"holdability",
"hoshi",
"iface",
"inactives",
"JCEKS",
"jdbc",
"jline",
"jquery",
"Miyazaki",
"Sugimoto"
"MSSQL",
"multibyte",
"nextval",
"NOWAIT",
"nparams",
"ognl",
"PKCS",
"rawtypes",
"rsmd",
"Savepoints",
"SCHEM",
"spel",
"springframework",
"sqlcov",
"sqlname",
"sqls",
"stupidtable",
"subparameter",
"Sugimoto",
"SYSPROP",
"thead",
"timestamptz",
"timetz",
"transactionisolation",
"uncapitalize",
"unmanaged",
"unmatch",
"UPDLOCK",
"Uroboro",
"uroborosql",
"vals",
"yzbat",
"yzyzybat",
"zzbat"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public AbstractResultSetWrapper(final ResultSet wrapped) {
*
* @see java.sql.Wrapper#unwrap(java.lang.Class)
*/
@SuppressWarnings("unchecked")
@Override
public <T> T unwrap(final Class<T> iface) throws SQLException {
if (iface != null && this.getClass().isAssignableFrom(iface)) {
return iface.cast(this);
if (iface != null && iface.isAssignableFrom(this.getClass())) {
return (T) this;
}

return wrapped.unwrap(iface);
}

Expand All @@ -67,10 +67,11 @@ public <T> T unwrap(final Class<T> iface) throws SQLException {
*/
@Override
public boolean isWrapperFor(final Class<?> iface) throws SQLException {
if (iface != null && this.getClass().isAssignableFrom(iface)) {
if (iface != null && iface.isAssignableFrom(this.getClass())) {
return true;
} else {
return wrapped.isWrapperFor(iface);
}
return wrapped.isWrapperFor(iface);
}

/**
Expand Down
26 changes: 17 additions & 9 deletions src/main/java/jp/co/future/uroborosql/SqlAgentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ public class SqlAgentImpl implements SqlAgent {
Thread.currentThread().getContextClassLoader()).getConstructor().newInstance();
COVERAGE_LOG.info("CoverageHandler : {}", sqlCoverageClassName);
} catch (Exception ex) {
COVERAGE_LOG.warn("Failed to generate CoverageHandler class. Class:{}, Cause:{}", sqlCoverageClassName,
COVERAGE_LOG.warn("Failed to instantiate CoverageHandler class. Class:{}, Cause:{}",
sqlCoverageClassName,
ex.getMessage());
COVERAGE_LOG.info("Turn off sql coverage due to failure to instantiate CoverageHandler class.");
}
}

Expand Down Expand Up @@ -1235,7 +1237,7 @@ public ResultSet query(final ExecutionContext executionContext) throws SQLExcept

Instant startTime = null;
if (LOG.isDebugEnabled()) {
LOG.debug("Execute search SQL.");
LOG.debug("Execute query sql. sqlName: {}", executionContext.getSqlName());
}
if (PERFORMANCE_LOG.isInfoEnabled()) {
startTime = Instant.now(getSqlConfig().getClock());
Expand Down Expand Up @@ -1384,7 +1386,9 @@ public int update(final ExecutionContext executionContext) throws SQLException {
// 更新移譲処理の指定がある場合は移譲処理を実行し結果を返却
if (executionContext.getUpdateDelegate() != null) {
MDC.remove(SUPPRESS_PARAMETER_LOG_OUTPUT);
LOG.debug("Performs update delegate of update process");
if (LOG.isInfoEnabled()) {
LOG.info("Performs update delegate of update process.");
}
return executionContext.getUpdateDelegate().apply(executionContext);
}

Expand All @@ -1396,7 +1400,7 @@ public int update(final ExecutionContext executionContext) throws SQLException {
executionContext.bindParams(stmt);

if (LOG.isDebugEnabled()) {
LOG.debug("Execute update SQL.");
LOG.debug("Execute update sql. sqlName: {}", executionContext.getSqlName());
}
if (PERFORMANCE_LOG.isInfoEnabled()) {
startTime = Instant.now(getSqlConfig().getClock());
Expand Down Expand Up @@ -1509,7 +1513,9 @@ public int[] batch(final ExecutionContext executionContext) throws SQLException
// 更新移譲処理の指定がある場合は移譲処理を実行し結果を返却
if (executionContext.getUpdateDelegate() != null) {
MDC.remove(SUPPRESS_PARAMETER_LOG_OUTPUT);
LOG.debug("Performs update delegate of batch process");
if (LOG.isInfoEnabled()) {
LOG.info("Performs update delegate of batch process.");
}
return new int[] { executionContext.getUpdateDelegate().apply(executionContext) };
}

Expand All @@ -1521,7 +1527,7 @@ public int[] batch(final ExecutionContext executionContext) throws SQLException
executionContext.bindBatchParams(stmt);

if (LOG.isDebugEnabled()) {
LOG.debug("Execute batch process.");
LOG.debug("Execute batch sql. sqlName: {}", executionContext.getSqlName());
}
if (PERFORMANCE_LOG.isInfoEnabled()) {
startTime = Instant.now(getSqlConfig().getClock());
Expand Down Expand Up @@ -1645,7 +1651,7 @@ public Map<String, Object> procedure(final ExecutionContext executionContext) th
executionContext.bindParams(callableStatement);

if (LOG.isDebugEnabled()) {
LOG.debug("Execute stored procedure.");
LOG.debug("Execute stored procedure. sqlName: {}", executionContext.getSqlName());
}
if (PERFORMANCE_LOG.isInfoEnabled()) {
startTime = Instant.now(getSqlConfig().getClock());
Expand Down Expand Up @@ -1788,7 +1794,9 @@ && getSqlConfig().getEventListenerHolder().hasBeforeParseSqlListener()) {
// SQLカバレッジ用のログを出力する
var coverageData = new CoverageData(sqlName, originalSql,
contextTransformer.getPassedRoute());
COVERAGE_LOG.info("{}", coverageData);
if (COVERAGE_LOG.isDebugEnabled()) {
COVERAGE_LOG.debug("coverage data: {}", coverageData);
}

coverageHandlerRef.get().accept(coverageData);
}
Expand Down Expand Up @@ -1837,7 +1845,7 @@ private void handleException(final ExecutionContext executionContext, final SQLE
cause = cause.getNextException();
}

if (LOG.isErrorEnabled() && outputExceptionLog) {
if (outputExceptionLog && LOG.isErrorEnabled()) {
var builder = new StringBuilder();
builder.append(System.lineSeparator()).append("Exception occurred in SQL execution.")
.append(System.lineSeparator());
Expand Down
24 changes: 13 additions & 11 deletions src/main/java/jp/co/future/uroborosql/SqlEntityQueryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,7 @@ public long count(final String col) {
public <T> T sum(final String col) {
var camelColumnName = CaseFormat.CAMEL_CASE.convert(col);
var mappingColumn = MappingUtils.getMappingColumn(context().getSchema(), entityType, camelColumnName);
Class<?> rawType = mappingColumn.getJavaType().getRawType();
if (!(short.class.equals(rawType) ||
int.class.equals(rawType) ||
long.class.equals(rawType) ||
float.class.equals(rawType) ||
double.class.equals(rawType) ||
Number.class.isAssignableFrom(mappingColumn.getJavaType().getRawType()))) {
if (!mappingColumn.isNumber()) {
throw new UroborosqlRuntimeException("Column is not of type Number. col=" + camelColumnName);
}
var column = tableMetadata().getColumn(camelColumnName);
Expand Down Expand Up @@ -530,7 +524,9 @@ public SqlEntityQuery<E> forUpdateNoWait() {
return this;
} else if (!agent().getSqlConfig().getSqlAgentProvider().isStrictForUpdateType()
&& dialect.supportsForUpdate()) {
LOG.warn("'FOR UPDATE NOWAIT' is not supported. Set 'FOR UPDATE' instead.");
if (LOG.isWarnEnabled()) {
LOG.warn("'FOR UPDATE NOWAIT' is not supported. Set 'FOR UPDATE' instead.");
}
this.forUpdateType = ForUpdateType.NORMAL;
return this;
} else {
Expand All @@ -549,7 +545,9 @@ public SqlEntityQuery<E> forUpdateWait() {
return forUpdateWait(agent().getSqlConfig().getSqlAgentProvider().getDefaultForUpdateWaitSeconds());
} else if (!agent().getSqlConfig().getSqlAgentProvider().isStrictForUpdateType()
&& dialect.supportsForUpdate()) {
LOG.warn("'FOR UPDATE WAIT' is not supported. Set 'FOR UPDATE' instead.");
if (LOG.isWarnEnabled()) {
LOG.warn("'FOR UPDATE WAIT' is not supported. Set 'FOR UPDATE' instead.");
}
this.forUpdateType = ForUpdateType.NORMAL;
return this;
} else {
Expand All @@ -570,7 +568,9 @@ public SqlEntityQuery<E> forUpdateWait(final int waitSeconds) {
return this;
} else if (!agent().getSqlConfig().getSqlAgentProvider().isStrictForUpdateType()
&& dialect.supportsForUpdate()) {
LOG.warn("'FOR UPDATE WAIT' is not supported. Set 'FOR UPDATE' instead.");
if (LOG.isWarnEnabled()) {
LOG.warn("'FOR UPDATE WAIT' is not supported. Set 'FOR UPDATE' instead.");
}
this.forUpdateType = ForUpdateType.NORMAL;
return this;
} else {
Expand All @@ -588,7 +588,9 @@ public SqlEntityQuery<E> hint(final String hint) {
if (dialect.supportsOptimizerHints()) {
this.optimizerHints.add(hint);
} else {
LOG.warn("Optimizer Hints is not supported.");
if (LOG.isWarnEnabled()) {
LOG.warn("Optimizer Hints is not supported.");
}
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private SqlParamUtils() {
* @return 入力内容をパラメータに分割した配列
*/
public static String[] parseLine(final String line) {
var sb = new StringBuffer();
var sb = new StringBuilder();
var matcher = PARAM_PAT.matcher(line);
while (matcher.find()) {
var arrayPart = matcher.group();
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/jp/co/future/uroborosql/client/SqlREPL.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ public class SqlREPL {
*/
public static void main(final String... args) {
((Logger) LoggerFactory.getLogger("jp.co.future.uroborosql.log")).setLevel(Level.INFO);
((Logger) LoggerFactory.getLogger("jp.co.future.uroborosql.log.event")).setLevel(Level.INFO);
((Logger) LoggerFactory.getLogger("jp.co.future.uroborosql.sql")).setLevel(Level.INFO);
((Logger) LoggerFactory.getLogger("jp.co.future.uroborosql.sql.dx")).setLevel(Level.TRACE);
((Logger) LoggerFactory.getLogger("jp.co.future.uroborosql.setting")).setLevel(Level.ERROR);
((Logger) LoggerFactory.getLogger("jp.co.future.uroborosql.performance")).setLevel(Level.INFO);
((Logger) LoggerFactory.getLogger("jp.co.future.uroborosql.event")).setLevel(Level.DEBUG);
((Logger) LoggerFactory.getLogger("jp.co.future.uroborosql.repl")).setLevel(Level.INFO);
((Logger) LoggerFactory.getLogger("jp.co.future.uroborosql.sql")).setLevel(Level.DEBUG);
((Logger) LoggerFactory.getLogger("jp.co.future.uroborosql.sql.parser")).setLevel(Level.ERROR);
((Logger) LoggerFactory.getLogger("jp.co.future.uroborosql.sql.repl")).setLevel(Level.ERROR);
((Logger) LoggerFactory.getLogger("jp.co.future.uroborosql.sql.coverage")).setLevel(Level.ERROR);
((Logger) LoggerFactory.getLogger("jp.co.future.uroborosql.performance")).setLevel(Level.INFO);
((Logger) LoggerFactory.getLogger("jp.co.future.uroborosql.setting")).setLevel(Level.ERROR);

var propFile = "repl.properties";
if (args.length != 0) {
Expand Down Expand Up @@ -183,7 +182,7 @@ private void initialize(final Terminal terminal) throws Exception {
Arrays.stream(paths.split(";")).forEach(path -> {
try {
var m = SYSPROP_PAT.matcher(path);
var sb = new StringBuffer();
var sb = new StringBuilder();
while (m.find()) {
var key = m.group(1);
var val = System.getProperty(key, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public TableNameCompleter(final List<ReplCommand> commands, final ConnectionSupp
}

/**
* DatabaseMetadateからテーブル名を取得して補完候補とする
* DatabaseMetadataからテーブル名を取得して補完候補とする
*
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,18 @@ public boolean contains(final Object o) {
}

/** where句の直後にくるANDやORを除外するための正規表現 */
private static final Pattern WHERE_CLAUSE_PATTERN = Pattern
.compile("(?i)(?<clause>(^|\\s+)(WHERE\\s+(--.*|/\\*[^(/\\*|\\*/)]+?\\*/\\s*)*\\s*))(AND\\s+|OR\\s+)");
private static final Pattern WHERE_CLAUSE_PATTERN = Pattern.compile(
"(?i)(?<clause>(\\bWHERE\\s+(--.*|/\\*[^(/\\*|\\*/)]+?\\*/\\s*)*\\s*))((AND|OR)\\s+)");

/** 各句の最初に現れるカンマを除去するための正規表現 */
private static final Pattern REMOVE_FIRST_COMMA_PATTERN = Pattern
.compile(
"(?i)(?<keyword>((^|\\s+)(SELECT|ORDER\\s+BY|GROUP\\s+BY|SET)\\s+|\\(\\s*)(--.*|/\\*[^(/\\*|\\*/)]+?\\*/\\s*)*\\s*)(,)");
private static final Pattern REMOVE_FIRST_COMMA_PATTERN = Pattern.compile(
"(?i)(?<keyword>(\\b(SELECT|ORDER\\s+BY|GROUP\\s+BY|SET)\\s+|\\(\\s*)(--.*|/\\*[^(/\\*|\\*/)]+?\\*/\\s*)*\\s*),");

/** 不要な空白、改行を除去するための正規表現 */
private static final Pattern CLEAR_BLANK_PATTERN = Pattern.compile("(?m)^\\s*(\\r\\n|\\r|\\n)");

/** ロガー */
private static final Logger LOG = LoggerFactory.getLogger("jp.co.future.uroborosql.log");
/** SQLロガー */
private static final Logger SQL_LOG = LoggerFactory.getLogger("jp.co.future.uroborosql.sql");

/** SqlConfig. */
private SqlConfig sqlConfig;
Expand Down Expand Up @@ -235,7 +234,7 @@ public String getExecutableSql() {
executableSqlCache = executableSql.toString();
if (executableSqlCache.toUpperCase().contains("WHERE")) {
// where句の直後に来るANDやORの除去
var buff = new StringBuffer();
var buff = new StringBuilder();
var matcher = WHERE_CLAUSE_PATTERN.matcher(executableSqlCache);
while (matcher.find()) {
var whereClause = matcher.group("clause");
Expand All @@ -245,7 +244,7 @@ public String getExecutableSql() {
executableSqlCache = buff.toString();
}
// 各句の直後に現れる不要なカンマの除去
var buff = new StringBuffer();
var buff = new StringBuilder();
var removeCommaMatcher = REMOVE_FIRST_COMMA_PATTERN.matcher(executableSqlCache);
while (removeCommaMatcher.find()) {
var clauseWords = removeCommaMatcher.group("keyword");
Expand Down Expand Up @@ -927,8 +926,8 @@ public void bindBatchParams(final PreparedStatement preparedStatement) throws SQ
bindParams(preparedStatement);
preparedStatement.addBatch();
}
if (LOG.isDebugEnabled()) {
LOG.debug("{} items Added for batch process.", batchParameters.size());
if (SQL_LOG.isDebugEnabled()) {
SQL_LOG.debug("{} items Added for batch process.", batchParameters.size());
}
}

Expand Down Expand Up @@ -959,8 +958,8 @@ public Map<String, Object> getOutParams(final CallableStatement callableStatemen
parameterIndex++;
}

if (LOG.isDebugEnabled()) {
LOG.debug("Stored procedure out parameter[{}]", out);
if (SQL_LOG.isDebugEnabled()) {
SQL_LOG.debug("Stored procedure out parameter[{}]", out);
}
return out;
}
Expand Down
Loading

0 comments on commit b8e24d4

Please sign in to comment.