File tree 3 files changed +70
-0
lines changed
main/java/org/springframework/data/neo4j/repository/query
test/java/org/springframework/data/neo4j/integration
3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -382,6 +382,14 @@ private Condition containingCondition(PersistentPropertyPath<Neo4jPersistentProp
382
382
Neo4jPersistentProperty property , Iterator <Object > actualParameters , boolean ignoreCase ) {
383
383
384
384
Expression cypherProperty = toCypherProperty (path , ignoreCase );
385
+
386
+ if (property .isDynamicLabels ()) {
387
+ Neo4jPersistentProperty leafProperty = path .getRequiredLeafProperty ();
388
+ Neo4jPersistentEntity <?> owner = (Neo4jPersistentEntity <?>) leafProperty .getOwner ();
389
+ String containerName = getContainerName (path , owner );
390
+ return toCypherParameter (nextRequiredParameter (actualParameters , property ), ignoreCase )
391
+ .in (Functions .labels (Cypher .anyNode (containerName )));
392
+ }
385
393
if (property .isCollectionLike ()) {
386
394
return toCypherParameter (nextRequiredParameter (actualParameters , property ), ignoreCase ).in (cypherProperty );
387
395
}
Original file line number Diff line number Diff line change 42
42
import org .springframework .beans .factory .annotation .Autowired ;
43
43
import org .springframework .context .annotation .Bean ;
44
44
import org .springframework .context .annotation .Configuration ;
45
+ import org .springframework .data .neo4j .integration .shared .common .Port ;
45
46
import org .springframework .data .neo4j .repository .Neo4jRepository ;
46
47
import org .springframework .data .neo4j .repository .config .EnableNeo4jRepositories ;
47
48
import org .springframework .data .neo4j .test .Neo4jImperativeTestConfiguration ;
@@ -446,6 +447,30 @@ void instantiateConcreteEntityType(@Autowired AbstractBaseEntityWithDynamicLabel
446
447
447
448
}
448
449
450
+ @ Nested
451
+ class FindByLabelsContaining extends SpringTestBase {
452
+
453
+ @ Override
454
+ Long createTestEntity (TransactionContext t ) {
455
+ t .run ("CREATE (p:Port:A:B {id: randomUUID()})" );
456
+ t .run ("CREATE (p:Port {id: randomUUID()})" );
457
+ t .run ("CREATE (p:Port:C:B {id: randomUUID()})" );
458
+ t .run ("CREATE (p:Port:D:A {id: randomUUID()})" );
459
+ return null ;
460
+ }
461
+
462
+ @ Test // GH-2638
463
+ void findByDynamicLabelsContainingShouldWork (@ Autowired PortRepository portRepository ) {
464
+
465
+ List <Port > ports = portRepository .findByLabelsContaining ("A" );
466
+ assertThat (ports ).hasSize (2 );
467
+ }
468
+ }
469
+
470
+ interface PortRepository extends Neo4jRepository <Port , UUID > {
471
+ List <Port > findByLabelsContaining (String label );
472
+ }
473
+
449
474
interface AbstractBaseEntityWithDynamicLabelsRepository extends Neo4jRepository <EntitiesWithDynamicLabels .AbstractBaseEntityWithDynamicLabels , String > {}
450
475
451
476
@ ExtendWith (SpringExtension .class )
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2011-2022 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package org .springframework .data .neo4j .integration .shared .common ;
17
+
18
+ import java .util .List ;
19
+ import java .util .UUID ;
20
+
21
+ import org .springframework .data .neo4j .core .schema .DynamicLabels ;
22
+ import org .springframework .data .neo4j .core .schema .GeneratedValue ;
23
+ import org .springframework .data .neo4j .core .schema .Id ;
24
+ import org .springframework .data .neo4j .core .schema .Node ;
25
+
26
+ /**
27
+ * @author Michael J. Simons
28
+ */
29
+ @ Node ("Port" )
30
+ public class Port {
31
+ @ Id
32
+ @ GeneratedValue
33
+ private UUID id ;
34
+ private String code ;
35
+ @ DynamicLabels
36
+ private List <String > labels ;
37
+ }
You can’t perform that action at this time.
0 commit comments