mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
WIP AutoTune refactor
This commit is contained in:
1 parent
5c1de0a886
commit
5b8ce8eaa0
27 files changed
+1092
-34
No files matched your search
@@ -9,6 +9,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
@@ -83,25 +84,48 @@ public class OrmQueryDetail implements Serializable {
|
||||
* Return true if equal in terms of autofetch (select and joins).
|
||||
*/
|
||||
public boolean isAutoTuneEqual(OrmQueryDetail otherDetail) {
|
||||
return autofetchPlanHash() == otherDetail.autofetchPlanHash();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the hash for the query plan.
|
||||
*/
|
||||
private int autofetchPlanHash() {
|
||||
|
||||
int hc = (baseProps == null ? 1 : baseProps.autofetchPlanHash());
|
||||
|
||||
if (fetchPaths != null) {
|
||||
for (OrmQueryProperties p : fetchPaths.values()) {
|
||||
hc = hc * 31 + p.autofetchPlanHash();
|
||||
if (!isSame(baseProps, otherDetail.baseProps)) {
|
||||
return false;
|
||||
}
|
||||
if (fetchPaths == null) {
|
||||
return otherDetail.fetchPaths == null;
|
||||
}
|
||||
Set<Map.Entry<String, OrmQueryProperties>> entries = fetchPaths.entrySet();
|
||||
for (Map.Entry<String, OrmQueryProperties> entry : entries) {
|
||||
OrmQueryProperties chunk = otherDetail.getChunk(entry.getKey(), false);
|
||||
if (!isSame(entry.getValue(), chunk)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return hc;
|
||||
return true;
|
||||
//return autofetchPlanHash() == otherDetail.autofetchPlanHash();
|
||||
}
|
||||
|
||||
private boolean isSame(OrmQueryProperties p1, OrmQueryProperties p2) {
|
||||
if (p1 == null) {
|
||||
return p2 == null;
|
||||
}
|
||||
return p1.isSame(p2);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Calculate the hash for the query plan.
|
||||
// */
|
||||
// private int autofetchPlanHash() {
|
||||
//
|
||||
// int hc = (baseProps == null ? 1 : baseProps.autofetchPlanHash());
|
||||
//
|
||||
// if (fetchPaths != null) {
|
||||
// for (OrmQueryProperties p : fetchPaths.values()) {
|
||||
// hc = hc * 31 + p.autofetchPlanHash();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return hc;
|
||||
// }
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (baseProps != null) {
|
||||
|
||||
@@ -27,10 +27,11 @@ public class OrmQueryDetailParser {
|
||||
this.parser = new SimpleTextParser(oql);
|
||||
}
|
||||
|
||||
public void parse() throws PersistenceException {
|
||||
public OrmQueryDetail parse() throws PersistenceException {
|
||||
|
||||
parser.nextWord();
|
||||
processInitial();
|
||||
return detail;
|
||||
}
|
||||
|
||||
protected void assign(DefaultOrmQuery<?> query) {
|
||||
@@ -42,7 +43,9 @@ public class OrmQueryDetailParser {
|
||||
}
|
||||
|
||||
private void processInitial() {
|
||||
if (parser.isMatch("find")) {
|
||||
if (parser.isMatch("select")) {
|
||||
readSelect();
|
||||
} else if (parser.isMatch("find")) {
|
||||
OrmQueryProperties props = readFindFetch();
|
||||
detail.setBase(props);
|
||||
} else {
|
||||
@@ -149,6 +152,19 @@ public class OrmQueryDetailParser {
|
||||
}
|
||||
}
|
||||
|
||||
private void readSelect() {
|
||||
String path = null;
|
||||
String props = parser.nextWord();
|
||||
if (props.startsWith("(")) {
|
||||
props = props.substring(1, props.length() - 1);
|
||||
OrmQueryProperties base = new OrmQueryProperties(path, props);
|
||||
detail.setBase(base);
|
||||
parser.nextWord();
|
||||
} else {
|
||||
process();
|
||||
}
|
||||
}
|
||||
|
||||
private OrmQueryProperties readFindFetch() {
|
||||
|
||||
boolean readAlias = false;
|
||||
|
||||
@@ -573,4 +573,11 @@ public class OrmQueryProperties implements Serializable {
|
||||
|
||||
return Collections.unmodifiableSet(set);
|
||||
}
|
||||
|
||||
public boolean isSame(OrmQueryProperties p2) {
|
||||
if (included == null) {
|
||||
return p2.included == null;
|
||||
}
|
||||
return included.equals(p2.included);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user