Commit Graph

107 Commits

Author SHA1 Message Date
Geoffrey Mina
7a57a235d8 DATACOUCH-226 - Enable strict @Field mapping
If the MappingCouchbaseConverter strict mode is enabled and no annotation is present, the property will not be eligible for document mapping.

This allows to specifically ignore some attributes in Couchbase only. For generally ignoring attributes in any Spring Data backing store, prefer the standard `@Transient`.

Closes #112
2016-05-20 17:52:41 +02:00
Anastasiia Smirnova
811c024041 DATACOUCH-224 - Improve concurrent save/insert, optimistic locking 2016-05-10 15:48:34 +02:00
Jonathan Edwards
117f0d0968 DATACOUCH 225 - Minimal SDK 2.2.6 support 2016-05-09 09:31:23 -06:00
Mark Paluch
db4c24d9f1 DATACOUCH-203 - Use Set to store qualifiers in CDI extension.
Qualifiers are now stored in their original set instead of using the toString representation.
2016-03-15 14:13:14 +01:00
Simon Baslé
4aa823722a DATACOUCH-212 - Take Version/CAS into account on save
This change takes the `Version` annotated field into account when performing a `save` (either in the `CouchbaseTemplate` or transitively in a `CouchbaseRepository`).

Having such a field with a non-zero value means that a CAS is available, activating optimistic locking. Version 1.4 and below of Spring Data Couchbase was taking this CAS into account, whereas in 2.0 we switched to using `upsert` internally, which ignores the CAS.

This change brings the behavior of `save` (when there's a non-zero CAS) closer to what was observed in 1.4 versions: an `OptimisticLockingFailureException` can now be raised in case of CAS mismatch.
2016-03-14 20:00:16 +01:00
Simon Baslé
39fb52d2a6 DATACOUCH-91 - Support auditing (via java config)
This commit adds support for auditing via the use of the four annotations (CreatedBy, LastModifiedBy, CreationDate, LastModificationDate), enabled via the EnableCouchbaseAuditing annotation.

As couchbase entities MUST have an id, the only case where the creation event can be detected is when the entity has a Version annotated field.
2016-03-11 15:35:35 +01:00
Simon Baslé
dea461458b DATACOUCH-215 - Separate SDK/SDC beans in javaconfig
This commit allows to separate creation of beans dedicated to Spring Data Couchbase from the ones that can be made more common (SDK instances) and now can be provided externally through a a strategy interface, `CouchbaseConfigurer`.

Rather than having to extend a few methods from the base Configuration
class, `CouchbaseConfigurer` represents all the components that the Spring Data integration requires.
2016-03-11 10:58:38 +01:00
James Thomson
8357122950 DATACOUCH-211 - Applying sort that's passed in via the Pagenate object in call to N1qlCouchbaseRepository::findAll 2016-03-10 21:31:23 +00:00
James Thomson
0149144bc0 DATACOUCH-214 - Adding case insensitive sorting
Closes #105
2016-03-10 22:10:47 +01:00
Simon Baslé
ee58b4d6e4 DATACOUCH-216 - Add template getter on repository interface 2016-03-10 12:13:55 +01:00
Simon Baslé
67373e501e DATACOUCH-204 - Add package-info on all packages 2016-02-23 16:25:07 +01:00
Andrzej Wisłowski
40e4212ad7 DATACOUCH-59 - Allow expiry touch on read
Configuration is based on Document annotation. When read of document takes place then touch action is executed on document. It is an asynchronous action so it does not block read. It is executed only on single reads (not view-based or N1QL-based ones).
2016-02-23 14:51:27 +01:00
Simon Baslé
338eb38f46 DATACOUCH-207 - Makes all BeanNames constants public 2016-02-22 16:00:01 +01:00
Simon Baslé
2f251e0ba9 DATACOUCH-209 - Change default Consistency to READ_YOUR_OWN_WRITES
Formerly UPDATE_AFTER, but the inconsistent view this would give eg. while writing tests or exploring Spring Data Couchbase was confusing to users.
2016-02-22 15:42:40 +01:00
Oliver Gierke
cdf94f45c5 DATACOUCH-202 - Adapted to new API in QueryMethod and QueryLookupStrategy. 2016-02-08 17:10:13 +01:00
Simon Baslé
0095313342 DATACOUCH-199 - Make automatic index creation opt-in
In addition to annotating the repository with xxxIndexed annotations, user must now opt-in to the feature by redefining the indexManager bean in the configuration. This is so production use of this feature is actively discouraged.
2016-02-05 18:08:05 +01:00
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é
933ff0feaa DATACOUCH-192 - Prefix all bean names with "couchbase" 2016-01-27 15:38:14 +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é
c589a13699 DATACOUCH-186 - Index-backed methods safe from deleted stales
This commit ensures that methods in the template and the repository base classes are correctly ignoring documents that have been deleted but are still identified by the view due to using weak consistency (Stale.TRUE).

FindByView in template now ignores null rows in its result list. It also correctly forces the includeDocs parameter in order not to risk a bad transcoding of the document (javadoc clarified).

DeleteAll in the repository CRUD implementation will correctly detect attempts at deleting a non-existing document (DocumentDoesNotExistException is also correctly mapped to a Spring Data exception now).

DeleteAll behavior with DataRetrievalFailureException is tested in RepositoryIndexUsageTest.
2016-01-18 18:24:50 +01:00
Simon Baslé
d81dc9aacc DATACOUCH-185 - view-based CRUD methods use default consistency
The CRUD methods that are backed by a view in SimpleCouchbaseRepository now take the default view consistency into account.
This includes findAll(), findAll(keys), count() and deleteAll().

PagingAndSortingRepository findAll methods already took the default N1QL consistency into account.

This is verified in an unit test and has been made more explicit in the repository documentation.
2016-01-08 16:21:20 +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é
cbe77e5fd4 DATACOUCH-177 - Upgrade SDK dependency to 2.2.2 2015-12-01 11:19:41 +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é
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é
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é
5beeaff9af DATACOUCH-170 - Fix N1QL annotation and inline querying in docs
In some places in the doc (javadoc, README, asciidoc), the annotation was still referred to as N1QL instead of Query...

Improved doc on inline statement for N1QL queries allowing the use of positional `$1` placeholders.
2015-10-15 17:28:37 +02:00
Simon Baslé
c6aa84ced4 DATACOUCH-165 - Add utilities to remove geo false positives
PointInShapeEvaluator can be used to check answers and remove false positives from answers that have been approximated (circle and polygon).

One implementations are provided, based on awt.

Hinted at the existence of the PointInShapeEvaluator in the message that warns about bounding box approximations.

Added mention of the AwtPointInShapeEvaluator in the asciidoc with code sample.
2015-10-14 16:49:51 +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é
e4b103cdfa DATACOUCH-158 - Allow more explicit expiry unit
The Document annotation now also support explicitly giving a TimeUnit for the expiry, ensuring the framework will correctly convert that to the expected Couchbase format.
2015-10-14 10:43:01 +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é
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é
2035a88dba DATACOUCH-154 - Guess design doc as uncapitalized class name.
In the SimpleCouchbaseRepository the guessed design document was lowercase of the entity class, whereas in ViewBasedCouchbaseQuery it is uncapitalized (only first letter is lowercase).

This has been made consistent, using the uncapitalize method. The doc now reflects that and explicitly have examples with camel case classes (UserInfo instead of User).
2015-07-30 17:44:53 +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é
508f190270 DATACOUCH-152 - Bump SDK to 2.2.0-dp2 and fix related TODOs.
ParametrizedQuery is now ParameterizedQuery, a few parameters have been added to the environment parsing, made use of N1QL Functions where newly available.
2015-07-27 13:22:05 +02:00
Simon Baslé
96e4b7ed37 DATACOUCH-149 - Switched to PersistentPropertyAccessor API.
Replaces all references to BeanWrapper with usage of PersistentPropertyAccessor API. MappingCouchbaseEntityInformation now extends PersistentEntityInformation to get rid of obsolete code implemented by the superclass.
2015-07-23 11:52:00 +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é
93405c5da8 DATACOUCH-142 - Update documentation and provide migration cheatsheet.
The documentation has been updated to reflect the changes in the new Spring Data Couchbase 2.0.

A simple list of major changes to take into account when migrating from 1.x to 2.x has been added.

README.md has also been updated.
2015-07-20 10:44:41 +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é
4f0ba9d215 DATACOUCH-143 - Log executed queries in DEBUG. 2015-07-16 16:48:45 +02:00