001package systems.dmx.core.storage.spi;
002
003import systems.dmx.core.model.AssociationModel;
004import systems.dmx.core.model.DMXObjectModel;
005import systems.dmx.core.model.IndexMode;
006import systems.dmx.core.model.RelatedAssociationModel;
007import systems.dmx.core.model.RelatedTopicModel;
008import systems.dmx.core.model.SimpleValue;
009import systems.dmx.core.model.TopicModel;
010import systems.dmx.core.service.ModelFactory;
011
012import java.util.Iterator;
013import java.util.List;
014
015
016
017public interface DMXStorage {
018
019
020
021    // === Topics ===
022
023    TopicModel fetchTopic(long topicId);
024
025    TopicModel fetchTopic(String key, Object value);
026
027    List<? extends TopicModel> fetchTopics(String key, Object value);
028
029    List<TopicModel> queryTopics(Object value);
030
031    List<? extends TopicModel> queryTopics(String key, Object value);
032
033    Iterator<? extends TopicModel> fetchAllTopics();
034
035    // ---
036
037    /**
038     * Stores a rudimentary topic in the DB.
039     * <p>
040     * Only the topic URI and the topic type URI are stored.
041     * The topic value (simple or composite) is <i>not</i> stored.
042     * The "Instantiation" association is <i>not</i> stored.
043     * <p>
044     * An URI uniqueness check is performed. If the DB already contains a topic or an association with
045     * the URI passed, an exception is thrown and nothing is stored.
046     *
047     * @param   topicModel  The topic to store. Once the method returns the topic model contains:
048     *                          - the ID of the stored topic.
049     *                          - an empty URI ("") in case <code>null</code> was passed.
050     *                          - an empty simple value ("") in case <code>null</code> was passed.
051     */
052    void storeTopic(TopicModel topicModel);
053
054    void storeTopicUri(long topicId, String uri);
055
056    void storeTopicTypeUri(long topicId, String topicTypeUri);
057
058    /**
059     * Stores and indexes a topic value.
060     *
061     * @param   indexValue  Optional: the value to be indexed. If indexValue is not specified, value is used.
062     */
063    void storeTopicValue(long topicId, SimpleValue value, List<IndexMode> indexModes, String indexKey,
064                                                                                      SimpleValue indexValue);
065
066    void indexTopicValue(long topicId, IndexMode indexMode, String indexKey, SimpleValue indexValue);
067
068    // ---
069
070    void deleteTopic(long topicId);
071
072
073
074    // === Associations ===
075
076    AssociationModel fetchAssociation(long assocId);
077
078    AssociationModel fetchAssociation(String key, Object value);
079
080    List<? extends AssociationModel> fetchAssociations(String key, Object value);
081
082    List<? extends AssociationModel> fetchAssociations(String assocTypeUri, long topicId1, long topicId2,
083                                                                            String roleTypeUri1, String roleTypeUri2);
084
085    List<? extends AssociationModel> fetchAssociationsBetweenTopicAndAssociation(String assocTypeUri, long topicId,
086                                                        long assocId, String topicRoleTypeUri, String assocRoleTypeUri);
087
088    Iterator<? extends AssociationModel> fetchAllAssociations();
089
090    long[] fetchPlayerIds(long assocId);
091
092    // ---
093
094    void storeAssociation(AssociationModel assocModel);
095
096    void storeAssociationUri(long assocId, String uri);
097
098    void storeAssociationTypeUri(long assocId, String assocTypeUri);
099
100    /**
101     * Stores and indexes an association value.
102     *
103     * @param   indexValue  Optional: the value to be indexed. If indexValue is not specified, value is used.
104     */
105    void storeAssociationValue(long assocId, SimpleValue value, List<IndexMode> indexModes, String indexKey,
106                                                                                            SimpleValue indexValue);
107
108    void indexAssociationValue(long assocId, IndexMode indexMode, String indexKey, SimpleValue indexValue);
109
110    void storeRoleTypeUri(long assocId, long playerId, String roleTypeUri);
111
112    // ---
113
114    void deleteAssociation(long assocId);
115
116
117
118    // === Generic Object ===
119
120    DMXObjectModel fetchObject(long id);
121
122
123
124    // === Traversal ===
125
126    List<? extends AssociationModel> fetchTopicAssociations(long topicId);
127
128    List<? extends AssociationModel> fetchAssociationAssociations(long assocId);
129
130    // ---
131
132    /**
133     * @param   assocTypeUri        may be null
134     * @param   myRoleTypeUri       may be null
135     * @param   othersRoleTypeUri   may be null
136     * @param   othersTopicTypeUri  may be null
137     */
138    List<? extends RelatedTopicModel> fetchTopicRelatedTopics(long topicId, String assocTypeUri,
139                                             String myRoleTypeUri, String othersRoleTypeUri, String othersTopicTypeUri);
140
141    /**
142     * @param   assocTypeUri        may be null
143     * @param   myRoleTypeUri       may be null
144     * @param   othersRoleTypeUri   may be null
145     * @param   othersTopicTypeUri  may be null
146     */
147    List<? extends RelatedAssociationModel> fetchTopicRelatedAssociations(long topicId, String assocTypeUri,
148                                             String myRoleTypeUri, String othersRoleTypeUri, String othersAssocTypeUri);
149
150    // ---
151
152    /**
153     * @param   assocTypeUri        may be null
154     * @param   myRoleTypeUri       may be null
155     * @param   othersRoleTypeUri   may be null
156     * @param   othersTopicTypeUri  may be null
157     */
158    List<? extends RelatedTopicModel> fetchAssociationRelatedTopics(long assocId, String assocTypeUri,
159                                             String myRoleTypeUri, String othersRoleTypeUri, String othersTopicTypeUri);
160
161    /**
162     * @param   assocTypeUri        may be null
163     * @param   myRoleTypeUri       may be null
164     * @param   othersRoleTypeUri   may be null
165     * @param   othersTopicTypeUri  may be null
166     */
167    List<? extends RelatedAssociationModel> fetchAssociationRelatedAssociations(long assocId, String assocTypeUri,
168                                             String myRoleTypeUri, String othersRoleTypeUri, String othersAssocTypeUri);
169
170    // ---
171
172    /**
173     * @param   objectId            id of a topic or an association
174     * @param   assocTypeUri        may be null
175     * @param   myRoleTypeUri       may be null
176     * @param   othersRoleTypeUri   may be null
177     * @param   othersTopicTypeUri  may be null
178     */
179    List<? extends RelatedTopicModel> fetchRelatedTopics(long objectId, String assocTypeUri,
180                                             String myRoleTypeUri, String othersRoleTypeUri, String othersTopicTypeUri);
181
182    /**
183     * @param   objectId            id of a topic or an association
184     * @param   assocTypeUri        may be null
185     * @param   myRoleTypeUri       may be null
186     * @param   othersRoleTypeUri   may be null
187     * @param   othersTopicTypeUri  may be null
188     */
189    List<? extends RelatedAssociationModel> fetchRelatedAssociations(long objectId, String assocTypeUri,
190                                             String myRoleTypeUri, String othersRoleTypeUri, String othersAssocTypeUri);
191
192
193
194    // === Properties ===
195
196    /**
197     * @param   id                  id of a topic or an association
198     */
199    Object fetchProperty(long id, String propUri);
200
201    /**
202     * @param   id                  id of a topic or an association
203     */
204    boolean hasProperty(long id, String propUri);
205
206    // ---
207
208    List<? extends TopicModel> fetchTopicsByProperty(String propUri, Object propValue);
209
210    List<? extends TopicModel> fetchTopicsByPropertyRange(String propUri, Number from, Number to);
211
212    List<? extends AssociationModel> fetchAssociationsByProperty(String propUri, Object propValue);
213
214    List<? extends AssociationModel> fetchAssociationsByPropertyRange(String propUri, Number from, Number to);
215
216    // ---
217
218    void storeTopicProperty(long topicId, String propUri, Object propValue, boolean addToIndex);
219
220    void storeAssociationProperty(long assocId, String propUri, Object propValue, boolean addToIndex);
221
222    // ---
223
224    void indexTopicProperty(long topicId, String propUri, Object propValue);
225
226    void indexAssociationProperty(long assocId, String propUri, Object propValue);
227
228    // ---
229
230    void deleteTopicProperty(long topicId, String propUri);
231
232    void deleteAssociationProperty(long assocId, String propUri);
233
234
235
236    // === DB ===
237
238    DMXTransaction beginTx();
239
240    boolean setupRootNode();
241
242    void shutdown();
243
244    // ---
245
246    Object getDatabaseVendorObject();
247
248    Object getDatabaseVendorObject(long objectId);
249
250    // ---
251
252    ModelFactory getModelFactory();
253}