티스토리 뷰
반응형
// DynamoDBMapper
// 객체 선언
@Autowired
private DynamoDBMapper dynamoDBMapper;
// 검색 조건으로 사용할 Attribute의 Value 지정
HashMap<String, AttributeValue> eav = new HashMap<>();
eav.put(":author", new AttributeValue().withS(author));
// Scan 방식. DB 전체를 조회하므로 속도 느림. Query 방식 권장
DynamoDBScanExpression scanExp =
new DynamoDBScanExpression()
.withFilterExpression("author = :v1")
.withExpressionAttributeValues(eav);
// Scan 할 Page 계산
int totalItemCount = dynamoDBMapper.count(Article.class, scanExp);
int pageUnitCount = 10;
int totalSegmentCount = totalItemCount / pageUnitCount + (totalItemCount % pageUnitCount == 0 ? 0 : 1);
// Scan 실행
// withTotalSegments와 withTotalSegments와 withSegment로 Page Navigation 구현
ScanResultPage<Article> page = dynamoDBMapper.scanPage(Article.class, scanExp.withTotalSegments(totalSegmentCount).withSegment(pageNo - 1));
String keyConditionExpression = "author = :author";
String filterConditionExpression = "articleId = :articleId";
DynamoDBQueryExpression<Article> scanExp =
new DynamoDBQueryExpression<Article>()
.withKeyConditionExpression(keyConditionExpression) // Partition Key
.withFilterExpression(filterConditionExpression) // Sort Key
.withIndexName(indexName) // Index 지정
.withExpressionAttributeValues(eav) // Attribute 값 지정
.withScanIndexForward(false) // 정렬키로 리스트 정렬(true: 오름차순, false: 내림차순)
.withLimit(limit); // 개수 제한
QueryResultPage<Article> page = dynamoDBMapper.queryPage(Article.class, scanExp); // Query 실행
List<Article> items = page.getResults(); // 결과 저장
반응형
'Programming' 카테고리의 다른 글
웹팩 등장 배경에 대한 이해 (0) | 2024.02.13 |
---|---|
SQL? NoSQL? NO! (1) | 2023.12.27 |
Dynamo DB 특징 및 단점 (1) | 2023.12.27 |
격세지감 크로스플랫폼 (0) | 2023.12.09 |
MySQL SQL Password Length 오류 (0) | 2022.06.30 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- PFF
- 고독
- 수요
- look
- 중요성
- c#
- FCFS
- Cocos2d-x
- N-step SCAN
- 병렬성
- 섹터 큐잉
- 동시성
- 페이징
- C-LOOK
- vmin
- 스와핑
- 주식
- grpc
- MoM
- 세그먼테이션
- QT
- 크로스플랫폼
- 메시지지향미들웨어
- 차이
- 파이썬
- 병행성
- SSTF
- scan
- 스위프트
- C-SCAN
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함