Skip to content

Commit

Permalink
Merge pull request #3170 from ebean-orm/feature/prefer-char-append
Browse files Browse the repository at this point in the history
Refactor prefer char append
  • Loading branch information
rbygrave authored Aug 18, 2023
2 parents 3bf316a + 00e594d commit c07d5e2
Show file tree
Hide file tree
Showing 56 changed files with 147 additions and 136 deletions.
4 changes: 2 additions & 2 deletions ebean-api/src/main/java/io/ebean/OrderBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ public String toStringFormat() {
sb.append(property);
}
if (!ascending) {
sb.append(" ").append("desc");
sb.append(' ').append("desc");
}
if (nulls != null) {
sb.append(" ").append(nulls).append(" ").append(highLow);
sb.append(' ').append(nulls).append(' ').append(highLow);
}
return sb.toString();
}
Expand Down
18 changes: 9 additions & 9 deletions ebean-api/src/main/java/io/ebean/bean/ToStringBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void start(Object bean) {
id.putIfAbsent(bean, 0);
}
if (counter <= MAX) {
sb.append(bean.getClass().getSimpleName()).append("@").append(counter).append("(");
sb.append(bean.getClass().getSimpleName()).append('@').append(counter).append('(');
}
}

Expand Down Expand Up @@ -77,7 +77,7 @@ public void addRaw(String content) {
*/
public void end() {
if (counter <= MAX) {
sb.append(")");
sb.append(')');
}
}

Expand All @@ -90,7 +90,7 @@ private void key(String name) {
} else {
sb.append(", ");
}
sb.append(name).append(":");
sb.append(name).append(':');
}

private void value(Object value) {
Expand Down Expand Up @@ -125,20 +125,20 @@ public void addMap(Map<?,?> map) {
sb.append("{}");
} else {
boolean firstElement = true;
sb.append("{");
sb.append('{');
for (Map.Entry<?, ?> entry : map.entrySet()) {
if (firstElement) {
firstElement = false;
} else {
sb.append(", ");
}
sb.append(entry.getKey()).append(":");
sb.append(entry.getKey()).append(':');
value(entry.getValue());
if (counter > MAX) {
return;
}
}
sb.append("}");
sb.append('}');
}
}

Expand All @@ -151,7 +151,7 @@ public void addCollection(Collection<?> c) {
return;
}
boolean firstElement = true;
sb.append("[");
sb.append('[');
for (Object o : c) {
if (firstElement) {
firstElement = false;
Expand All @@ -163,7 +163,7 @@ public void addCollection(Collection<?> c) {
return;
}
}
sb.append("]");
sb.append(']');
}

private boolean push(Object bean) {
Expand All @@ -178,7 +178,7 @@ private boolean push(Object bean) {
Integer idx = id.putIfAbsent(bean, counter++);
if (idx != null) {
--counter;
sb.append(bean.getClass().getSimpleName()).append("@").append(idx);
sb.append(bean.getClass().getSimpleName()).append('@').append(idx);
return false;
}
first = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public String limit(String dbSql, int firstRow, int maxRows) {
sb.append(dbSql);

if (maxRows > 0) {
sb.append(" ").append(LIMIT);
sb.append(" ").append(maxRows);
sb.append(' ').append(LIMIT);
sb.append(' ').append(maxRows);
}
if (firstRow > 0) {
sb.append(" ").append(OFFSET).append(" ");
sb.append(' ').append(OFFSET).append(' ');
sb.append(firstRow);
}
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public interface SpiExpressionRequest {
*/
SpiExpressionRequest append(String expression);

/**
* Append to the expression sql without any parsing.
*/
SpiExpressionRequest append(char c);

/**
* Append to the expression sql with logical property parsing to db columns with logical path prefix.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private void logQuery(MetaQueryMetric metric) {
}

private void appendQueryName(MetaQueryMetric metric, StringBuilder sb) {
sb.append("query:").append(padName(metric.name())).append(" ");
sb.append("query:").append(padName(metric.name())).append(' ');
}

private void appendProfileAndSql(MetaQueryMetric metric, StringBuilder sb) {
Expand All @@ -136,7 +136,7 @@ private void appendProfileAndSql(MetaQueryMetric metric, StringBuilder sb) {

private void log(MetaTimedMetric metric) {
StringBuilder sb = new StringBuilder();
sb.append(padNameTimed(metric.name())).append(" ");
sb.append(padNameTimed(metric.name())).append(' ');
appendCounters(metric, sb);
out(sb.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public boolean equals(Object o) {
@Override
public String toString() {
StringBuilder sb = new StringBuilder(30);
sb.append(type).append(" ").append(table).append(" ");
sb.append(type).append(' ').append(table).append(' ');
for (TableJoinColumn column : columns) {
sb.append(column).append(" ");
sb.append(column).append(' ');
}
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void addSql(SpiExpressionRequest request) {
if (propMap.isEmpty()) {
return;
}
request.append("(");
request.append('(');
int count = 0;
for (Map.Entry<String, Object> entry : propMap.entrySet()) {
Object value = entry.getValue();
Expand All @@ -84,7 +84,7 @@ public void addSql(SpiExpressionRequest request) {
}
count++;
}
request.append(")");
request.append(')');
}

/**
Expand All @@ -105,9 +105,9 @@ public void queryPlanHash(StringBuilder builder) {
} else {
builder.append(" =?");
}
builder.append(",");
builder.append(',');
}
builder.append("]");
builder.append(']');
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void writeDocQuery(DocQueryContext context) throws IOException {
public void queryPlanHash(StringBuilder builder) {
builder.append("ArrayContains[").append(propName)
.append(" b:").append(contains)
.append(" ?:").append(values.length).append("]");
.append(" ?:").append(values.length).append(']');
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void queryPlanHash(StringBuilder builder) {
} else {
builder.append("ArrayIsNotEmpty[");
}
builder.append(propName).append("]");
builder.append(propName).append(']');
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void addSql(SpiExpressionRequest request) {

@Override
public void queryPlanHash(StringBuilder builder) {
builder.append("Between[").append(propName).append("]");
builder.append("Between[").append(propName).append(']');
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void addSql(SpiExpressionRequest request) {

@Override
public void queryPlanHash(StringBuilder builder) {
builder.append("BetweenProperties[").append("low:").append(lowProperty).append(" high:").append(highProperty).append("]");
builder.append("BetweenProperties[").append("low:").append(lowProperty).append(" high:").append(highProperty).append(']');
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public void addSql(SpiExpressionRequest request) {
@Override
public void queryPlanHash(StringBuilder builder) {
if (not) {
builder.append("Ine[").append(propName).append("]");
builder.append("Ine[").append(propName).append(']');
} else {
builder.append("Ieq[").append(propName).append("]");
builder.append("Ieq[").append(propName).append(']');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ public void addSql(SpiExpressionRequest request) {
if (list.isEmpty()) {
request.append(SQL_TRUE);
} else {
request.append("(");
request.append('(');
for (int i = 0; i < list.size(); i++) {
SpiExpression item = list.get(i);
if (i > 0) {
request.append(" and ");
}
item.addSql(request);
}
request.append(")");
request.append(')');
}
}

Expand All @@ -229,9 +229,9 @@ public void queryPlanHash(StringBuilder builder) {
builder.append("Example[");
for (SpiExpression expr : list) {
expr.queryPlanHash(builder);
builder.append(",");
builder.append(',');
}
builder.append("]");
builder.append(']');
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ public void queryPlanHash(StringBuilder builder) {
builder.append("textRoot:true ");
}
if (allDocNestedPath != null) {
builder.append("path:").append(allDocNestedPath).append(" ");
builder.append("path:").append(allDocNestedPath).append(' ');
}
for (SpiExpression expr : list) {
expr.queryPlanHash(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public String parseDeploy(String logicalProp) {
*/
@Override
public void appendLike(boolean rawLikeExpression) {
sql.append(" ");
sql.append(' ');
sql.append(queryRequest.dbLikeClause(rawLikeExpression));
}

Expand Down Expand Up @@ -114,15 +114,18 @@ public StringBuilder buffer() {
return sql;
}

/**
* Append text the underlying sql expression.
*/
@Override
public SpiExpressionRequest append(String expression) {
sql.append(expression);
return this;
}

@Override
public SpiExpressionRequest append(char c) {
sql.append(c);
return this;
}

@Override
public SpiExpressionRequest property(String expression) {
if (deployParser == null) {
Expand Down Expand Up @@ -160,7 +163,7 @@ private void bindLog(Object val) {
if (bindLog == null) {
bindLog = new StringBuilder();
} else {
bindLog.append(",");
bindLog.append(',');
}
bindLog.append(val);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ CQuery<?> compileSubQuery(BeanQueryRequest<?> queryRequest) {
@Override
public void queryPlanHash(StringBuilder builder) {
builder.append("ExistsQuery[").append(" not:").append(not);
builder.append(" sql:").append(sql).append(" ?:").append(bindParams.size()).append("]");
builder.append(" sql:").append(sql).append(" ?:").append(bindParams.size()).append(']');
}

@Override
Expand All @@ -95,7 +95,7 @@ public void addSql(SpiExpressionRequest request) {
if (not) {
request.append("not ");
}
request.append("exists (").parse(sql).append(")");
request.append("exists (").parse(sql).append(')');
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public SpiExpression copyForPlanKey() {
@Override
public void queryPlanHash(StringBuilder builder) {
builder.append("ExistsSqlQuery[").append(" not:").append(not);
builder.append(" sql:").append(subQuery).append(" ?:").append(bindParams.length).append("]");
builder.append(" sql:").append(subQuery).append(" ?:").append(bindParams.length).append(']');
}

@Override
Expand All @@ -73,7 +73,7 @@ public void addSql(SpiExpressionRequest request) {
if (not) {
request.append("not ");
}
request.append("exists (").parse(subQuery).append(")");
request.append("exists (").parse(subQuery).append(')');
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void queryPlanHash(StringBuilder builder) {
// query plan specific to the number of parameters in the IN clause
builder.append(idCollection.size());
}
builder.append("]");
builder.append(']');
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void queryPlanHash(StringBuilder builder) {
builder.append(bindValues.size());
}
}
builder.append("]");
builder.append(']');
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ public void queryPlanHash(StringBuilder builder) {
} else {
builder.append("InPairs[");
}
builder.append(property0).append("-");
builder.append(property1).append("-");
builder.append(separator).append("-");
builder.append(property0).append('-');
builder.append(property1).append('-');
builder.append(separator).append('-');
builder.append(suffix).append(" ?");
if (!multiValueSupported || entries.isEmpty()) {
// query plan specific to the number of parameters in the IN clause
builder.append(entries.size());
}
builder.append("]");
builder.append(']');
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public void addSql(SpiExpressionRequest request) {
if (prop != null && prop.isDbEncrypted()) {
pname = prop.beanProperty().decryptProperty(propName);
}
request.append("(").property(pname).append(" >= ? and ").property(pname).append(" < ?)");
request.append('(').property(pname).append(" >= ? and ").property(pname).append(" < ?)");
}

@Override
public void queryPlanHash(StringBuilder builder) {
builder.append("InRange[").append(propName).append("]");
builder.append("InRange[").append(propName).append(']');
}

@Override
Expand Down
Loading

0 comments on commit c07d5e2

Please sign in to comment.