Interface DocResult

All Superinterfaces:
AutoCloseable, FetchResult<AltibaseDocument>, Iterable<AltibaseDocument>, Iterator<AltibaseDocument>
All Known Implementing Classes:
DocResultImpl

public interface DocResult extends FetchResult<AltibaseDocument>
AltibaseCollection의 조회 연산 결과를 나타내는 특화된 인터페이스이다.

이 인터페이스는 두 가지 모드로 동작한다. 처음에는 데이터베이스 커서로부터 실시간으로 문서를 스트리밍하여 메모리 사용을 최소화한다. 모든 문서를 한 번 순회하고 나면(예: fetchAll(), count() 호출 또는 전체 루프 순회 완료), 결과는 내부적으로 캐시된다. 캐시가 완료된 후에는 데이터베이스 연결 없이도 동일한 결과 집합을 여러 번 재순회할 수 있다.

AutoCloseable을 상속하므로 try-with-resources 구문과 함께 사용하는 것이 권장된다.

사용 패턴 예제


 // 1. Iterator를 사용한 순차 처리 (대용량 결과셋에 적합한 스트리밍 방식)
 try (DocResult results = booksCollection.find().execute()) {
     while (results.hasNext()) {
         AltibaseDocument doc = results.next();
         System.out.println("Title: " + doc.getString("title"));
     }
 }

 // 2. 향상된 for-loop 구문 사용
 try (DocResult results = booksCollection.find().execute()) {
     // 이 루프를 통해 모든 결과를 순회하면, 결과는 내부에 캐시된다.
     for (AltibaseDocument doc : results) {
         System.out.println(doc.toJson());
     }
 }

 // 3. 모든 결과를 List로 한 번에 가져오기 (즉시 캐시 모드로 전환)
 List<AltibaseDocument> allDocuments;
 try (DocResult results = booksCollection.find().execute()) {
     allDocuments = results.fetchAll();
 }

 // 4. 캐시된 결과 재순회 (rewind() 사용)
 try (DocResult results = booksCollection.find().execute()) {
     // 먼저 fetchAll() 등으로 모든 결과를 소비하여 내부 캐시를 활성화한다.
     List<AltibaseDocument> initialList = results.fetchAll();
     System.out.println("Found " + initialList.size() + " documents.");

     // 커서를 처음으로 되돌린다.
     results.rewind();

     // 데이터베이스 재조회 없이 캐시된 데이터로 다시 순회한다.
     for (AltibaseDocument doc : results) {
         // 추가적인 처리 수행
     }
 }
 
Since:
1.0
See Also:
  • Method Details

    • rewind

      void rewind()
      이터레이터의 커서를 결과 집합의 시작 지점으로 되돌린다.

      주의: 이 메서드는 fetchAll(), count()를 호출했거나, 혹은 수동으로 모든 결과를 순회하여 내부 캐시가 채워진 후에만 호출할 수 있다. 아직 데이터베이스로부터 결과를 스트리밍하는 도중에 호출하면 AltibaseQueryException이 발생한다.

      Throws:
      AltibaseQueryException - 결과 집합이 아직 완전히 메모리에 로드되지 않은 경우