Commit Graph

62 Commits

Author SHA1 Message Date
Jens Schauder
b1115833ab DATAJDBC-184 - Polishing.
Minor changes to JavaDoc and formatting.

Original pull request: #49.
2018-03-23 12:47:38 +01:00
Kazuki Shimizu
924bb55394 DATAJDBC-184 - Support the delimiter character naming strategy.
Original pull request: #49.
2018-03-23 12:45:06 +01:00
Jens Schauder
46f65149b8 DATAJDBC-186 - Polishing.
JavaDoc.
2018-03-21 11:45:11 -05:00
Jens Schauder
f7274a2efa DATAJDBC-186 - Removed requirement for id properties.
It is now ok for an entity to be “new” after saving.
We now only check that an entity is not new when the id is provided by the database.
If in such a case the entity is still “new” after saving it basically means obtaining the id from JDBC and setting it in the entity failed.

Removed need for entities in maps to have an id.

Together these changes simplify the requirements for Map values, which now can be value objects.
2018-03-21 11:44:59 -05:00
Jens Schauder
8885ce342b DATAJDBC-183 - Polishing.
Removed calls to System.out.
Formatting.
Import order.
2018-03-21 11:42:58 -05:00
Jens Schauder
cb302e90a6 DATAJDBC-183 - Using dedicated class for handling map entries.
Instead of using Map.Entry we now use a dedicated class to hold key and value of a map entry.
This avoids side effects from the implementation of Map.Entry.

Replaced call to saveReferencedEntities with insertReferencedEntities which is simpler but equivalent since referenced entities always get only inserted, never updated.

Removed superfluous methods resulting from that change.
2018-03-21 11:42:46 -05:00
Jens Schauder
31eeba743f DATAJDBC-142 - Using getName instead of getColumnName for constructing PropertyPaths. 2018-03-21 11:40:18 -05:00
Jens Schauder
964f319ae6 DATAJDBC-166 - Polishing.
Formatting.
Import order.
Use of AssertJ.
2018-03-21 11:37:32 -05:00
Jens Schauder
a2b7699256 DATAJDBC-166 - Allow registration of RowMappers based on result type.
RowMapper can be configured either via the @Query(rowMapperClass = …​.) or by registerign a RowMapperMap bean and register RowMapper per method return type.

                @Bean
                RowMapperMap rowMappers() {
                        return new ConfigurableRowMapperMap() //
                                        .register(Person.class, new PersonRowMapper()) //
                                        .register(Address.class, new AddressRowMapper());
                }

When determining the RowMapper to use for a method the following steps are followed based on the return type of the method:

1. If the type is a simple type no RowMapper is used. Instead the query is expected to return a single row with a single column and a conversion to the return type is applied to that value.

2. The entity classes in the RowMapperMap are iterated until one is found that is a superclass or interface of the return type in question. The RowMapper registered for that class is used. Iterating happens in the order of registration, so make sure to register more general types after specific ones.

If applicable wrapper type like collections or Optional are unwrapped. So a return type of Optional<Person> will use the type Person in the steps above.
2018-03-21 11:37:05 -05:00
Jens Schauder
18bf6ca77c DATAJDBC-181 - Use NamingStrategy for instantiating entities.
The ResultSetParameterValueProvider uses the relevant property for a requested parameter in order to obtain the proper column name to use.

Improved mocking of ResultSets in tests to actually fail when a non existing column gets requested instead of just returning null.
2018-03-09 09:18:28 -06:00
Jens Schauder
043bd4de35 DATAJDBC-165 - Allows configuration of custom RowMapper on @Query annotation. 2018-03-09 09:15:31 -06:00
Jens Schauder
5f6a44d00a DATAJDBC-182 - Polishing.
Extracted method to maintain a single level of abstraction.
Added description to assertion that wasn't obvious to me.
Added JavaDoc on existing method.
Commented repository methods in test with issue ids to ease understanding the purpose of each method.
2018-03-09 10:19:55 +01:00
Kazuki Shimizu
73fe1ca93b DATAJDBC-182 - Support modifying annotated queries.
Added @Modify for marking queries that perform DML or DDL.
Modifying queries with return type boolean or Boolean return wether the number of updated rows is greater 0.
This shouldn't be used for DML statements since it will always return false.

Original pull request: ##48.
2018-03-09 10:18:14 +01:00
Jens Schauder
ac4da66d99 DATAJDBC-175 - Polishing.
Code formatting.
2018-03-07 16:14:18 +01:00
Kazuki Shimizu
369ca6d599 DATAJDBC-175 - Supports simple types as return type for annotated methods.
Original pull request: #43.
2018-03-07 16:01:32 +01:00
Jens Schauder
1603296385 DATAJDBC-130 - Polishing.
Formatting.
Tiny fixes in JavaDoc.
Fixed some type parameters.
Replaced concrete classes with interfaces.
2018-02-22 13:05:52 -06:00
Jens Schauder
f5de195768 DATAJDBC-130 - Support entities with List valued properties. 2018-02-22 13:05:39 -06:00
Jens Schauder
7ed2ed7d7e DATAJDBC-172 - Polishing.
Formatting.
Added @author tag.
2018-02-08 15:30:04 +01:00
Kazuki Shimizu
6f6499026a DATAJDBC-172 - Support entity type, Optional and Stream as return type of @Query methods.
Original pull request: #40.
2018-02-08 15:27:30 +01:00
Jens Schauder
9a90d7e09b DATAJDBC-161 - Polishing.
Removed second constructor and made tests use the new constructor.
Changed parameter type to the interface SqlSession.
Added some JavaDoc.
2018-02-06 14:22:39 +01:00
Kazuki Shimizu
66556f93c4 DATAJDBC-161 - Share a SqlSession between statements.
Original pull request: #29.
2018-02-06 14:21:34 +01:00
Greg Turnquist
0fdd885224 DATAJDBC-164 - Polishing. 2018-01-26 09:49:51 -06:00
Jens Schauder
bc209b1114 DATAJDBC-164 - Add support for basic @Query annotation. 2018-01-26 09:48:43 -06:00
Jens Schauder
2163a26917 DATAJDBC-157 - Replace dots in MyBatis statement ids with dashes. 2018-01-26 09:32:43 -06:00
Mark Paluch
06b15da50d DATAJDBC-163 - Update copyright years to 2018. 2018-01-09 08:49:39 +01:00
Jens Schauder
fe00e928a5 DATAJDBC-162 - Prevent NPE for missing PropertyPath in DbActionExecutionException. 2018-01-08 10:59:01 +01:00
Michael Simons
235abe44e8 Fix typo (#28)
Thanks
2017-12-14 15:57:41 +01:00
Jens Schauder
ae4e2a7deb DATAJDBC-158 - BasicJdbcPersistentEntityInformation honors Persistable implementations. 2017-12-04 09:27:34 -06:00
Greg Turnquist
b044a13af1 DATAJDBC-151 - Reform Spring Data JDBC to stop autoconfiguration
In the past, Spring Data JDBC performed autoconfiguration such as gleaning whether or not MyBatis is on the classpath, and also whether or not certain other beans exist. This commit removes such flexible settings and instead wires up a JdbcMappingContext seeking an optional NamingStrategy and optional ConversionCustomizer. The other required beans will alert the end user if they don't exist.

All relevant test cases are updated to inject the proper components.

All autoconfiguration is being moved outside Spring Data JDBC, to eventually join Spring Boot after being shook out as an independent module.
2017-11-28 15:20:21 +01:00
Jens Schauder
0b2708ff9a DATAJDBC-150 - Provides better error message when execution of a DbAction fails. 2017-11-27 11:43:34 -06:00
Jens Schauder
3c9765c9b8 DATAJDBC-147 - Support registration von converters via ConversionCustomizers. 2017-11-01 10:44:44 -05:00
Jens Schauder
207278c891 DATAJDBC-145 - Back-reference in insert now honours NamingStrategy.
Added a property path to DbActions in order to make them aware of the property it is related to.
Then used the JdbcPersistentProperty based on that get the name of the back-reference name of that property back to the root entity of that property.
This gets the NamingStrategy properly involved, as it should.

Instead of using the vanilla PropertyPath a new JdbcPropertyPath is introduced.
It allows for an empty path avoiding various null-checks.

Upgraded SD-Commons dependency to 2.1.x in order to utilise DATACMNS-1199.
Removed the now superfluous PropertyPaths and used PropertyPath methods instead.

Related issues:
DATACMNS-1204
DATACMSN-1199
2017-11-01 10:27:05 -05:00
Jens Schauder
eeafc04fde DATAJDBC-146 - Excluding id when provided as additional parameter.
If the id of an entity is provided as an additional parameter, i.e. the foreign key to an entity is the primary key, no id column is generated in the insert since it gets generated for the additional parameter.
2017-11-01 10:04:06 -05:00
Jens Schauder
2fbb3b00c7 DATAJDBC-136 - Fix ClassNotFoundException when MyBatis is not on the classpath. 2017-10-27 12:13:51 -05:00
Jens Schauder
1ae44c0006 DATAJDBC-131 - Polishing after review.
Put generics back in and added @SupressWarnings where this caused warnings.
Extracted the test “isMap” into a “isQualified” method on the property.
2017-10-27 10:30:59 -05:00
Jens Schauder
b385f7f24f DATAJDBC-131 - Basic support for Maps
Aggregate roots with properties of type java.util.Map get properly inserted, updated and deleted.

Known limitations:
- Naming strategy does not allow for multiple references via Set, Map or directly to the same entity.
- The table for the referenced Entity contains the column for the map key.
    A workaround for that would be to manipulate the DbActions in the AggregateChange yourself.
2017-10-27 10:30:54 -05:00
Jens Schauder
482f330f02 DATAJDBC-144 - Using correct column names from NamingStrategy.
The list of columns used in the SqlGenerator contained property names instead of column names, leading to errors when a non-trivial NamingStrategy was used.
2017-10-27 10:17:03 -05:00
Jens Schauder
20ecbcb151 DATAJDBC-123 - Polishing.
Incorporating review comments.

Code formatting.
Improved comments.
Better method name.
Converted initialiser to before method.
2017-09-19 11:13:55 -05:00
Jens Schauder
806bb24ff5 DATAJDBC-123 - MyBatis integration on DbAction level.
If MyBatis-spring is available and a SqlSessionFactory in the Application Context we look for matching mapped sql statements instead of using the default generated SQL.

Introduced DataAccessStrategy as a new abstraction level, operating on a single entity. JdbcEntityOperations only contain operations related to complete Aggregates. Thereby also solving DATAJDBC-132.

Integration tests ending in HsqlIntegrationTest will only get executed using HsqlDb.

Related issue: DATAJDBC-132.
2017-09-19 11:13:42 -05:00
Jens Schauder
fd2ae05795 DATAJDBC-113 - Polishing.
Applied changes from review.
Removed superfluous @ConstructorProperties annotations.
Fixed formatting.
Improved usage of generics.
2017-09-13 09:33:29 -05:00
Jens Schauder
9b7b1267bb DATAJDBC-113 - Added support for Set-valued references.
When loading the referenced entities get loaded by a separate select statement.
Changes to a collection get handled just like 1-1 relationships by deleting all and reinserting them again.

Introduced a separate method in JdbcPersistentProperty instead of just unsing the table name, although it currently still is the table name.

Now providing SqlTypes in SqlParameterSource, since MySql has a problem with null parameters when it doesn't know the type.

Fixed an error where a SQL-statement generated by the SqlGenerator was obviously wrong.
2017-09-13 09:33:13 -05:00
Jens Schauder
2067fb6952 DATAJDBC-124 - findById now returns Optional.empty when no data is found.
The uderlying JdbcEntityTemplate still throws exceptions coming from the NamedParameterJdbcTemplate.
2017-08-15 09:28:27 -05:00
Jens Schauder
1f2dc16d05 DATAJDBC-120 - Changed events to support manipulation of DbChange.
This change enables the manipulation of the DbChange instance before it gets interpreted and turned into SQL statements.

Only for Aggregate Roots events get fired, since these are the abstraction the repositories work on.
Insert and Update events got removed, since this distinction doesn't exist on the Aggregate Root level.
It only exists on the level of entities and/or tables which is represented by DbActions.

Improved some tests to properly check all the events triggered.
2017-08-15 09:20:55 -05:00
Jens Schauder
fe5ae93fd0 DATAJDBC-107 - Polishing.
Code formatting.
Added @author tag.
Tiny code simplifications.
2017-08-14 09:15:16 +02:00
Greg Turnquist
f7bff01d3e DATAJDBC-107 - Implement naming strategy.
Created NamingStrategy and a default implementation that replicates the current solution. Several unit tests illustrates how to override the default and plugin a custom solution including a ThreadLocal, contextual one that could be user-based if, for example, Spring Security's SecurityContextHolder was used.
2017-08-14 09:14:15 +02:00
Jens Schauder
36daba0f42 DATAJDBC-119 - Fix broken tests with other databases.
Fixed sql scripts for the various databases.

Postgres doesn't handle BigInts properly when just past to setObject. It needs special SqlType information.

Postgres can only handle BigInts up to Long.MAX_VALUE.

MySql stores dates only with seconds precision.
2017-08-08 09:46:12 -05:00
Jens Schauder
c55dd9e177 DATAJDBC-112 - Processing feedback from review.
Code formatting. Removed few superfluous lines of code.

Renamed JdbcInterpreter to DefaultJdbcInterpreter.
The prefix Jdbc doesn't really carry much information in the SD JDBC project.

Renamed jdbcConverter fields to jdbcEntityWriter in order to match the type names.

Renamed DbChange to AggregateChange.
It isn't really about the database but about the aggregate.
2017-08-07 14:04:48 -05:00
Jens Schauder
fec4f99257 DATAJDBC-112 - Allow aggregate roots to refer to other entities.
Aggregate roots that reference other entities get correctly stored, updated and loaded.
In order to keep this a simple as possible, referenced entities get deleted and recreated on each update.
While this is inefficient it gets the job done and makes sense if we assume referenced entities are owned by that aggregate root.
References to other aggregate root could be implemented by using just the id. With the event mechanism one could even inject repositories into the entities, so they could provide getters to the actual referenced aggregate root.

The process of storing an entity now works as follows:

The request to store an entity is converted into a DbChange object containing a list of DbActions. Each DbAction represents a single change made to the data base, I.e. an insert, update or delete statement.

This DbChange then gets interpreted by the interpreter to actually create sql statements and execute them.

This should allow various customizations in the future and for users:

- We could read the DbActions from the aggregate root itself, if it implements a given interface
- A user can modify the way DbActions get created for a requested change. Either by replacing the Jdbc[Delete]EntityWriter that performs this conversion or by modifying the DbChange in an event handler.
- By changing the interpreter actually performing the actions one could change completely the sql used for the actions.

Since we currently only do one-to-one relationships selects are simply joins.

In order to encapsulate the construction of select statements from entities the SelectBuilder got introduced.
Also SqlGenerators and the generated sql is properly cached, if it does not depend on additional information.

This commit also contains necessary changes due to DATACMNS-1101.

Related issues:
DATACMNS-1101
DATAJDBC-115
2017-08-07 14:04:07 -05:00
Jens Schauder
dda4223341 DATAJDBC-104 - Introducing conversions for storing properties.
All properties get passed through a conversion step to convert them to types that can be passed to JDBC drivers.

Conversions happen in the newly introduced JdbcEnitityTemplate. It contains most of the code formerly found in the SimpleJdbcRepository.
2017-08-07 14:03:07 -05:00
Jens Schauder
323a56c156 DATAJDBC-115 - Adapt to changes in Spring Commons API.
Original pull request: #8.
2017-07-13 16:50:44 +02:00