{"action":"created","issue":{"url":"https://api.github.com/repos/Syncleus/Ferma/issues/10","labels_url":"https://api.github.com/repos/Syncleus/Ferma/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/Syncleus/Ferma/issues/10/comments","events_url":"https://api.github.com/repos/Syncleus/Ferma/issues/10/events","html_url":"https://github.com/Syncleus/Ferma/issues/10","id":108375553,"number":10,"title":"OrientDB 2.1.x Transaction/Concurrency Compatibility","user":{"login":"Jotschi","id":326605,"avatar_url":"https://avatars.githubusercontent.com/u/326605?v=3","gravatar_id":"","url":"https://api.github.com/users/Jotschi","html_url":"https://github.com/Jotschi","followers_url":"https://api.github.com/users/Jotschi/followers","following_url":"https://api.github.com/users/Jotschi/following{/other_user}","gists_url":"https://api.github.com/users/Jotschi/gists{/gist_id}","starred_url":"https://api.github.com/users/Jotschi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jotschi/subscriptions","organizations_url":"https://api.github.com/users/Jotschi/orgs","repos_url":"https://api.github.com/users/Jotschi/repos","events_url":"https://api.github.com/users/Jotschi/events{/privacy}","received_events_url":"https://api.github.com/users/Jotschi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-25T17:45:44Z","updated_at":"2015-10-17T18:47:29Z","closed_at":null,"body":"OrientDB's transaction handling requires some workarounds to be applied in order to be used in combination with Ferma.\r\n\r\n* OrientGraph instances are not threadsafe. \r\n* A new transaction has to be created for each thread.\r\n* OrientDB Elements (eg.: OrientVertex) are not threafsafe. Thus the element has to be reloaded when switching threads of passing a ferma element from one thread to another.\r\n\r\nI created my own vertex frame which internally deals with some of those requirements:\r\n```java\r\npublic class OrientVertexFrame extends AbstractVertexFrame {\r\n\r\n\tprivate Object id;\r\n        // ThreadLocal which will hold the base element reference for each thread and \r\n       // reload the element if required.\r\n\tpublic ThreadLocal<Element> threadLocalElement = ThreadLocal.withInitial(() -> ((WrappedVertex)getGraph().getVertex(id)).getBaseElement());\r\n        \r\n        // ThreadLocal which will hold the current active graph (eg.: Transaction)\r\n\tpublic static ThreadLocal<FramedGraph> threadLocalGraph = new ThreadLocal<>();\r\n\r\n\t@Override\r\n\tprotected void init(FramedGraph graph, Element element) {\r\n\t\tsuper.init(graph, element);\r\n\t\tthis.id = element.getId();\r\n\t}\r\n\r\n\t@Override\r\n\tpublic Vertex getElement() {\r\n\t\tElement vertex = threadLocalElement.get();\r\n\r\n\t\t// Unwrap wrapped vertices\r\n\t\tif (vertex instanceof WrappedElement) {\r\n\t\t\tvertex = (Vertex) ((WrappedElement) vertex).getBaseElement();\r\n\t\t}\r\n\t\treturn (Vertex)vertex;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic FramedGraph getGraph() {\r\n\t\treturn new DelegatingFramedGraph<>(threadLocalGraph.get(), true, false);\r\n\t}\r\n}\r\n```\r\n\r\nTransactions should set the thread local and restore it within the duration of the transaction. I created an autoclosable which handles those transactions and updates to the threadlocal.\r\n"},"comment":{"url":"https://api.github.com/repos/Syncleus/Ferma/issues/comments/148942457","html_url":"https://github.com/Syncleus/Ferma/issues/10#issuecomment-148942457","issue_url":"https://api.github.com/repos/Syncleus/Ferma/issues/10","id":148942457,"user":{"login":"freemo","id":3033346,"avatar_url":"https://avatars.githubusercontent.com/u/3033346?v=3","gravatar_id":"","url":"https://api.github.com/users/freemo","html_url":"https://github.com/freemo","followers_url":"https://api.github.com/users/freemo/followers","following_url":"https://api.github.com/users/freemo/following{/other_user}","gists_url":"https://api.github.com/users/freemo/gists{/gist_id}","starred_url":"https://api.github.com/users/freemo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freemo/subscriptions","organizations_url":"https://api.github.com/users/freemo/orgs","repos_url":"https://api.github.com/users/freemo/repos","events_url":"https://api.github.com/users/freemo/events{/privacy}","received_events_url":"https://api.github.com/users/freemo/received_events","type":"User","site_admin":false},"created_at":"2015-10-17T18:47:29Z","updated_at":"2015-10-17T18:47:29Z","body":"Do you think this is something that might be useful as a part of Ferma? I\nwill have to take a closer look at it.\n\nOn Sat, Oct 17, 2015 at 2:46 PM, Johannes Schüth <notifications@github.com>\nwrote:\n\n> I create a small extension library which provides some abstract classes\n> and other useful stuff when dealing with transactions in ferma + orientdb.\n>\n> The project currently is just a collection of tests and classes. I have no\n> plan to release it. It can be used as a reference when using orientb with\n> ferma.\n>\n> https://github.com/Jotschi/ferma-orientdb-extension\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/Syncleus/Ferma/issues/10#issuecomment-148942423>.\n>\n"}}