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
18174a8e
Commit
18174a8e
authored
Feb 13, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Add opt-in support for Neo4j-OGM native types"
See gh-15637
parent
af21b847
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
88 deletions
+41
-88
Neo4jDataAutoConfiguration.java
.../autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java
+5
-45
Neo4jProperties.java
...mework/boot/autoconfigure/data/neo4j/Neo4jProperties.java
+2
-5
Neo4jDataAutoConfigurationTests.java
...configure/data/neo4j/Neo4jDataAutoConfigurationTests.java
+26
-28
application-properties.adoc
...cs/src/main/asciidoc/appendix/application-properties.adoc
+1
-0
spring-boot-features.adoc
...ing-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+7
-10
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java
View file @
18174a8e
/*
/*
* Copyright 2012-201
9
the original author or authors.
* Copyright 2012-201
8
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -20,9 +20,6 @@ import java.util.List;
...
@@ -20,9 +20,6 @@ import java.util.List;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
import
org.neo4j.ogm.driver.NativeTypesException
;
import
org.neo4j.ogm.driver.NativeTypesNotAvailableException
;
import
org.neo4j.ogm.driver.NativeTypesNotSupportedException
;
import
org.neo4j.ogm.session.SessionFactory
;
import
org.neo4j.ogm.session.SessionFactory
;
import
org.neo4j.ogm.session.event.EventListener
;
import
org.neo4j.ogm.session.event.EventListener
;
...
@@ -37,14 +34,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
...
@@ -37,14 +34,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
import
org.springframework.boot.autoconfigure.domain.EntityScanPackages
;
import
org.springframework.boot.autoconfigure.domain.EntityScanPackages
;
import
org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers
;
import
org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException
;
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.context.annotation.Import
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.data.neo4j.transaction.Neo4jTransactionManager
;
import
org.springframework.data.neo4j.transaction.Neo4jTransactionManager
;
import
org.springframework.data.neo4j.web.support.OpenSessionInViewInterceptor
;
import
org.springframework.data.neo4j.web.support.OpenSessionInViewInterceptor
;
import
org.springframework.lang.Nullable
;
import
org.springframework.transaction.PlatformTransactionManager
;
import
org.springframework.transaction.PlatformTransactionManager
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
...
@@ -58,7 +53,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
...
@@ -58,7 +53,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
* @author Vince Bickers
* @author Vince Bickers
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Kazuki Shimizu
* @author Kazuki Shimizu
* @author Michael Simons
* @since 1.4.0
* @since 1.4.0
*/
*/
@Configuration
@Configuration
...
@@ -79,45 +73,11 @@ public class Neo4jDataAutoConfiguration {
...
@@ -79,45 +73,11 @@ public class Neo4jDataAutoConfiguration {
public
SessionFactory
sessionFactory
(
org
.
neo4j
.
ogm
.
config
.
Configuration
configuration
,
public
SessionFactory
sessionFactory
(
org
.
neo4j
.
ogm
.
config
.
Configuration
configuration
,
ApplicationContext
applicationContext
,
ApplicationContext
applicationContext
,
ObjectProvider
<
EventListener
>
eventListeners
)
{
ObjectProvider
<
EventListener
>
eventListeners
)
{
try
{
SessionFactory
sessionFactory
=
new
SessionFactory
(
configuration
,
SessionFactory
sessionFactory
=
new
SessionFactory
(
configuration
,
getPackagesToScan
(
applicationContext
));
getPackagesToScan
(
applicationContext
));
eventListeners
.
forEach
(
sessionFactory:
:
register
);
eventListeners
.
stream
()
.
forEach
(
sessionFactory:
:
register
);
return
sessionFactory
;
return
sessionFactory
;
}
}
catch
(
NativeTypesException
ex
)
{
InvalidConfigurationPropertyValueException
translatedMessage
=
translateNativeTypesException
(
ex
);
throw
(
translatedMessage
!=
null
)
?
translatedMessage
:
ex
;
}
}
@Nullable
private
static
InvalidConfigurationPropertyValueException
translateNativeTypesException
(
NativeTypesException
cause
)
{
String
propertyName
=
Neo4jProperties
.
CONFIGURATION_PREFIX
+
".use-native-types"
;
boolean
propertyValue
=
true
;
if
(
cause
instanceof
NativeTypesNotAvailableException
)
{
String
message
=
String
.
format
(
"The native type module for your Neo4j-OGM driver is not available. "
+
"Please add the following dependency to your build:%n'%s'."
,
((
NativeTypesNotAvailableException
)
cause
).
getRequiredModule
());
return
new
InvalidConfigurationPropertyValueException
(
propertyName
,
propertyValue
,
message
);
}
if
(
cause
instanceof
NativeTypesNotSupportedException
)
{
String
message
=
String
.
format
(
"The configured Neo4j-OGM driver %s does not support Neo4j native types. "
+
"Please consider one of the drivers that support Neo4js native types like the Bolt or the embedded driver."
,
cause
.
getDriverClassName
());
return
new
InvalidConfigurationPropertyValueException
(
propertyName
,
propertyValue
,
message
);
}
return
null
;
}
@Bean
@Bean
@ConditionalOnMissingBean
(
PlatformTransactionManager
.
class
)
@ConditionalOnMissingBean
(
PlatformTransactionManager
.
class
)
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jProperties.java
View file @
18174a8e
...
@@ -36,11 +36,9 @@ import org.springframework.util.ClassUtils;
...
@@ -36,11 +36,9 @@ import org.springframework.util.ClassUtils;
* @author Michael Simons
* @author Michael Simons
* @since 1.4.0
* @since 1.4.0
*/
*/
@ConfigurationProperties
(
prefix
=
Neo4jProperties
.
CONFIGURATION_PREFIX
)
@ConfigurationProperties
(
prefix
=
"spring.data.neo4j"
)
public
class
Neo4jProperties
implements
ApplicationContextAware
{
public
class
Neo4jProperties
implements
ApplicationContextAware
{
static
final
String
CONFIGURATION_PREFIX
=
"spring.data.neo4j"
;
static
final
String
EMBEDDED_DRIVER
=
"org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver"
;
static
final
String
EMBEDDED_DRIVER
=
"org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver"
;
static
final
String
HTTP_DRIVER
=
"org.neo4j.ogm.drivers.http.driver.HttpDriver"
;
static
final
String
HTTP_DRIVER
=
"org.neo4j.ogm.drivers.http.driver.HttpDriver"
;
...
@@ -76,8 +74,7 @@ public class Neo4jProperties implements ApplicationContextAware {
...
@@ -76,8 +74,7 @@ public class Neo4jProperties implements ApplicationContextAware {
private
Boolean
openInView
;
private
Boolean
openInView
;
/**
/**
* Disables the conversion of java.time.* and spatial types in Neo4j-OGM entities and
* Whether to use Neo4j native types wherever possible.
* uses Neo4j native types wherever possible.
*/
*/
private
boolean
useNativeTypes
=
false
;
private
boolean
useNativeTypes
=
false
;
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java
View file @
18174a8e
...
@@ -18,6 +18,8 @@ package org.springframework.boot.autoconfigure.data.neo4j;
...
@@ -18,6 +18,8 @@ package org.springframework.boot.autoconfigure.data.neo4j;
import
com.github.benmanes.caffeine.cache.Caffeine
;
import
com.github.benmanes.caffeine.cache.Caffeine
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.neo4j.ogm.driver.NativeTypesNotAvailableException
;
import
org.neo4j.ogm.driver.NativeTypesNotSupportedException
;
import
org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
;
import
org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
;
import
org.neo4j.ogm.session.Session
;
import
org.neo4j.ogm.session.Session
;
import
org.neo4j.ogm.session.SessionFactory
;
import
org.neo4j.ogm.session.SessionFactory
;
...
@@ -32,7 +34,6 @@ import org.springframework.boot.autoconfigure.data.neo4j.city.City;
...
@@ -32,7 +34,6 @@ import org.springframework.boot.autoconfigure.data.neo4j.city.City;
import
org.springframework.boot.autoconfigure.data.neo4j.country.Country
;
import
org.springframework.boot.autoconfigure.data.neo4j.country.Country
;
import
org.springframework.boot.autoconfigure.domain.EntityScan
;
import
org.springframework.boot.autoconfigure.domain.EntityScan
;
import
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
;
import
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
;
import
org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException
;
import
org.springframework.boot.test.context.FilteredClassLoader
;
import
org.springframework.boot.test.context.FilteredClassLoader
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.WebApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.WebApplicationContextRunner
;
...
@@ -47,7 +48,6 @@ import org.springframework.data.neo4j.web.support.OpenSessionInViewInterceptor;
...
@@ -47,7 +48,6 @@ import org.springframework.data.neo4j.web.support.OpenSessionInViewInterceptor;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.context.WebApplicationContext
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegalStateException
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
...
@@ -158,35 +158,33 @@ public class Neo4jDataAutoConfigurationTests {
...
@@ -158,35 +158,33 @@ public class Neo4jDataAutoConfigurationTests {
}
}
@Test
@Test
public
void
shouldDealWithNativeTypesNotAvailableException
()
{
public
void
shouldFailWhenNativeTypesAreNotAvailable
()
{
assertThatIllegalStateException
().
isThrownBy
(()
->
{
this
.
contextRunner
this
.
contextRunner
.
withClassLoader
(
.
withClassLoader
(
new
FilteredClassLoader
(
"org.neo4j.ogm.drivers.bolt.types"
))
new
FilteredClassLoader
(
"org.neo4j.ogm.drivers.bolt.types"
))
.
withPropertyValues
(
"spring.data.neo4j.uri=bolt://localhost:7687"
,
.
withPropertyValues
(
"spring.data.neo4j.uri=bolt://localhost:7687"
,
"spring.data.neo4j.use-native-types:true"
)
"spring.data.neo4j.use-native-types:true"
)
.
withConfiguration
(
.
withConfiguration
(
AutoConfigurations
.
of
(
Neo4jDataAutoConfiguration
.
class
,
AutoConfigurations
.
of
(
Neo4jDataAutoConfiguration
.
class
,
TransactionAutoConfiguration
.
class
))
TransactionAutoConfiguration
.
class
))
.
run
((
context
)
->
context
.
getBean
(
SessionFactory
.
class
));
.
run
((
context
)
->
{
}).
withRootCauseInstanceOf
(
InvalidConfigurationPropertyValueException
.
class
)
assertThat
(
context
).
hasFailed
();
.
withStackTraceContaining
(
assertThat
(
context
.
getStartupFailure
()).
hasRootCauseInstanceOf
(
"The native type module for your Neo4j-OGM driver is not available. Please add the following dependency to your build:"
);
NativeTypesNotAvailableException
.
class
);
});
}
}
@Test
@Test
public
void
shouldDealWithNativeTypesNotSupportedException
()
{
public
void
shouldFailWhenNativeTypesAreNotSupported
()
{
assertThatIllegalStateException
().
isThrownBy
(()
->
{
this
.
contextRunner
this
.
contextRunner
.
withPropertyValues
(
"spring.data.neo4j.uri=http://localhost:7474"
,
.
withPropertyValues
(
"spring.data.neo4j.uri=http://localhost:7474"
,
"spring.data.neo4j.use-native-types:true"
)
"spring.data.neo4j.use-native-types:true"
)
.
withConfiguration
(
.
withConfiguration
(
AutoConfigurations
.
of
(
Neo4jDataAutoConfiguration
.
class
,
AutoConfigurations
.
of
(
Neo4jDataAutoConfiguration
.
class
,
TransactionAutoConfiguration
.
class
))
TransactionAutoConfiguration
.
class
))
.
run
((
context
)
->
context
.
getBean
(
SessionFactory
.
class
));
.
run
((
context
)
->
{
}).
withRootCauseInstanceOf
(
InvalidConfigurationPropertyValueException
.
class
)
assertThat
(
context
).
hasFailed
();
.
withStackTraceContaining
(
assertThat
(
context
.
getStartupFailure
()).
hasRootCauseInstanceOf
(
" The configured Neo4j-OGM driver org.neo4j.ogm.drivers.http.driver.HttpDriver does not support Neo4j native types."
);
NativeTypesNotSupportedException
.
class
);
});
}
}
@Test
@Test
...
...
spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix/application-properties.adoc
View file @
18174a8e
...
@@ -695,6 +695,7 @@ content into your application. Rather, pick only the properties that you need.
...
@@ -695,6 +695,7 @@ content into your application. Rather, pick only the properties that you need.
spring.data.neo4j.password= # Login password of the server.
spring.data.neo4j.password= # Login password of the server.
spring.data.neo4j.repositories.enabled=true # Whether to enable Neo4j repositories.
spring.data.neo4j.repositories.enabled=true # Whether to enable Neo4j repositories.
spring.data.neo4j.uri= # URI used by the driver. Auto-detected by default.
spring.data.neo4j.uri= # URI used by the driver. Auto-detected by default.
spring.data.neo4j.use-native-types=false # Whether to use Neo4j native types wherever possible.
spring.data.neo4j.username= # Login user of the server.
spring.data.neo4j.username= # Login user of the server.
# DATA REST ({sc-spring-boot-autoconfigure}/data/rest/RepositoryRestProperties.{sc-ext}[RepositoryRestProperties])
# DATA REST ({sc-spring-boot-autoconfigure}/data/rest/RepositoryRestProperties.{sc-ext}[RepositoryRestProperties])
...
...
spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
18174a8e
...
@@ -4441,22 +4441,19 @@ in your configuration, e.g. `spring.data.neo4j.uri=file://var/tmp/graph.db`.
...
@@ -4441,22 +4441,19 @@ in your configuration, e.g. `spring.data.neo4j.uri=file://var/tmp/graph.db`.
[[boot-features-neo4j-ogm-native-types]]
[[boot-features-neo4j-ogm-native-types]]
==== Using
native t
ypes
==== Using
Native T
ypes
Neo4j-OGM can map some types, like
`java.time.*` to `String` based properties or
Neo4j-OGM can map some types, like
those in `java.time.*`, to `String`-based properties
use one of the various native types that Neo4j provides.
or to one of the native types that Neo4j provides. For backwards compatibility reasons
For backwards compatibility reasons the default for Neo4j-OGM is using a `String` based representation.
the default for Neo4j-OGM is to use a `String`-based representation. To use native types,
To change that behaviour, please add one of `org.neo4j:neo4j-ogm-bolt-native-types` or `org.neo4j:neo4j-ogm-embedded-native-types`
add a dependency on either `org.neo4j:neo4j-ogm-bolt-native-types` or
to the dependencies of your application
`org.neo4j:neo4j-ogm-embedded-native-types`, and configure the
and use the following property in your Spring Boot configuration
:
`spring.data.neo4j.use-native-types` property as shown in the following example
:
[source,properties,indent=0]
[source,properties,indent=0]
----
----
spring.data.neo4j.use-native-types=true
spring.data.neo4j.use-native-types=true
----
----
Please refer to the Neo4j-OGM reference for more information about
https://neo4j.com/docs/ogm-manual/current/reference/#reference:native-property-types[native property types].
[[boot-features-neo4j-ogm-session]]
[[boot-features-neo4j-ogm-session]]
...
...
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