File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed
main/java/org/springframework/data/neo4j/repository/query
test/java/org/springframework/data/neo4j/integration Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -417,6 +417,14 @@ private Condition containingCondition(PersistentPropertyPath<Neo4jPersistentProp
417417 Neo4jPersistentProperty property , Iterator <Object > actualParameters , boolean ignoreCase ) {
418418
419419 Expression cypherProperty = toCypherProperty (path , ignoreCase );
420+
421+ if (property .isDynamicLabels ()) {
422+ Neo4jPersistentProperty leafProperty = path .getRequiredLeafProperty ();
423+ Neo4jPersistentEntity <?> owner = (Neo4jPersistentEntity <?>) leafProperty .getOwner ();
424+ String containerName = getContainerName (path , owner );
425+ return toCypherParameter (nextRequiredParameter (actualParameters , property ), ignoreCase )
426+ .in (Functions .labels (Cypher .anyNode (containerName )));
427+ }
420428 if (property .isCollectionLike ()) {
421429 return toCypherParameter (nextRequiredParameter (actualParameters , property ), ignoreCase ).in (cypherProperty );
422430 }
Original file line number Diff line number Diff line change 4141import org .springframework .beans .factory .annotation .Autowired ;
4242import org .springframework .context .annotation .Bean ;
4343import org .springframework .context .annotation .Configuration ;
44+ import org .springframework .data .neo4j .integration .shared .common .Port ;
4445import org .springframework .data .neo4j .repository .Neo4jRepository ;
4546import org .springframework .data .neo4j .repository .config .EnableNeo4jRepositories ;
4647import org .springframework .data .neo4j .test .Neo4jImperativeTestConfiguration ;
@@ -462,6 +463,30 @@ void instantiateConcreteEntityType(@Autowired AbstractBaseEntityWithDynamicLabel
462463
463464 }
464465
466+ @ Nested
467+ class FindByLabelsContaining extends SpringTestBase {
468+
469+ @ Override
470+ Long createTestEntity (Transaction t ) {
471+ t .run ("CREATE (p:Port:A:B {id: randomUUID()})" );
472+ t .run ("CREATE (p:Port {id: randomUUID()})" );
473+ t .run ("CREATE (p:Port:C:B {id: randomUUID()})" );
474+ t .run ("CREATE (p:Port:D:A {id: randomUUID()})" );
475+ return null ;
476+ }
477+
478+ @ Test // GH-2638
479+ void findByDynamicLabelsContainingShouldWork (@ Autowired PortRepository portRepository ) {
480+
481+ List <Port > ports = portRepository .findByLabelsContaining ("A" );
482+ assertThat (ports ).hasSize (2 );
483+ }
484+ }
485+
486+ interface PortRepository extends Neo4jRepository <Port , UUID > {
487+ List <Port > findByLabelsContaining (String label );
488+ }
489+
465490 interface AbstractBaseEntityWithDynamicLabelsRepository extends Neo4jRepository <EntitiesWithDynamicLabels .AbstractBaseEntityWithDynamicLabels , String > {}
466491
467492 @ 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