Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public final class OrmQueryProperties implements Serializable {
private final String path;
private final boolean allProperties;
private final Set<String> included;
private final String immutableHashPrefix;
private final String immutableHashSuffix;
private final FetchConfig fetchConfig;
private final boolean cache;
/**
Expand Down Expand Up @@ -75,8 +77,10 @@ public OrmQueryProperties(String path) {
this.parentPath = SplitName.parent(path);
this.allProperties = false;
this.included = null;
this.immutableHashPrefix = buildImmutableQueryPlanHashPrefix(path, null);
this.cache = false;
this.fetchConfig = DEFAULT_FETCH;
this.immutableHashSuffix = buildImmutableQueryPlanHashSuffix(fetchConfig);
}

public OrmQueryProperties(String path, String rawProperties) {
Expand All @@ -89,13 +93,15 @@ public OrmQueryProperties(String path, String rawProperties, FetchConfig fetchCo
OrmQueryPropertiesParser.Response response = OrmQueryPropertiesParser.parse(rawProperties);
this.allProperties = response.allProperties;
this.included = immutableIncluded(response.included);
this.immutableHashPrefix = buildImmutableQueryPlanHashPrefix(path, this.included);
if (fetchConfig != null) {
this.fetchConfig = fetchConfig;
this.cache = fetchConfig.isCache();
} else {
this.cache = false;
this.fetchConfig = DEFAULT_FETCH;
}
this.immutableHashSuffix = buildImmutableQueryPlanHashSuffix(this.fetchConfig);
}

public OrmQueryProperties(String path, Set<String> included) {
Expand All @@ -107,17 +113,21 @@ public OrmQueryProperties(String path, Set<String> included) {
this.parentPath = SplitName.parent(path);
this.included = immutableIncluded(included);
this.allProperties = false;
this.immutableHashPrefix = buildImmutableQueryPlanHashPrefix(path, this.included);
this.fetchConfig = fetchConfig;
this.cache = fetchConfig.isCache();
this.immutableHashSuffix = buildImmutableQueryPlanHashSuffix(fetchConfig);
}

OrmQueryProperties(String path, OrmQueryProperties other, FetchConfig fetchConfig) {
this.path = path;
this.parentPath = SplitName.parent(path);
this.allProperties = other.allProperties;
this.included = other.included;
this.immutableHashPrefix = other.immutableHashPrefix;
this.fetchConfig = fetchConfig;
this.cache = fetchConfig.isCache();
this.immutableHashSuffix = buildImmutableQueryPlanHashSuffix(fetchConfig);
}

/**
Expand All @@ -132,6 +142,10 @@ private OrmQueryProperties(OrmQueryProperties source, FetchConfig sourceFetchCon
this.filterMany = source.filterMany;
this.markForQueryJoin = source.markForQueryJoin;
this.included = source.included;
this.immutableHashPrefix = source.immutableHashPrefix;
this.immutableHashSuffix = source.fetchConfig == sourceFetchConfig
? source.immutableHashSuffix
: buildImmutableQueryPlanHashSuffix(sourceFetchConfig);
}

private static Set<String> immutableIncluded(Set<String> included) {
Expand All @@ -141,6 +155,23 @@ private static Set<String> immutableIncluded(Set<String> included) {
return Collections.unmodifiableSet(new LinkedHashSet<>(included));
}

private static String buildImmutableQueryPlanHashPrefix(String path, Set<String> included) {
StringBuilder builder = new StringBuilder();
builder.append('{');
if (path != null) {
builder.append(path);
}
if (included != null) {
builder.append("/i");
appendSet(builder, included);
}
return builder.toString();
}

private static String buildImmutableQueryPlanHashSuffix(FetchConfig fetchConfig) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put } in the suffix?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, although an alternative is to just include the immutableHashSuffix into the immutableHashPrefix. Hmm.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, scratch my thought ... the immutableHashSuffix needs to be separate, so yeah that ending } could go in there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #3768

return fetchConfig == null ? "" : "/c" + fetchConfig.hashCode();
}

/**
* Creates a copy of the OrmQueryProperties.
*/
Expand Down Expand Up @@ -427,14 +458,7 @@ boolean isSameByAutoTune(OrmQueryProperties p2) {
* Calculate the query plan hash.
*/
public void queryPlanHash(StringBuilder builder) {
builder.append('{');
if (path != null) {
builder.append(path);
}
if (included != null) {
builder.append("/i");
appendSet(builder, included);
}
builder.append(immutableHashPrefix);
if (secondaryQueryJoins != null) {
builder.append("/s");
appendSet(builder, secondaryQueryJoins);
Expand All @@ -443,9 +467,7 @@ public void queryPlanHash(StringBuilder builder) {
builder.append("/f");
filterMany.queryPlanHash(builder);
}
if (fetchConfig != null) {
builder.append("/c").append(fetchConfig.hashCode());
}
builder.append(immutableHashSuffix);
builder.append('}');
}

Expand Down
Loading