001 package de.deepamehta.core.storage.spi; 002 003 import de.deepamehta.core.model.AssociationModel; 004 import de.deepamehta.core.model.DeepaMehtaObjectModel; 005 import de.deepamehta.core.model.IndexMode; 006 import de.deepamehta.core.model.RelatedAssociationModel; 007 import de.deepamehta.core.model.RelatedTopicModel; 008 import de.deepamehta.core.model.SimpleValue; 009 import de.deepamehta.core.model.TopicModel; 010 011 import java.util.Iterator; 012 import java.util.List; 013 014 015 016 public 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 List<AssociationModel> fetchAssociations(String assocTypeUri, long topicId1, long topicId2, String roleTypeUri1, 078 String roleTypeUri2); 079 080 List<AssociationModel> fetchAssociationsBetweenTopicAndAssociation(String assocTypeUri, long topicId, long assocId, 081 String topicRoleTypeUri, String assocRoleTypeUri); 082 083 Iterator<AssociationModel> fetchAllAssociations(); 084 085 long[] fetchPlayerIds(long assocId); 086 087 // --- 088 089 void storeAssociation(AssociationModel assocModel); 090 091 void storeAssociationUri(long assocId, String uri); 092 093 void storeAssociationTypeUri(long assocId, String assocTypeUri); 094 095 /** 096 * Stores and indexes an association value. 097 * 098 * @param indexValue Optional: the value to be indexed. If indexValue is not specified, value is used. 099 */ 100 void storeAssociationValue(long assocId, SimpleValue value, List<IndexMode> indexModes, String indexKey, 101 SimpleValue indexValue); 102 103 void indexAssociationValue(long assocId, IndexMode indexMode, String indexKey, SimpleValue indexValue); 104 105 void storeRoleTypeUri(long assocId, long playerId, String roleTypeUri); 106 107 // --- 108 109 void deleteAssociation(long assocId); 110 111 112 113 // === Generic Object === 114 115 DeepaMehtaObjectModel fetchObject(long id); 116 117 118 119 // === Traversal === 120 121 List<AssociationModel> fetchTopicAssociations(long topicId); 122 123 List<AssociationModel> fetchAssociationAssociations(long assocId); 124 125 // --- 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<RelatedTopicModel> fetchTopicRelatedTopics(long topicId, String assocTypeUri, 134 String myRoleTypeUri, String othersRoleTypeUri, String othersTopicTypeUri); 135 136 /** 137 * @param assocTypeUri may be null 138 * @param myRoleTypeUri may be null 139 * @param othersRoleTypeUri may be null 140 * @param othersTopicTypeUri may be null 141 */ 142 List<RelatedAssociationModel> fetchTopicRelatedAssociations(long topicId, String assocTypeUri, 143 String myRoleTypeUri, String othersRoleTypeUri, String othersAssocTypeUri); 144 145 // --- 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<RelatedTopicModel> fetchAssociationRelatedTopics(long assocId, String assocTypeUri, 154 String myRoleTypeUri, String othersRoleTypeUri, String othersTopicTypeUri); 155 156 /** 157 * @param assocTypeUri may be null 158 * @param myRoleTypeUri may be null 159 * @param othersRoleTypeUri may be null 160 * @param othersTopicTypeUri may be null 161 */ 162 List<RelatedAssociationModel> fetchAssociationRelatedAssociations(long assocId, String assocTypeUri, 163 String myRoleTypeUri, String othersRoleTypeUri, String othersAssocTypeUri); 164 165 // --- 166 167 /** 168 * @param objectId id of a topic or an association 169 * @param assocTypeUri may be null 170 * @param myRoleTypeUri may be null 171 * @param othersRoleTypeUri may be null 172 * @param othersTopicTypeUri may be null 173 */ 174 List<RelatedTopicModel> fetchRelatedTopics(long objectId, String assocTypeUri, 175 String myRoleTypeUri, String othersRoleTypeUri, String othersTopicTypeUri); 176 177 /** 178 * @param objectId id of a topic or an association 179 * @param assocTypeUri may be null 180 * @param myRoleTypeUri may be null 181 * @param othersRoleTypeUri may be null 182 * @param othersTopicTypeUri may be null 183 */ 184 List<RelatedAssociationModel> fetchRelatedAssociations(long objectId, String assocTypeUri, 185 String myRoleTypeUri, String othersRoleTypeUri, String othersAssocTypeUri); 186 187 188 189 // === Properties === 190 191 /** 192 * @param id id of a topic or an association 193 */ 194 Object fetchProperty(long id, String propUri); 195 196 /** 197 * @param id id of a topic or an association 198 */ 199 boolean hasProperty(long id, String propUri); 200 201 // --- 202 203 List<TopicModel> fetchTopicsByProperty(String propUri, Object propValue); 204 205 List<TopicModel> fetchTopicsByPropertyRange(String propUri, Number from, Number to); 206 207 List<AssociationModel> fetchAssociationsByProperty(String propUri, Object propValue); 208 209 List<AssociationModel> fetchAssociationsByPropertyRange(String propUri, Number from, Number to); 210 211 // --- 212 213 void storeTopicProperty(long topicId, String propUri, Object propValue, boolean addToIndex); 214 215 void storeAssociationProperty(long assocId, String propUri, Object propValue, boolean addToIndex); 216 217 // --- 218 219 void deleteTopicProperty(long topicId, String propUri); 220 221 void deleteAssociationProperty(long assocId, String propUri); 222 223 224 225 // === DB === 226 227 DeepaMehtaTransaction beginTx(); 228 229 boolean setupRootNode(); 230 231 void shutdown(); 232 233 // --- 234 235 Object getDatabaseVendorObject(); 236 237 Object getDatabaseVendorObject(long objectId); 238 }