From e4d37f0aa65ce66f62c7967212651ee849375820 Mon Sep 17 00:00:00 2001 From: Mert Z Date: Tue, 23 Jan 2018 21:22:05 +0300 Subject: [PATCH] DATAKV-206 - Support for custom identifier generators. Original pull request: #29. --- .../data/keyvalue/core/KeyValueTemplate.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/org/springframework/data/keyvalue/core/KeyValueTemplate.java b/src/main/java/org/springframework/data/keyvalue/core/KeyValueTemplate.java index 800c548..f0bc152 100644 --- a/src/main/java/org/springframework/data/keyvalue/core/KeyValueTemplate.java +++ b/src/main/java/org/springframework/data/keyvalue/core/KeyValueTemplate.java @@ -46,6 +46,7 @@ import org.springframework.util.CollectionUtils; * @author Oliver Gierke * @author Thomas Darimont * @author Mark Paluch + * @author Mert Zeybekler */ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPublisherAware { @@ -88,6 +89,26 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub this.identifierGenerator = DefaultIdentifierGenerator.INSTANCE; } + /** + * Create new {@link KeyValueTemplate} using the given {@link KeyValueAdapter} and {@link MappingContext}. + * + * @param adapter must not be {@literal null}. + * @param mappingContext must not be {@literal null}. + * @param identifierGenerator must not be {@literal null}. + */ + public KeyValueTemplate(KeyValueAdapter adapter, + MappingContext, ? extends KeyValuePersistentProperty> mappingContext, + IdentifierGenerator identifierGenerator) { + + Assert.notNull(adapter, "Adapter must not be null!"); + Assert.notNull(mappingContext, "MappingContext must not be null!"); + Assert.notNull(identifierGenerator, "IdentifierGenerator must not be null!"); + + this.adapter = adapter; + this.mappingContext = mappingContext; + this.identifierGenerator = identifierGenerator; + } + /** * Set the {@link PersistenceExceptionTranslator} used for converting {@link RuntimeException}. *