I am interested in generating gwt rpc consumable code from sql2java. Going through velocity template files and looks like it is a not a simple task for new bee.
Wondering if anyone had done this before.
Thanks
Balaji
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't have any experience with GWT RPC coding but I can join your effort.
As maintainer for the actual velocity templates, I have some experience about the way to get information from the database model to the code to be generated. However I will need some example code from you in order to prepare the templates.
Could you provide me with the DDL script of your table and the resulting code you would expect to be generated?
Regards,
Alain
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Rpc is a bridge between client and server. We need java code at both the end.
Let us say the client needs couple of Planets, an async request is raised; and the client continues its work. The request is sent to a servlet in the server. This does required processing and returns a planet or a list of planets. Back in the client, a pre-specified function is invoked by passing the planet data that came from the server.
${pkg}.client.Planet.java is equivalent to PlanetBean.java
if PlanetBean.java is a pure pojo without any extra lib reference, then we can use the same. Otherwise Planet.java will be specific to gwt rpc communication. Planet.java will be serialized.
// this kind of interface will be perTable
// PlanetFetcher is like PlanetManager - just in the client side
package ${pkg}.client;
public interface PlanetFetcher extends RemoteService {
public Planet[] loadAll(int startRow, int numRows);
// all PlanetManager methods will be listed here
}
// for each Fetcher interface
package ${pkg}.client;
interface PlanetFetcherAsync {
public void loadAll(int startRow, int numRows, AsyncCallback callback);
// .. repeat for all methods
}
// for each Fetcher, in the server side :
package ${pkg}.server;
public class PlanetFetcherImpl extends RemoteServiceServlet implements
PlanetFetcher {
Planet[] planets = new Planet[planetBeans.length];
for(int i = 0; i < planetBeans.length; i++)
{
planets[i] = createPlanet(planetBeans[i]); // transform the data
}
return planets;
}
// Instead of above logic where PlanetFetcher using PlanetManager,
// PlanetFetcher can be written us a replica of PlanetManager - except for the return datatype + inheritence
// This option need to be checked against maintaining the two files.
// If this kind of code generation is feasible thru some kind of programming, that will be a big plus.
// repeat for all methods
}
Above 4 classes (including Planet.java) will be created on a perTable basis.
We can have one helper class for all tables. this is perSchema stuff
package ${pkg}.client;
class DataFetcher
{
// copy the following into server side web.xml
/*
<servlet>
<servlet-name>PlanetFetcher</servlet-name>
<servlet-class>${pkg}.server.PlanetFetcherImpl</servlet-class>
</servlet>
Note that the java code under ${pkg}.client are not actually java. They are waiting to be converted to javascript. So, these code has some limitation in terms of usage.
The List, Map kind of objects need annotation like :
/**
* This field is a Map that must always contain Strings as its keys and
* values.
*
* @gwt.typeArgs <java.lang.String,java.lang.String>
*/
public Map mapOfStringToString;
All sql2java generated code will go under ${pkg}.server.somewhere
sql2java + Gwt RPC
------------------
Looks like adding these template files should satisfy our need. I wasn't sure how to handle differing package dir like client and server; hence I raised the request in the forum.
Regards
Balaji
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am interested in generating gwt rpc consumable code from sql2java. Going through velocity template files and looks like it is a not a simple task for new bee.
Wondering if anyone had done this before.
Thanks
Balaji
Hi Balaji,
I don't have any experience with GWT RPC coding but I can join your effort.
As maintainer for the actual velocity templates, I have some experience about the way to get information from the database model to the code to be generated. However I will need some example code from you in order to prepare the templates.
Could you provide me with the DDL script of your table and the resulting code you would expect to be generated?
Regards,
Alain
Hi Alain,
Thanks for your prompt response. I had put my thoughts in this write up. Hope it is clear and useful.
a sample table
create table Planet (
planetName varchar(50),
weight int(8)
);
Standard sql2java
---------------
Out of many files generated the following are of my interest
PlanetBean.java
PlanetManager.java
Gwt RPC
--------
http://code.google.com/webtoolkit/documentation/com.google.gwt.doc.DeveloperGuide.RemoteProcedureCalls.html
will be accurate than my understanding given here. Guess you would have seen the design diagram there.
Rpc is a bridge between client and server. We need java code at both the end.
Let us say the client needs couple of Planets, an async request is raised; and the client continues its work. The request is sent to a servlet in the server. This does required processing and returns a planet or a list of planets. Back in the client, a pre-specified function is invoked by passing the planet data that came from the server.
${pkg}.client.Planet.java is equivalent to PlanetBean.java
if PlanetBean.java is a pure pojo without any extra lib reference, then we can use the same. Otherwise Planet.java will be specific to gwt rpc communication. Planet.java will be serialized.
// this kind of interface will be perTable
// PlanetFetcher is like PlanetManager - just in the client side
package ${pkg}.client;
public interface PlanetFetcher extends RemoteService {
public Planet[] loadAll(int startRow, int numRows);
// all PlanetManager methods will be listed here
}
// for each Fetcher interface
package ${pkg}.client;
interface PlanetFetcherAsync {
public void loadAll(int startRow, int numRows, AsyncCallback callback);
// .. repeat for all methods
}
// for each Fetcher, in the server side :
package ${pkg}.server;
public class PlanetFetcherImpl extends RemoteServiceServlet implements
PlanetFetcher {
public Planet[] loadAll()
{
PlanetManager planetManager = PlanetManager.getInstance();
PlanetBean[] planetBeans = planetManager.loadAll();
Planet[] planets = new Planet[planetBeans.length];
for(int i = 0; i < planetBeans.length; i++)
{
planets[i] = createPlanet(planetBeans[i]); // transform the data
}
return planets;
}
// Instead of above logic where PlanetFetcher using PlanetManager,
// PlanetFetcher can be written us a replica of PlanetManager - except for the return datatype + inheritence
// This option need to be checked against maintaining the two files.
// If this kind of code generation is feasible thru some kind of programming, that will be a big plus.
// repeat for all methods
}
Above 4 classes (including Planet.java) will be created on a perTable basis.
We can have one helper class for all tables. this is perSchema stuff
package ${pkg}.client;
class DataFetcher
{
// copy the following into server side web.xml
/*
<servlet>
<servlet-name>PlanetFetcher</servlet-name>
<servlet-class>${pkg}.server.PlanetFetcherImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PlanetFetcher</servlet-name>
<url-pattern>/PlanetFetcher</url-pattern>
</servlet-mapping>
... repeat for each table
*/
// copy the following into module.xml
/*
<servlet path="/PlanetFetcher" class="${pkg}.server.PlanetFetcherImpl"/>
... repeat for each table
*/
public static PlanetFetcherAsync getPlanetFetcherAsync()
{
PlanetFetcherAsync svc = (PlanetFetcherAsync) GWT.create(PlanetFetcher.class);
ServiceDefTarget endpoint = (ServiceDefTarget) svc;
endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "PlanetFetcher");
return svc;
}
// repeat getFetcherAsync() for all table
}
Note that the java code under ${pkg}.client are not actually java. They are waiting to be converted to javascript. So, these code has some limitation in terms of usage.
The List, Map kind of objects need annotation like :
/**
* This field is a Map that must always contain Strings as its keys and
* values.
*
* @gwt.typeArgs <java.lang.String,java.lang.String>
*/
public Map mapOfStringToString;
All sql2java generated code will go under ${pkg}.server.somewhere
sql2java + Gwt RPC
------------------
Looks like adding these template files should satisfy our need. I wasn't sure how to handle differing package dir like client and server; hence I raised the request in the forum.
Regards
Balaji