best practice orient db connection (in web application)

379 views
Skip to first unread message

Giuseppe Annunziata

unread,
Jan 8, 2015, 10:09:56 AM1/8/15
to orient-...@googlegroups.com
Hello,
 I'm novice on OrientDB and I'd like to use it in a web application that write and read graph-like linked informations.
My question is about which is the best approach to create connection to an orientdb graph; this essentially depends on intimate OrientDB and its driver architecture.
I think there are three kinds of approach: 
- create a "connection" for each group of query/insert/update, then close/release it
- create a "connection" at start of web page elaboration, and close/release it
- create a "connection-less" reference and use it (like Jongo library do for MongoDB, that handle it transparently)

Which is the best? There are some other best approaches?


Emanuel

unread,
Jan 13, 2015, 6:34:23 AM1/13/15
to orient-...@googlegroups.com
Hi Giuseppe,

What are you using to write the web application ? is it java ? or other ? like you said depends a lot on the driver you use.

bye

Emanuel
--

---
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 orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Giuseppe Annunziata

unread,
Jan 14, 2015, 6:19:29 AM1/14/15
to orient-...@googlegroups.com
Hi Emanuel,
  basically Java platform, usually we use Play Framework! but sometimes we need to use Servlet containers (like Tomcat, Jetty, ecc.).

Thank you for interesting of.

Mathieu Bodin

unread,
Jan 14, 2015, 12:02:52 PM1/14/15
to
As far I can see in the documentation, you may use a Servlet Filter to set the database on the thread before an release it after. It correspond to the second approach. I don't know if there is other one, as I think that usage of the Java API tied you to ODatabaseRecordThreadLocal.INSTANCE as you will see later.

Beware, documentation will change (I hope) once 2.0 is released as all the pool stuff is changed.

Just ensure that ODatabaseRecordThreadLocal.INSTANCE.get() return something during the whole HTTP response computation. It should work correctly if you use one database, with one user.

When playing with SpringMVC, you do the same thing through an HandlerInterceptor. May be there is such thing in Play.

Thomas Müller

unread,
Jan 21, 2015, 3:12:33 AM1/21/15
to
I used following servlet filter in my ee 7 web application:

@WebFilter("/*")
public class OrientDBFilter implements Filter {

   
@Inject
   
OrientDbProducers odbProducer;

   
@Inject
   
Log log;

   
@Override
   
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException {

       
try {
            chain
.doFilter(request, response);
       
} catch (IOException e) {
           
throw new ServletException(e);
       
} finally {

           
ODatabaseDocumentInternal database = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
           
if (database != null) {

                database
.close();
               
ODatabaseRecordThreadLocal.INSTANCE.remove();
           
}
       
}
   
}

   
@Override
   
public void destroy() {

        odbProducer
.getGraphFactory().close();
   
}

   
@Override
   
public void init(FilterConfig filterConfig) throws ServletException {
   
}

}


Reply all
Reply to author
Forward
0 new messages