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

Use StringBuilder instead of StringBuffer

上级 3f26a9ef
......@@ -67,6 +67,8 @@ Newer version or compatible software works too.
<h2>Building the Software</h2>
<p>
You need to install a JDK, for example the Sun JDK version 1.4, 1.5 or 1.6.
Ensure that Java binary directory is included in the PATH environment variable, and that
the environment variable JAVA_HOME points to your Java installation.
On the command line, go to the directory h2 and execute the following command:
</p>
<pre>
......
......@@ -18,7 +18,13 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>-
<ul><li>Microsoft Windows Vista: when using the the installer, Vista wrote
"This program may not have installed correctly." This message should no longer appear
(in the h2.nsi file, the line 'RequestExecutionLevel highest' was added).
</li><li>The Recover tool did not always work when the database contains
referential integrity constraints.
</li><li>Java 1.5 is now required to run H2. If required, Retrotranslator can be used
to create a Java 1.4 version (http://retrotranslator.sourceforge.net/).
</li></ul>
<h2>Version 1.1.113 (2009-05-21)</h2>
......
......@@ -47,7 +47,7 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>Option to shutdown all the running servers (on the same VM).
</li><li>Optimize ID=? OR ID=?: convert to IN(...)
</li><li>Index organized tables CREATE TABLE...(...) ORGANIZATION INDEX (store in data file) (probably file format changes are required for rowId)
</li><li>Better space re-use in the files after deleting data: shrink the data file without closing the database (if the end of the file is empty)
</li><li>[Requires page store] Better space re-use in the files after deleting data: shrink the data file without closing the database (if the end of the file is empty)
</li><li>Implement INSTEAD OF trigger (for views, tables, metadata tables).
</li><li>Triggers for metadata tables; use for PostgreSQL catalog
</li><li>Support triggers for INFORMATION_SCHEMA tables (to better support PostgreSQL catalog: rebuild after creating new tables)
......
......@@ -23,6 +23,7 @@ import org.h2.table.Column;
import org.h2.table.PlanItem;
import org.h2.table.Table;
import org.h2.table.TableFilter;
import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils;
import org.h2.value.Value;
......@@ -146,18 +147,15 @@ public class Update extends Prepared {
}
public String getPlanSQL() {
StringBuilder buff = new StringBuilder("UPDATE ");
StatementBuilder buff = new StatementBuilder("UPDATE ");
buff.append(tableFilter.getPlanSQL(false)).append("\nSET ");
Table table = tableFilter.getTable();
int columnCount = table.getColumns().length;
for (int i = 0, j = 0; i < columnCount; i++) {
for (int i = 0; i < columnCount; i++) {
Expression newExpr = expressions[i];
if (newExpr != null) {
if (j > 0) {
buff.append(",\n");
}
j++;
Column column = table.getColumn(i);
buff.appendExceptFirst(",\n");
buff.append(column.getName()).append(" = ").append(newExpr.getSQL());
}
}
......
......@@ -47,20 +47,16 @@ public class ConstraintCheck extends Constraint {
public String getCreateSQLForCopy(Table forTable, String quotedName) {
StringBuilder buff = new StringBuilder("ALTER TABLE ");
buff.append(forTable.getSQL()).append(" ADD CONSTRAINT ");
buff.append(quotedName);
buff.append(forTable.getSQL()).append(" ADD CONSTRAINT ").append(quotedName);
if (comment != null) {
buff.append(" COMMENT ").append(StringUtils.quoteStringSQL(comment));
}
buff.append(" CHECK").append(StringUtils.enclose(expr.getSQL()));
buff.append(" NOCHECK");
buff.append(" CHECK").append(StringUtils.enclose(expr.getSQL())).append(" NOCHECK");
return buff.toString();
}
public String getShortDescription() {
StringBuilder buff = new StringBuilder(getName());
buff.append(": ").append(expr.getSQL());
return buff.toString();
return getName() + ": " + expr.getSQL();
}
public String getCreateSQLWithoutIndexes() {
......@@ -120,10 +116,7 @@ public class ConstraintCheck extends Constraint {
// don't check at startup
return;
}
StringBuilder buff = new StringBuilder("SELECT 1 FROM ");
buff.append(filter.getTable().getSQL());
buff.append(" WHERE NOT(").append(expr.getSQL()).append(')');
String sql = buff.toString();
String sql = "SELECT 1 FROM " + filter.getTable().getSQL() + " WHERE NOT(" + expr.getSQL() + ")";
LocalResult r = session.prepare(sql).query(1);
if (r.next()) {
throw Message.getSQLException(ErrorCode.CHECK_CONSTRAINT_VIOLATED_1, getName());
......
......@@ -68,8 +68,7 @@ public class Comment extends DbObjectBase {
public String getCreateSQL() {
StringBuilder buff = new StringBuilder("COMMENT ON ");
buff.append(getTypeName(objectType)).append(' ').
append(objectName).append(" IS ");
buff.append(getTypeName(objectType)).append(' ').append(objectName).append(" IS ");
if (commentText == null) {
buff.append("NULL");
} else {
......
......@@ -198,8 +198,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
}
private String getFilePrefix(String dir) {
StringBuilder buff = new StringBuilder();
buff.append(dir);
StringBuilder buff = new StringBuilder(dir);
buff.append('/');
for (int i = 0; i < databaseName.length(); i++) {
char ch = databaseName.charAt(i);
......
......@@ -54,9 +54,7 @@ public class UserAggregate extends DbObjectBase {
}
public String getCreateSQL() {
StringBuilder buff = new StringBuilder("CREATE FORCE AGGREGATE ");
buff.append(getSQL()).append(" FOR ").append(Parser.quoteIdentifier(className));
return buff.toString();
return "CREATE FORCE AGGREGATE " + getSQL() + " FOR " + Parser.quoteIdentifier(className);
}
public int getType() {
......
......@@ -1319,8 +1319,7 @@ public class Function extends Expression implements FunctionCall {
if (i == -1) {
break;
}
buff.append(s.substring(start, i));
buff.append(with);
buff.append(s.substring(start, i)).append(with);
start = i + len;
}
buff.append(s.substring(start));
......
......@@ -556,13 +556,9 @@ public class FullText {
};
result.addRow(row);
} else {
StringBuilder buff = new StringBuilder();
buff.append(StringUtils.quoteIdentifier(index.schema)).
append('.').
append(StringUtils.quoteIdentifier(index.table)).
append(" WHERE ").
append(key);
String query = buff.toString();
String query = StringUtils.quoteIdentifier(index.schema) +
"." + StringUtils.quoteIdentifier(index.table) +
" WHERE " + key;
result.addRow(new String[] { query });
}
rowCount++;
......@@ -639,10 +635,8 @@ public class FullText {
private static void indexExistingRows(Connection conn, String schema, String table) throws SQLException {
FullText.FullTextTrigger existing = new FullText.FullTextTrigger();
existing.init(conn, schema, null, table, false, Trigger.INSERT);
StringBuilder buff = new StringBuilder("SELECT * FROM ");
buff.append(StringUtils.quoteIdentifier(schema)).
append('.').append(StringUtils.quoteIdentifier(table));
ResultSet rs = conn.createStatement().executeQuery(buff.toString());
String sql = "SELECT * FROM " + StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(table);
ResultSet rs = conn.createStatement().executeQuery(sql);
int columnCount = rs.getMetaData().getColumnCount();
while (rs.next()) {
Object[] row = new Object[columnCount];
......
......@@ -224,12 +224,14 @@ public class FullTextLucene extends FullText {
String trigger = StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(TRIGGER_PREFIX + table);
stat.execute("DROP TRIGGER IF EXISTS " + trigger);
StringBuilder buff = new StringBuilder("CREATE TRIGGER IF NOT EXISTS ");
buff.append(trigger);
buff.append(" AFTER INSERT, UPDATE, DELETE ON ");
buff.append(StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(table));
buff.append(" FOR EACH ROW CALL \"");
buff.append(FullTextLucene.FullTextTrigger.class.getName());
buff.append("\"");
buff.append(trigger).
append(" AFTER INSERT, UPDATE, DELETE ON ").
append(StringUtils.quoteIdentifier(schema)).
append('.').
append(StringUtils.quoteIdentifier(table)).
append(" FOR EACH ROW CALL \"").
append(FullTextLucene.FullTextTrigger.class.getName()).
append("\"");
stat.execute(buff.toString());
}
......@@ -279,9 +281,8 @@ public class FullTextLucene extends FullText {
private static void indexExistingRows(Connection conn, String schema, String table) throws SQLException {
FullTextLucene.FullTextTrigger existing = new FullTextLucene.FullTextTrigger();
existing.init(conn, schema, null, table, false, Trigger.INSERT);
StringBuilder buff = new StringBuilder("SELECT * FROM ");
buff.append(StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(table));
ResultSet rs = conn.createStatement().executeQuery(buff.toString());
String sql = "SELECT * FROM " + StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(table);
ResultSet rs = conn.createStatement().executeQuery(sql);
int columnCount = rs.getMetaData().getColumnCount();
while (rs.next()) {
Object[] row = new Object[columnCount];
......
......@@ -150,10 +150,8 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
}
public SQLException getDuplicateKeyException() {
StringBuilder buff = new StringBuilder(getName());
buff.append(" ON ").append(table.getSQL()).append('(');
buff.append(getColumnListSQL()).append(')');
return Message.getSQLException(ErrorCode.DUPLICATE_KEY_1, buff.toString());
String sql = getName() + " ON " + table.getSQL() + "(" + getColumnListSQL() + ")";
return Message.getSQLException(ErrorCode.DUPLICATE_KEY_1, sql);
}
public String getPlanSQL() {
......
......@@ -51,15 +51,11 @@ public class LinkedIndex extends BaseIndex {
}
public void add(Session session, Row row) throws SQLException {
StringBuilder buff = new StringBuilder("INSERT INTO ");
buff.append(targetTableName);
buff.append(" VALUES(");
for (int i = 0, j = 0; i < row.getColumnCount(); i++) {
StatementBuilder buff = new StatementBuilder("INSERT INTO ");
buff.append(targetTableName).append(" VALUES(");
for (int i = 0; i < row.getColumnCount(); i++) {
Value v = row.getValue(i);
if (j > 0) {
buff.append(',');
}
j++;
buff.appendExceptFirst(",");
if (isNull(v)) {
buff.append("NULL");
} else {
......
......@@ -150,14 +150,9 @@ public class JdbcSQLException extends SQLException {
private void buildMessage() {
StringBuilder buff = new StringBuilder(originalMessage == null ? "- " : originalMessage);
if (sql != null) {
buff.append("; SQL statement:\n");
buff.append(sql);
buff.append("; SQL statement:\n").append(sql);
}
buff.append(" [");
buff.append(getErrorCode());
buff.append('-');
buff.append(Constants.BUILD_ID);
buff.append(']');
buff.append(" [").append(getErrorCode()).append('-').append(Constants.BUILD_ID).append(']');
message = buff.toString();
}
......
......@@ -416,15 +416,15 @@ implements XAConnection, XAResource
private String quoteXid(Xid xid) {
StringBuilder buff = new StringBuilder();
buff.append("\"f:");
buff.append(xid.getFormatId());
buff.append(",bq:");
buff.append(ByteUtils.convertBytesToString(xid.getBranchQualifier()));
buff.append(",gx:");
buff.append(ByteUtils.convertBytesToString(xid.getGlobalTransactionId()));
buff.append(",c:");
buff.append(xid.getClass().getName());
buff.append("\"");
buff.append("\"f:").
append(xid.getFormatId()).
append(",bq:").
append(ByteUtils.convertBytesToString(xid.getBranchQualifier())).
append(",gx:").
append(ByteUtils.convertBytesToString(xid.getGlobalTransactionId())).
append(",c:").
append(xid.getClass().getName()).
append("\"");
return buff.toString();
}
......
......@@ -54,12 +54,12 @@ implements Xid
*/
public String getAsString() {
StringBuilder buff = new StringBuilder(PREFIX);
buff.append('_');
buff.append(formatId);
buff.append('_');
buff.append(ByteUtils.convertBytesToString(branchQualifier));
buff.append('_');
buff.append(ByteUtils.convertBytesToString(globalTransactionId));
buff.append('_').
append(formatId).
append('_').
append(ByteUtils.convertBytesToString(branchQualifier)).
append('_').
append(ByteUtils.convertBytesToString(globalTransactionId));
return buff.toString();
}
......
......@@ -215,8 +215,7 @@ public class Trace {
return;
}
StringBuilder buff = new StringBuilder(sql.length() + params.length() + 20);
buff.append(lineSeparator);
buff.append("/*SQL");
buff.append(lineSeparator).append("/*SQL");
boolean space = false;
if (params.length() > 0) {
// This looks like a bug, but it is intentional:
......@@ -226,26 +225,23 @@ public class Trace {
// of the statement simplifies separating the SQL statement
// from the parameters (no need to parse).
space = true;
buff.append(" l:");
buff.append(sql.length());
buff.append(" l:").append(sql.length());
}
if (count > 0) {
space = true;
buff.append(" #:");
buff.append(count);
buff.append(" #:").append(count);
}
if (time > 0) {
space = true;
buff.append(" t:");
buff.append(time);
buff.append(" t:").append(time);
}
if (!space) {
buff.append(' ');
}
buff.append("*/");
buff.append(StringUtils.javaEncode(sql));
buff.append(StringUtils.javaEncode(params));
buff.append(';');
buff.append("*/").
append(StringUtils.javaEncode(sql)).
append(StringUtils.javaEncode(params)).
append(';');
sql = buff.toString();
traceWriter.write(TraceSystem.INFO, module, sql, null);
}
......
......@@ -360,13 +360,11 @@ public class TraceObject {
try {
for (Map.Entry<String, Class < ? >> entry : map.entrySet()) {
String key = entry.getKey();
buff.append(key);
buff.append(':');
Class< ? > clazz = entry.getValue();
buff.append(clazz.getName());
buff.append(key).append(':').append(clazz.getName());
}
} catch (Exception e) {
buff.append(e.toString() + ": " + map.toString());
buff.append(e.toString()).append(": ").append(map.toString());
}
buff.append("*/");
return buff.toString();
......
......@@ -38,12 +38,7 @@ public class Constant extends SchemaObjectBase {
}
public String getCreateSQL() {
StringBuilder buff = new StringBuilder();
buff.append("CREATE CONSTANT ");
buff.append(getSQL());
buff.append(" VALUE ");
buff.append(value.getSQL());
return buff.toString();
return "CREATE CONSTANT " + getSQL() + " VALUE " + value.getSQL();
}
public int getType() {
......
......@@ -88,12 +88,8 @@ public class Schema extends DbObjectBase {
if (system) {
return null;
}
StringBuilder buff = new StringBuilder();
buff.append("CREATE SCHEMA IF NOT EXISTS ");
buff.append(getSQL());
buff.append(" AUTHORIZATION ");
buff.append(owner.getSQL());
return buff.toString();
return "CREATE SCHEMA IF NOT EXISTS " +
getSQL() + " AUTHORIZATION " + owner.getSQL();
}
public int getType() {
......
......@@ -69,18 +69,13 @@ public class Sequence extends SchemaObjectBase {
}
public synchronized String getCreateSQL() {
StringBuilder buff = new StringBuilder();
buff.append("CREATE SEQUENCE ");
buff.append(getSQL());
buff.append(" START WITH ");
buff.append(value);
StringBuilder buff = new StringBuilder("CREATE SEQUENCE ");
buff.append(getSQL()).append(" START WITH ").append(value);
if (increment != 1) {
buff.append(" INCREMENT BY ");
buff.append(increment);
buff.append(" INCREMENT BY ").append(increment);
}
if (cacheSize != DEFAULT_CACHE_SIZE) {
buff.append(" CACHE ");
buff.append(cacheSize);
buff.append(" CACHE ").append(cacheSize);
}
if (belongsToTable) {
buff.append(" BELONGS_TO_TABLE");
......
......@@ -229,28 +229,23 @@ public class TriggerObject extends SchemaObjectBase {
}
public String getCreateSQLForCopy(Table table, String quotedName) {
StringBuilder buff = new StringBuilder();
buff.append("CREATE FORCE TRIGGER ");
StringBuilder buff = new StringBuilder("CREATE FORCE TRIGGER ");
buff.append(quotedName);
if (before) {
buff.append(" BEFORE ");
} else {
buff.append(" AFTER ");
}
buff.append(getTypeNameList());
buff.append(" ON ");
buff.append(table.getSQL());
buff.append(getTypeNameList()).append(" ON ").append(table.getSQL());
if (rowBased) {
buff.append(" FOR EACH ROW");
}
if (noWait) {
buff.append(" NOWAIT");
} else {
buff.append(" QUEUE ");
buff.append(queueSize);
buff.append(" QUEUE ").append(queueSize);
}
buff.append(" CALL ");
buff.append(Parser.quoteIdentifier(triggerClassName));
buff.append(" CALL ").append(Parser.quoteIdentifier(triggerClassName));
return buff.toString();
}
......
......@@ -286,9 +286,7 @@ public class PageParser {
break;
default:
if (c >= 128) {
buff.append("&#");
buff.append((int) c);
buff.append(';');
buff.append("&#").append((int) c).append(';');
} else {
buff.append(c);
}
......
......@@ -288,15 +288,15 @@ class WebThread extends Thread implements DatabaseEventListener {
private String getComboBox(String[] elements, String selected) {
StringBuilder buff = new StringBuilder();
for (String value : elements) {
buff.append("<option value=\"");
buff.append(PageParser.escapeHtmlData(value));
buff.append("\"");
buff.append("<option value=\"").
append(PageParser.escapeHtmlData(value)).
append("\"");
if (value.equals(selected)) {
buff.append(" selected");
}
buff.append('>');
buff.append(PageParser.escapeHtml(value));
buff.append("</option>");
buff.append('>').
append(PageParser.escapeHtml(value)).
append("</option>");
}
return buff.toString();
}
......@@ -1278,11 +1278,9 @@ class WebThread extends Thread implements DatabaseEventListener {
for (int i = 0; i < list.size(); i++) {
String s = list.get(i);
if (!s.startsWith("@")) {
buff.append(PageParser.escapeHtml(s + ";"));
buff.append("<br />");
buff.append(PageParser.escapeHtml(s + ";")).append("<br />");
}
buff.append(getResult(conn, i + 1, s, list.size() == 1, false));
buff.append("<br />");
buff.append(getResult(conn, i + 1, s, list.size() == 1, false)).append("<br />");
}
result = buff.toString();
}
......@@ -1721,9 +1719,7 @@ class WebThread extends Thread implements DatabaseEventListener {
if (!isResultSet) {
buff.append("${text.result.updateCount}: " + stat.getUpdateCount());
time = System.currentTimeMillis() - time;
buff.append("<br />(");
buff.append(time);
buff.append(" ms)");
buff.append("<br />(").append(time).append(" ms)");
stat.close();
return buff.toString();
}
......@@ -1839,18 +1835,18 @@ class WebThread extends Thread implements DatabaseEventListener {
private String getHistoryString() {
StringBuilder buff = new StringBuilder();
ArrayList<String> history = session.getCommands();
buff.append("<table cellspacing=0 cellpadding=0>");
buff.append("<tr><th></th><th>Command</th></tr>");
buff.append("<table cellspacing=0 cellpadding=0><tr><th></th><th>Command</th></tr>");
for (int i = history.size() - 1; i >= 0; i--) {
String sql = history.get(i);
buff.append("<tr><td>");
buff.append("<a href=\"getHistory.do?id=");
buff.append(i);
buff
.append("&jsessionid=${sessionId}\" target=\"h2query\" ><img width=16 height=16 src=\"ico_write.gif\" onmouseover = \"this.className ='icon_hover'\" onmouseout = \"this.className ='icon'\" class=\"icon\" alt=\"${text.resultEdit.edit}\" title=\"${text.resultEdit.edit}\" border=\"1\"/></a>");
buff.append("</td><td>");
buff.append(PageParser.escapeHtml(sql));
buff.append("</td></tr>");
buff.append("<tr><td><a href=\"getHistory.do?id=").
append(i).
append("&jsessionid=${sessionId}\" target=\"h2query\" >").
append("<img width=16 height=16 src=\"ico_write.gif\" onmouseover = \"this.className ='icon_hover'\" ").
append("onmouseout = \"this.className ='icon'\" class=\"icon\" alt=\"${text.resultEdit.edit}\" ").
append("title=\"${text.resultEdit.edit}\" border=\"1\"/></a>").
append("</td><td>").
append(PageParser.escapeHtml(sql)).
append("</td></tr>");
}
buff.append("</table>");
return buff.toString();
......@@ -1861,23 +1857,23 @@ class WebThread extends Thread implements DatabaseEventListener {
if (meta == null) {
return "No parameter meta data";
}
buff.append("<table cellspacing=0 cellpadding=0>");
buff.append("<tr><th>className</th><th>mode</th><th>type</th>");
buff.append("<th>typeName</th><th>precision</th><th>scale</th></tr>");
buff.append("<table cellspacing=0 cellpadding=0>").
append("<tr><th>className</th><th>mode</th><th>type</th>").
append("<th>typeName</th><th>precision</th><th>scale</th></tr>");
for (int i = 0; i < meta.getParameterCount(); i++) {
buff.append("</tr><td>");
buff.append(meta.getParameterClassName(i + 1));
buff.append("</td><td>");
buff.append(meta.getParameterMode(i + 1));
buff.append("</td><td>");
buff.append(meta.getParameterType(i + 1));
buff.append("</td><td>");
buff.append(meta.getParameterTypeName(i + 1));
buff.append("</td><td>");
buff.append(meta.getPrecision(i + 1));
buff.append("</td><td>");
buff.append(meta.getScale(i + 1));
buff.append("</td></tr>");
buff.append("</tr><td>").
append(meta.getParameterClassName(i + 1)).
append("</td><td>").
append(meta.getParameterMode(i + 1)).
append("</td><td>").
append(meta.getParameterType(i + 1)).
append("</td><td>").
append(meta.getParameterTypeName(i + 1)).
append("</td><td>").
append(meta.getPrecision(i + 1)).
append("</td><td>").
append(meta.getScale(i + 1)).
append("</td></tr>");
}
buff.append("</table>");
return buff.toString();
......@@ -1889,11 +1885,11 @@ class WebThread extends Thread implements DatabaseEventListener {
time = System.currentTimeMillis() - time;
StringBuilder buff = new StringBuilder();
if (edit) {
buff.append("<form id=\"editing\" name=\"editing\" method=\"post\" "
+ "action=\"editResult.do?jsessionid=${sessionId}\" id=\"mainForm\" target=\"h2result\">");
buff.append("<input type=\"hidden\" name=\"op\" value=\"1\" />");
buff.append("<input type=\"hidden\" name=\"row\" value=\"\" />");
buff.append("<table cellspacing=0 cellpadding=0 id=\"editTable\">");
buff.append("<form id=\"editing\" name=\"editing\" method=\"post\" " +
"action=\"editResult.do?jsessionid=${sessionId}\" id=\"mainForm\" target=\"h2result\">" +
"<input type=\"hidden\" name=\"op\" value=\"1\" />" +
"<input type=\"hidden\" name=\"row\" value=\"\" />" +
"<table cellspacing=0 cellpadding=0 id=\"editTable\">");
} else {
buff.append("<table cellspacing=0 cellpadding=0>");
}
......
......@@ -52,30 +52,28 @@ public class LinkSchema {
while (rs.next()) {
String table = rs.getString("TABLE_NAME");
StringBuilder buff = new StringBuilder();
buff.append("DROP TABLE IF EXISTS ");
buff.append(StringUtils.quoteIdentifier(targetSchema));
buff.append('.');
buff.append(StringUtils.quoteIdentifier(table));
String sql = buff.toString();
stat.execute(sql);
buff.append("DROP TABLE IF EXISTS ").
append(StringUtils.quoteIdentifier(targetSchema)).
append('.').
append(StringUtils.quoteIdentifier(table));
stat.execute(buff.toString());
buff = new StringBuilder();
buff.append("CREATE LINKED TABLE ");
buff.append(StringUtils.quoteIdentifier(targetSchema));
buff.append('.');
buff.append(StringUtils.quoteIdentifier(table));
buff.append('(');
buff.append(StringUtils.quoteStringSQL(driver));
buff.append(", ");
buff.append(StringUtils.quoteStringSQL(url));
buff.append(", ");
buff.append(StringUtils.quoteStringSQL(user));
buff.append(", ");
buff.append(StringUtils.quoteStringSQL(password));
buff.append(", ");
buff.append(StringUtils.quoteStringSQL(table));
buff.append(')');
sql = buff.toString();
stat.execute(sql);
buff.append("CREATE LINKED TABLE ").
append(StringUtils.quoteIdentifier(targetSchema)).
append('.').
append(StringUtils.quoteIdentifier(table)).
append('(').
append(StringUtils.quoteStringSQL(driver)).
append(", ").
append(StringUtils.quoteStringSQL(url)).
append(", ").
append(StringUtils.quoteStringSQL(user)).
append(", ").
append(StringUtils.quoteStringSQL(password)).
append(", ").
append(StringUtils.quoteStringSQL(table)).
append(')');
stat.execute(buff.toString());
result.addRow(new String[] { table });
}
} finally {
......
......@@ -1341,12 +1341,10 @@ public class MetaTable extends Table {
}
String columnList = null;
if (columns != null) {
StringBuilder buff = new StringBuilder();
for (int j = 0; j < columns.length; j++) {
if (j > 0) {
buff.append(',');
}
buff.append(columns[j].column.getName());
StatementBuilder buff = new StatementBuilder();
for (IndexColumn col : columns) {
buff.appendExceptFirst(",");
buff.append(col.column.getName());
}
columnList = buff.toString();
}
......
......@@ -458,19 +458,17 @@ public class TableData extends Table implements RecordReader {
}
private String getDeadlockDetails(ObjectArray<Session> sessions) {
StringBuilder buff = new StringBuilder();
StatementBuilder buff = new StatementBuilder();
for (Session s : sessions) {
buff.append('\n');
Table lock = s.getWaitForLock();
buff.append("Session ").append(s).append(" is waiting to lock ").append(lock);
buff.append(" while locking ");
Table[] locks = s.getLocks();
for (int j = 0; j < locks.length; j++) {
if (j > 0) {
buff.append(", ");
}
Table t = locks[j];
buff.append(t);
buff.append("\nSession ").
append(s.toString()).
append(" is waiting to lock ").
append(lock.toString()).
append(" while locking ");
for (Table t : s.getLocks()) {
buff.appendExceptFirst(", ");
buff.append(t.toString());
if (t instanceof TableData) {
if (((TableData) t).lockExclusive == s) {
buff.append(" (exclusive)");
......
......@@ -296,31 +296,28 @@ public class TableLink extends Table {
}
public String getCreateSQL() {
StringBuilder buff = new StringBuilder();
buff.append("CREATE FORCE ");
StringBuilder buff = new StringBuilder("CREATE FORCE ");
if (getTemporary()) {
if (globalTemporary) {
buff.append("GLOBAL ");
}
buff.append("TEMP ");
}
buff.append("LINKED TABLE ");
buff.append(getSQL());
buff.append("LINKED TABLE ").append(getSQL());
if (comment != null) {
buff.append(" COMMENT ");
buff.append(StringUtils.quoteStringSQL(comment));
buff.append(" COMMENT ").append(StringUtils.quoteStringSQL(comment));
}
buff.append('(');
buff.append(StringUtils.quoteStringSQL(driver));
buff.append(", ");
buff.append(StringUtils.quoteStringSQL(url));
buff.append(", ");
buff.append(StringUtils.quoteStringSQL(user));
buff.append(", ");
buff.append(StringUtils.quoteStringSQL(password));
buff.append(", ");
buff.append(StringUtils.quoteStringSQL(originalTable));
buff.append(')');
buff.append('(').
append(StringUtils.quoteStringSQL(driver)).
append(", ").
append(StringUtils.quoteStringSQL(url)).
append(", ").
append(StringUtils.quoteStringSQL(user)).
append(", ").
append(StringUtils.quoteStringSQL(password)).
append(", ").
append(StringUtils.quoteStringSQL(originalTable)).
append(')');
if (emitUpdates) {
buff.append(" EMIT UPDATES");
}
......
......@@ -246,9 +246,7 @@ public class TableView extends Table {
public String getSQL() {
if (getTemporary()) {
StringBuilder buff = new StringBuilder(querySQL.length());
buff.append('(').append(querySQL).append(')');
return buff.toString();
return "(" + querySQL + ")";
}
return super.getSQL();
}
......
......@@ -181,18 +181,18 @@ public class ConvertTraceFile extends Tool {
timeTotal = 1;
}
for (Stat stat : list) {
StringBuilder buff = new StringBuilder(100);
buff.append("-- ");
buff.append(padNumberLeft(100 * stat.time / timeTotal, 3));
buff.append("% ");
accumTime += stat.time;
buff.append(padNumberLeft(100 * accumTime / timeTotal, 3));
buff.append('%');
buff.append(padNumberLeft(stat.time, 8));
buff.append(padNumberLeft(stat.executeCount, 8));
buff.append(padNumberLeft(stat.resultCount, 8));
buff.append(' ');
buff.append(stat.sql);
StringBuilder buff = new StringBuilder(100);
buff.append("-- ").
append(padNumberLeft(100 * stat.time / timeTotal, 3)).
append("% ").
append(padNumberLeft(100 * accumTime / timeTotal, 3)).
append('%').
append(padNumberLeft(stat.time, 8)).
append(padNumberLeft(stat.executeCount, 8)).
append(padNumberLeft(stat.resultCount, 8)).
append(' ').
append(stat.sql);
scriptWriter.println(buff.toString());
}
}
......
......@@ -119,8 +119,7 @@ public class RunScript extends Tool {
StringBuilder buff = new StringBuilder();
i++;
for (; i < args.length; i++) {
buff.append(' ');
buff.append(args[i]);
buff.append(' ').append(args[i]);
}
options = buff.toString();
} else if (arg.equals("-help") || arg.equals("-?")) {
......@@ -228,8 +227,7 @@ public class RunScript extends Tool {
s = StringUtils.replaceAll(s, "\n", "\n--> ");
s = StringUtils.replaceAll(s, "\r", "\r--> ");
}
buff.append(' ');
buff.append(s);
buff.append(' ').append(s);
}
}
buff.append("\n;");
......
......@@ -62,12 +62,10 @@ public abstract class Tool {
protected void printNoDatabaseFilesFound(String dir, String db) {
StringBuilder buff = new StringBuilder("No database files have been found");
if (dir != null) {
buff.append(" in directory ");
buff.append(dir);
buff.append(" in directory ").append(dir);
}
if (db != null) {
buff.append(" for the database ");
buff.append(db);
buff.append(" for the database ").append(db);
}
out.println(buff.toString());
}
......
......@@ -682,16 +682,11 @@ public class ValueLob extends Value {
}
StringBuilder buff = new StringBuilder();
if (type == Value.CLOB) {
buff.append("SPACE(");
buff.append(getPrecision());
buff.append("SPACE(").append(getPrecision());
} else {
buff.append("CAST(REPEAT('00', ");
buff.append(getPrecision());
buff.append(") AS BINARY");
buff.append("CAST(REPEAT('00', ").append(getPrecision()).append(") AS BINARY");
}
buff.append(" /* ");
buff.append(fileName);
buff.append(" */)");
buff.append(" /* ").append(fileName).append(" */)");
return buff.toString();
}
......
......@@ -121,8 +121,8 @@ public class ValueUuid extends Value {
private void appendHex(StringBuilder buff, long x, int bytes) {
for (int i = bytes * 8 - 4; i >= 0; i -= 8) {
buff.append(Integer.toHexString((int) (x >> i) & 0xf));
buff.append(Integer.toHexString((int) (x >> (i - 4)) & 0xf));
buff.append(Integer.toHexString((int) (x >> i) & 0xf)).
append(Integer.toHexString((int) (x >> (i - 4)) & 0xf));
}
}
......
......@@ -15,6 +15,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.FieldDoc;
......@@ -254,25 +255,22 @@ public class Doclet {
return;
}
Parameter[] params = method.parameters();
StringBuilder buff = new StringBuilder();
StatementBuilder buff = new StatementBuilder();
buff.append('(');
for (int j = 0; j < params.length; j++) {
if (j > 0) {
buff.append(", ");
}
buff.append(getTypeName(false, params[j].type()));
for (Parameter p : params) {
buff.appendExceptFirst(", ");
buff.append(getTypeName(false, p.type()));
buff.append(' ');
buff.append(params[j].name());
buff.append(p.name());
}
buff.append(')');
ClassDoc[] exceptions = method.thrownExceptions();
if (exceptions.length > 0) {
buff.append(" throws ");
for (int k = 0; k < exceptions.length; k++) {
if (k > 0) {
buff.append(", ");
}
buff.append(exceptions[k].typeName());
buff.resetCount();
for (ClassDoc ex : exceptions) {
buff.appendExceptFirst(", ");
buff.append(ex.typeName());
}
}
if (isDeprecated(method)) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论