Dynamic EntityManagerFactory creation and RequestFactory service stubs problem
Hi, we would like to integrate GWT 2.1 RequestFactory in our application. Our application's backend uses JPA and has one database per customer. So we have to tell our EntityManagerFactory which database it should use, depending on the customer who did the server request. Currently we have http://our-app.com/ as application URL and we send to our backend on each request. That way we can construct an EntityManagerFactory with a custom properties map which contains a datasource name similar to "appdatasource-". So every time we got a new customer, we just have to add a new JDBC resource and connection pool which points to the new customers database to our J2EE server. So we tried this approach with RequestFactory and defined our service interface like this: @Service(Person.class) public interface PersonRequest extends RequestContext { Request> findAllPersons(String uniqueCustomerName); Request> findPersonsByAge(int min, int max, String uniqueCustomerName); InstanceRequest persist(String uniqueCustomerName); InstanceRequest remove(String uniqueCustomerName); Request findPerson(Long id); } So everything is fine except the method "Request findPerson(Long id)" which is required by the GWT RequestFactory servlet. So we can't add a second parameter to this method. But this second parameter is required for our dynamic EntityManagerFactory configuration. Are there any plans for a GWT 2.1.x release which supports such a scenario? It would be nice if the required findEntity method would support additional custom parameters (maybe via Java5 VarArgs) or if there is a way to transport additional information from client to server during a RequestFactory request which can then be accessed during server side method execution. Does anybody have an idea for a nasty workaround for that problem that is possible with the current GWT 2.1 implementation? -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Re: Dynamic EntityManagerFactory creation and RequestFactory service stubs problem
On 6 nov, 19:26, Jack wrote: > Hi, > > we would like to integrate GWT 2.1 RequestFactory in our application. > Our application's backend uses JPA and has one database per customer. > So we have to tell our EntityManagerFactory which database it should > use, depending on the customer who did the server request. > Currently we havehttp://our-app.com/ as > application URL and we send to our backend on > each request. That way we can construct an EntityManagerFactory with a > custom properties map which contains a datasource name similar to > "appdatasource-". So every time we got a new > customer, we just have to add a new JDBC resource and connection pool > which points to the new customers database to our J2EE server. > > So we tried this approach with RequestFactory and defined our service > interface like this: > > @Service(Person.class) > public interface PersonRequest extends RequestContext { > > Request> findAllPersons(String > uniqueCustomerName); > > Request> findPersonsByAge(int min, int max, String > uniqueCustomerName); > > InstanceRequest persist(String > uniqueCustomerName); > > InstanceRequest remove(String > uniqueCustomerName); > > Request findPerson(Long id); > > } > > So everything is fine except the method "Request > findPerson(Long id)" which is required by the GWT RequestFactory > servlet. So we can't add a second parameter to this method. But this > second parameter is required for our dynamic EntityManagerFactory > configuration. > > Are there any plans for a GWT 2.1.x release which supports such a > scenario? The changes to expect are listed in http://code.google.com/p/google-web-toolkit/wiki/RequestFactory_2_1_1 > It would be nice if the required findEntity method would > support additional custom parameters (maybe via Java5 VarArgs) or if > there is a way to transport additional information from client to > server during a RequestFactory request which can then be accessed > during server side method execution. > > Does anybody have an idea for a nasty workaround for that problem that > is possible with the current GWT 2.1 implementation? One that I wouldn't call "nasty": 1. extend DefaultRequestTransport to send the uniqueCustomerName (say, within an HTTP header) 2. initialize() your RequestFactory with an instance of your extended RequestTransport 3. on the server-side, get the HttpServletRequest using RequestFactoryServlet.getThreadLocalRequest(), to extract the uniqueCustomerName from it and use it to create the EntityManagerFactory. That way, you don't have to send the uniqueCustomerName explicitly in each and every request, it'll be done automatically and transparently by your RequestTransport. -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Re: Dynamic EntityManagerFactory creation and RequestFactory service stubs problem
Oh that sounds pretty nice. Haven't realized that its possible that way.. hehe..and its not nasty at all :) I'll give it a try. Thanks! And a second question that comes to my mind: When using RequestFactory our domain objects are only defined by interfaces. Is there a class in the framework that posts some sort of PropertyChangeEvent on the provided EventBus whenever a property is changed on client-side (This event should be fired whenever a setter method is called on client side). If not is there a way to integrate such a feature? I asks this because currently we have an own simple binding system which synchronizes UI and domain objects using PropertyChangeEvents fired by the domain object. Of cause we could use the new Editor Framework but it would be nice to do a step by step transition. On 6 Nov., 21:35, Thomas Broyer wrote: > On 6 nov, 19:26, Jack wrote: > > > > > > > Hi, > > > we would like to integrate GWT 2.1 RequestFactory in our application. > > Our application's backend uses JPA and has one database per customer. > > So we have to tell our EntityManagerFactory which database it should > > use, depending on the customer who did the server request. > > Currently we havehttp://our-app.com/ as > > application URL and we send to our backend on > > each request. That way we can construct an EntityManagerFactory with a > > custom properties map which contains a datasource name similar to > > "appdatasource-". So every time we got a new > > customer, we just have to add a new JDBC resource and connection pool > > which points to the new customers database to our J2EE server. > > > So we tried this approach with RequestFactory and defined our service > > interface like this: > > > @Service(Person.class) > > public interface PersonRequest extends RequestContext { > > > Request> findAllPersons(String > > uniqueCustomerName); > > > Request> findPersonsByAge(int min, int max, String > > uniqueCustomerName); > > > InstanceRequest persist(String > > uniqueCustomerName); > > > InstanceRequest remove(String > > uniqueCustomerName); > > > Request findPerson(Long id); > > > } > > > So everything is fine except the method "Request > > findPerson(Long id)" which is required by the GWT RequestFactory > > servlet. So we can't add a second parameter to this method. But this > > second parameter is required for our dynamic EntityManagerFactory > > configuration. > > > Are there any plans for a GWT 2.1.x release which supports such a > > scenario? > > The changes to expect are listed > inhttp://code.google.com/p/google-web-toolkit/wiki/RequestFactory_2_1_1 > > > It would be nice if the required findEntity method would > > support additional custom parameters (maybe via Java5 VarArgs) or if > > there is a way to transport additional information from client to > > server during a RequestFactory request which can then be accessed > > during server side method execution. > > > Does anybody have an idea for a nasty workaround for that problem that > > is possible with the current GWT 2.1 implementation? > > One that I wouldn't call "nasty": > 1. extend DefaultRequestTransport to send the uniqueCustomerName (say, > within an HTTP header) > 2. initialize() your RequestFactory with an instance of your extended > RequestTransport > 3. on the server-side, get the HttpServletRequest using > RequestFactoryServlet.getThreadLocalRequest(), to extract the > uniqueCustomerName from it and use it to create the > EntityManagerFactory. > That way, you don't have to send the uniqueCustomerName explicitly in > each and every request, it'll be done automatically and transparently > by your RequestTransport. -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Re: Dynamic EntityManagerFactory creation and RequestFactory service stubs problem
Ok it works like a charm with a custom RequestTransport and a custom header. Thanks for that tip! But RequestFactory docs should really mention what to add to web.xml and that you need a json implementation from json.org and a javax.validation implementation in your server classpath to make things work with Eclipse + GWT Plugin + Jetty. Otherwise you got some nice java.lang.NoClassDefFoundError from jetty. On 6 Nov., 21:35, Thomas Broyer wrote: > On 6 nov, 19:26, Jack wrote: > > > > > > > Hi, > > > we would like to integrate GWT 2.1 RequestFactory in our application. > > Our application's backend uses JPA and has one database per customer. > > So we have to tell our EntityManagerFactory which database it should > > use, depending on the customer who did the server request. > > Currently we havehttp://our-app.com/ as > > application URL and we send to our backend on > > each request. That way we can construct an EntityManagerFactory with a > > custom properties map which contains a datasource name similar to > > "appdatasource-". So every time we got a new > > customer, we just have to add a new JDBC resource and connection pool > > which points to the new customers database to our J2EE server. > > > So we tried this approach with RequestFactory and defined our service > > interface like this: > > > @Service(Person.class) > > public interface PersonRequest extends RequestContext { > > > Request> findAllPersons(String > > uniqueCustomerName); > > > Request> findPersonsByAge(int min, int max, String > > uniqueCustomerName); > > > InstanceRequest persist(String > > uniqueCustomerName); > > > InstanceRequest remove(String > > uniqueCustomerName); > > > Request findPerson(Long id); > > > } > > > So everything is fine except the method "Request > > findPerson(Long id)" which is required by the GWT RequestFactory > > servlet. So we can't add a second parameter to this method. But this > > second parameter is required for our dynamic EntityManagerFactory > > configuration. > > > Are there any plans for a GWT 2.1.x release which supports such a > > scenario? > > The changes to expect are listed > inhttp://code.google.com/p/google-web-toolkit/wiki/RequestFactory_2_1_1 > > > It would be nice if the required findEntity method would > > support additional custom parameters (maybe via Java5 VarArgs) or if > > there is a way to transport additional information from client to > > server during a RequestFactory request which can then be accessed > > during server side method execution. > > > Does anybody have an idea for a nasty workaround for that problem that > > is possible with the current GWT 2.1 implementation? > > One that I wouldn't call "nasty": > 1. extend DefaultRequestTransport to send the uniqueCustomerName (say, > within an HTTP header) > 2. initialize() your RequestFactory with an instance of your extended > RequestTransport > 3. on the server-side, get the HttpServletRequest using > RequestFactoryServlet.getThreadLocalRequest(), to extract the > uniqueCustomerName from it and use it to create the > EntityManagerFactory. > That way, you don't have to send the uniqueCustomerName explicitly in > each and every request, it'll be done automatically and transparently > by your RequestTransport. -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Re: Dynamic EntityManagerFactory creation and RequestFactory service stubs problem
On 7 nov, 02:56, Jack wrote: > Ok it works like a charm with a custom RequestTransport and a custom > header. Thanks for that tip! > > But RequestFactory docs should really mention what to add to web.xml > and that you need a json implementation from json.org and a > javax.validation implementation in your server classpath to make > things work with Eclipse + GWT Plugin + Jetty. Otherwise you got some > nice java.lang.NoClassDefFoundError from jetty. You can use the gwt-servlet-deps.jar which includes those required dependencies (unless you're using Maven, in which case you'd add dependencies to javax.validation and json in your pom) -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Re: Dynamic EntityManagerFactory creation and RequestFactory service stubs problem
On 7 nov, 00:46, Jack wrote: > Oh that sounds pretty nice. Haven't realized that its possible that > way.. hehe..and its not nasty at all :) > I'll give it a try. Thanks! > > And a second question that comes to my mind: > When using RequestFactory our domain objects are only defined by > interfaces. Is there a class in the framework that posts some sort of > PropertyChangeEvent on the provided EventBus whenever a property is > changed on client-side (This event should be fired whenever a setter > method is called on client side). If not is there a way to integrate > such a feature? On each setter call, no (this is because a RequestContext is a kind of "transaction": it accumulates changes to entity proxies and method calls on the RequestContext –currently limited to a single method call AFAIK– to later send them all in one go to the server when you call fire()). When the server responds, it tells the client to fire EntityProxyChange events on the event bus, those are the ones you'll listen to to update the rest of your app. At least this is how I understand how it's supposed to be! -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.