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