Thursday, December 12, 2013

How to retrieve a (graph connecion) static server variable from GWT RequestFactory

Hi,

I know this concern a bit more GWT...

I am developing my first CWT app. And i use RequestFactory.
I take the example from "GWT In action second Edition".

Inside the ContactService class where are the methods to access the database i wish to connect Neo4J Graph.
In th construstor i added this

/---------------------------------
         private static GraphDatabaseService graphDB;
public ContactService () {
String DB_PATH = "/home/myName/Developer/Workspace/MyGWTApp/DATA";
graphDB = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
}
 
/---------------------------------------------
I can CRUD with passing the static variable graphDB to the method, fetch(graphDB, id), persist(graphDB, c), and so on...
All is working well. The first time the constructor give me a link the the graph.

My problem is when i develop another service class by example FriendService i need again my connection to graphDB.
I cannot recreate the same thing with the constructor 

/---------------------------------
         private static GraphDatabaseService graphDB;
public FriendService () {
String DB_PATH = "/home/myName/Developer/Workspace/MyGWTApp/DATA";
graphDB = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
}
 
/---------------------------------------------
That is normal with Neo4J. I must retrieve only the value of my static variable graphDB.
But how to do that?

I trie to create a servlet like that
/********************************************
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;


public class Neo4jServletContextListener implements ServletContextListener{
 
public static GraphDatabaseService getGraphDB(ServletContext context) {
return (GraphDatabaseService) context.getAttribute("neo4j");
}
@Override
public void contextDestroyed(ServletContextEvent arg0) {
getGraphDB(arg0.getServletContext()).shutdown();
//System.out.println("ServletContextListener destroyed");
}
 
@Override
public void contextInitialized(ServletContextEvent arg0) {
String DB_PATH = "/home/myName/Developer/Workspace/MyGWTApp/DATA";
GraphDatabaseService graphDB = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
ServletContext context = arg0.getServletContext();
context.setAttribute ("neo4j", graphDB);
//System.out.println("ServletContextListener started");
}
}
/***********************************************************
But it is impossible to make this
graphDB = (GraphDatabaseService) getServletContext().getAttribute("neo4j");

Could you help me please.
Thanks.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate