HHH-6258: Performance enhancement to toFragmentString method to only append to the StringBuffer, and not do inserts into the beginning, which causes additional buffer allocations and copies that are unnecessary. Also, changed the StringBuffer to a StringBuilder.
This commit is contained in:
parent
02a866c702
commit
bf066b8121
|
@ -68,49 +68,65 @@ public class InFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toFragmentString() {
|
public String toFragmentString() {
|
||||||
if ( values.size()==0 ) return "1=2";
|
|
||||||
StringBuffer buf = new StringBuffer( values.size() * 5 );
|
if (values.size() == 0) {
|
||||||
buf.append(columnName);
|
return "1=2";
|
||||||
//following doesn't handle (null, not null) but unnecessary
|
}
|
||||||
//since this would mean all rows
|
|
||||||
if ( values.size()>1 ) {
|
StringBuilder buf = new StringBuilder(values.size() * 5);
|
||||||
boolean allowNull = false;
|
|
||||||
buf.append(" in (");
|
if (values.size() == 1) {
|
||||||
Iterator iter = values.iterator();
|
Object value = values.get(0);
|
||||||
while ( iter.hasNext() ) {
|
buf.append(columnName);
|
||||||
Object value = iter.next();
|
|
||||||
if ( NULL.equals(value) ) {
|
if (NULL.equals(value)) {
|
||||||
allowNull = true;
|
buf.append(" is null");
|
||||||
}
|
} else {
|
||||||
else if ( NOT_NULL.equals(value) ) {
|
if (NOT_NULL.equals(value)) {
|
||||||
throw new IllegalArgumentException("not null makes no sense for in expression");
|
buf.append(" is not null");
|
||||||
}
|
} else {
|
||||||
else {
|
buf.append('=').append(value);
|
||||||
buf.append(value);
|
}
|
||||||
buf.append(", ");
|
}
|
||||||
}
|
return buf.toString();
|
||||||
}
|
}
|
||||||
buf.setLength( buf.length()-2 );
|
|
||||||
buf.append(')');
|
boolean allowNull = false;
|
||||||
if (allowNull) {
|
|
||||||
buf.insert(0, " is null or ")
|
for (Object value : values) {
|
||||||
.insert(0, columnName)
|
if (NULL.equals(value)) {
|
||||||
.insert(0, '(')
|
allowNull = true;
|
||||||
.append(')');
|
} else {
|
||||||
}
|
if (NOT_NULL.equals(value)) {
|
||||||
}
|
throw new IllegalArgumentException("not null makes no sense for in expression");
|
||||||
else {
|
}
|
||||||
Object value = values.iterator().next();
|
}
|
||||||
if ( NULL.equals(value) ) {
|
}
|
||||||
buf.append(" is null");
|
|
||||||
}
|
if (allowNull) {
|
||||||
else if ( NOT_NULL.equals(value) ) {
|
buf.append('(').append(columnName).append(" is null or ").append(columnName).append(" in (");
|
||||||
buf.append(" is not null");
|
} else {
|
||||||
}
|
buf.append(columnName).append(" in (");
|
||||||
else {
|
}
|
||||||
buf.append("=").append(value);
|
|
||||||
}
|
for (Object value : values) {
|
||||||
}
|
if (NULL.equals(value)) {
|
||||||
return buf.toString();
|
;
|
||||||
|
} else {
|
||||||
|
buf.append(value);
|
||||||
|
buf.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.setLength(buf.length() - 2);
|
||||||
|
|
||||||
|
if (allowNull) {
|
||||||
|
buf.append("))");
|
||||||
|
} else {
|
||||||
|
buf.append(')');
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.toString();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue