2020
2121package com .arangodb .springframework .core .mapping ;
2222
23- import java .lang .annotation .Annotation ;
24- import java .util .ArrayList ;
25- import java .util .Arrays ;
26- import java .util .Collection ;
27- import java .util .HashMap ;
28- import java .util .List ;
29- import java .util .Map ;
30- import java .util .Optional ;
31- import java .util .Set ;
32- import java .util .stream .Collectors ;
33-
23+ import com .arangodb .entity .CollectionType ;
24+ import com .arangodb .model .CollectionCreateOptions ;
25+ import com .arangodb .springframework .annotation .Document ;
26+ import com .arangodb .springframework .annotation .Edge ;
27+ import com .arangodb .springframework .annotation .FulltextIndex ;
28+ import com .arangodb .springframework .annotation .FulltextIndexes ;
29+ import com .arangodb .springframework .annotation .GeoIndex ;
30+ import com .arangodb .springframework .annotation .GeoIndexes ;
31+ import com .arangodb .springframework .annotation .HashIndex ;
32+ import com .arangodb .springframework .annotation .HashIndexes ;
33+ import com .arangodb .springframework .annotation .PersistentIndex ;
34+ import com .arangodb .springframework .annotation .PersistentIndexes ;
35+ import com .arangodb .springframework .annotation .SkiplistIndex ;
36+ import com .arangodb .springframework .annotation .SkiplistIndexes ;
37+ import com .arangodb .springframework .annotation .TtlIndex ;
3438import org .springframework .beans .BeansException ;
3539import org .springframework .context .ApplicationContext ;
3640import org .springframework .context .expression .BeanFactoryAccessor ;
3741import org .springframework .context .expression .BeanFactoryResolver ;
3842import org .springframework .core .annotation .AnnotatedElementUtils ;
3943import org .springframework .data .mapping .IdentifierAccessor ;
44+ import org .springframework .data .mapping .MappingException ;
4045import org .springframework .data .mapping .TargetAwareIdentifierAccessor ;
4146import org .springframework .data .mapping .model .BasicPersistentEntity ;
4247import org .springframework .data .util .TypeInformation ;
4752import org .springframework .lang .Nullable ;
4853import org .springframework .util .StringUtils ;
4954
50- import com .arangodb .entity .CollectionType ;
51- import com .arangodb .model .CollectionCreateOptions ;
52- import com .arangodb .springframework .annotation .Document ;
53- import com .arangodb .springframework .annotation .Edge ;
54- import com .arangodb .springframework .annotation .FulltextIndex ;
55- import com .arangodb .springframework .annotation .FulltextIndexes ;
56- import com .arangodb .springframework .annotation .GeoIndex ;
57- import com .arangodb .springframework .annotation .GeoIndexes ;
58- import com .arangodb .springframework .annotation .HashIndex ;
59- import com .arangodb .springframework .annotation .HashIndexes ;
60- import com .arangodb .springframework .annotation .PersistentIndex ;
61- import com .arangodb .springframework .annotation .PersistentIndexes ;
62- import com .arangodb .springframework .annotation .SkiplistIndex ;
63- import com .arangodb .springframework .annotation .SkiplistIndexes ;
55+ import java .lang .annotation .Annotation ;
56+ import java .util .ArrayList ;
57+ import java .util .Arrays ;
58+ import java .util .Collection ;
59+ import java .util .HashMap ;
60+ import java .util .List ;
61+ import java .util .Map ;
62+ import java .util .Optional ;
63+ import java .util .Set ;
64+ import java .util .stream .Collectors ;
6465
6566/**
6667 * @author Mark Vollmary
@@ -78,6 +79,7 @@ public class DefaultArangoPersistentEntity<T> extends BasicPersistentEntity<T, A
7879
7980 private ArangoPersistentProperty arangoIdProperty ;
8081 private ArangoPersistentProperty revProperty ;
82+ private ArangoPersistentProperty ttlIndexedProperty ;
8183 private final Collection <ArangoPersistentProperty > hashIndexedProperties ;
8284 private final Collection <ArangoPersistentProperty > skiplistIndexedProperties ;
8385 private final Collection <ArangoPersistentProperty > persistentIndexedProperties ;
@@ -187,11 +189,23 @@ public void setApplicationContext(final ApplicationContext applicationContext) t
187189 public void addPersistentProperty (final ArangoPersistentProperty property ) {
188190 super .addPersistentProperty (property );
189191 if (property .isArangoIdProperty ()) {
192+ if (arangoIdProperty != null ) {
193+ throw new MappingException ("Found multiple id indexed properties!" );
194+ }
190195 arangoIdProperty = property ;
191196 }
192197 if (property .isRevProperty ()) {
198+ if (revProperty != null ) {
199+ throw new MappingException ("Found multiple rev indexed properties!" );
200+ }
193201 revProperty = property ;
194202 }
203+ if (property .getTtlIndexed ().isPresent ()) {
204+ if (ttlIndexedProperty != null ) {
205+ throw new MappingException ("Found multiple ttl indexed properties!" );
206+ }
207+ ttlIndexedProperty = property ;
208+ }
195209 property .getHashIndexed ().ifPresent (i -> hashIndexedProperties .add (property ));
196210 property .getSkiplistIndexed ().ifPresent (i -> skiplistIndexedProperties .add (property ));
197211 property .getPersistentIndexed ().ifPresent (i -> persistentIndexedProperties .add (property ));
@@ -252,6 +266,15 @@ public Collection<FulltextIndex> getFulltextIndexes() {
252266 return indexes ;
253267 }
254268
269+ @ Override
270+ public Optional <TtlIndex > getTtlIndex () {
271+ return getIndex (TtlIndex .class );
272+ }
273+
274+ private <A extends Annotation > Optional <A > getIndex (final Class <A > annotation ) {
275+ return Optional .ofNullable (AnnotatedElementUtils .findMergedAnnotation (getType (), annotation ));
276+ }
277+
255278 public <A extends Annotation > Collection <A > getIndexes (final Class <A > annotation ) {
256279 final List <A > indexes = findAnnotations (annotation ).stream ().filter (a -> annotation .isInstance (a ))
257280 .map (a -> annotation .cast (a )).collect (Collectors .toList ());
@@ -283,6 +306,11 @@ public Collection<ArangoPersistentProperty> getFulltextIndexedProperties() {
283306 return fulltextIndexedProperties ;
284307 }
285308
309+ @ Override
310+ public Optional <ArangoPersistentProperty > getTtlIndexedProperty () {
311+ return Optional .ofNullable (ttlIndexedProperty );
312+ }
313+
286314 @ SuppressWarnings ("unchecked" )
287315 public <A extends Annotation > Set <A > findAnnotations (final Class <A > annotationType ) {
288316 return (Set <A >) repeatableAnnotationCache .computeIfAbsent (annotationType ,
0 commit comments