Sure,

hope this helps.

Regards,
  -Stefán

*Here is the graph Aware Context:*

package com.activitystream.ashistorical.graph;

import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import org.springframework.util.Assert;

public class TenantAwareContext {

    private static final ThreadLocal<OrientGraph> graph = new 
ThreadLocal<OrientGraph>();

    public static void setTenantGraph(OrientGraph tenantGraph) {
        Assert.notNull(tenantGraph, "Tenant must be set (No Tenant found 
for given domain?)");
        graph.set(tenantGraph);
    }

    public static OrientGraph getTenantGraph() {
        return graph.get();
    }

    public static void clearTenant() {
        graph.remove();
    }

}

*Here is the filter:*

package com.activitystream.ashistorical.graph;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TenantConnectionFilter implements HandlerInterceptor {

    public GraphManager graphManager;

    public TenantConnectionFilter(GraphManager graphManager) {
        this.graphManager = graphManager;
    }

    public TenantConnectionFilter() {
        logger.warn("damn");
    }

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, 
HttpServletResponse httpServletResponse, Object o) throws Exception {
        
TenantAwareContext.setTenantGraph(graphManager.getTenantGraph("mobilitus"));
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, 
HttpServletResponse httpServletResponse, Object o, ModelAndView 
modelAndView) throws Exception {
        TenantAwareContext.getTenantGraph().shutdown();
    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, 
HttpServletResponse httpServletResponse, Object o, Exception e) throws 
Exception {

    }
}

*Here is the graph manager:*

package com.activitystream.ashistorical.graph;

import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class GraphManager {

    private Map<String, OrientGraphFactory> openGraphs = new HashMap<>();

    public OrientGraph getTenantGraph(String tenant) {

        if (!openGraphs.containsKey(tenant)) {
            OrientGraphFactory factory = new 
OrientGraphFactory("plocal:/var/www/data/" + tenant).setupPool(1, 10);
            OrientGraph graph = factory.getTx();
            
graph.getRawGraph().getStorage().getConfiguration().dateTimeFormat = 
"yyyy-MM-dd HH:mm:ss:SSS";
            graph.getRawGraph().getStorage().getConfiguration().update();
            GraphModel.verify(graph);
            openGraphs.put(tenant, factory);
        }
        return openGraphs.get(tenant).getTx();
    }

}


On Thursday, 20 March 2014 16:15:00 UTC, Andrey Yesyev wrote:
>
> Could you please provide a code snippet?
>
> I'm using Spring MVC and this issue is in my Controllers. Looks like I'm 
> missing something here.
>
> On Thursday, March 20, 2014 11:42:26 AM UTC-4, [email protected]:
>>
>> Hi,
>>
>> I'm using Spring.
>>
>> To make sure connections were alive for the whole duration of request I 
>> had to but this into Filter and make it available as ThreadLocal connection.
>> That way any serialization, happening as a part of the custom REST API we 
>> have, can rely on the connection all the way.
>>
>> It's working for me without any problems.
>>
>> Hope this helps.
>>
>> Regards,
>>   -Stefán
>>
>>
>> On Thursday, 20 March 2014 15:32:43 UTC, Andrey Yesyev wrote:
>>>
>>> Well, this issue 
>>> https://github.com/orientechnologies/orientdb/issues/2135 is claimed to 
>>> be closed.
>>> I just updated my libs from maven and still experiencing this issue,
>>>
>>> On Thursday, March 20, 2014 10:09:22 AM UTC-4, 
>>> [email protected]:
>>>>
>>>> Hi,
>>>>
>>>> If you use maven then its version: "1.7-rc2-SNAPSHOT".
>>>>
>>>> Regards,
>>>>   -Stefan
>>>>
>>>> On Thursday, 20 March 2014 13:34:21 UTC, Andrey Yesyev wrote:
>>>>>
>>>>> Hi there,
>>>>>
>>>>> Guys, where I can get the latest updates and bug fixes?
>>>>> I'm interested in 1.7rc2
>>>>>
>>>>> Thanks!
>>>>>
>>>>> -Andrey
>>>>>
>>>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to