提交 e662eb1d authored 作者: Thomas Mueller's avatar Thomas Mueller

Use StringBuilder instead of StringBuffer

上级 53a3af71
...@@ -168,9 +168,8 @@ public class Bnf { ...@@ -168,9 +168,8 @@ public class Bnf {
page = "functions.html"; page = "functions.html";
} }
String link = StringUtils.urlEncode(found.getTopic().toLowerCase()); String link = StringUtils.urlEncode(found.getTopic().toLowerCase());
buff.append("<a href=\""+page+"#"+link+"\">"); buff.append("<a href=\"").append(page).append("#").
buff.append(s); append(link).append("\">").append(s).append("</a>");
buff.append("</a>");
} }
return buff.toString(); return buff.toString();
} }
......
...@@ -260,8 +260,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -260,8 +260,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
} else { } else {
buff.append(columnList); buff.append(columnList);
} }
buff.append(" FROM "); buff.append(" FROM ").append(table.getSQL());
buff.append(table.getSQL());
String newTableSQL = buff.toString(); String newTableSQL = buff.toString();
execute(newTableSQL, true); execute(newTableSQL, true);
newTable = (TableData) newTable.getSchema().getTableOrView(session, newTable.getName()); newTable = (TableData) newTable.getSchema().getTableOrView(session, newTable.getName());
......
...@@ -336,8 +336,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -336,8 +336,7 @@ public class ScriptCommand extends ScriptBase {
if (len <= 0) { if (len <= 0) {
break; break;
} }
buff.append(ByteUtils.convertBytesToString(bytes, len)); buff.append(ByteUtils.convertBytesToString(bytes, len)).append("')");
buff.append("')");
String sql = buff.toString(); String sql = buff.toString();
add(sql, true); add(sql, true);
} }
...@@ -357,8 +356,8 @@ public class ScriptCommand extends ScriptBase { ...@@ -357,8 +356,8 @@ public class ScriptCommand extends ScriptBase {
if (len < 0) { if (len < 0) {
break; break;
} }
buff.append(StringUtils.quoteStringSQL(new String(chars, 0, len))); buff.append(StringUtils.quoteStringSQL(new String(chars, 0, len))).
buff.append(", NULL)"); append(", NULL)");
String sql = buff.toString(); String sql = buff.toString();
add(sql, true); add(sql, true);
} }
......
...@@ -616,14 +616,14 @@ public class ConstraintReferential extends Constraint { ...@@ -616,14 +616,14 @@ public class ConstraintReferential extends Constraint {
buff.appendExceptFirst(", "); buff.appendExceptFirst(", ");
buff.append(c.getSQL()); buff.append(c.getSQL());
} }
buff.append(") C WHERE NOT EXISTS(SELECT 1 FROM "); buff.append(") C WHERE NOT EXISTS(SELECT 1 FROM ").
buff.append(refTable.getSQL()).append(" P WHERE "); append(refTable.getSQL()).append(" P WHERE ");
buff.resetCount(); buff.resetCount();
int i = 0; int i = 0;
for (IndexColumn c : columns) { for (IndexColumn c : columns) {
buff.appendExceptFirst(" AND "); buff.appendExceptFirst(" AND ");
buff.append("C.").append(c.getSQL()).append('='); buff.append("C.").append(c.getSQL()).append('=').
buff.append("P.").append(refColumns[i++].getSQL()); append("P.").append(refColumns[i++].getSQL());
} }
buff.append(')'); buff.append(')');
String sql = buff.toString(); String sql = buff.toString();
......
...@@ -151,8 +151,8 @@ public class UpdatableRow { ...@@ -151,8 +151,8 @@ public class UpdatableRow {
// public boolean isRowDeleted(Value[] row) throws SQLException { // public boolean isRowDeleted(Value[] row) throws SQLException {
// StringBuilder buff = new StringBuilder(); // StringBuilder buff = new StringBuilder();
// buff.append("SELECT COUNT(*) FROM "); // buff.append("SELECT COUNT(*) FROM ").
// buff.append(StringUtils.quoteIdentifier(tableName)); // append(StringUtils.quoteIdentifier(tableName));
// appendKeyCondition(buff); // appendKeyCondition(buff);
// PreparedStatement prep = conn.prepareStatement(buff.toString()); // PreparedStatement prep = conn.prepareStatement(buff.toString());
// setKey(prep, 1, row); // setKey(prep, 1, row);
......
...@@ -551,8 +551,7 @@ public class TableData extends Table implements RecordReader { ...@@ -551,8 +551,7 @@ public class TableData extends Table implements RecordReader {
} else { } else {
buff.append("MEMORY "); buff.append("MEMORY ");
} }
buff.append("TABLE "); buff.append("TABLE ").append(getSQL());
buff.append(getSQL());
if (comment != null) { if (comment != null) {
buff.append(" COMMENT ").append(StringUtils.quoteStringSQL(comment)); buff.append(" COMMENT ").append(StringUtils.quoteStringSQL(comment));
} }
......
...@@ -109,14 +109,12 @@ public class MultiDimension { ...@@ -109,14 +109,12 @@ public class MultiDimension {
*/ */
public String generatePreparedQuery(String table, String scalarColumn, String[] columns) { public String generatePreparedQuery(String table, String scalarColumn, String[] columns) {
StringBuilder buff = new StringBuilder("SELECT D.* FROM "); StringBuilder buff = new StringBuilder("SELECT D.* FROM ");
buff.append(StringUtils.quoteIdentifier(table)); buff.append(StringUtils.quoteIdentifier(table)).
buff.append(" D, TABLE(_FROM_ BIGINT=?, _TO_ BIGINT=?) WHERE "); append(" D, TABLE(_FROM_ BIGINT=?, _TO_ BIGINT=?) WHERE ").
buff.append(StringUtils.quoteIdentifier(scalarColumn)); append(StringUtils.quoteIdentifier(scalarColumn)).
buff.append(" BETWEEN _FROM_ AND _TO_"); append(" BETWEEN _FROM_ AND _TO_");
for (String col : columns) { for (String col : columns) {
buff.append(" AND "); buff.append(" AND ").append(StringUtils.quoteIdentifier(col)).append("+1 BETWEEN ?+1 AND ?+1");
buff.append(StringUtils.quoteIdentifier(col));
buff.append("+1 BETWEEN ?+1 AND ?+1");
} }
return buff.toString(); return buff.toString();
} }
......
...@@ -260,13 +260,13 @@ public class Recover extends Tool implements DataHandler { ...@@ -260,13 +260,13 @@ public class Recover extends Tool implements DataHandler {
byte[] passwordHash = sha.getHashWithSalt(userPasswordHash, salt); byte[] passwordHash = sha.getHashWithSalt(userPasswordHash, salt);
boolean admin = sql.indexOf("ADMIN") >= 0; boolean admin = sql.indexOf("ADMIN") >= 0;
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
buff.append("CREATE USER "); buff.append("CREATE USER ").
buff.append(Parser.quoteIdentifier(userName)); append(Parser.quoteIdentifier(userName)).
buff.append(" SALT '"); append(" SALT '").
buff.append(ByteUtils.convertBytesToString(salt)); append(ByteUtils.convertBytesToString(salt)).
buff.append("' HASH '"); append("' HASH '").
buff.append(ByteUtils.convertBytesToString(passwordHash)); append(ByteUtils.convertBytesToString(passwordHash)).
buff.append('\''); append('\'');
if (admin) { if (admin) {
buff.append(" ADMIN"); buff.append(" ADMIN");
} }
...@@ -1025,11 +1025,11 @@ public class Recover extends Tool implements DataHandler { ...@@ -1025,11 +1025,11 @@ public class Recover extends Tool implements DataHandler {
byte[] salt = RandomUtils.getSecureBytes(Constants.SALT_LEN); byte[] salt = RandomUtils.getSecureBytes(Constants.SALT_LEN);
byte[] passwordHash = sha.getHashWithSalt(userPasswordHash, salt); byte[] passwordHash = sha.getHashWithSalt(userPasswordHash, salt);
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
buff.append("SALT '"); buff.append("SALT '").
buff.append(ByteUtils.convertBytesToString(salt)); append(ByteUtils.convertBytesToString(salt)).
buff.append("' HASH '"); append("' HASH '").
buff.append(ByteUtils.convertBytesToString(passwordHash)); append(ByteUtils.convertBytesToString(passwordHash)).
buff.append('\''); append('\'');
byte[] replacement = buff.toString().getBytes(); byte[] replacement = buff.toString().getBytes();
System.arraycopy(replacement, 0, s.getBytes(), saltIndex, replacement.length); System.arraycopy(replacement, 0, s.getBytes(), saltIndex, replacement.length);
store.seek(pageSize * pageId); store.seek(pageSize * pageId);
......
...@@ -268,8 +268,10 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -268,8 +268,10 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
public String getStatus() { public String getStatus() {
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
if (isRunning(false)) { if (isRunning(false)) {
buff.append(service.getType()).append(" server running on "); buff.append(service.getType()).
buff.append(service.getURL()).append(" ("); append(" server running on ").
append(service.getURL()).
append(" (");
if (service.getAllowOthers()) { if (service.getAllowOthers()) {
buff.append("others can connect"); buff.append("others can connect");
} else { } else {
...@@ -277,8 +279,10 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -277,8 +279,10 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
} }
buff.append(')'); buff.append(')');
} else { } else {
buff.append("The " + service.getType() + " server could not be started. Possible cause: another server is already running on "); buff.append("The ").
buff.append(service.getURL()); append(service.getType()).
append(" server could not be started. Possible cause: another server is already running on ").
append(service.getURL());
} }
return buff.toString(); return buff.toString();
} }
......
...@@ -482,8 +482,7 @@ public class Shell extends Tool { ...@@ -482,8 +482,7 @@ public class Shell extends Tool {
for (int j = label.length(); j < longest; j++) { for (int j = label.length(); j < longest; j++) {
buff.append(' '); buff.append(' ');
} }
buff.append(": "); buff.append(": ").append(rs.getString(i + 1));
buff.append(rs.getString(i + 1));
} }
} else { } else {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
...@@ -512,8 +511,7 @@ public class Shell extends Tool { ...@@ -512,8 +511,7 @@ public class Shell extends Tool {
} }
if (rowCount == 0 && listMode) { if (rowCount == 0 && listMode) {
for (String label : columns) { for (String label : columns) {
buff.append(label); buff.append(label).append('\n');
buff.append('\n');
} }
println(buff.toString()); println(buff.toString());
} }
......
...@@ -141,8 +141,7 @@ public class ScriptReader { ...@@ -141,8 +141,7 @@ public class ScriptReader {
insideRemark = true; insideRemark = true;
blockRemark = true; blockRemark = true;
if (!skipRemarks) { if (!skipRemarks) {
buff.append((char) last); buff.append((char) last).append((char) c);
buff.append((char) c);
} }
while (true) { while (true) {
c = read(); c = read();
...@@ -173,8 +172,7 @@ public class ScriptReader { ...@@ -173,8 +172,7 @@ public class ScriptReader {
insideRemark = true; insideRemark = true;
blockRemark = false; blockRemark = false;
if (!skipRemarks) { if (!skipRemarks) {
buff.append((char) last); buff.append((char) last).append((char) c);
buff.append((char) c);
} }
while (true) { while (true) {
c = read(); c = read();
...@@ -205,8 +203,7 @@ public class ScriptReader { ...@@ -205,8 +203,7 @@ public class ScriptReader {
insideRemark = true; insideRemark = true;
blockRemark = false; blockRemark = false;
if (!skipRemarks) { if (!skipRemarks) {
buff.append((char) last); buff.append((char) last).append((char) c);
buff.append((char) c);
} }
while (true) { while (true) {
c = read(); c = read();
......
...@@ -706,9 +706,9 @@ public class StringUtils { ...@@ -706,9 +706,9 @@ public class StringUtils {
break; break;
default: default:
if (ch < ' ' || ch > 127) { if (ch < ' ' || ch > 127) {
buff.append("&#x"); buff.append("&#x").
buff.append(Integer.toHexString(ch)); append(Integer.toHexString(ch)).
buff.append(';'); append(';');
} else { } else {
buff.append(ch); buff.append(ch);
} }
...@@ -734,8 +734,7 @@ public class StringUtils { ...@@ -734,8 +734,7 @@ public class StringUtils {
buff.append(s.substring(index)); buff.append(s.substring(index));
break; break;
} }
buff.append(s.substring(index, next)); buff.append(s.substring(index, next)).append(after);
buff.append(after);
index = next + before.length(); index = next + before.length();
} }
return buff.toString(); return buff.toString();
......
...@@ -292,11 +292,8 @@ java org.h2.test.TestAll timer ...@@ -292,11 +292,8 @@ java org.h2.test.TestAll timer
/* /*
recover tool: move shell tool: document encoding problem. mac: use
alter table add constraint behind insert into select java -Dfile.encoding=UTF-8;
j > 0 -> StatementBuilder
buff.append... chain
BaseIndex or TableData should have its own compareMode BaseIndex or TableData should have its own compareMode
(default is: Database.compareMode when created). (default is: Database.compareMode when created).
...@@ -307,9 +304,6 @@ this mean changing the collation is allowed if there are tables. ...@@ -307,9 +304,6 @@ this mean changing the collation is allowed if there are tables.
test case for running out of disk space (using a special file system) test case for running out of disk space (using a special file system)
shell tool: document encoding problem. mac: use
java -Dfile.encoding=UTF-8
auto-build: prepare release auto-build: prepare release
documentation: rolling review at roadmap.html: done documentation: rolling review at roadmap.html: done
......
...@@ -444,8 +444,8 @@ public class BuildBase { ...@@ -444,8 +444,8 @@ public class BuildBase {
StringBuilder buff = new StringBuilder(value.length * 2); StringBuilder buff = new StringBuilder(value.length * 2);
for (byte c : value) { for (byte c : value) {
int x = c & 0xff; int x = c & 0xff;
buff.append(Integer.toString(x >> 4, 16)); buff.append(Integer.toString(x >> 4, 16)).
buff.append(Integer.toString(x & 0xf, 16)); append(Integer.toString(x & 0xf, 16));
} }
return buff.toString(); return buff.toString();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论