mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Remove MdBindHash, tidy DefaultOrmQuery
This commit is contained in:
@@ -1,30 +1,7 @@
|
||||
package io.ebeaninternal.server.querydefn;
|
||||
|
||||
import io.ebean.CacheMode;
|
||||
import io.ebean.CountDistinctOrder;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.DtoQuery;
|
||||
import io.ebean.Expression;
|
||||
import io.ebean.ExpressionFactory;
|
||||
import io.ebean.ExpressionList;
|
||||
import io.ebean.FetchConfig;
|
||||
import io.ebean.FetchGroup;
|
||||
import io.ebean.FetchPath;
|
||||
import io.ebean.FutureIds;
|
||||
import io.ebean.FutureList;
|
||||
import io.ebean.FutureRowCount;
|
||||
import io.ebean.OrderBy;
|
||||
import io.ebean.*;
|
||||
import io.ebean.OrderBy.Property;
|
||||
import io.ebean.PagedList;
|
||||
import io.ebean.PersistenceContextScope;
|
||||
import io.ebean.ProfileLocation;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.QueryIterator;
|
||||
import io.ebean.QueryType;
|
||||
import io.ebean.RawSql;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.UpdateQuery;
|
||||
import io.ebean.Version;
|
||||
import io.ebean.bean.CallOrigin;
|
||||
import io.ebean.bean.ObjectGraphNode;
|
||||
import io.ebean.bean.ObjectGraphOrigin;
|
||||
@@ -32,31 +9,10 @@ import io.ebean.bean.PersistenceContext;
|
||||
import io.ebean.event.BeanQueryRequest;
|
||||
import io.ebean.event.readaudit.ReadEvent;
|
||||
import io.ebean.plugin.BeanType;
|
||||
import io.ebean.plugin.LoadErrorHandler;
|
||||
import io.ebeaninternal.api.BindHash;
|
||||
import io.ebeaninternal.api.BindParams;
|
||||
import io.ebeaninternal.api.CQueryPlanKey;
|
||||
import io.ebeaninternal.api.CacheIdLookup;
|
||||
import io.ebeaninternal.api.CacheIdLookupMany;
|
||||
import io.ebeaninternal.api.CacheIdLookupSingle;
|
||||
import io.ebeaninternal.api.HashQuery;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.NaturalKeyQueryData;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionList;
|
||||
import io.ebeaninternal.api.SpiExpressionValidation;
|
||||
import io.ebeaninternal.api.SpiNamedParam;
|
||||
import io.ebeaninternal.api.SpiQuery;
|
||||
import io.ebeaninternal.api.SpiQuerySecondary;
|
||||
import io.ebeaninternal.api.SpiTransaction;
|
||||
import io.ebeaninternal.api.*;
|
||||
import io.ebeaninternal.server.autotune.ProfilingListener;
|
||||
import io.ebeaninternal.server.core.SpiOrmQueryRequest;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.deploy.BeanNaturalKey;
|
||||
import io.ebeaninternal.server.deploy.BeanPropertyAssocMany;
|
||||
import io.ebeaninternal.server.deploy.InheritInfo;
|
||||
import io.ebeaninternal.server.deploy.TableJoin;
|
||||
import io.ebeaninternal.server.deploy.*;
|
||||
import io.ebeaninternal.server.el.ElPropertyDeploy;
|
||||
import io.ebeaninternal.server.expression.DefaultExpressionList;
|
||||
import io.ebeaninternal.server.expression.IdInExpression;
|
||||
@@ -68,14 +24,7 @@ import io.ebeaninternal.server.transaction.ExternalJdbcTransaction;
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
@@ -93,8 +42,6 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
||||
|
||||
private static final FetchConfig FETCH_LAZY = FetchConfig.ofLazy();
|
||||
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
private final Class<T> beanType;
|
||||
|
||||
private final ExpressionFactory expressionFactory;
|
||||
@@ -285,8 +232,6 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
||||
|
||||
private boolean orderById;
|
||||
|
||||
private final String bindHashAlgorithm;
|
||||
|
||||
private ProfileLocation profileLocation;
|
||||
|
||||
public DefaultOrmQuery(BeanDescriptor<T> desc, SpiEbeanServer server, ExpressionFactory expressionFactory) {
|
||||
@@ -295,7 +240,6 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
||||
this.beanType = desc.getBeanType();
|
||||
this.server = server;
|
||||
this.orderById = server.getServerConfig().isDefaultOrderById();
|
||||
this.bindHashAlgorithm = "MD5"; // TODO: server.getServerConfig().isUseMd5BindHash();
|
||||
this.disableLazyLoading = server.getServerConfig().isDisableLazyLoading();
|
||||
this.expressionFactory = expressionFactory;
|
||||
this.detail = new OrmQueryDetail();
|
||||
@@ -1300,8 +1244,7 @@ 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 = bindHashAlgorithm == null ? new HashCodeBindHash() : new MdBindHash(bindHashAlgorithm);
|
||||
BindHash hash = new HashCodeBindHash();// : new MdBindHash(bindHashAlgorithm);
|
||||
BindHash hash = new HashCodeBindHash();
|
||||
queryBindHash(hash);
|
||||
hash.finish();
|
||||
return new HashQuery(queryPlanKey, hash);
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* Licensed Materials - Property of FOCONIS AG
|
||||
* (C) Copyright FOCONIS AG.
|
||||
*/
|
||||
|
||||
package io.ebeaninternal.server.querydefn;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import io.ebeaninternal.api.BindHash;
|
||||
|
||||
/**
|
||||
* Bind hash that uses a MessageDigest to compute a collision resistent hash.
|
||||
*
|
||||
* @author Roland Praml, FOCONIS AG
|
||||
*
|
||||
*/
|
||||
public class MdBindHash implements BindHash {
|
||||
private MessageDigest md;
|
||||
private byte[] buffer;
|
||||
private int hashCode;
|
||||
|
||||
public MdBindHash(String algorithm) {
|
||||
try {
|
||||
md = MessageDigest.getInstance(algorithm);
|
||||
} catch (NoSuchAlgorithmException nsae) {
|
||||
throw new InternalError(algorithm + " not supported", nsae);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindHash update(int v) {
|
||||
md.update((byte) (v >>> 24));
|
||||
md.update((byte) (v >>> 16));
|
||||
md.update((byte) (v >>> 8));
|
||||
md.update((byte) (v >>> 0));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindHash update(long v) {
|
||||
md.update((byte) (v >>> 56));
|
||||
md.update((byte) (v >>> 48));
|
||||
md.update((byte) (v >>> 40));
|
||||
md.update((byte) (v >>> 32));
|
||||
md.update((byte) (v >>> 24));
|
||||
md.update((byte) (v >>> 16));
|
||||
md.update((byte) (v >>> 8));
|
||||
md.update((byte) (v >>> 0));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindHash update(boolean boolValue) {
|
||||
md.update(boolValue ? (byte) 1 : (byte) 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindHash update(Object value) {
|
||||
if (value == null) {
|
||||
md.update((byte) 0);
|
||||
|
||||
// do some special handling for known object types
|
||||
} else if (value instanceof String) {
|
||||
md.update(((String) value).getBytes());
|
||||
|
||||
} else if (value instanceof Long) {
|
||||
update(((Long) value).longValue());
|
||||
|
||||
} else if (value instanceof Double) {
|
||||
double d = ((Double) value).doubleValue();
|
||||
update(Double.doubleToLongBits(d));
|
||||
|
||||
} else if (value instanceof UUID) {
|
||||
UUID uuid = (UUID) value;
|
||||
update(uuid.getLeastSignificantBits());
|
||||
update(uuid.getMostSignificantBits());
|
||||
|
||||
} else if (value instanceof Date) {
|
||||
update(((Date) value).getTime());
|
||||
|
||||
} else if (value instanceof Instant) {
|
||||
update(((Instant) value).getEpochSecond());
|
||||
update(((Instant) value).getNano());
|
||||
|
||||
} else if (value instanceof LocalDate) {
|
||||
update(((LocalDate) value).toEpochDay());
|
||||
|
||||
} else if (value instanceof LocalTime) {
|
||||
update(((LocalTime) value).toSecondOfDay());
|
||||
update(((LocalTime) value).toNanoOfDay());
|
||||
|
||||
} else if (value instanceof LocalDateTime) {
|
||||
update(((LocalDateTime) value).toLocalDate().toEpochDay());
|
||||
update(((LocalDateTime) value).toLocalTime().toSecondOfDay());
|
||||
update(((LocalDateTime) value).toLocalTime().toNanoOfDay());
|
||||
|
||||
} else {
|
||||
// Fall back to hashCode for all other types
|
||||
updateOther(value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all other object. May be overridden to handle joda dates.
|
||||
*/
|
||||
protected void updateOther(Object value) {
|
||||
// Fall back to hashCode for all other types
|
||||
update(value.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
buffer = md.digest();
|
||||
hashCode = Arrays.hashCode(buffer);
|
||||
md = null; // clear memory
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof MdBindHash && Arrays.equals(buffer, ((MdBindHash) obj).buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user