View Javadoc
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 cz.zcu.mre.data.core.MREData;
25  import org.apache.jena.arq.querybuilder.SelectBuilder;
26  import org.apache.jena.arq.querybuilder.UpdateBuilder;
27  import org.apache.jena.query.Query;
28  import org.apache.jena.rdf.model.Resource;
29  import org.apache.jena.sparql.modify.request.UpdateDeleteInsert;
30  
31  /**
32   * SPARQL Builder Interface for Java Beans and MREData instances.
33   *
34   * @author Petr Vcelak (vcelak@kiv.zcu.cz)
35   */
36  public interface SPARQLBuilder extends SPARQLBuilderVariables {
37  
38      /**
39       * Build ASK query for the instance.
40       *
41       * @param instance The instance.
42       * @return Prepared Query instance.
43       */
44      Query ask(Object instance);
45  
46      /**
47       * Build ASK query for test if the instance URI and type is
48       * persistent/exist. This method produces only one triple (instance URI,
49       * rdf:type property and class URI for object) in the WHERE part.
50       *
51       * @param instance The instance.
52       * @return The ASK Query with only one triple (instance URI, rdf:type
53       * property and class URI for object).
54       */
55      Query askExist(Object instance);
56  
57      /**
58       * Build ASK query for test if the instance is persistent/exist. This method
59       * produces only one triple (instance URI, rdf:type property and class URI
60       * for object) in the WHERE part.
61       *
62       * @param instance The instance.
63       * @return The ASK Query with only one triple (instance URI, rdf:type
64       * property and class URI for object).
65       */
66      Query askExistAll(Object instance);
67  
68      /**
69       * Generate SELECT for list of instances that is based on the instance
70       * (type) and its attributes.
71       *
72       * This can work as query for "select all instances" and "select instance(s)
73       * with value of one/more attributes".
74       *
75       * @param instance The instance for building a complete general SELECT.
76       * @return Query instance that defines member attributes and rdf:type.
77       */
78      Query select(Object instance);
79      
80      /**
81       * Generate SELECT builder for list all instances that is based on the
82       * instance (type) and NO its attribute values.
83       *
84       * This can work as query for "select all instances" and "select instance(s)
85       * with value of one/more attributes".
86       *
87       * @param instance The instance for building a complete general SELECT.
88       * @return Select Builder instance.
89       */
90      SelectBuilder selectAllBuilder(MREData instance);
91  
92      /**
93       * Generate SELECT for list all instances that is based on the instance
94       * (type) and NO its attribute values.
95       *
96       * This can work as query for "select all instances" and "select instance(s)
97       * with value of one/more attributes".
98       *
99       * @param instance The instance for building a complete general SELECT.
100      * @return Query instance that defines member attributes and rdf:type.
101      */
102     Query selectAll(MREData instance);
103 
104     /**
105      * Build query to SELECT the resource rdf:type.
106      *
107      * @param resourceURI The resource URI as a String.
108      * @return Prepared Query instance.
109      */
110     Query selectType(String resourceURI);
111 
112     /**
113      * Build query to SELECT the resource rdf:type.
114      *
115      * @param resource The resource URI.
116      * @return Prepared Query instance.
117      */
118     Query selectType(Resource resource);
119 
120     /**
121      * Build DELETE update query for the instance removal.
122      *
123      * @param instance The instance to remove.
124      * @return Prepared UpdateBuilder instance.
125      */
126     UpdateBuilder delete(Object instance);
127 
128     /**
129      * Build DELETE update query for the deep instance removal. Remove
130      * recursively all sub-instances.
131      *
132      * @param instance The instance to deeply remove.
133      * @return Prepared UpdateBuilder instance.
134      */
135     UpdateBuilder deleteAll(Object instance);
136 
137     /**
138      * Build INSERT update query for making instance persistent.
139      *
140      * @param instance The instance for insert.
141      * @return Prepared UpdateBuilder instance.
142      */
143     UpdateBuilder insert(Object instance);
144 
145     /**
146      * Build INSERT update query for making the instance persistent. Inserts
147      * recursively all sub-instances.
148      *
149      * @param instance The instance for insert.
150      * @return Prepared UpdateBuilder instance.
151      */
152     UpdateBuilder insertAll(Object instance);
153 
154     /**
155      * Build DELETE INSERT update query for updating the instance.
156      *
157      * @param instanceOld The old instance is for delete part.
158      * @param instanceNew The new instance is for insert part.
159      * @return Prepared UpdateDeleteInsert builder instance.
160      */
161     UpdateDeleteInsert update(Object instanceOld, Object instanceNew);
162 
163     /**
164      * Build DELETE INSERT update query for updating the instance. Prepare
165      * delete and inserts recursively for all sub-instances.
166      *
167      * @param instanceOld The old instance is for delete part.
168      * @param instanceNew The new instance is for insert part.
169      * @return Prepared UpdateDeleteInsert builder instance.
170      */
171     UpdateDeleteInsert updateAll(Object instanceOld, Object instanceNew);
172 
173 }