-
Notifications
You must be signed in to change notification settings - Fork 377
DATAJDBC-329 - Replacing JdbcConfiguration. #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright 2019 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 | ||
| * | ||
| * http://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.data.jdbc.core.convert; | ||
|
|
||
| import org.springframework.data.relational.core.conversion.RelationalConverter; | ||
|
|
||
| /** | ||
| * A {@link JdbcConverter} is responsible for converting for values to the native relational representation and vice | ||
| * versa. | ||
| * | ||
| * @author Jens Schauder | ||
| * | ||
| * @since 1.1 | ||
| */ | ||
| public interface JdbcConverter extends RelationalConverter {} |
109 changes: 109 additions & 0 deletions
109
.../main/java/org/springframework/data/jdbc/repository/config/AbstractJdbcConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* | ||
| * Copyright 2017-2019 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 | ||
| * | ||
| * http://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.data.jdbc.repository.config; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import org.springframework.context.ApplicationEventPublisher; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.core.convert.converter.Converter; | ||
| import org.springframework.data.jdbc.core.DataAccessStrategy; | ||
| import org.springframework.data.jdbc.core.DefaultDataAccessStrategy; | ||
| import org.springframework.data.jdbc.core.JdbcAggregateTemplate; | ||
| import org.springframework.data.jdbc.core.SqlGeneratorSource; | ||
| import org.springframework.data.jdbc.core.convert.BasicJdbcConverter; | ||
| import org.springframework.data.jdbc.core.convert.JdbcConverter; | ||
| import org.springframework.data.jdbc.core.convert.JdbcCustomConversions; | ||
| import org.springframework.data.jdbc.core.mapping.JdbcMappingContext; | ||
| import org.springframework.data.relational.core.conversion.RelationalConverter; | ||
| import org.springframework.data.relational.core.mapping.NamingStrategy; | ||
| import org.springframework.data.relational.core.mapping.RelationalMappingContext; | ||
| import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; | ||
|
|
||
| /** | ||
| * Beans that must be registered for Spring Data JDBC to work. | ||
| * | ||
| * @author Greg Turnquist | ||
| * @author Jens Schauder | ||
| * @author Mark Paluch | ||
| * @author Michael Simons | ||
| * @author Christoph Strobl | ||
| * @since 1.1 | ||
| */ | ||
| @Configuration | ||
| public abstract class AbstractJdbcConfiguration { | ||
|
|
||
| /** | ||
| * Register a {@link RelationalMappingContext} and apply an optional {@link NamingStrategy}. | ||
| * | ||
| * @param namingStrategy optional {@link NamingStrategy}. Use {@link NamingStrategy#INSTANCE} as fallback. | ||
| * @return must not be {@literal null}. | ||
| */ | ||
| @Bean | ||
| public JdbcMappingContext jdbcMappingContext(Optional<NamingStrategy> namingStrategy) { | ||
|
|
||
| JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy.orElse(NamingStrategy.INSTANCE)); | ||
| mappingContext.setSimpleTypeHolder(jdbcCustomConversions().getSimpleTypeHolder()); | ||
|
|
||
| return mappingContext; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a {@link RelationalConverter} using the configured {@link #jdbcMappingContext(Optional)}. Will get | ||
| * {@link #jdbcCustomConversions()} applied. | ||
| * | ||
| * @see #jdbcMappingContext(Optional) | ||
| * @see #jdbcCustomConversions() | ||
| * @return must not be {@literal null}. | ||
| */ | ||
| @Bean | ||
| public JdbcConverter relationalConverter(RelationalMappingContext mappingContext) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about naming this bean
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. arg, missed that. |
||
| return new BasicJdbcConverter(mappingContext, jdbcCustomConversions()); | ||
| } | ||
|
|
||
| /** | ||
| * Register custom {@link Converter}s in a {@link JdbcCustomConversions} object if required. These | ||
| * {@link JdbcCustomConversions} will be registered with the {@link #relationalConverter(RelationalMappingContext)}. | ||
| * Returns an empty {@link JdbcCustomConversions} instance by default. | ||
| * | ||
| * @return must not be {@literal null}. | ||
| */ | ||
| @Bean | ||
| public JdbcCustomConversions jdbcCustomConversions() { | ||
| return new JdbcCustomConversions(); | ||
| } | ||
|
|
||
| /** | ||
| * Register a {@link JdbcAggregateTemplate} as a bean for easy use in applications that need a lower level of | ||
| * abstraction than the normal repository abstraction. | ||
| * | ||
| * @param publisher for publishing events. Must not be {@literal null}. | ||
| * @param context the mapping context to be used. Must not be {@literal null}. | ||
| * @param converter the conversions used when reading and writing from/to the database. Must not be {@literal null}. | ||
| * @param operations {@link NamedParameterJdbcOperations} used for accessing the database. Must not be | ||
| * {@literal null}. | ||
| * @return a {@link JdbcAggregateTemplate}. Guaranteed to be not {@literal null}. | ||
| */ | ||
| @Bean | ||
| public JdbcAggregateTemplate jdbcAggregateTemplate(ApplicationEventPublisher publisher, | ||
| RelationalMappingContext context, RelationalConverter converter, NamedParameterJdbcOperations operations) { | ||
|
|
||
| DataAccessStrategy dataAccessStrategy = new DefaultDataAccessStrategy(new SqlGeneratorSource(context), context, | ||
| converter, operations); | ||
| return new JdbcAggregateTemplate(publisher, context, converter, dataAccessStrategy); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inception year is 2019.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about that. Since it is actually a copy of the
JdbcConfigurationI thought keeping the inception date would be appropriate.What do you think?