Skip to content

Commit 4c6b14a

Browse files
committed
WIP Issue #99 (again?)
1 parent f0a2dff commit 4c6b14a

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright © 2018 spring-data-dynamodb (https://github.com/spring-data-dynamodb/spring-data-dynamodb)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.socialsignin.spring.data.dynamodb.marshaller;
17+
18+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTypeConverter;
19+
20+
import java.time.Instant;
21+
22+
public class Instant2EpocheNDynamoDBMarshaller implements DynamoDBTypeConverter<Long, Instant> {
23+
24+
@Override
25+
public Long convert(Instant getterReturnResult) {
26+
if (getterReturnResult == null) {
27+
return null;
28+
} else {
29+
return getterReturnResult.toEpochMilli();
30+
}
31+
}
32+
33+
@Override
34+
public Instant unconvert(Long obj) {
35+
if (obj == null) {
36+
return null;
37+
} else {
38+
return Instant.ofEpochMilli(obj);
39+
}
40+
}
41+
42+
}

src/test/java/org/socialsignin/spring/data/dynamodb/domain/sample/User.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@
1515
*/
1616
package org.socialsignin.spring.data.dynamodb.domain.sample;
1717

18+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
19+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey;
1820
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
21+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBIndexHashKey;
22+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBIndexRangeKey;
23+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperFieldModel;
1924
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMarshalling;
2025
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
26+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTypeConverted;
27+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTyped;
28+
import org.socialsignin.spring.data.dynamodb.marshaller.Instant2EpocheNDynamoDBMarshaller;
2129
import org.socialsignin.spring.data.dynamodb.marshaller.Instant2IsoDynamoDBMarshaller;
2230

2331
import java.time.Instant;
@@ -26,6 +34,7 @@
2634

2735
@DynamoDBTable(tableName = "user")
2836
public class User {
37+
public static final String TENANT_ID_INDEX_NAME = "TENANT_ID_INDEX_NAME";
2938

3039
private String id;
3140

@@ -43,6 +52,8 @@ public class User {
4352
private String postCode;
4453

4554
private Set<String> testSet;
55+
private String tenantId;
56+
private Instant creationTimestamp;
4657

4758
public Set<String> getTestSet() {
4859
return testSet;
@@ -87,13 +98,36 @@ public void setPostCode(String postCode) {
8798
}
8899

89100
@DynamoDBHashKey(attributeName = "Id")
101+
@DynamoDBAutoGeneratedKey
90102
public String getId() {
91103
return id;
92104
}
93105

94106
public void setId(String id) {
95107
this.id = id;
96108
}
109+
110+
@DynamoDBAttribute
111+
@DynamoDBIndexHashKey(globalSecondaryIndexName = TENANT_ID_INDEX_NAME)
112+
public String getTenantId() {
113+
return this.tenantId;
114+
}
115+
116+
public void setTenantId(String tenantId) {
117+
this.tenantId = tenantId;
118+
}
119+
120+
@DynamoDBAttribute
121+
@DynamoDBTyped(DynamoDBMapperFieldModel.DynamoDBAttributeType.N)
122+
@DynamoDBTypeConverted(converter = Instant2EpocheNDynamoDBMarshaller.class)
123+
@DynamoDBIndexRangeKey(globalSecondaryIndexNames = TENANT_ID_INDEX_NAME)
124+
public Instant getCreationTimestamp() {
125+
return this.creationTimestamp;
126+
}
127+
128+
public void setCreationTimestamp(Instant creationTimestamp) {
129+
this.creationTimestamp = creationTimestamp;
130+
}
97131

98132
public String getName() {
99133
return name;

0 commit comments

Comments
 (0)