8000 add deduplicate · arangodb/spring-data@9ac47f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ac47f9

Browse files
add deduplicate
1 parent c2b4bc2 commit 9ac47f9

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

src/main/java/com/arangodb/springframework/annotation/PersistentIndex.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,9 @@
5353
*/
5454
boolean sparse() default false;
5555

56+
/**
57+
* If {@literal true}, then set deduplicate to index
58+
*/
59+
boolean deduplicate() default false;
60+
5661
}

src/main/java/com/arangodb/springframework/annotation/PersistentIndexed.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@
4545
*/
4646
boolean sparse() default false;
4747

48+
/**
49+
* If {@literal true}, then set deduplicate to index
50+
*/
51+
boolean deduplicate() default false;
52+
4853
}

src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,19 @@ private static void ensureSkiplistIndex(final CollectionOperations collection,
245245

246246
private static void ensurePersistentIndex(final CollectionOperations collection, final PersistentIndex annotation) {
247247
collection.ensurePersistentIndex(Arrays.asList(annotation.fields()),
248-
new PersistentIndexOptions().unique(annotation.unique()).sparse(annotation.sparse()));
248+
new PersistentIndexOptions()
249+
.unique(annotation.unique())
250+
.sparse(annotation.sparse())
251+
.deduplicate(annotation.deduplicate()));
249252
}
250253

251254
private static void ensurePersistentIndex(final CollectionOperations collection,
252255
final ArangoPersistentProperty value) {
253256
final PersistentIndexOptions options = new PersistentIndexOptions();
254-
value.getPersistentIndexed().ifPresent(i -> options.unique(i.unique()).sparse(i.sparse()));
257+
value.getPersistentIndexed().ifPresent(i -> options
258+
.unique(i.unique())
259+
.sparse(i.sparse())
260+
.deduplicate(i.deduplicate()));
255261
collection.ensurePersistentIndex(Collections.singleton(value.getFieldName()), options);
256262
}
257263

@@ -684,7 +690,8 @@ public <T> void upsert(final Iterable<T> value, final UpsertStrategy strategy) t
684690

685691
@Override
686692
public <T> void repsert(final T value) throws DataAccessException {
687-
@SuppressWarnings("unchecked") final Class<T> clazz = (Class<T>) value.getClass();
693+
@SuppressWarnings("unchecked")
694+
final Class<T> clazz = (Class<T>) value.getClass();
688695
final String collectionName = _collection(clazz).name();
689696

690697
potentiallyEmitEvent(new BeforeSaveEvent<>(value));
@@ -697,8 +704,7 @@ public <T> void repsert(final T value) throws DataAccessException {
697704
.put("@col", collectionName)
698705
.put("doc", value)
699706
.get(),
700-
clazz
701-
).first();
707+
clazz).first();
702708
} catch (final ArangoDBException e) {
703709
throw exceptionTranslator.translateExceptionIfPossible(e);
704710
}
@@ -724,8 +730,7 @@ public <T> void repsert(final Iterable<? extends T> values, final Class<T> entit
724730
.put("@col", collectionName)
725731
.put("docs", values)
726732
.get(),
727-
entityClass
728-
).asListRemaining();
733+
entityClass).asListRemaining();
729734
} catch (final ArangoDBException e) {
730735
throw translateExceptionIfPossible(e);
731736
}
@@ -743,13 +748,15 @@ private void updateDBFieldsFromObjects(final Iterable<?> values, final Iterable<
743748
}
744749

745750
private void updateDBFieldsFromObject(final Object toModify, final Object toRead) {
746-
final ArangoPersistentEntity<?> entityToRead = converter.getMappingContext().getPersistentEntity(toRead.getClass());
751+
final ArangoPersistentEntity<?> entityToRead = converter.getMappingContext()
752+
.getPersistentEntity(toRead.getClass());
747753
final PersistentPropertyAccessor<?> accessorToRead = entityToRead.getPropertyAccessor(toRead);
748754
final ArangoPersistentProperty idPropertyToRead = entityToRead.getIdProperty();
749755
final Optional<ArangoPersistentProperty> arangoIdPropertyToReadOptional = entityToRead.getArangoIdProperty();
750756
final Optional<ArangoPersistentProperty> revPropertyToReadOptional = entityToRead.getRevProperty();
751757

752-
final ArangoPersistentEntity<?> entityToModify = converter.getMappingContext().getPersistentEntity(toModify.getClass());
758+
final ArangoPersistentEntity<?> entityToModify = converter.getMappingContext()
759+
.getPersistentEntity(toModify.getClass());
753760
final PersistentPropertyAccessor<?> accessorToWrite = entityToModify.getPropertyAccessor(toModify);
754761
final ArangoPersistentProperty idPropertyToWrite = entityToModify.getIdProperty();
755762

@@ -760,7 +767,8 @@ private void updateDBFieldsFromObject(final Object toModify, final Object toRead
760767
if (arangoIdPropertyToReadOptional.isPresent()) {
761768
ArangoPersistentProperty arangoIdPropertyToRead = arangoIdPropertyToReadOptional.get();
762769
entityToModify.getArangoIdProperty().filter(arangoId -> !arangoId.isImmutable())
763-
.ifPresent(arangoId -> accessorToWrite.setProperty(arangoId, accessorToRead.getProperty(arangoIdPropertyToRead)));
770+
.ifPresent(arangoId -> accessorToWrite.setProperty(arangoId,
771+
accessorToRead.getProperty(arangoIdPropertyToRead)));
764772
}
765773

766774
if (revPropertyToReadOptional.isPresent()) {

0 commit comments

Comments
 (0)
0