1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.socialsignin.spring.data.dynamodb.mapping;
17  
18  import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
19  import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBIgnore;
20  import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBVersionAttribute;
21  import org.springframework.data.annotation.Id;
22  import org.springframework.data.annotation.Reference;
23  import org.springframework.data.annotation.Transient;
24  import org.springframework.data.mapping.Association;
25  import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
26  import org.springframework.data.mapping.model.Property;
27  import org.springframework.data.mapping.model.SimpleTypeHolder;
28  
29  import java.lang.annotation.Annotation;
30  import java.util.Collection;
31  import java.util.Collections;
32  import java.util.HashSet;
33  import java.util.Set;
34  
35  
36  
37  
38  
39  
40  
41  class DynamoDBPersistentPropertyImpl extends AnnotationBasedPersistentProperty<DynamoDBPersistentProperty>
42  		implements
43  			DynamoDBPersistentProperty {
44  
45  	private static final Collection<Class<? extends Annotation>> ASSOCIATION_ANNOTATIONS;
46  	private static final Collection<Class<? extends Annotation>> ID_ANNOTATIONS;
47  
48  	static {
49  
50  		Set<Class<? extends Annotation>> annotations = new HashSet<Class<? extends Annotation>>();
51  
52  		annotations.add(Reference.class); 
53  		ASSOCIATION_ANNOTATIONS = Collections.unmodifiableSet(annotations);
54  
55  		annotations = new HashSet<>();
56  		annotations.add(Id.class);
57  		annotations.add(DynamoDBHashKey.class);
58  		ID_ANNOTATIONS = annotations;
59  	}
60  
61  	
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  	public DynamoDBPersistentPropertyImpl(Property property, DynamoDBPersistentEntityImpl<?> owner,
73  			SimpleTypeHolder simpleTypeHolder) {
74  		super(property, owner, simpleTypeHolder);
75  	}
76  
77  	@Override
78  	public boolean isWritable() {
79  		return !isAnnotationPresent(DynamoDBIgnore.class);
80  	}
81  
82  	public boolean isHashKeyProperty() {
83  		return isAnnotationPresent(DynamoDBHashKey.class);
84  	}
85  
86  	public boolean isCompositeIdProperty() {
87  		return isAnnotationPresent(Id.class);
88  	}
89  
90  	
91  
92  
93  
94  
95  
96  	@Override
97  	public boolean isIdProperty() {
98  
99  		for (Class<? extends Annotation> annotation : ID_ANNOTATIONS) {
100 			if (isAnnotationPresent(annotation)) {
101 				return true;
102 			}
103 		}
104 
105 		return false;
106 	}
107 
108 	
109 
110 
111 
112 
113 
114 	
115 
116 	public boolean isEntity() {
117 
118 		return isAnnotationPresent(Reference.class);
119 		
120 		
121 		
122 		
123 
124 		
125 
126 	}
127 
128 	
129 
130 
131 
132 
133 
134 	@Override
135 	public boolean isAssociation() {
136 
137 		for (Class<? extends Annotation> annotationType : ASSOCIATION_ANNOTATIONS) {
138 			if (findAnnotation(annotationType) != null) {
139 				
140 				
141 				
142 				return true;
143 			}
144 		}
145 
146 		return false;
147 	}
148 
149 	
150 
151 
152 
153 
154 
155 	@Override
156 	public boolean isTransient() {
157 		return isAnnotationPresent(Transient.class) || super.isTransient() || isAnnotationPresent(DynamoDBIgnore.class);
158 	}
159 
160 	@Override
161 	public boolean isVersionProperty() {
162 		return super.isVersionProperty() || isAnnotationPresent(DynamoDBVersionAttribute.class);
163 	}
164 
165 	
166 
167 
168 
169 
170 
171 	@Override
172 	protected Association<DynamoDBPersistentProperty> createAssociation() {
173 		return new Association<DynamoDBPersistentProperty>(this, null);
174 	}
175 }