Skip to content

Commit 4509a7b

Browse files
committed
Created example for #36
1 parent ab2c43d commit 4509a7b

File tree

4 files changed

+180
-0
lines changed

4 files changed

+180
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.socialsignin.spring.data.dynamodb.core;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
import org.socialsignin.spring.data.dynamodb.domain.sample.FeedUserRepository;
7+
import org.socialsignin.spring.data.dynamodb.domain.sample.UserRepository;
8+
import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.data.domain.PageRequest;
12+
import org.springframework.data.domain.Sort;
13+
import org.springframework.data.domain.Sort.Direction;
14+
import org.springframework.test.context.ContextConfiguration;
15+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
16+
17+
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
18+
19+
@RunWith(SpringJUnit4ClassRunner.class)
20+
@ContextConfiguration(classes={FeedUserIT.TestAppConfig.class, ConfigurationTI.class})
21+
public class FeedUserIT {
22+
23+
@Configuration
24+
@EnableDynamoDBRepositories(basePackages = "org.socialsignin.spring.data.dynamodb.domain.sample")
25+
public static class TestAppConfig {
26+
}
27+
28+
@Autowired
29+
FeedUserRepository feedUserRepository;
30+
31+
@Autowired
32+
private AmazonDynamoDB amazonDynamoDB;
33+
34+
@Before
35+
public void setUp() {
36+
}
37+
38+
@Test
39+
public void feed_test(){
40+
PageRequest pageRequest = new PageRequest(1, 10, new Sort(Direction.DESC, "usrNo"));
41+
feedUserRepository.findByUsrNo(2, pageRequest); //runnable
42+
feedUserRepository.findByUsrNoAndFeedOpenYn(2, true, pageRequest); //not runnable
43+
}
44+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package org.socialsignin.spring.data.dynamodb.domain.sample;
2+
3+
import java.util.Date;
4+
5+
import org.springframework.data.annotation.Id;
6+
7+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
8+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey;
9+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
10+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBIndexHashKey;
11+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBIndexRangeKey;
12+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBNativeBoolean;
13+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
14+
15+
@DynamoDBTable(tableName = "feed_user")
16+
public class FeedUser {
17+
@Id
18+
@DynamoDBHashKey
19+
@DynamoDBAutoGeneratedKey
20+
private String id;
21+
22+
@DynamoDBIndexHashKey(globalSecondaryIndexName = "idx_global_usrNo_feedOpenYn")
23+
private int usrNo;
24+
25+
@DynamoDBAttribute
26+
private String feedId;
27+
28+
@DynamoDBAttribute
29+
private Date feedRegDate;
30+
31+
@DynamoDBAttribute
32+
@DynamoDBNativeBoolean
33+
@DynamoDBIndexRangeKey(globalSecondaryIndexName = "idx_global_usrNo_feedOpenYn")
34+
private boolean feedOpenYn;
35+
36+
public String getId() {
37+
return id;
38+
}
39+
40+
public void setId(String id) {
41+
this.id = id;
42+
}
43+
44+
public int getUsrNo() {
45+
return usrNo;
46+
}
47+
48+
public void setUsrNo(int usrNo) {
49+
this.usrNo = usrNo;
50+
}
51+
52+
public String getFeedId() {
53+
return feedId;
54+
}
55+
56+
public void setFeedId(String feedId) {
57+
this.feedId = feedId;
58+
}
59+
60+
public Date getFeedRegDate() {
61+
return feedRegDate;
62+
}
63+
64+
public void setFeedRegDate(Date feedRegDate) {
65+
this.feedRegDate = feedRegDate;
66+
}
67+
68+
public boolean isFeedOpenYn() {
69+
return feedOpenYn;
70+
}
71+
72+
public void setFeedOpenYn(boolean feedOpenYn) {
73+
this.feedOpenYn = feedOpenYn;
74+
}
75+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.socialsignin.spring.data.dynamodb.domain.sample;
2+
3+
import java.util.List;
4+
5+
import org.socialsignin.spring.data.dynamodb.repository.DynamoDBPagingAndSortingRepository;
6+
import org.springframework.data.domain.Pageable;
7+
8+
public interface FeedUserRepository extends DynamoDBPagingAndSortingRepository<FeedUser, String>{
9+
public List<FeedUser> findByUsrNo(int usrNo, Pageable pageable);
10+
public List<FeedUser> findByUsrNoAndFeedOpenYn(int usrNo, boolean feedOpenYn, Pageable pageable);
11+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"AttributeDefinitions": [
3+
{
4+
"AttributeName": "id",
5+
"AttributeType": "S"
6+
},
7+
{
8+
"AttributeName": "usrNo",
9+
"AttributeType": "N"
10+
},
11+
{
12+
"AttributeName": "feedOpenYn",
13+
"AttributeType": "N"
14+
}
15+
],
16+
"KeySchema": [
17+
{
18+
"AttributeName": "id",
19+
"KeyType": "HASH"
20+
}
21+
],
22+
"ProvisionedThroughput": {
23+
"ReadCapacityUnits": "10",
24+
"WriteCapacityUnits": "10"
25+
},
26+
"GlobalSecondaryIndexes": [
27+
{
28+
"IndexName": "idx_global_usrNo_feedOpenYn",
29+
"KeySchema": [
30+
{
31+
"AttributeName": "usrNo",
32+
"KeyType": "HASH"
33+
},
34+
{
35+
"AttributeName": "feedOpenYn",
36+
"KeyType": "RANGE"
37+
}
38+
39+
],
40+
"Projection": {
41+
"ProjectionType": "ALL"
42+
},
43+
"ProvisionedThroughput": {
44+
"ReadCapacityUnits": 10,
45+
"WriteCapacityUnits": 10
46+
}
47+
}
48+
],
49+
"TableName": "feed_user"
50+
}

0 commit comments

Comments
 (0)