Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
ab4b1c4e
Commit
ab4b1c4e
authored
Nov 24, 2020
by
Gerrit Meier
Committed by
Stephane Nicoll
Dec 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect Persistent and RelationshipProperties with Neo4j
See gh-24239
parent
1f71927a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
173 additions
and
1 deletion
+173
-1
Neo4jDataAutoConfiguration.java
.../autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java
+4
-1
Neo4jDataAutoConfigurationTests.java
...configure/data/neo4j/Neo4jDataAutoConfigurationTests.java
+23
-0
Neo4jReactiveRepositoriesAutoConfigurationTests.java
...eo4j/Neo4jReactiveRepositoriesAutoConfigurationTests.java
+22
-0
AnnotatedWithNode.java
...boot/autoconfigure/data/neo4j/scan/AnnotatedWithNode.java
+33
-0
AnnotatedWithPersistent.java
...utoconfigure/data/neo4j/scan/AnnotatedWithPersistent.java
+33
-0
AnnotatedWithRelationshipProperties.java
.../data/neo4j/scan/AnnotatedWithRelationshipProperties.java
+27
-0
NotAnnotatedEntity.java
...oot/autoconfigure/data/neo4j/scan/NotAnnotatedEntity.java
+31
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java
View file @
ab4b1c4e
...
@@ -35,6 +35,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
...
@@ -35,6 +35,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.annotation.Persistent
;
import
org.springframework.data.neo4j.core.DatabaseSelectionProvider
;
import
org.springframework.data.neo4j.core.DatabaseSelectionProvider
;
import
org.springframework.data.neo4j.core.Neo4jClient
;
import
org.springframework.data.neo4j.core.Neo4jClient
;
import
org.springframework.data.neo4j.core.Neo4jOperations
;
import
org.springframework.data.neo4j.core.Neo4jOperations
;
...
@@ -42,6 +43,7 @@ import org.springframework.data.neo4j.core.Neo4jTemplate;
...
@@ -42,6 +43,7 @@ import org.springframework.data.neo4j.core.Neo4jTemplate;
import
org.springframework.data.neo4j.core.convert.Neo4jConversions
;
import
org.springframework.data.neo4j.core.convert.Neo4jConversions
;
import
org.springframework.data.neo4j.core.mapping.Neo4jMappingContext
;
import
org.springframework.data.neo4j.core.mapping.Neo4jMappingContext
;
import
org.springframework.data.neo4j.core.schema.Node
;
import
org.springframework.data.neo4j.core.schema.Node
;
import
org.springframework.data.neo4j.core.schema.RelationshipProperties
;
import
org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager
;
import
org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager
;
import
org.springframework.data.neo4j.repository.config.Neo4jRepositoryConfigurationExtension
;
import
org.springframework.data.neo4j.repository.config.Neo4jRepositoryConfigurationExtension
;
import
org.springframework.transaction.PlatformTransactionManager
;
import
org.springframework.transaction.PlatformTransactionManager
;
...
@@ -76,7 +78,8 @@ public class Neo4jDataAutoConfiguration {
...
@@ -76,7 +78,8 @@ public class Neo4jDataAutoConfiguration {
@ConditionalOnMissingBean
@ConditionalOnMissingBean
public
Neo4jMappingContext
neo4jMappingContext
(
ApplicationContext
applicationContext
,
public
Neo4jMappingContext
neo4jMappingContext
(
ApplicationContext
applicationContext
,
Neo4jConversions
neo4jConversions
)
throws
ClassNotFoundException
{
Neo4jConversions
neo4jConversions
)
throws
ClassNotFoundException
{
Set
<
Class
<?>>
initialEntityClasses
=
new
EntityScanner
(
applicationContext
).
scan
(
Node
.
class
);
Set
<
Class
<?>>
initialEntityClasses
=
new
EntityScanner
(
applicationContext
).
scan
(
Node
.
class
,
Persistent
.
class
,
RelationshipProperties
.
class
);
Neo4jMappingContext
context
=
new
Neo4jMappingContext
(
neo4jConversions
);
Neo4jMappingContext
context
=
new
Neo4jMappingContext
(
neo4jConversions
);
context
.
setInitialEntitySet
(
initialEntityClasses
);
context
.
setInitialEntitySet
(
initialEntityClasses
);
return
context
;
return
context
;
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java
View file @
ab4b1c4e
...
@@ -19,6 +19,11 @@ package org.springframework.boot.autoconfigure.data.neo4j;
...
@@ -19,6 +19,11 @@ package org.springframework.boot.autoconfigure.data.neo4j;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.TestAutoConfigurationPackage
;
import
org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithNode
;
import
org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithPersistent
;
import
org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithRelationshipProperties
;
import
org.springframework.boot.autoconfigure.data.neo4j.scan.NotAnnotatedEntity
;
import
org.springframework.boot.autoconfigure.neo4j.Neo4jAutoConfiguration
;
import
org.springframework.boot.autoconfigure.neo4j.Neo4jAutoConfiguration
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
...
@@ -29,6 +34,7 @@ import org.springframework.data.neo4j.core.Neo4jClient;
...
@@ -29,6 +34,7 @@ import org.springframework.data.neo4j.core.Neo4jClient;
import
org.springframework.data.neo4j.core.Neo4jOperations
;
import
org.springframework.data.neo4j.core.Neo4jOperations
;
import
org.springframework.data.neo4j.core.Neo4jTemplate
;
import
org.springframework.data.neo4j.core.Neo4jTemplate
;
import
org.springframework.data.neo4j.core.convert.Neo4jConversions
;
import
org.springframework.data.neo4j.core.convert.Neo4jConversions
;
import
org.springframework.data.neo4j.core.mapping.Neo4jMappingContext
;
import
org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager
;
import
org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager
;
import
org.springframework.transaction.PlatformTransactionManager
;
import
org.springframework.transaction.PlatformTransactionManager
;
import
org.springframework.transaction.ReactiveTransactionManager
;
import
org.springframework.transaction.ReactiveTransactionManager
;
...
@@ -137,6 +143,17 @@ class Neo4jDataAutoConfigurationTests {
...
@@ -137,6 +143,17 @@ class Neo4jDataAutoConfigurationTests {
.
hasBean
(
"myCustomTransactionManager"
));
.
hasBean
(
"myCustomTransactionManager"
));
}
}
@Test
void
shouldFilterInitialEntityScanWithKnownAnnotations
()
{
this
.
contextRunner
.
withUserConfiguration
(
PackageConfig
.
class
).
run
((
context
)
->
{
Neo4jMappingContext
mappingContext
=
context
.
getBean
(
Neo4jMappingContext
.
class
);
assertThat
(
mappingContext
.
hasPersistentEntityFor
(
AnnotatedWithNode
.
class
)).
isTrue
();
assertThat
(
mappingContext
.
hasPersistentEntityFor
(
AnnotatedWithPersistent
.
class
)).
isTrue
();
assertThat
(
mappingContext
.
hasPersistentEntityFor
(
AnnotatedWithRelationshipProperties
.
class
)).
isTrue
();
assertThat
(
mappingContext
.
hasPersistentEntityFor
(
NotAnnotatedEntity
.
class
)).
isFalse
();
});
}
@Configuration
(
proxyBeanMethods
=
false
)
@Configuration
(
proxyBeanMethods
=
false
)
static
class
CustomDatabaseSelectionProviderConfiguration
{
static
class
CustomDatabaseSelectionProviderConfiguration
{
...
@@ -147,4 +164,10 @@ class Neo4jDataAutoConfigurationTests {
...
@@ -147,4 +164,10 @@ class Neo4jDataAutoConfigurationTests {
}
}
@Configuration
(
proxyBeanMethods
=
false
)
@TestAutoConfigurationPackage
(
AnnotatedWithPersistent
.
class
)
static
class
PackageConfig
{
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jReactiveRepositoriesAutoConfigurationTests.java
View file @
ab4b1c4e
...
@@ -26,9 +26,14 @@ import org.springframework.boot.autoconfigure.data.neo4j.city.CityRepository;
...
@@ -26,9 +26,14 @@ import org.springframework.boot.autoconfigure.data.neo4j.city.CityRepository;
import
org.springframework.boot.autoconfigure.data.neo4j.city.ReactiveCityRepository
;
import
org.springframework.boot.autoconfigure.data.neo4j.city.ReactiveCityRepository
;
import
org.springframework.boot.autoconfigure.data.neo4j.country.CountryRepository
;
import
org.springframework.boot.autoconfigure.data.neo4j.country.CountryRepository
;
import
org.springframework.boot.autoconfigure.data.neo4j.country.ReactiveCountryRepository
;
import
org.springframework.boot.autoconfigure.data.neo4j.country.ReactiveCountryRepository
;
import
org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithNode
;
import
org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithPersistent
;
import
org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithRelationshipProperties
;
import
org.springframework.boot.autoconfigure.data.neo4j.scan.NotAnnotatedEntity
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.neo4j.core.ReactiveNeo4jTemplate
;
import
org.springframework.data.neo4j.core.ReactiveNeo4jTemplate
;
import
org.springframework.data.neo4j.core.mapping.Neo4jMappingContext
;
import
org.springframework.data.neo4j.repository.ReactiveNeo4jRepository
;
import
org.springframework.data.neo4j.repository.ReactiveNeo4jRepository
;
import
org.springframework.data.neo4j.repository.config.EnableReactiveNeo4jRepositories
;
import
org.springframework.data.neo4j.repository.config.EnableReactiveNeo4jRepositories
;
...
@@ -84,6 +89,17 @@ public class Neo4jReactiveRepositoriesAutoConfigurationTests {
...
@@ -84,6 +89,17 @@ public class Neo4jReactiveRepositoriesAutoConfigurationTests {
.
hasSingleBean
(
ReactiveCountryRepository
.
class
));
.
hasSingleBean
(
ReactiveCountryRepository
.
class
));
}
}
@Test
void
shouldFilterInitialEntityScanWithKnownAnnotations
()
{
this
.
contextRunner
.
withUserConfiguration
(
PackageConfig
.
class
).
run
((
context
)
->
{
Neo4jMappingContext
mappingContext
=
context
.
getBean
(
Neo4jMappingContext
.
class
);
assertThat
(
mappingContext
.
hasPersistentEntityFor
(
AnnotatedWithNode
.
class
)).
isTrue
();
assertThat
(
mappingContext
.
hasPersistentEntityFor
(
AnnotatedWithPersistent
.
class
)).
isTrue
();
assertThat
(
mappingContext
.
hasPersistentEntityFor
(
AnnotatedWithRelationshipProperties
.
class
)).
isTrue
();
assertThat
(
mappingContext
.
hasPersistentEntityFor
(
NotAnnotatedEntity
.
class
)).
isFalse
();
});
}
@Configuration
(
proxyBeanMethods
=
false
)
@Configuration
(
proxyBeanMethods
=
false
)
@TestAutoConfigurationPackage
(
City
.
class
)
@TestAutoConfigurationPackage
(
City
.
class
)
static
class
TestConfiguration
{
static
class
TestConfiguration
{
...
@@ -109,4 +125,10 @@ public class Neo4jReactiveRepositoriesAutoConfigurationTests {
...
@@ -109,4 +125,10 @@ public class Neo4jReactiveRepositoriesAutoConfigurationTests {
}
}
@Configuration
(
proxyBeanMethods
=
false
)
@TestAutoConfigurationPackage
(
AnnotatedWithPersistent
.
class
)
static
class
PackageConfig
{
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/AnnotatedWithNode.java
0 → 100644
View file @
ab4b1c4e
/*
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
neo4j
.
scan
;
import
org.springframework.data.neo4j.core.schema.GeneratedValue
;
import
org.springframework.data.neo4j.core.schema.Id
;
import
org.springframework.data.neo4j.core.schema.Node
;
/**
* @author Gerrit Meier
*/
@Node
public
class
AnnotatedWithNode
{
@Id
@GeneratedValue
private
Long
id
;
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/AnnotatedWithPersistent.java
0 → 100644
View file @
ab4b1c4e
/*
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
neo4j
.
scan
;
import
org.springframework.data.annotation.Persistent
;
import
org.springframework.data.neo4j.core.schema.GeneratedValue
;
import
org.springframework.data.neo4j.core.schema.Id
;
/**
* @author Gerrit Meier
*/
@Persistent
public
class
AnnotatedWithPersistent
{
@Id
@GeneratedValue
private
Long
id
;
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/AnnotatedWithRelationshipProperties.java
0 → 100644
View file @
ab4b1c4e
/*
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
neo4j
.
scan
;
import
org.springframework.data.neo4j.core.schema.RelationshipProperties
;
/**
* @author Gerrit Meier
*/
@RelationshipProperties
public
class
AnnotatedWithRelationshipProperties
{
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/NotAnnotatedEntity.java
0 → 100644
View file @
ab4b1c4e
/*
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
neo4j
.
scan
;
import
org.springframework.data.neo4j.core.schema.GeneratedValue
;
import
org.springframework.data.neo4j.core.schema.Id
;
/**
* @author Gerrit Meier
*/
public
class
NotAnnotatedEntity
{
@Id
@GeneratedValue
private
Long
id
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment