Skip to content

Commit 5e926e9

Browse files
authored
Make embeddables diggable
1 parent 6f356fd commit 5e926e9

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ profiling/
1919
*.iws
2020
.idea/
2121
*uuid.state
22+
23+
# Eclipse
24+
/**/.project
25+
/**/.classpath
26+
/**/.settings/
27+
/**/bin/

ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocOne.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,31 @@ Object naturalKeyVal(Map<String, Object> values) {
210210
@Override
211211
public ElPropertyValue buildElPropertyValue(String propName, String remainder, ElPropertyChainBuilder chain, boolean propertyDeploy) {
212212
if (embedded) {
213-
BeanProperty embProp = embeddedPropsMap.get(remainder);
213+
String embName = remainder;
214+
int basePos = remainder.indexOf('.');
215+
if (basePos > -1) {
216+
embName = remainder.substring(0, basePos);
217+
}
218+
BeanProperty embProp = embeddedPropsMap.get(embName);
214219
if (embProp == null) {
215-
String msg = "Embedded Property " + remainder + " not found in " + fullName();
220+
String msg = "Embedded Property " + embName + " not found in " + fullName();
216221
throw new PersistenceException(msg);
217222
}
223+
224+
if (basePos == -1) {
225+
// we set chain as embedded (and stop future processing)
226+
// only if we not dig into one of the properties of the embeddable
227+
if (chain == null) {
228+
chain = new ElPropertyChainBuilder(true, propName);
229+
}
230+
231+
chain.add(this);
232+
chain.setEmbedded(true);
233+
return chain.add(embProp).build();
234+
}
218235
if (chain == null) {
219-
chain = new ElPropertyChainBuilder(true, propName);
236+
chain = new ElPropertyChainBuilder(false, propName);
220237
}
221-
chain.add(this);
222-
chain.setEmbedded(true);
223-
return chain.add(embProp).build();
224238
}
225239
return createElPropertyValue(propName, remainder, chain, propertyDeploy);
226240
}

ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeAlias.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class SqlTreeAlias {
3535
void addManyWhereJoins(Set<String> manyWhereJoins) {
3636
if (manyWhereJoins != null) {
3737
for (String include : manyWhereJoins) {
38-
addPropertyJoin(include, manyWhereJoinProps);
38+
addPropertyJoin(include, manyWhereJoinProps, null);
3939
}
4040
}
4141
}
@@ -56,18 +56,22 @@ public void addJoin(Set<String> propJoins, STreeType desc) {
5656
if (desc.isEmbeddedPath(propJoin)) {
5757
addEmbeddedPropertyJoin(propJoin);
5858
} else {
59-
addPropertyJoin(propJoin, joinProps);
59+
addPropertyJoin(propJoin, joinProps, desc);
6060
}
6161
}
6262
}
6363
}
64-
65-
private void addPropertyJoin(String include, TreeSet<String> set) {
66-
if (set.add(include)) {
67-
String[] split = SplitName.split(include);
68-
if (split[0] != null) {
69-
addPropertyJoin(split[0], set);
70-
}
64+
65+
private void addPropertyJoin(String include, TreeSet<String> set, STreeType desc) {
66+
if (include == null) {
67+
return;
68+
}
69+
String[] split = SplitName.split(include);
70+
if (desc != null && desc.isEmbeddedPath(include)) {
71+
addEmbeddedPropertyJoin(include);
72+
addPropertyJoin(split[0], set, desc);
73+
} else if (set.add(include)) {
74+
addPropertyJoin(split[0], set, desc);
7175
}
7276
}
7377

ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,12 @@ private SqlTreeNodeExtraJoin findExtraJoinRoot(String includeProp, SqlTreeNodeEx
684684

685685
SqlTreeNodeExtraJoin parentJoin = joinRegister.get(parentPropertyName);
686686
if (parentJoin == null) {
687+
if (desc.isEmbeddedPath(parentPropertyName)) {
688+
// digging in embedded property
689+
// so we have to join parent property path
690+
includeProp = parentPropertyName;
691+
continue;
692+
}
687693
// we need to create this the parent implicitly...
688694
parentJoin = createJoinLeaf(parentPropertyName);
689695
}

0 commit comments

Comments
 (0)