[ 
https://issues.apache.org/jira/browse/IGNITE-13005?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17148053#comment-17148053
 ] 

Manuel Núñez commented on IGNITE-13005:
---------------------------------------

[~ilyak] and sorry for the delay ... too many things on the tray

> Spring Data 2 - "JPA style" and working with multiple Ignite instances on 
> same JVM
> ----------------------------------------------------------------------------------
>
>                 Key: IGNITE-13005
>                 URL: https://issues.apache.org/jira/browse/IGNITE-13005
>             Project: Ignite
>          Issue Type: Improvement
>          Components: spring
>    Affects Versions: 2.7.6, 2.8.1
>            Reporter: Manuel Núñez
>            Assignee: Manuel Núñez
>            Priority: Major
>              Labels: spring-data
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> I have it working for Spring Data 2 (2.7.6, 2.8.1) module with some 
> interesting improvements.
> Code is 100% compatible with previous versions. 
> [https://github.com/hawkore/ignite-hk/tree/master/modules/spring-data-2.0]
>  * Supports multiple ignite instances on same JVM (@RepositoryConfig).
>  * Supports query tuning parameters in {{@Query}} annotation
>  * Supports projections
>  * Supports {{Page}} and {{Stream}} responses
>  * Supports Sql Fields Query resultset transformation into the domain entity
>  * Supports named parameters ({{:myParam}}) into SQL queries, declared using 
> {{@Param("myParam")}}
>  * Supports advanced parameter binding and SpEL expressions into SQL queries:
>  ** *Template variables*:
>  *** {{#entityName}} - the simple class name of the domain entity
>  ** *Method parameter expressions*: Parameters are exposed for indexed access 
> ({{[0]}} is the first query method's param) or via the name declared using 
> {{@Param}}. The actual SpEL expression binding is triggered by {{?#}}. 
> Example: {{?#\{[0]\}} or {{?#\{#myParamName\}}}
>  ** *Advanced SpEL expressions*: While advanced parameter binding is a very 
> useful feature, the real power of SpEL stems from the fact, that the 
> expressions can refer to framework abstractions or other application 
> components through SpEL EvaluationContext extension model.
>  * Supports SpEL expressions into Text queries ({{TextQuery}}). 
> Some examples:
> {code:java}
> // Spring Data Repositories using different ignite instances on same JVM
> @RepositoryConfig(igniteInstance = "FLIGHTS_BBDD", cacheName = "ROUTES")
> public interface FlightRouteRepository extends IgniteRepository<Route, 
> String> {
> ...
> }
> @RepositoryConfig(igniteInstance = "GEO_BBDD", cacheName = "POIS")
> public interface PoiRepository extends IgniteRepository<Poi, String> {
> ...
> }
> {code}
> {code:java}
> // named parameter
> @Query(value = "SELECT * from #{#entityName} where email = :email")
> User searchUserByEmail(@Param("email") String email);
> {code}
> {code:java}
> // indexed parameters
> @Query(value = "SELECT * from #{#entityName} where country = ?#{[0] and city 
> = ?#{[1]}")
> List<User> searchUsersByCity(@Param("country") String country, @Param("city") 
> String city, Pageable pageable);
> {code}
> {code:java}
> // ordered method parameters
> @Query(value = "SELECT * from #{#entityName} where email = ?")
> User searchUserByEmail(String email);
> {code}
> {code:java}
> // Advanced SpEL expressions
> @Query(value = "SELECT * from #{#entityName} where uuidCity = 
> ?#{mySpELFunctionsBean.cityNameToUUID(#city)}")
> List<User> searchUsersByCity(@Param("city") String city, Pageable pageable);
> {code}
> {code:java}
> // textQuery - evaluated SpEL named parameter
> @Query(textQuery = true, value = "email: #{#email}")
> User searchUserByEmail(@Param("email") String email);
> {code}
> {code:java}
> // textQuery - evaluated SpEL named parameter
> @Query(textQuery = true, value = "#{#textToSearch}")
> List<User> searchUsersByText(@Param("textToSearch") String text, Pageable 
> pageable);
> {code}
> {code:java}
> // textQuery - evaluated SpEL indexed parameter
> @Query(textQuery = true, value = "#{[0]}")
> List<User> searchUsersByText(String textToSearch, Pageable pageable);
> {code}
> {code:java}
> // Static Projection
> @Query(value =
>                "SELECT DISTINCT m.id, m.name, m.logos FROM #{#entityName} e 
> USE INDEX (ORIGIN_IDX) INNER JOIN \"flightMerchants\".Merchant m ON m"
>                    + "._key=e"
>                    + ".merchant WHERE e.origin = :origin and e.disabled = 
> :disabled GROUP BY m.id, m.name, m.logos ORDER BY m.name")
> List<AProjection> searchMerchantsByOrigin(@Param("origin") String origin, 
> @Param("disabled") boolean disabled);
> {code}
> {code:java}
> // Dynamic Projection
> @Query(value =
>                "SELECT DISTINCT m.id, m.name, m.logos FROM #{#entityName} e 
> USE INDEX (ORIGIN_IDX) INNER JOIN \"flightMerchants\".Merchant m ON m"
>                    + "._key=e"
>                    + ".merchant WHERE e.origin = :origin and e.disabled = 
> :disabled GROUP BY m.id, m.name, m.logos ORDER BY m.name")
> <P> List<P> searchMerchantsByOrigin(Class<P> projection, @Param("origin") 
> String origin, @Param("disabled") boolean disabled);
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to