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         * @param   indexValue  Optional: the value to be indexed. If indexValue is not specified, value is used.
058         */
059        void storeTopicValue(long topicId, SimpleValue value, List<IndexMode> indexModes, String indexKey,
060                                                                                          SimpleValue indexValue);
061        // ---
062    
063        void deleteTopic(long topicId);
064    
065    
066    
067        // === Associations ===
068    
069        AssociationModel fetchAssociation(long id);
070    
071        List<AssociationModel> fetchAssociations(String assocTypeUri, long topicId1, long topicId2, String roleTypeUri1,
072                                                                                                    String roleTypeUri2);
073    
074        List<AssociationModel> fetchAssociationsBetweenTopicAndAssociation(String assocTypeUri, long topicId, long assocId,
075                                                                          String topicRoleTypeUri, String assocRoleTypeUri);
076    
077        Iterator<AssociationModel> fetchAllAssociations();
078    
079        // ---
080    
081        void storeAssociation(AssociationModel assocModel);
082    
083        void storeAssociationUri(long assocId, String uri);
084    
085        void storeAssociationTypeUri(long assocId, String assocTypeUri);
086    
087        /**
088         * @param   indexValue  Optional: the value to be indexed. If indexValue is not specified, value is used.
089         */
090        void storeAssociationValue(long assocId, SimpleValue value, List<IndexMode> indexModes, String indexKey,
091                                                                                                SimpleValue indexValue);
092    
093        void storeRoleTypeUri(long assocId, long playerId, String roleTypeUri);
094    
095        // ---
096    
097        void deleteAssociation(long assocId);
098    
099    
100    
101        // === Traversal ===
102    
103        List<AssociationModel> fetchTopicAssociations(long topicId);
104    
105        List<AssociationModel> fetchAssociationAssociations(long assocId);
106    
107        // ---
108    
109        /**
110         * @param   assocTypeUri        may be null
111         * @param   myRoleTypeUri       may be null
112         * @param   othersRoleTypeUri   may be null
113         * @param   othersTopicTypeUri  may be null
114         */
115        List<RelatedTopicModel> fetchTopicRelatedTopics(long topicId, String assocTypeUri,
116                                                 String myRoleTypeUri, String othersRoleTypeUri, String othersTopicTypeUri);
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<RelatedAssociationModel> fetchTopicRelatedAssociations(long topicId, String assocTypeUri,
125                                                 String myRoleTypeUri, String othersRoleTypeUri, String othersAssocTypeUri);
126    
127        // ---
128    
129        /**
130         * @param   assocTypeUri        may be null
131         * @param   myRoleTypeUri       may be null
132         * @param   othersRoleTypeUri   may be null
133         * @param   othersTopicTypeUri  may be null
134         */
135        List<RelatedTopicModel> fetchAssociationRelatedTopics(long assocId, String assocTypeUri,
136                                                 String myRoleTypeUri, String othersRoleTypeUri, String othersTopicTypeUri);
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<RelatedAssociationModel> fetchAssociationRelatedAssociations(long assocId, String assocTypeUri,
145                                                 String myRoleTypeUri, String othersRoleTypeUri, String othersAssocTypeUri);
146    
147        // ---
148    
149        /**
150         * @param   id                  id of a topic or an association
151         * @param   assocTypeUri        may be null
152         * @param   myRoleTypeUri       may be null
153         * @param   othersRoleTypeUri   may be null
154         * @param   othersTopicTypeUri  may be null
155         */
156        List<RelatedTopicModel> fetchRelatedTopics(long id, String assocTypeUri,
157                                                 String myRoleTypeUri, String othersRoleTypeUri, String othersTopicTypeUri);
158    
159        /**
160         * @param   id                  id of a topic or an association
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> fetchRelatedAssociations(long id, String assocTypeUri,
167                                                 String myRoleTypeUri, String othersRoleTypeUri, String othersAssocTypeUri);
168    
169    
170    
171        // === Properties ===
172    
173        Object fetchTopicProperty(long topicId, String propUri);
174    
175        Object fetchAssociationProperty(long assocId, String propUri);
176    
177        // ---
178    
179        List<TopicModel> fetchTopicsByProperty(String propUri, Object propValue);
180    
181        List<TopicModel> fetchTopicsByPropertyRange(String propUri, Number from, Number to);
182    
183        List<AssociationModel> fetchAssociationsByProperty(String propUri, Object propValue);
184    
185        List<AssociationModel> fetchAssociationsByPropertyRange(String propUri, Number from, Number to);
186    
187        // ---
188    
189        void storeTopicProperty(long topicId, String propUri, Object propValue, boolean addToIndex);
190    
191        void storeAssociationProperty(long assocId, String propUri, Object propValue, boolean addToIndex);
192    
193        // ---
194    
195        boolean hasTopicProperty(long topicId, String propUri);
196    
197        boolean hasAssociationProperty(long assocId, String propUri);
198    
199        // ---
200    
201        void deleteTopicProperty(long topicId, String propUri);
202    
203        void deleteAssociationProperty(long assocId, String propUri);
204    
205    
206    
207        // === DB ===
208    
209        DeepaMehtaTransaction beginTx();
210    
211        boolean setupRootNode();
212    
213        void shutdown();
214    }