172 | | * {{{<T> T findValue(ResourceRefR4 ref, Key<T> key) throws ResponseException}}} -> The same as the above but for the current revision. This method is the server alternative of ResourceAccess.getRaw(Key<T>).. |
| 172 | * {{{<T> T findValue(ResourceRefR4 ref, Key<T> key) throws ResponseException}}} -> The same as the above but for the current revision. This method is the server alternative of ResourceAccess.getRaw(Key<T>). |
| 173 | * {{{List<HistoryEntry> findHistory(ResourceRefR4 ref, RevisionId from, RevisionId to, int offset, int limit) throws ResponseException}}} -> Retrieves the history for a given resource in given state of its existence. Needed for syncing from the Facade. |
| 174 | * {{{public RevisionId changeResource(ResourceRefR4 ref, Change change) throws ResponseException}}} -> Registers change, alternative to the ResourcesAccess' registerChange method. |
| 175 | * Implementations: |
| 176 | * [browser:branches/private/tsachev/paragraphs/modules/org.sophie2.base.connectivity/src/main/java/org/sophie2/base/connectivity/resources/ResourceServiceAccessImpl.java ResourceServiceAccessImpl] -> The implementation till now, using the mem accesses. The old logic stays here... |
| 177 | * [browser:branches/private/tsachev/paragraphs/modules/org.sophie2.server.core/src/main/java/org/sophie2/server/core/persistence/db/ResourceServiceDBImpl.java ResourceServiceDBImpl] -> The new logic for managing the resource model on server: |
| 178 | * Needed classes to turn the resource object model (Keys, ResourceModels, Changes, Immutables, etc..) to storable in the DB data. |
| 179 | * Keys -> The have values and ids, in the database there are only simple ids, the table that connects resource, revision, and key with value needs the key parts to be iterated (and if the path is not existing to be created in the DB, if the server receive key path it is already created by a changer...) and for the last part of for the given sub-resource to be set the new value, or read a value from the DB. |
| 180 | * Resources -> The same as the keys, making new resource is just set of a children key. |
| 181 | * Revisions -> Their id is storable in the database (String) and their causing Changes are immutables. |
| 182 | * Immutables -> Using the Persistence API they are stored to XML or binary data, that is passed as a stream (IO Reader) to the JDBC API, which can handle it. |
| 183 | * So the only problem is finding a key path in the database and creating the missing paths (Resources) if any for it... |
| 184 | * For that thing is used the class [browser:branches/private/tsachev/paragraphs/modules/org.sophie2.server.core/src/main/java/org/sophie2/server/core/persistence/db/ResourceChangeHierarchy.java ResourceChangeHierarchy]. It iterates by the Key parts and devides them to paths to Resource and normal paths, for the last part of the key it build the resource path in the database and at that stage the ResourceDAO's methods with key paths and resource paths can be used. The hierarchy uses [browser:branches/private/tsachev/paragraphs/modules/org.sophie2.server.core/src/main/java/org/sophie2/server/core/persistence/db/ResourceVisitor.java ResourceVisitor]s to update or check resources and retrieve, update, set, check keys. The visitors have two methods - visitResource and visitKey. |
| 185 | * Finding values: |
| 186 | * The service uses the hierarchy with a special visitor [browser:branches/private/tsachev/paragraphs/modules/org.sophie2.server.core/src/main/java/org/sophie2/server/core/persistence/db/ReadKeyVisitor.java ReadKeyVisitor] which reads a key from the DB. It visitResource method don't do anything, but the {{{public void visitKey(String resourcePath, String keyPath, Object value) throws ResponseException}}} method uses the built from the hierarchy resource path and keyPath with the findValue method of the ResourceDAO to directly retrieve the value of the key from the database. There two problems here, the Children and Root keys, that are not kept just as immutable values in the database. For that reason this visitor extends the [browser:branches/private/tsachev/paragraphs/modules/org.sophie2.server.core/src/main/java/org/sophie2/server/core/persistence/db/RootAndChildrenVisitor.java RootAndChildrenVisitor] class.which handles them with the findResourceKeys and findChildResources methods from the ResourceDAO. |
| 187 | * All key based visitors extend the [browser:branches/private/tsachev/paragraphs/modules/org.sophie2.server.core/src/main/java/org/sophie2/server/core/persistence/db/KeyResourceVisitor.java KeyResourceVisitor] Which devides the keys to three kind - regular/children/roots because their values in the database are set or retrieved differently. |
| 188 | * Finding the history. This thing is simple, the findHistory method of the ResourceDAO is directly used and then the String representations of the changes in the database are converted to Change objects with the Sophie 2 Persistence API. |
| 189 | * Doing changes -> The third function of the service is more complicate because of the different types of the changes, so it will be described in a different section. |