Commit Graph

53 Commits

Author SHA1 Message Date
sedooe
0fe791f2bc DATAJDBC-168 - Run integration tests with testcontainers.
Added testcontainers as dependency and configured MySql and Postrgres datasources to use it.

Original pull request: #34.
2018-02-02 11:33:58 +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
Jens Schauder
ab6da6edff DATAJDBC-156 - Describe available mappings in README.
Includes the major limitations and their rational.
2018-01-26 09:26:20 -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
Jens Schauder
08691d6c45 DATAJDBC-151 - Polishing.
Removed unused code.

Moved more of the context configuration into the common TestConfiguration.
2017-11-28 15:20:35 +01: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
Greg Turnquist
0ef1a63bda DATAJDBC-154 - Polishing. 2017-11-27 11:43:13 -06:00
Jens Schauder
d5193e4418 DATAJDBC-154 - Include some basic getting started documentation in the readme. 2017-11-27 11:27:52 -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
Greg Turnquist
1291b5d33c DATAJDBC-131 - Fix unit tests driven by DATAJDBC-144 2017-10-27 10:31:05 -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
Mark Paluch
3706826739 DATAJDBC-134 - Added explicit automatic module name for JDK 9. 2017-09-21 14:17:53 +02: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
Greg Turnquist
96e3b2c681 DATAJDBC-119 - Polish 2017-08-08 09:51:19 -05: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
Greg Turnquist
b8fe3c67c0 DATAJDBC-122 - Introduce code of conduct 2017-08-08 08:48:09 +02: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
15fcf171fb DATAJDBC-114 - Adding test to prevent dependency circles.
Added a test that finds dependency circles.

Removed the dependency circles found by that test.
2017-08-07 14:04:38 -05:00
Jens Schauder
0229f89996 DATAJDBC-112 - Polishing
Updated Readme
2017-08-07 14:04:28 -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
Jens Schauder
b05886e442 DATAJDBC-100 - @EnableJdbcRepositories.
Adds the @EnableJdbcRepositories annotation, which when used on a Spring configuration enables scanning packages for JDBC repositories.

Original pull request: #6.
2017-06-20 14:49:58 +02:00
Jens Schauder
95e033c3cf DATAJDBC-99 - Adapt changes in CrudRepository.
The method names in the CrudRepository have changed.

Related issue: DATACMNS-944
Original pull request: #5.
2017-06-19 13:25:25 +02:00
Oliver Gierke
1af9146f4d DATAJDBC-99 - Polishing.
Introduced interface for JdbcPersistentEntity to be consistent with other store implementations.

Introduced JdbcPersistentEntityInformation.getRequiredId(…) to return a value and throw an exception if it can't be obtained.

Added serialVersionUIDs to event implementations. Extracted Unset and SpecifiedIdentifier into top level classes to be able to reduce visibility. Introduced Specified interface and factory methods on Identifier to be able to create Identifier instances in all ways needed (specified / optional).

Extracted JdbcEvent interface from the previously thus named class to be able to let WithId and WithEntity extend that interface to avoid the cast in the default method of WithId. WithId now simply redeclares getId returning Specified so that the guarantees of returned object type simply adapt as soon as event types also implement that interface. Reduced the visibility of SimpleJdbcEvent as listeners could now just refer to JdbcEvent. Switched to a nullable field for the entity in SimpleJdbcEvent as ApplicationEvent already implies potential serializability and Optional is not Serializable.

Reorganized integration test setup to use configuration classes over FactoryBean implementations. Switched to AssertJ for test assertions.

Renamed UnableToSetIdException to UnableToSetId. A bit of Javadoc here and there. Formatting. No abbreviated variable names.

Original pull request: #5.
2017-06-19 13:25:15 +02:00
Jens Schauder
f0eaf862cf DATAJDBC-109 - Adapt to API changes in Spring Data Commons.
Original pull request: #5.
2017-06-19 13:25:04 +02:00
Jens Schauder
1582a4d475 DATAJDBC-105 - Test with multiple databases.
Different databases are now supported by means of Maven Profiles and Spring Profiles. There is one Profile for each supported database. The default Profile is equivalent to hql. There is a Maven Profile all-dbs, which runs the integration tests against all databases.

The databases need to be started outside the build. The build assumes the default configuration as I found it after `brew install <database>`

For now we support the databases mysql, postgres and hsqldb.

In order to make the new databases work setting of properties and reading generated ids was improved to do some simple conversions. This might be considered a first step towards DATAJDBC-104.

The project root contains some basic scripts for starting and stopping databases, as well as running a build against all supported databases. Integration tests using a database now use Rules instead of JUnit runners. This gives more flexibility when adding fancy stuff to the Tests in the form of other Rules.

Related issue: DATAJDBC-104.
Original pull request: #5.
2017-06-19 13:24:52 +02:00
Jens Schauder
94d8960558 DATAJDBC-99 - Polishing.
Events now use the id as source. The id is encapsulated in a value object to support null ids in BeforeInsert events. Entity references in events are now Optionals. Dropped redundant Event suffix from events. Added "@since 2.0" to classes. Replaced constructors and getters with Lombok annotations. Simplified pom.xml. Extracted interface JdbcPersistentEntity and JdbcPersistentProperty. Integration tests use the Spring Test framework. Fixed test for entities with primitive id type.

Original pull request: #5.
2017-06-19 13:24:26 +02:00
Jens Schauder
25fa2d423e DATAJDBC-99 - Event support.
The repository publishes events before and after inserting, updating and deleting entities, as well as after instantiation of entities. JdbcEvent ist the common super class of all events and makes the id and the entity available (if possible). Added issue id comments to tests from previous issues.

Original pull request: #5.
2017-06-19 13:23:56 +02:00
Jens Schauder
1f1753e734 DATAJDBC-98 - Update implemented.
New instances get saved with an insert statement. Existing instances get updated. Also added some test to find certain corner cases that I feared may cause problems:

- ID properties being not editable (no setter and final).
- ID properties being primitive.
- ID properties not being named "id"

and fixed the issues resulting from those.

Original pull request: #5.
2017-06-19 13:23:36 +02:00
Jens Schauder
21490b8397 DATAJDBC-96 - Database based ID generation.
No longer using batch inserts, which won't (easily) hold up for long anyway, since we need to decide between update and insert anyway. If one wants to support batch insert one also has to check if any autoid columns are present, because those seem not to work with batch inserts with many or at least some drivers.

Related ticket: SPR-1836.
Original pull request: #5.
2017-06-19 13:23:15 +02:00
Jens Schauder
2181d8d3c6 DATAJDBC-97 - Basic implementation of all CRUD methods.
Original pull request: #5.
2017-06-19 13:23:03 +02:00