Configuration for db embedded in web app

169 views
Skip to first unread message

Argh Skwidge

unread,
Jul 9, 2014, 7:48:46 AM7/9/14
to orient-...@googlegroups.com
So I've just started playing with OrientDB and I want to embed it in a Java web app. That part has proved fairly easy, but I'm a little confused about how best to manage configuration.

Essentially I've followed the filter pattern shown at https://code.google.com/p/orient/wiki/JavaWebApps . This gives me an OrientGraph instance per request object, which is great. These instructions don't really cover database-wide configuration though, of the type I would put in an orientdb-server-config.xml file in other circumstances.

I did find https://github.com/orientechnologies/orientdb/wiki/Embedded-Server and https://github.com/orientechnologies/orientdb/wiki/Configuration which seem to be two different ways of doing the same thing - global configuration. Both pages were last edited on the same day.

How should I be doing global configuration in my web app?

Andrey Kovalev

unread,
Jul 9, 2014, 11:33:22 AM7/9/14
to orient-...@googlegroups.com
In my opinion developers of OrientDB won't be able to advice you what to do. Also you provided not too much information about your environment.
Do you use any framework? Do you use any web server and etc? 

Let's say you have Tomcat only and you use servlets. I would initialize OrientDB database pool in application initialization/deployment listener and put it into application context. And then in your DAOs I will call getTx() or aquire() each time. Something like this.

Argh Skwidge

unread,
Jul 10, 2014, 6:15:22 AM7/10/14
to orient-...@googlegroups.com
OK, A little more info.

I'm developing RESTful services in a Tomcat 7 container. I'm probably going to use Jersey for the REST and Guice for injection - but I'm not committed to these frameworks just yet, I will use something else if it plays better with OrientDB.

I'm adding an OrientGraph instance to each request using the filter pattern given in https://code.google.com/p/orient/wiki/JavaWebApps. I'm using the OrientGraph constructor though:

OrientGraph graph = new OrientGraph(dbUrl, username, password);

and cleaning up when the filter returns with:

graph.shutdown();

This is because I want to make use of the record level security [ https://github.com/orientechnologies/orientdb/wiki/Security ] as it seems like such an elegant solution to the problem of insecure direct object references. [ https://www.owasp.org/index.php/Top_10_2013-A4-Insecure_Direct_Object_References ] Factory methods like acquire() and getTx() don't allow me to use different authentication values each time, so I would end up having to write my own security model all over again (why re-invent the wheel?)

I planned to use container-managed authentication, so I am creating an OrientDB Realm [ http://tomcat.apache.org/tomcat-7.0-doc/realm-howto.html ] which will look up OUser and ORule records using with a global read-only account. (Probably just, "reader".)

I would like, eventually, to be able to configure things like clustering, backup, remote access ports for administration, logging, pools, caches, etc... at an application-wide level. This presumably should be done before I create any OrientGraph instances.

I can find suitable hooks in Tomcat to make sure this happens in a timely fashion. But where are the correct hooks in OrientDB?

Argh Skwidge

unread,
Jul 10, 2014, 6:31:01 AM7/10/14
to orient-...@googlegroups.com
Oh, and I'm using the latest release version of OrientDB (1.7.4) as imported by Apache Ivy.

Artem Orobets

unread,
Jul 10, 2014, 8:35:08 AM7/10/14
to orient-...@googlegroups.com
Hi Argh,

It is not clear how do you connect to the database.

There is 3 different ways to use orientdb
  • Embedded mode. When you connection url starts with "plocal:"
  • You start OrientDB server separately. In this case your connection url starts with "remote:"
  • You embed a server into your application so it runs on the same JVM as your application. This is the way that you have found there
What approach do you use? 


Best regards,
Artem Orobets

Orient Technologies

the Company behind OrientDB



--

---
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.

Andrey Kovalev

unread,
Jul 10, 2014, 2:08:59 PM7/10/14
to orient-...@googlegroups.com
Check my question here
You are right, there is no beautiful way to authenticate different users in orientdb. I think currently you should go with a common web approach, you must create one db user with WRITER/READER role and connect to db under this user.

In my opinion Filter approach is not the best one. It is better to initialize db pool in one of the application listeners. Also if you have just started take a look at this project. Probably it is more suitable for your standalone application.
Also I think you may try to create a custom OrientDB resource class. So db pool will be available straight away after deployment of your application. Check here.

Argh Skwidge

unread,
Jul 11, 2014, 2:21:38 AM7/11/14
to orient-...@googlegroups.com
I am using embedded mode, with a plocal URL.

String dbUrl = "plocal:/orientdb-community-1.7.4/databases/GratefulDeadConcerts";
OrientGraph graph = new OrientGraph(dbUrl, dbUser, dbPass);

Artem Orobets

unread,
Jul 11, 2014, 6:00:55 AM7/11/14
to orient-...@googlegroups.com
Hi Argh,

In this case you can only configure Orient with OGlobalConfiguration before db is opened.

However, if you want to configure sharding you have to start a separate server or embed a server into your application.

Best regards,
Artem Orobets

Orient Technologies

the Company behind OrientDB



--

Argh Skwidge

unread,
Jul 11, 2014, 7:26:32 AM7/11/14
to orient-...@googlegroups.com
Thanks, that was the answer I was looking for.


On Friday, 11 July 2014 22:00:55 UTC+12, Artem Orobets wrote:
Hi Argh,

In this case you can only configure Orient with OGlobalConfiguration before db is opened.

However, if you want to configure sharding you have to start a separate server or embed a server into your application.
Reply all
Reply to author
Forward
0 new messages