提交 5acc65e8 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Do not concatenate non-constant expressions inside calls to StringBuilder

上级 bfc27535
...@@ -1154,10 +1154,10 @@ public class Parser { ...@@ -1154,10 +1154,10 @@ public class Parser {
TableFilter sourceTableFilter = readSimpleTableFilterWithAliasExcludes(0, excludeIdentifiers); TableFilter sourceTableFilter = readSimpleTableFilterWithAliasExcludes(0, excludeIdentifiers);
command.setSourceTableFilter(sourceTableFilter); command.setSourceTableFilter(sourceTableFilter);
StringBuilder buff = new StringBuilder( StringBuilder buff = new StringBuilder("SELECT * FROM ")
"SELECT * FROM "+sourceTableFilter.getTable().getName()); .append(sourceTableFilter.getTable().getName());
if (sourceTableFilter.getTableAlias() != null) { if (sourceTableFilter.getTableAlias() != null) {
buff.append(" AS "+sourceTableFilter.getTableAlias()); buff.append(" AS ").append(sourceTableFilter.getTableAlias());
} }
Prepared preparedQuery = prepare(session, buff.toString(), null/*paramValues*/); Prepared preparedQuery = prepare(session, buff.toString(), null/*paramValues*/);
command.setQuery((Select) preparedQuery); command.setQuery((Select) preparedQuery);
...@@ -1208,7 +1208,7 @@ public class Parser { ...@@ -1208,7 +1208,7 @@ public class Parser {
" AS " + command.getTargetTableFilter().getTableAlias()); " AS " + command.getTargetTableFilter().getTableAlias());
} }
targetMatchQuerySQL targetMatchQuerySQL
.append(" WHERE " + command.getOnCondition().getSQL()); .append(" WHERE ").append(command.getOnCondition().getSQL());
command.setTargetMatchQuery( command.setTargetMatchQuery(
(Select) parse(targetMatchQuerySQL.toString())); (Select) parse(targetMatchQuerySQL.toString()));
......
...@@ -423,10 +423,10 @@ public class ScriptCommand extends ScriptBase { ...@@ -423,10 +423,10 @@ public class ScriptCommand extends ScriptBase {
int id; int id;
if (v.getType() == Value.CLOB) { if (v.getType() == Value.CLOB) {
id = writeLobStream(v); id = writeLobStream(v);
buff.append("SYSTEM_COMBINE_CLOB(" + id + ")"); buff.append("SYSTEM_COMBINE_CLOB(").append(id).append(')');
} else if (v.getType() == Value.BLOB) { } else if (v.getType() == Value.BLOB) {
id = writeLobStream(v); id = writeLobStream(v);
buff.append("SYSTEM_COMBINE_BLOB(" + id + ")"); buff.append("SYSTEM_COMBINE_BLOB(").append(id).append(')');
} else { } else {
buff.append(v.getSQL()); buff.append(v.getSQL());
} }
...@@ -471,8 +471,8 @@ public class ScriptCommand extends ScriptBase { ...@@ -471,8 +471,8 @@ public class ScriptCommand extends ScriptBase {
try (InputStream input = v.getInputStream()) { try (InputStream input = v.getInputStream()) {
for (int i = 0;; i++) { for (int i = 0;; i++) {
StringBuilder buff = new StringBuilder(lobBlockSize * 2); StringBuilder buff = new StringBuilder(lobBlockSize * 2);
buff.append("INSERT INTO SYSTEM_LOB_STREAM VALUES(" + id + buff.append("INSERT INTO SYSTEM_LOB_STREAM VALUES(").append(id)
", " + i + ", NULL, '"); .append(", ").append(i).append(", NULL, '");
int len = IOUtils.readFully(input, bytes, lobBlockSize); int len = IOUtils.readFully(input, bytes, lobBlockSize);
if (len <= 0) { if (len <= 0) {
break; break;
...@@ -490,7 +490,8 @@ public class ScriptCommand extends ScriptBase { ...@@ -490,7 +490,8 @@ public class ScriptCommand extends ScriptBase {
try (Reader reader = v.getReader()) { try (Reader reader = v.getReader()) {
for (int i = 0;; i++) { for (int i = 0;; i++) {
StringBuilder buff = new StringBuilder(lobBlockSize * 2); StringBuilder buff = new StringBuilder(lobBlockSize * 2);
buff.append("INSERT INTO SYSTEM_LOB_STREAM VALUES(" + id + ", " + i + ", "); buff.append("INSERT INTO SYSTEM_LOB_STREAM VALUES(").append(id).append(", ").append(i)
.append(", ");
int len = IOUtils.readFully(reader, chars, lobBlockSize); int len = IOUtils.readFully(reader, chars, lobBlockSize);
if (len == 0) { if (len == 0) {
break; break;
......
...@@ -197,9 +197,9 @@ public class FreeSpaceBitSet { ...@@ -197,9 +197,9 @@ public class FreeSpaceBitSet {
on = 0; on = 0;
} }
} }
buff.append("\n"); buff.append('\n')
buff.append(" on " + onCount + " off " + offCount); .append(" on ").append(onCount).append(" off ").append(offCount)
buff.append(" " + 100 * onCount / (onCount+offCount) + "% used "); .append(' ').append(100 * onCount / (onCount+offCount)).append("% used ");
} }
buff.append('['); buff.append('[');
for (int i = 0;;) { for (int i = 0;;) {
......
...@@ -259,18 +259,18 @@ public class Page { ...@@ -259,18 +259,18 @@ public class Page {
public String toString() { public String toString() {
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
buff.append("id: ").append(System.identityHashCode(this)).append('\n'); buff.append("id: ").append(System.identityHashCode(this)).append('\n');
buff.append("version: ").append(Long.toHexString(version)).append("\n"); buff.append("version: ").append(Long.toHexString(version)).append('\n');
buff.append("pos: ").append(Long.toHexString(pos)).append("\n"); buff.append("pos: ").append(Long.toHexString(pos)).append('\n');
if (pos != 0) { if (pos != 0) {
int chunkId = DataUtils.getPageChunkId(pos); int chunkId = DataUtils.getPageChunkId(pos);
buff.append("chunk: ").append(Long.toHexString(chunkId)).append("\n"); buff.append("chunk: ").append(Long.toHexString(chunkId)).append('\n');
} }
for (int i = 0; i <= keys.length; i++) { for (int i = 0; i <= keys.length; i++) {
if (i > 0) { if (i > 0) {
buff.append(" "); buff.append(" ");
} }
if (children != null) { if (children != null) {
buff.append("[" + Long.toHexString(children[i].pos) + "] "); buff.append('[').append(Long.toHexString(children[i].pos)).append("] ");
} }
if (i < keys.length) { if (i < keys.length) {
buff.append(keys[i]); buff.append(keys[i]);
......
...@@ -134,7 +134,7 @@ public class RowImpl implements Row { ...@@ -134,7 +134,7 @@ public class RowImpl implements Row {
StatementBuilder buff = new StatementBuilder("( /* key:"); StatementBuilder buff = new StatementBuilder("( /* key:");
buff.append(getKey()); buff.append(getKey());
if (version != 0) { if (version != 0) {
buff.append(" v:" + version); buff.append(" v:").append(version);
} }
if (isDeleted()) { if (isDeleted()) {
buff.append(" deleted"); buff.append(" deleted");
......
...@@ -64,7 +64,7 @@ public class SimpleRow implements SearchRow { ...@@ -64,7 +64,7 @@ public class SimpleRow implements SearchRow {
StatementBuilder buff = new StatementBuilder("( /* key:"); StatementBuilder buff = new StatementBuilder("( /* key:");
buff.append(getKey()); buff.append(getKey());
if (version != 0) { if (version != 0) {
buff.append(" v:" + version); buff.append(" v:").append(version);
} }
buff.append(" */ "); buff.append(" */ ");
for (Value v : data) { for (Value v : data) {
......
...@@ -387,7 +387,7 @@ public class TableLink extends Table { ...@@ -387,7 +387,7 @@ public class TableLink extends Table {
if (readOnly) { if (readOnly) {
buff.append(" READONLY"); buff.append(" READONLY");
} }
buff.append(" /*" + JdbcSQLException.HIDE_SQL + "*/"); buff.append(" /*").append(JdbcSQLException.HIDE_SQL).append("*/");
return buff.toString(); return buff.toString();
} }
......
...@@ -1477,7 +1477,7 @@ public class Recover extends Tool implements DataHandler { ...@@ -1477,7 +1477,7 @@ public class Recover extends Tool implements DataHandler {
private void writeRow(PrintWriter writer, Data s, Value[] data) { private void writeRow(PrintWriter writer, Data s, Value[] data) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("INSERT INTO " + storageName + " VALUES("); sb.append("INSERT INTO ").append(storageName).append(" VALUES(");
for (valueId = 0; valueId < recordLength; valueId++) { for (valueId = 0; valueId < recordLength; valueId++) {
try { try {
Value v = s.readValue(); Value v = s.readValue();
......
...@@ -184,15 +184,15 @@ public class AbbaLockingDetector implements Runnable { ...@@ -184,15 +184,15 @@ public class AbbaLockingDetector implements Runnable {
* stack frames) * stack frames)
*/ */
private static String getStackTraceForThread(ThreadInfo info) { private static String getStackTraceForThread(ThreadInfo info) {
StringBuilder sb = new StringBuilder("\"" + StringBuilder sb = new StringBuilder().append('"')
info.getThreadName() + "\"" + " Id=" + .append(info.getThreadName()).append("\"" + " Id=")
info.getThreadId() + " " + info.getThreadState()); .append(info.getThreadId()).append(' ').append(info.getThreadState());
if (info.getLockName() != null) { if (info.getLockName() != null) {
sb.append(" on " + info.getLockName()); sb.append(" on ").append(info.getLockName());
} }
if (info.getLockOwnerName() != null) { if (info.getLockOwnerName() != null) {
sb.append(" owned by \"" + info.getLockOwnerName() + sb.append(" owned by \"").append(info.getLockOwnerName())
"\" Id=" + info.getLockOwnerId()); .append("\" Id=").append(info.getLockOwnerId());
} }
if (info.isSuspended()) { if (info.isSuspended()) {
sb.append(" (suspended)"); sb.append(" (suspended)");
...@@ -229,22 +229,25 @@ public class AbbaLockingDetector implements Runnable { ...@@ -229,22 +229,25 @@ public class AbbaLockingDetector implements Runnable {
private static void dumpStackTraceElement(ThreadInfo info, private static void dumpStackTraceElement(ThreadInfo info,
StringBuilder sb, int i, StackTraceElement e) { StringBuilder sb, int i, StackTraceElement e) {
sb.append('\t').append("at ").append(e.toString()); sb.append('\t').append("at ").append(e)
sb.append('\n'); .append('\n');
if (i == 0 && info.getLockInfo() != null) { if (i == 0 && info.getLockInfo() != null) {
Thread.State ts = info.getThreadState(); Thread.State ts = info.getThreadState();
switch (ts) { switch (ts) {
case BLOCKED: case BLOCKED:
sb.append("\t- blocked on " + info.getLockInfo()); sb.append("\t- blocked on ")
sb.append('\n'); .append(info.getLockInfo())
.append('\n');
break; break;
case WAITING: case WAITING:
sb.append("\t- waiting on " + info.getLockInfo()); sb.append("\t- waiting on ")
sb.append('\n'); .append(info.getLockInfo())
.append('\n');
break; break;
case TIMED_WAITING: case TIMED_WAITING:
sb.append("\t- waiting on " + info.getLockInfo()); sb.append("\t- waiting on ")
sb.append('\n'); .append(info.getLockInfo())
.append('\n');
break; break;
default: default:
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论