From 49f08970cf096d5ae43a457087bfbb50c4143f59 Mon Sep 17 00:00:00 2001 From: Kazuki Shimizu Date: Fri, 13 Apr 2018 23:23:41 +0900 Subject: [PATCH 1/4] DATAJDBC-182 - Add explanation for modifying query on README --- README.adoc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.adoc b/README.adoc index cbddaccba5..faedfefa60 100644 --- a/README.adoc +++ b/README.adoc @@ -152,6 +152,19 @@ When determining the `RowMapper` to use for a method the following steps are fol If applicable, wrapper types like collections or `Optional` are unwrapped. Thus, a return type of `Optional` will use the type `Person` in the steps above. +==== Modifying query + +You can mark as a modifying query using the `@Modifying` on query method. + +[source,java] +---- +@Modifying +@Query("UPDATE DUMMYENTITY SET name = :name WHERE id = :id") +boolean updateName(@Param("id") Long id, @Param("name") String name); +---- + +The return types that can be specified are `void`, `int`(updated record count) and `boolean`(whether record was updated). + === Id generation Spring Data JDBC uses the id to identify entities, but also to determine if an entity is new or already existing in the database. From d41cb91f85d93a73a74541a4f4edac27cd921737 Mon Sep 17 00:00:00 2001 From: Kazuki Shimizu Date: Fri, 13 Apr 2018 23:44:11 +0900 Subject: [PATCH 2/4] DATAJDBC-184 - Add explanation for DelimiterNamingStrategy on README --- README.adoc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.adoc b/README.adoc index faedfefa60..fd5b9f551c 100644 --- a/README.adoc +++ b/README.adoc @@ -184,6 +184,15 @@ If you are not using autoincrement-columns, you can use a `BeforeSave`-listener If you use the standard implementations of `CrudRepository` as provided by Spring Data JDBC, it will expect a certain table structure. You can tweak that by providing a https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/model/NamingStrategy.java[`NamingStrategy`] in your application context. +.Optional classes of NamingStrategy +|=== +| Class | Description + +| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/model/DelimiterNamingStrategy.java[`DelimiterNamingStrategy`] +| The delimiter character implementation of NamingStrategy. The default delimiter is `_`(underscore), resulting in snake case. This class does not used by default. +|=== + + === Events Spring Data JDBC triggers events which will get published to any matching `ApplicationListener` in the application context. From f9dadacceb90c43f869bfb23e412654c2a514023 Mon Sep 17 00:00:00 2001 From: Kazuki Shimizu Date: Fri, 13 Apr 2018 23:58:24 +0900 Subject: [PATCH 3/4] DATAJDBC-178 - Add explanation for NamespaceStrategy on README --- README.adoc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index fd5b9f551c..9c0f41d436 100644 --- a/README.adoc +++ b/README.adoc @@ -243,7 +243,7 @@ For each operation in `CrudRepository` Spring Data JDBC will execute multiple st If there is a https://github.com/mybatis/mybatis-3/blob/master/src/main/java/org/apache/ibatis/session/SqlSessionFactory.java[`SqlSessionFactory`] in the application context, it will be checked if it offers a statement for each step. If one is found, that statement will be used (including its configured mapping to an entity). -The name of the statement is constructed by concatenating the fully qualified name of the entity type with `Mapper.` and a string determining the kind of statement. +By default, the name of the statement is constructed by concatenating the fully qualified name of the entity type with `Mapper.` and a string determining the kind of statement. E.g. if an instance of `org.example.User` is to be inserted, Spring Data JDBC will look for a statement named `org.example.UserMapper.insert`. Upon execution of the statement an instance of [`MyBatisContext`] will get passed as an argument which makes various arguments available to the statement. @@ -315,6 +315,10 @@ Note that the type used for prefixing the statement name is the name of the aggr `getDomainType` the type of aggregate roots to count. |=== +==== NamespaceStrategy + +You can customize the namespace part of a statement name using https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mybatis/NamespaceStrategy.java[`NamespaceStrategy`]. + == Features planned for the not too distant future === Advanced query annotation support From d8ca69128a677b309796377a9f25b8749d867ba4 Mon Sep 17 00:00:00 2001 From: Kazuki Shimizu Date: Sat, 14 Apr 2018 03:03:07 +0900 Subject: [PATCH 4/4] Polishing --- README.adoc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/README.adoc b/README.adoc index 9c0f41d436..3148e0d74a 100644 --- a/README.adoc +++ b/README.adoc @@ -131,12 +131,12 @@ You can configure the `RowMapper` to use, using either the `@Query(rowMapperClas [source,java] ---- - @Bean - RowMapperMap rowMappers() { - return new ConfigurableRowMapperMap() // - .register(Person.class, new PersonRowMapper()) // - .register(Address.class, new AddressRowMapper()); - } +@Bean +RowMapperMap rowMappers() { + return new ConfigurableRowMapperMap() // + .register(Person.class, new PersonRowMapper()) // + .register(Address.class, new AddressRowMapper()); +} ---- @@ -189,7 +189,7 @@ You can tweak that by providing a https://github.com/spring-projects/spring-data | Class | Description | https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/model/DelimiterNamingStrategy.java[`DelimiterNamingStrategy`] -| The delimiter character implementation of NamingStrategy. The default delimiter is `_`(underscore), resulting in snake case. This class does not used by default. +| The delimiter character implementation of NamingStrategy. The default delimiter is `_`(underscore), resulting in snake case. |=== @@ -323,9 +323,7 @@ You can customize the namespace part of a statement name using https://github.co === Advanced query annotation support -* customizable `RowMapper` * projections -* modifying queries * SpEL expressions === MyBatis per method support