1 /*
2 * Copyright 2018-2022 Medical Information Systems Research Group (https://medical.zcu.cz),
3 * Department of Computer Science and Engineering, University of West Bohemia.
4 * Address: Univerzitni 8, 306 14 Plzen, Czech Republic.
5 *
6 * Author Petr Vcelak (vcelak@kiv.zcu.cz).
7 *
8 * This file is part of MRECore project.
9 *
10 * MRECore is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License.
13 *
14 * MRECore is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MRECore. If not, see <http://www.gnu.org/licenses/>.
21 */
22 package cz.zcu.mre.service.data;
23
24 import java.util.List;
25 import java.util.stream.Stream;
26 import org.apache.jena.query.QuerySolution;
27 import org.apache.jena.rdf.model.Resource;
28
29 /**
30 * Data Service Interface.
31 *
32 * @author Petr Vcelak (vcelak@kiv.zcu.cz)
33 * @param <T> Object type.
34 */
35 public interface DataService<T> {
36
37 T createInstance(T example);
38
39 T createInstance(T example, Resource uri);
40
41 T createInstance(Resource type);
42
43 T createInstance(Resource type, Resource uri);
44
45 T createInstance(String typeURI);
46
47 T createInstance(String typeURI, Resource uri);
48
49 /**
50 * ASK if instance is persistent.
51 *
52 * @param instance The T instance.
53 * @return true or false.
54 */
55 boolean isPersistent(T instance);
56
57 /**
58 * Save T instance.
59 *
60 * @param instance The instance.
61 * @return status.
62 */
63 boolean save(T instance);
64
65 /**
66 * Deeply save T instance.
67 *
68 * @param instance The T instance.
69 * @return status.
70 */
71 boolean saveAll(T instance);
72
73 /**
74 * Insert T instance.
75 *
76 * @param instance The T instance.
77 * @return status.
78 */
79 boolean insert(T instance);
80
81 /**
82 * Deeply insert T instance.
83 *
84 * @param instance The T instance.
85 * @return status.
86 */
87 boolean insertAll(T instance);
88
89 /**
90 * Update T instance.
91 *
92 * @param instance The instance.
93 * @return status.
94 */
95 boolean update(T instance);
96
97 /**
98 * Deeply update T instance.
99 *
100 * @param instance The instance.
101 * @return status.
102 */
103 boolean updateAll(T instance);
104
105 /**
106 * Delete T instance.
107 *
108 * @param instance The instance.
109 * @return status.
110 */
111 boolean delete(T instance);
112
113 /**
114 * Deeply delete T instance.
115 *
116 * @param instance The instance.
117 * @return status.
118 */
119 boolean deleteAll(T instance);
120
121 /**
122 * Get the stream of T instances found by rdf:type.
123 *
124 * @param type RDF class as a type for instances.
125 * @return Stream of T instances.
126 */
127 Stream<T> stream(String type);
128
129 /**
130 * Get the stream of T instances found by rdf:type.
131 *
132 * @param type RDF class as a type for instances.
133 * @return Stream of T instances.
134 */
135 Stream<T> stream(Resource type);
136
137 /**
138 * Get the stream of T instances found by example.
139 *
140 * @param example An example.
141 * @return Stream of T instances.
142 */
143 Stream<T> stream(T example);
144
145 /**
146 * Get the stream of all T instances.
147 *
148 * @param example An example.
149 * @return Stream of T instances.
150 */
151 Stream<T> streamAll(T example);
152
153 /**
154 * Parse List of QuerySolution instances to build T instances as a stream.
155 *
156 * @param result MRE-query result as a List of QuerySolution instances.
157 * @return Stream with MREData instances.
158 */
159 Stream<T> asStream(List<QuerySolution> result);
160
161 /**
162 * Get the list of T instances found by rdf:type.
163 *
164 * @param type RDF class as a type for instances.
165 * @return List of T instances.
166 */
167 List<T> list(String type);
168
169 /**
170 * Get the list of T instances found by rdf:type.
171 *
172 * @param type RDF class as a type for instances.
173 * @return List of T instances.
174 */
175 List<T> list(Resource type);
176
177 /**
178 * Get list of T instances found by example.
179 *
180 * @param example An example.
181 * @return List of T instances.
182 */
183 List<T> list(T example);
184
185 /**
186 * Get list of all T instances.
187 *
188 * @param example An example class.
189 * @return List of all T instances.
190 */
191 List<T> listAll(T example);
192
193 /**
194 * Get the T instance by its URI.
195 *
196 * @param resourceUri The URI as a String.
197 * @return Null or T instance.
198 */
199 T get(String resourceUri);
200
201 /**
202 * Get the T instance by its URI.
203 *
204 * @param resourceUri The URI as a String.
205 * @return Null or T instance.
206 */
207 T getAll(String resourceUri);
208
209 /**
210 * Get the T instance by its URI.
211 *
212 * @param resourceUri The URI as a Resource.
213 * @return Null or T instance.
214 */
215 T get(Resource resourceUri);
216
217 /**
218 * Get the T instance by its URI.
219 *
220 * @param resourceUri The URI as a Resource.
221 * @return Null or T instance.
222 */
223 T getAll(Resource resourceUri);
224
225 /**
226 * Get one T instance by example.
227 *
228 * @param example An example.
229 * @return Null or T instance.
230 */
231 T get(T example);
232
233 /**
234 * Get one MREData instance by example.
235 *
236 * @param example An example.
237 * @return Null or MREData instance.
238 */
239 T getAll(T example);
240
241 /**
242 * User-defined SELECT query.
243 *
244 * @param query SPARQL.
245 * @return Stream of QuerySolution instances.
246 */
247 Stream<QuerySolution> select(String query);
248 }