-
Notifications
You must be signed in to change notification settings - Fork 25
/
DocumentTemplate.java
89 lines (77 loc) · 3.26 KB
/
DocumentTemplate.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package jakarta.nosql.document;
import jakarta.nosql.PreparedStatement;
import jakarta.nosql.Template;
import java.util.Optional;
import java.util.stream.Stream;
/**
* The <b>DocumentTemplate</b> class is a type of <b>Template</b> explicitly made for simplifying
* document-oriented tasks on NoSQL databases.
* These databases store data as documents, individual data sets that can be grouped into collections.
* The query syntax belongs to each provider; thus, it is not Jakarta's NoSQL scope to define it.
* Accordingly, it might vary from implementation and NoSQL provider.
*/
public interface DocumentTemplate extends Template {
/**
* Returns the number of elements from document collection
*
* @param documentCollection the document collection
* @return the number of elements
* @throws NullPointerException when document collection is null
* @throws UnsupportedOperationException when the database dot not have support
*/
long count(String documentCollection);
/**
* Returns the number of elements from document collection
*
* @param <T> entityType
* @param entityType the document collection
* @return the number of elements
* @throws NullPointerException when document collection is null
* @throws UnsupportedOperationException when the database dot not have support
*/
<T> long count(Class<T> entityType);
/**
* Executes a query database, then bring the result as a {@link Stream}
*
* @param query the query
* @param <T> the entity type
* @return the result as {@link Stream}
* @throws NullPointerException when the query is null
* @throws UnsupportedOperationException when the provider does not support query by text
*/
<T> Stream<T> query(String query);
/**
* Executes a query database, then bring the result as a unique result
*
* @param query the query
* @param <T> the entity type
* @return the result as {@link Optional}
* @throws NullPointerException when the query is null
* @throws UnsupportedOperationException when the provider does not support query by text
*/
<T> Optional<T> singleResult(String query);
/**
* Creates a {@link PreparedStatement} from the query
*
* @param query the query
* @return a {@link PreparedStatement} instance
* @throws NullPointerException when the query is null
* @throws UnsupportedOperationException when the provider does not support query by text
*/
PreparedStatement prepare(String query);
}