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