mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-12-01 15:37:14 +00:00
No effective change - remove unused HashQueryPlan etc
This commit is contained in:
1 parent
9f91d8bcf9
commit
7110f4a59b
5 files changed
-239
No files matched your search
@@ -1,57 +0,0 @@
|
|||||||
package io.ebeaninternal.api;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A hash for a query plan.
|
|
||||||
*/
|
|
||||||
public class HashQueryPlan {
|
|
||||||
|
|
||||||
private final String rawSql;
|
|
||||||
|
|
||||||
private final int planHash;
|
|
||||||
|
|
||||||
private final int bindCount;
|
|
||||||
|
|
||||||
public HashQueryPlan(String rawSql, int planHash, int bindCount) {
|
|
||||||
this.rawSql = rawSql;
|
|
||||||
this.planHash = planHash;
|
|
||||||
this.bindCount = bindCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return planHash + ":" + bindCount + (rawSql != null ? ":r" : "");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return as a partial key. For rawSql hash the sql is part of the key and as such
|
|
||||||
* needs to be included in order to have a complete key. Typically the MD5 of the sql
|
|
||||||
* can be used as a shot form proxy for the actual sql.
|
|
||||||
*/
|
|
||||||
public String getPartialKey() {
|
|
||||||
return planHash + "_" + bindCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int hc = planHash;
|
|
||||||
hc = hc * 92821 + bindCount;
|
|
||||||
hc = hc * 92821 + (rawSql == null ? 0 : rawSql.hashCode());
|
|
||||||
return hc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (obj == this) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!(obj instanceof HashQueryPlan)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
HashQueryPlan e = (HashQueryPlan) obj;
|
|
||||||
//noinspection StringEquality
|
|
||||||
return e.planHash == planHash
|
|
||||||
&& e.bindCount == bindCount
|
|
||||||
&& ((e.rawSql == rawSql) || (e.rawSql != null && e.rawSql.equals(rawSql)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
package io.ebeaninternal.api;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to build HashQueryPlan instances.
|
|
||||||
*/
|
|
||||||
public class HashQueryPlanBuilder {
|
|
||||||
|
|
||||||
private int planHash;
|
|
||||||
|
|
||||||
private int bindCount;
|
|
||||||
|
|
||||||
public HashQueryPlanBuilder() {
|
|
||||||
this.planHash = 92821;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return planHash + ":" + bindCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a class to the hash calculation.
|
|
||||||
*/
|
|
||||||
public HashQueryPlanBuilder add(Class<?> cls) {
|
|
||||||
planHash = planHash * 92821 + cls.getName().hashCode();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add an object to the hash calculation.
|
|
||||||
*/
|
|
||||||
public HashQueryPlanBuilder add(Object object) {
|
|
||||||
planHash = planHash * 92821 + (object == null ? 0 : object.hashCode());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add the set with order being important.
|
|
||||||
*/
|
|
||||||
public HashQueryPlanBuilder addOrdered(Set<?> set) {
|
|
||||||
if (set == null) {
|
|
||||||
add(false);
|
|
||||||
} else {
|
|
||||||
add(true);
|
|
||||||
for (Object o : set) {
|
|
||||||
add(o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add an integer to the hash calculation.
|
|
||||||
*/
|
|
||||||
public HashQueryPlanBuilder add(int hashValue) {
|
|
||||||
planHash = planHash * 92821 + (hashValue);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a boolean to the hash calculation.
|
|
||||||
*/
|
|
||||||
public HashQueryPlanBuilder add(boolean booleanValue) {
|
|
||||||
planHash = planHash * 92821 + (booleanValue ? 92821 : 0);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a number to the bind count for the hash.
|
|
||||||
*/
|
|
||||||
public void bind(int extraBindCount) {
|
|
||||||
bindCount += extraBindCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void bindIfNotNull(Object someValue) {
|
|
||||||
if (someValue != null) {
|
|
||||||
bindCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build and return the calculated HashQueryPlan.
|
|
||||||
*/
|
|
||||||
public String build() {
|
|
||||||
return planHash + "_" + bindCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPlanHash() {
|
|
||||||
return planHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getBindCount() {
|
|
||||||
return bindCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1054,7 +1054,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
|||||||
// calculateQueryPlanHash is called just after potential AutoTune tuning
|
// calculateQueryPlanHash is called just after potential AutoTune tuning
|
||||||
// so queryPlanHash is calculated well before this method is called
|
// so queryPlanHash is calculated well before this method is called
|
||||||
int hc = queryBindHash();
|
int hc = queryBindHash();
|
||||||
|
|
||||||
return new HashQuery(queryPlanKey, hc);
|
return new HashQuery(queryPlanKey, hc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
package io.ebeaninternal.api;
|
|
||||||
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
public class HashQueryPlanBuilderTest {
|
|
||||||
|
|
||||||
int combine(int v0, int v1) {
|
|
||||||
return new HashQueryPlanBuilder().add(v0).add(v1).build().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test_pair_0_1() {
|
|
||||||
assertThat(combine(0, 31)).isNotEqualTo(combine(1, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test_pair_0_10_adjust_0() {
|
|
||||||
assertThat(combine(0, 310)).isNotEqualTo(combine(10, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test_pair_0_10_adjust_10() {
|
|
||||||
assertThat(combine(0, 320)).isNotEqualTo(combine(10, 10));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test_pair_0_10_adjust_40() {
|
|
||||||
assertThat(combine(0, 350)).isNotEqualTo(combine(10, 40));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test_pair_0_10_adjust_90() {
|
|
||||||
assertThat(combine(0, 400)).isNotEqualTo(combine(10, 90));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package io.ebeaninternal.api;
|
|
||||||
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
public class HashQueryPlanTest {
|
|
||||||
|
|
||||||
private HashQueryPlan hqp(String raw, int plan, int bind) {
|
|
||||||
return new HashQueryPlan(raw, plan, bind);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int hc(String raw, int plan, int bind) {
|
|
||||||
return hqp(raw, plan, bind).hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEquals() throws Exception {
|
|
||||||
|
|
||||||
assertThat(hqp("foo", 10, 7)).isEqualTo(hqp("foo", 10, 7));
|
|
||||||
assertThat(hqp("foo", 10, 7)).isNotEqualTo(hqp("foo", 11, 7));
|
|
||||||
assertThat(hqp("foo", 10, 7)).isNotEqualTo(hqp("foo", 9, 7));
|
|
||||||
assertThat(hqp("foo", 10, 7)).isNotEqualTo(hqp("foo", 10, 8));
|
|
||||||
assertThat(hqp("foo", 10, 7)).isNotEqualTo(hqp("foo", 10, 6));
|
|
||||||
assertThat(hqp("foo", 10, 7)).isNotEqualTo(hqp("bar", 10, 6));
|
|
||||||
assertThat(hqp("foo", 10, 7)).isNotEqualTo(hqp(null, 10, 7));
|
|
||||||
assertThat(hqp(null, 10, 7)).isNotEqualTo(hqp("foo", 10, 7));
|
|
||||||
assertThat(hqp(null, 10, 7)).isEqualTo(hqp(null, 10, 7));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHashCode() throws Exception {
|
|
||||||
|
|
||||||
assertThat(hc("foo", 10, 7)).isEqualTo(hc("foo", 10, 7));
|
|
||||||
assertThat(hc("foo", 10, 7)).isNotEqualTo(hc("foo", 11, 7));
|
|
||||||
assertThat(hc("foo", 10, 7)).isNotEqualTo(hc("foo", 9, 7));
|
|
||||||
assertThat(hc("foo", 10, 7)).isNotEqualTo(hc("foo", 10, 8));
|
|
||||||
assertThat(hc("foo", 10, 7)).isNotEqualTo(hc("foo", 10, 6));
|
|
||||||
assertThat(hc("foo", 10, 7)).isNotEqualTo(hc("bar", 10, 6));
|
|
||||||
assertThat(hc("foo", 10, 7)).isNotEqualTo(hc(null, 10, 7));
|
|
||||||
assertThat(hc(null, 10, 7)).isNotEqualTo(hc("foo", 10, 7));
|
|
||||||
assertThat(hc(null, 10, 7)).isEqualTo(hc(null, 10, 7));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user