提交 0a6aa17d authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add StringUtils.join()

上级 edba4fd8
......@@ -218,7 +218,6 @@ import org.h2.table.TableFilter.TableFilterVisitor;
import org.h2.table.TableView;
import org.h2.util.IntervalUtils;
import org.h2.util.ParserUtil;
import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils;
import org.h2.util.Utils;
import org.h2.util.geometry.EWKTUtils;
......@@ -981,13 +980,8 @@ public class Parser {
if (expectedList == null || expectedList.isEmpty()) {
return DbException.getSyntaxError(sqlCommand, parseIndex);
}
StatementBuilder buff = new StatementBuilder();
for (String e : expectedList) {
buff.appendExceptFirst(", ");
buff.append(e);
}
return DbException.getSyntaxError(sqlCommand, parseIndex,
buff.toString());
StringUtils.join(new StringBuilder(), expectedList, ", ").toString());
}
private Prepared parseBackup() {
......
......@@ -5,6 +5,7 @@
*/
package org.h2.command.ddl;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.h2.api.ErrorCode;
......@@ -18,7 +19,7 @@ import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.table.Table;
import org.h2.table.TableView;
import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils;
/**
* This class represents the statement
......@@ -75,12 +76,11 @@ public class DropTable extends SchemaCommand {
throw DbException.get(ErrorCode.CANNOT_DROP_TABLE_1, tableName);
}
if (dropAction == ConstraintActionType.RESTRICT) {
StatementBuilder buff = new StatementBuilder();
ArrayList<String> dependencies = new ArrayList<>();
CopyOnWriteArrayList<TableView> dependentViews = table.getDependentViews();
if (dependentViews != null && !dependentViews.isEmpty()) {
for (TableView v : dependentViews) {
buff.appendExceptFirst(", ");
buff.append(v.getName());
dependencies.add(v.getName());
}
}
if (session.getDatabase()
......@@ -89,14 +89,14 @@ public class DropTable extends SchemaCommand {
if (constraints != null && !constraints.isEmpty()) {
for (Constraint c : constraints) {
if (c.getTable() != table) {
buff.appendExceptFirst(", ");
buff.append(c.getName());
dependencies.add(c.getName());
}
}
}
}
if (buff.length() > 0) {
throw DbException.get(ErrorCode.CANNOT_DROP_2, tableName, buff.toString());
if (!dependencies.isEmpty()) {
throw DbException.get(ErrorCode.CANNOT_DROP_2, tableName,
StringUtils.join(new StringBuilder(), dependencies, ", ").toString());
}
}
......
......@@ -372,12 +372,7 @@ public class WebApp {
if (query.endsWith("\n") || tQuery.endsWith(";")) {
list.add(0, "1#(Newline)#\n");
}
StatementBuilder buff = new StatementBuilder();
for (String s : list) {
buff.appendExceptFirst("|");
buff.append(s);
}
result = buff.toString();
result = StringUtils.join(new StringBuilder(), list, "|").toString();
}
session.put("autoCompleteList", result);
} catch (Throwable e) {
......
......@@ -522,6 +522,24 @@ public class StringUtils {
return builder.toString();
}
/**
* Join specified strings and add them to the specified string builder.
*
* @param builder string builder
* @param strings strings to join
* @param separator separator
* @return the specified string builder
*/
public static StringBuilder join(StringBuilder builder, ArrayList<String> strings, String separator) {
for (int i = 0, l = strings.size(); i < l; i++) {
if (i > 0) {
builder.append(separator);
}
builder.append(strings.get(i));
}
return builder;
}
/**
* Creates an XML attribute of the form name="value".
* A single space is prepended to the name,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论