Commit Graph

34 Commits

Author SHA1 Message Date
Simon Baslé
6d747e97f5 DATACOUCH-180 - Allow named parameters in inline N1QL queries
Choice of placeholder "mode" is determined by the syntax used inside the query, early during repository instantiation.

An IllegalArgumentException is thrown if both named and positional parameters are used.
2016-02-02 15:23:53 +01:00
Simon Baslé
524e8202f6 DATACOUCH-196 - Fix ViewIndexed generated map and improve usability
The generated view's default map function now emits meta.id so that CRUD findAll(ids) works.

The default value for the view name is now "all".

The ViewIndexed isn't documented as applicable to METHODs (deferred feature).
2016-01-29 17:20:57 +01:00
Simon Baslé
8f5e9e3df8 DATACOUCH-187 - Allow counting queries and single projections.
This change allows simple projections to types long, boolean, String when an inline N1QL query uses an aggregation function like AVG, COUNT.

The projection's result must be a single row with a single key/value pair in the N1QL response. Only the value gets returned.
2016-01-27 12:23:16 +01:00
Simon Baslé
6876e179f3 DATACOUCH-190 - Document SpEL support example. 2016-01-18 18:30:59 +01:00
Simon Baslé
15d0d27d71 DATACOUCH-189 - Test and document how to change repo implementation
Added an integration test for custom method customization.
Moved the integration test for base class customization.
Put the samples in the documentation in a new "Changing Repository Behaviour" section.
2016-01-18 18:29:03 +01:00
Simon Baslé
a1955a0af5 DATACOUCH-184 - Fix support for defining repository base class
This fixes the fact that EnableCouchbaseRepository(repositoryBaseClass = Something.class) was ignored.

Now using reflection to choose the target implementation. Note that custom base classes MUST extend SimpleCouchbaseRepository (or its subclass N1qlCouchbaseRepository).

An example in the form of an integration test has been added in src/integration/java/org/springframework/data/couchbase/repository/base/RepositoryBaseTest.java.
2016-01-07 18:16:14 +01:00
Simon Baslé
aa3f9c380b DATACOUCH-176 - Geo false positive autoelimination
So far with geo queries a bounding box approximation was performed on Circle and Polygon queries (since Couchbase internally only supports Bounding Box queries).

It was confusing since in previous iteration it was up to the user to remove these false positives "after the fact" in code calling the repository.

This change allows for the framework to retain enough information to perform false positives elimination automatically and transparently for the user.
2015-12-01 11:02:08 +01:00
Simon Baslé
b78ed124ec DATACOUCH-173 - Add cleanup on some integration tests 2015-11-16 16:34:57 +01:00
Simon Baslé
2378e7145b DATACOUCH-166 - Improve SpEL support, prefix is now #{ 2015-11-16 14:15:50 +01:00
Simon Baslé
2f68740247 DATACOUCH-161 - Improve multitemplate mapping configuration
The configuration step made it look like a new mapping was necessary in overrides, whereas it is actually possible and clearer to mutate the base mapping.

Added a convenience method to get the MappingContext from the repository mapping.
2015-11-16 14:08:33 +01:00
Simon Baslé
95ea97244a DATACOUCH-172 - Fix PagingAndSorting consistency
Default consistency from template wasn't used in PagingAndSorting findAll methods.
2015-11-16 14:02:36 +01:00
Simon Baslé
40d131aab0 DATACOUCH-169 - Automatic index creation
Main indexes (ie indexes that can be used by repositories to retrieve ALL the documents of a particular entity type) are covered.

Repository interfaces can be annotated with an annotation for each type of main index that can be automatically created.

The IndexManager is responsible for creating said indexes (potentially skipping creation if an index is already in place, or if the IndexManager has been configured to skip it, see constructor).
Since IndexManager is created as a bean (either in JavaConfig or xml), there can be a different instance eg. in Prod vs Dev.

Added doc and integration test.

Renamed package core.view to core.query since it now contains various non-view related annotations and classes.
2015-11-16 13:57:38 +01:00
Simon Baslé
8ed7d7e336 DATACOUCH-174 - Fix declaration of repositories in xml 2015-11-16 10:02:33 +01:00
Simon Baslé
58d98c5f28 DATACOUCH-168 - Support and document all reduce functions
Detection whether or not reduce should be activated is now centralized. Triggers are:
  - using the count prefix instead of find in method name
  - setting reduce = true in the View annotation explicitly.

The reduce can thus be returning any kind of value (added an integration example with _stats), which is now properly documented.
2015-10-20 18:15:55 +02:00
Simon Baslé
ec129e86a8 DATACOUCH-166 - Add basic SpEL support
Added the step of parsing SpEL expressions delimited by ${ } in StringN1qlBasedQuery, then the actual evaluation of each expression.

Refactored StringN1qlBasedQuery to use SpEL across the board, including for N1QL specific placeholders (SELECT-FROM, WHERE filter, etc...).

Refactored StringN1qlBasedQuery to use local methods rather than static methods, and amended the unit tests accordingly (using mocks).

Refactored getStatement and getCountStatement so they can see the parameters passed in at runtime.

Added unit tests + integration test.

Added SpEL support example in documentation.
2015-10-20 18:06:50 +02:00
Simon Baslé
6294b03f46 DATACOUCH-165 - Fix geo integration test (bad merge multiBucket) 2015-10-16 16:53:08 +02:00
Simon Baslé
a2f26f4310 DATACOUCH-165 - Add geospatial support
Add support for geo queries through the use of Spatial Views. This needs the query method to be annotated with @Dimensional (or a meta-annotation of it that is runtime retained).

See SpatialViewQueryCreator javadoc for supported part types and corresponding expected arguments (to be documented).
In a nutshell WITHIN Box (other shapes supported but approximated to bounding box), NEAR Point+Distance (approximated to bounding box), plus a few simple operators for dimensions beyond 2.

When approximating, a DEBUG log is made along the logging of the query.

Conversion methods from Shapes to bounding boxes are done in a GeoUtils class.

Unit and Integration test of the feature.

Added documentation for @Dimensional query derivation.
2015-10-14 15:26:22 +02:00
Simon Baslé
2914f57897 DATACOUCH-161 - Allow repositories to use different templates
Added a configuration bean that allows to express what CouchbaseOperations each repository should use, individually or by domain type.

Added documentation for the feature in repository section.
2015-10-14 15:22:54 +02:00
Simon Baslé
7654af7608 DATACOUCH-164 - Use stable Couchbase SDK
Make modifications due to name changing in 2.2.0, the latest stable release of the Couchbase SDK.
2015-09-21 16:46:51 +02:00
Simon Baslé
56ae8217e9 DATACOUCH-138 - Add Page/Slice/PagingAndSortingRepo
Add support for Page / Slice in N1QL query derived methods.
Add PagingAndSortingRepository support through a N1qlCouchbaseRepository implementation. It will only be used as a base if N1QL is actually available on the cluster.

Refactor out some steps of entity related query creation in a N1qlUtils class, so that they can be also done eg. in repository base classes.

Add tests for both N1qlUtils and the N1qlCouchbaseRepository.

Document that PagingAndSortingRepository is supported provided N1QL is available on the Couchbase cluster.
2015-09-21 15:17:53 +02:00
Simon Baslé
ef4a79efff DATACOUCH-163 - Fix integration test relative to typeKey 2015-09-16 17:20:10 -04:00
Simon Baslé
89e56d6342 DATACOUCH-159 - Improved performance of decoding of longs.
Original pull requests: #67.
Cherry-pick of e5bed8e, adapted with polishing from 6fec488.
2015-08-31 19:04:01 +02:00
Simon Baslé
f57a03ad21 DATACOUCH-156 - Make generated N1QL queries filter on the type field.
The generated N1QL queries currently don't filter on the type at all.

Add a criteria to the WHERE clause that checks the field holding type information is matching the entity fully qualified class name.

Add a placeholder for inline N1QL queries that can be replaced by the same type information criteria.
2015-07-31 18:58:00 +02:00
Simon Baslé
60196095a6 DATACOUCH-155 - Correctly escape property path.
Additionally to resolving a POJO attribute to JSON field name, the path conversion step will also escape each part of the doted path, in order to avoid problems with N1QL keywords.
2015-07-31 17:59:18 +02:00
Simon Baslé
f543e2b037 DATACOUCH-148 - Allow to configure repository queries consistency globally.
The consistency to apply on generated view queries (Stale) and N1QL queries (ScanConsistency) can now be chosen via the configuration, through a more abstract Consistency enumeration.

It is accessed from the CouchbaseOperations interface but is used in the repository only. In xml, the consistency attribute is on the couchbase:template element (string value of the enum to be passed in).

Documentation has been amended to describe this feature.
2015-07-30 11:21:02 +02:00
Simon Baslé
5114ddb867 DATACOUCH-145 - Use Id/Field annotations from Couchbase SDK
The @Field annotation has been removed in favor of the one from the Couchbase SDK.

Similarly, CouchbasePersistentEntity now recognize the SDK's @Id annotation. Note that if both Spring Data and Couchbase @Id are present (on two distinct fields), the one from Spring Data will be taken into account.
2015-07-20 17:12:05 +02:00
Simon Baslé
712bc66006 DATACOUCH-144 - Detect N1QL dependency and fail fast if not available.
Detect N1QL is not available at configuration time for the repositories and at runtime for the template. This throws a UnsupportedCouchbaseFeatureException.

The ClusterInfo is captured at bootstrap and used to determine if the feature is available. The xml configuration will need the ClusterInfo-related credentials to be provided explicitly.
2015-07-20 11:25:39 +02:00
Simon Baslé
e0972d57b9 DATACOUCH-140 - Use Converter to match query params and stored values.
When deriving a query, use the CouchbaseConverter to transform the parameters for fields that would be converted upon storage.

Reworked the DateConverters so that reading conversion is done from any Number (since N1QL may return longs in Double scientific notation for example).
2015-07-17 12:02:41 +02:00
Simon Baslé
4b453d4246 DATACOUCH-139 - Add limited support for @View query derivation.
@View can now trigger a basic query derivation. If viewName's explicitly
set, query derivation is attempted. Otherwise, no derivation is made but
instead the viewName is guessed by using the method name and removing a
"find" or "count" prefix.

Methods prefixed with "count" (and in general detected as count
projections) will trigger a reduce on the view.
2015-07-16 09:19:06 +02:00
Simon Baslé
4920acc214 DATACOUCH-141 - Change query lookup order and make N1QL default.
The @N1QL annotation was changed to @Query, for discoverability and also
convey that this is now the preferred method.

Order is now view if @View present, N1ql inline if @Query present with
a Statement, N1ql query derivation if @Query without attribute or no
annotation.

@View can be without attribute in order to compute the view
and design document from method name.
2015-07-13 16:20:15 +02:00
Simon Baslé
2bf2d3e544 DATACOUCH-134 - allow changing the name of field storing type. 2015-07-13 14:55:21 +02:00
Simon Baslé
c29727595c DATACOUCH-137 - queryDerivation for N1QL annotated methods.
Abstracted the N1QL-based variants in AbstractN1qlBasedQuery. This implementation doesn't recognize QueryParams or QueryPlan anymore in the method parameters so that the method signatures are not store-dependent.

Added query derivation from PartTree to N1QL query, using N1qlQueryCreator.

Unit tested the mapping between a Part.Type and the corresponding N1QL Expression.
2015-07-10 16:40:54 +02:00
Simon Baslé
9deaf6b480 DATACOUCH-136 - Add @N1QL query annotation.
The annotation allows to execute N1QL queries that are provided inline. For ease of use, one can use the placeholder $SELECT_ENTITY$ instead of writing the SELECT and FROM clauses.

QueryParams passed in as a method parameter will be used to enrich the Query. Other parameters on the annotated method will be used as values for positional placeholders in the statement.

The template's findByN1QL now expect enough data to reconstruct the full CouchbaseDocument (including ID and CAS), the ad hoc version of it has been renamed findByN1QLProjection.
2015-07-10 14:50:34 +02:00
Simon Baslé
b9f23f3fd5 DATACOUCH-135 - Migrate to Couchbase SDK 2.0 and add N1QL find method.
Adaptation were made to use SDK 2.0:
 - Reworked the configuration approach (more parts to be configured, like Environment, Cluster and Bucket)
 - Added a new xml schema for configuration of 2.0 version
 - Adapted the template
 - Added N1QL support in the template (findByN1QL)
 - Removed the cache package
 - Adapted the repository
 - Better separated Unit Tests from Integration Tests

All integration and unit tests pass, except one (SimpleCouchbaseRepositoryTests.shouldFindCustom).

Customisation of a ViewQuery will be addressed in another ticket.
2015-07-10 14:46:30 +02:00