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        void storeTopic(TopicModel topicModel);
036    
037        void storeTopicUri(long topicId, String uri);
038    
039        void storeTopicTypeUri(long topicId, String topicTypeUri);
040    
041        /**
042         * @param   indexValue  Optional: the value to be indexed. If indexValue is not specified, value is used.
043         */
044        void storeTopicValue(long topicId, SimpleValue value, List<IndexMode> indexModes, String indexKey,
045                                                                                          SimpleValue indexValue);
046        // ---
047    
048        void deleteTopic(long topicId);
049    
050    
051    
052        // === Associations ===
053    
054        AssociationModel fetchAssociation(long id);
055    
056        List<AssociationModel> fetchAssociations(String assocTypeUri, long topicId1, long topicId2, String roleTypeUri1,
057                                                                                                    String roleTypeUri2);
058    
059        List<AssociationModel> fetchAssociationsBetweenTopicAndAssociation(String assocTypeUri, long topicId, long assocId,
060                                                                          String topicRoleTypeUri, String assocRoleTypeUri);
061    
062        Iterator<AssociationModel> fetchAllAssociations();
063    
064        // ---
065    
066        void storeAssociation(AssociationModel assocModel);
067    
068        void storeAssociationUri(long assocId, String uri);
069    
070        void storeAssociationTypeUri(long assocId, String assocTypeUri);
071    
072        /**
073         * @param   indexValue  Optional: the value to be indexed. If indexValue is not specified, value is used.
074         */
075        void storeAssociationValue(long assocId, SimpleValue value, List<IndexMode> indexModes, String indexKey,
076                                                                                                SimpleValue indexValue);
077    
078        void storeRoleTypeUri(long assocId, long playerId, String roleTypeUri);
079    
080        // ---
081    
082        void deleteAssociation(long assocId);
083    
084    
085    
086        // === Traversal ===
087    
088        List<AssociationModel> fetchTopicAssociations(long topicId);
089    
090        List<AssociationModel> fetchAssociationAssociations(long assocId);
091    
092        // ---
093    
094        /**
095         * @param   assocTypeUri        may be null
096         * @param   myRoleTypeUri       may be null
097         * @param   othersRoleTypeUri   may be null
098         * @param   othersTopicTypeUri  may be null
099         */
100        List<RelatedTopicModel> fetchTopicRelatedTopics(long topicId, String assocTypeUri,
101                                                 String myRoleTypeUri, String othersRoleTypeUri, String othersTopicTypeUri);
102    
103        /**
104         * @param   assocTypeUri        may be null
105         * @param   myRoleTypeUri       may be null
106         * @param   othersRoleTypeUri   may be null
107         * @param   othersTopicTypeUri  may be null
108         */
109        List<RelatedAssociationModel> fetchTopicRelatedAssociations(long topicId, String assocTypeUri,
110                                                 String myRoleTypeUri, String othersRoleTypeUri, String othersAssocTypeUri);
111    
112        // ---
113    
114        /**
115         * @param   assocTypeUri        may be null
116         * @param   myRoleTypeUri       may be null
117         * @param   othersRoleTypeUri   may be null
118         * @param   othersTopicTypeUri  may be null
119         */
120        List<RelatedTopicModel> fetchAssociationRelatedTopics(long assocId, String assocTypeUri,
121                                                 String myRoleTypeUri, String othersRoleTypeUri, String othersTopicTypeUri);
122    
123        /**
124         * @param   assocTypeUri        may be null
125         * @param   myRoleTypeUri       may be null
126         * @param   othersRoleTypeUri   may be null
127         * @param   othersTopicTypeUri  may be null
128         */
129        List<RelatedAssociationModel> fetchAssociationRelatedAssociations(long assocId, String assocTypeUri,
130                                                 String myRoleTypeUri, String othersRoleTypeUri, String othersAssocTypeUri);
131    
132        // ---
133    
134        /**
135         * @param   id                  id of a topic or an association
136         * @param   assocTypeUri        may be null
137         * @param   myRoleTypeUri       may be null
138         * @param   othersRoleTypeUri   may be null
139         * @param   othersTopicTypeUri  may be null
140         */
141        List<RelatedTopicModel> fetchRelatedTopics(long id, String assocTypeUri,
142                                                 String myRoleTypeUri, String othersRoleTypeUri, String othersTopicTypeUri);
143    
144        /**
145         * @param   id                  id of a topic or an association
146         * @param   assocTypeUri        may be null
147         * @param   myRoleTypeUri       may be null
148         * @param   othersRoleTypeUri   may be null
149         * @param   othersTopicTypeUri  may be null
150         */
151        List<RelatedAssociationModel> fetchRelatedAssociations(long id, String assocTypeUri,
152                                                 String myRoleTypeUri, String othersRoleTypeUri, String othersAssocTypeUri);
153    
154    
155    
156        // === Properties ===
157    
158        Object fetchTopicProperty(long topicId, String propUri);
159    
160        Object fetchAssociationProperty(long assocId, String propUri);
161    
162        // ---
163    
164        List<TopicModel> fetchTopicsByProperty(String propUri, Object propValue);
165    
166        List<TopicModel> fetchTopicsByPropertyRange(String propUri, Number from, Number to);
167    
168        List<AssociationModel> fetchAssociationsByProperty(String propUri, Object propValue);
169    
170        List<AssociationModel> fetchAssociationsByPropertyRange(String propUri, Number from, Number to);
171    
172        // ---
173    
174        void storeTopicProperty(long topicId, String propUri, Object propValue, boolean addToIndex);
175    
176        void storeAssociationProperty(long assocId, String propUri, Object propValue, boolean addToIndex);
177    
178        // ---
179    
180        boolean hasTopicProperty(long topicId, String propUri);
181    
182        boolean hasAssociationProperty(long assocId, String propUri);
183    
184        // ---
185    
186        void deleteTopicProperty(long topicId, String propUri);
187    
188        void deleteAssociationProperty(long assocId, String propUri);
189    
190    
191    
192        // === DB ===
193    
194        DeepaMehtaTransaction beginTx();
195    
196        boolean setupRootNode();
197    
198        void shutdown();
199    }