mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Change BindHash from interface to implementation, Delete unused server persist BindValues
This commit is contained in:
@@ -1,37 +1,29 @@
|
||||
package io.ebeaninternal.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* BindHash implementation.
|
||||
*
|
||||
* @author Roland Praml, FOCONIS AG
|
||||
*
|
||||
*/
|
||||
public interface BindHash {
|
||||
public class BindHash {
|
||||
|
||||
/**
|
||||
* Update with boolean value.
|
||||
*/
|
||||
BindHash update(boolean boolValue);
|
||||
private final List<Object> values = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Update with int value.
|
||||
*/
|
||||
BindHash update(int intValue);
|
||||
public BindHash update(Object value) {
|
||||
values.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update with long value.
|
||||
*/
|
||||
BindHash update(long longValue);
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof BindHash && ((BindHash) obj).values.equals(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update with object value.
|
||||
*/
|
||||
BindHash update(Object value);
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return values.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* finishes the hash. May be used to compute internal state. After finish, no
|
||||
* update method must be called
|
||||
*/
|
||||
void finish();
|
||||
|
||||
}
|
||||
|
||||
@@ -410,7 +410,7 @@ public class BindParams implements Serializable {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hc = getClass().hashCode();
|
||||
`` hc = hc * 92821 + (isInParam ? 0 : 1);
|
||||
hc = hc * 92821 + (isInParam ? 0 : 1);
|
||||
hc = hc * 92821 + (isOutParam ? 0 : 1);
|
||||
hc = hc * 92821 + (type);
|
||||
hc = hc * 92821 + (inValue == null ? 0 : inValue.hashCode());
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
package io.ebeaninternal.server.persist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Holds a list of bind values for binding to a PreparedStatement.
|
||||
*/
|
||||
class BindValues {
|
||||
|
||||
private final ArrayList<Value> list = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Create with a Binder.
|
||||
*/
|
||||
public BindValues() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a bind value with its JDBC datatype.
|
||||
*
|
||||
* @param value the bind value
|
||||
* @param dbType the type as per java.sql.Types
|
||||
*/
|
||||
public void add(Object value, int dbType, String name) {
|
||||
list.add(new Value(value, dbType, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* List of bind values.
|
||||
*/
|
||||
public ArrayList<Value> values() {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Value has additionally the JDBC data type.
|
||||
*/
|
||||
public static class Value {
|
||||
|
||||
private final Object value;
|
||||
|
||||
private final int dbType;
|
||||
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Create the value.
|
||||
*/
|
||||
Value(Object value, int dbType, String name) {
|
||||
this.value = value;
|
||||
this.dbType = dbType;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type as per java.sql.Types.
|
||||
*/
|
||||
public int getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value.
|
||||
*/
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the property name.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,33 +77,6 @@ public class Binder {
|
||||
return asOfStandardsBased;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the values to the Prepared Statement.
|
||||
*/
|
||||
public void bind(BindValues bindValues, DataBind dataBind, StringBuilder bindBuf) throws SQLException {
|
||||
String logPrefix = "";
|
||||
ArrayList<BindValues.Value> list = bindValues.values();
|
||||
for (BindValues.Value bindValue : list) {
|
||||
Object val = bindValue.getValue();
|
||||
int dt = bindValue.getDbType();
|
||||
bindObject(dataBind, val, dt);
|
||||
|
||||
if (bindBuf != null) {
|
||||
bindBuf.append(logPrefix);
|
||||
if (logPrefix.isEmpty()) {
|
||||
logPrefix = ", ";
|
||||
}
|
||||
bindBuf.append(bindValue.getName());
|
||||
bindBuf.append("=");
|
||||
if (isLob(dt)) {
|
||||
bindBuf.append("[LOB]");
|
||||
} else {
|
||||
bindBuf.append(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the parameters to the preparedStatement returning the bind log.
|
||||
*/
|
||||
|
||||
@@ -1244,9 +1244,8 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
||||
public HashQuery queryHash() {
|
||||
// calculateQueryPlanHash is called just after potential AutoTune tuning
|
||||
// so queryPlanHash is calculated well before this method is called
|
||||
BindHash hash = new HashCodeBindHash();
|
||||
BindHash hash = new BindHash();
|
||||
queryBindHash(hash);
|
||||
hash.finish();
|
||||
return new HashQuery(queryPlanKey, hash);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package io.ebeaninternal.server.querydefn;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import io.ebeaninternal.api.BindHash;
|
||||
|
||||
/**
|
||||
* HashCode builder that uses Object.hashCode for computing bind-hashes.
|
||||
* This is a fast and lightweight implementation, but may produce collisions.
|
||||
*
|
||||
* @author Roland Praml, FOCONIS AG
|
||||
*/
|
||||
public class HashCodeBindHash implements BindHash {
|
||||
|
||||
private final List<Object> values = new ArrayList<>();
|
||||
private int hashCode;
|
||||
|
||||
@Override
|
||||
public BindHash update(int intValue) {
|
||||
values.add(intValue);
|
||||
hashCode = hashCode * 92821 + intValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindHash update(long longValue) {
|
||||
values.add(longValue);
|
||||
hashCode = hashCode * 92821 + Long.hashCode(longValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindHash update(boolean boolValue) {
|
||||
values.add(boolValue);
|
||||
hashCode = hashCode * 92821 + Boolean.hashCode(boolValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindHash update(Object value) {
|
||||
values.add(value);
|
||||
hashCode = hashCode * 92821 + Objects.hashCode(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof HashCodeBindHash && ((HashCodeBindHash) obj).values.equals(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user