Re: Feedback on Java Code Generator

"Shawn Hartsock" <[email protected]>
Newsgroups gmane.org.user-groups.trijug.juglist
Message-ID <[email protected]>
I don't know if this answers all your questions or not... but I've hit
on a combination in the last six months that is very promising,
shallow learning curve, and reasonably easy to maintain.

What I've been doing depends on the case:

A) Assuming there is an existing database and need for new CRUD interfaces:
  1) reverse engineer EJB3 Entity beans with JPA annotated classes
using the Hibernate3 reverse engineer tool
  2) incorporate the EJB3 Entity beans into Groovy & Grails, the data
model is straight Java... the rest will be Groovy... see:
http://hartsock.blogspot.com/2007/11/groovy-grails-and-jpa.html
  3) Use grails to auto generate initial Controllers and Views and
graft on new features as requested.

B) Assuming there is no data model You start in groovy and stay there.
Use the Grails ORM DSL to create "compliant" mappings that match
database conventions for the company you are working with.

If you have scenario A (which is unfortunately very common) I find
that you end up making heavy use of Command object to "normalize" and
"denormalize" data as you work with it. You can use bi-jected Services
inside your controllers to do this work. The result is you write a
"temporary" data model that represents what you want to see on the
screen, generate MVC, move the Groovy Entity away from the domain
model and then write a service to catch this temporary entity and map
it on to "real" database entities. Alternately you can do complex
partial mappings between tables and objects using either Hiberante3 or
the Grails DSL but that's "new" Grails teritory. You may choose to use
the older grails 0.5.6 (I think) documented in the Grails book (they
had the book at South Point if you're in a hurry).

Grails handles round-tripping well if you know how to use it. You can
also completely customize the code generators if you have the mind to
do that you can totally alter what they do using plugins. I've heard
rumor Grails runs in Java 1.4 but no lower. I know if you use too new
of a Groovy version you can't get away with that. Groovy and Grails
are both very reflection centric but they hide that from you pretty
well.

If you suddenly get a request for a "SOAP" service for anything you
are doing flip the "Expose as SOAP" switch or expose via RMI switch
and Grails will take care of all the serialization issues. If you are
doing Ajax work you can flip between different Ajax libraries by
changing configurations and not mess with the JavaScript directly at
all.

Things don't work perfectly, however, as I've noted:
http://hartsock.blogspot.com/2007/11/groovy-grails-gorm-and-its-flaws.html

But it's getting really really damn close to perfect and the plugins
hold out a great deal of promise. The Eclipse IDE is terrible for
Grails work but at least doesn't get in your way. The IntelliJ IDEA
project has more features but I felt the features caused more problems
than they solved. I haven't worked with NetBeans at all.

One of my coworkers swears by command line only and this Mac editor
called TextPad or something. I've been known to work command line and
vi when working groovy and grails. Wouldn't dream of touching Java
from only vi though because the Eclipse editor is so much better.

Both Hibernate3 and GORM (the Grails ORM on top of Hibernate3) provide
the best ORM I've seen bar none... (but I don't have access to any
commercial ORM). Vanilla JPA handles many-to-many a little bit better
than GORM right now but I've seen progress there. The typical answer
to this problem is to use a bridging object to bridge the two classes
and hold the relationship. Hibernate3 and GORM both deal with foreign
keys well. The GORM ORM DSL is a little tough to learn but it is much
easier to work with than JPA once you've got it down. It would be nice
to have an IDE to deal with GORM DSL... oh well... I also haven't
tried to do a GORM deploy on an older application server.

You can switch Grails' Ajax libraries by altering a configuration
parameter. So you can pick DWR, YUI, GWT, Prototype, or Dojo... if you
write your code properly you can switch libraries without changing
your code at all so it can be a "because I said so" type of choice.
Additional plugins support ZK and OpenLaszlo so you could do Flash
from Grails... but I don't know anybody doing that right now.

http://grails.org/
http://grails.org/Plugins

More on Grails:
http://hartsock.blogspot.com/2007/11/grails-xfire-plugin.html
http://del.icio.us/hartsock/groovy%2Bgrails

On another project I'm using Eclipse RCP. I don't like Eclipse RCP
very much right now. I have heard great things about Flex but I'm
cautious of hitching my wagon to a proprietary platform... and I can't
get the Adobe tools to work on Linux for some reason. I also I'm
hesitant to give up all my hard won knowledge of Java. Grails is on
top of Spring and Groovy uses all Java API and convention so there's a
shallower learning curve to use Grails. Also it packages to a WAR and
that deploys nicely into my J2EE systems. I'm looking to do two-way
JNDI between a Grails project and J2EE project shortly... I will also
be working with SSO and grails this year.

I'm staying with Eclipse RCP and hope to see a Groovy Builder on top
of SWT this year to make development easier. The RCP offers the
ability to export my desktop projects as binaries and built in
distribution of upgrades for them. A serious problem for traditional
desktop applications. Some of my projects simply must deploy onto
Windows desktops from CD-ROM. That means looking a bit like Open
Office.

In this thread:
http://www.nabble.com/How-to-distribute-Groovy-based-Swing-programs-to14622475.html

We talked about the best way to deploy Groovy Swing Builder
applications which would be my first choice for Desktop UI since
JavaFX is still not ready for prime time. There's no solid answer on
"best" way to do this yet. I have a pipe-dream of wedding a Groovy
Builder to the Eclipse RCP to leverage the plugin distribution model
but that could be a long-way off. As it is I'm not very happy with the
RCP right now but I probably am too new with it's API to be
comfortable just yet. RCP seems opaque. Even the training materials
are hard to "get into" for some reason... could just be missing "cool"
factor though.

I would like to but will NOT have time to play with Flex, JavaFX, and
ZK this year. ZK is the number one project on Sourceforge and in my
opinion is architecturally (see http://www.zkoss.org/) unique and
promising but it could also easily go the way of the Lisp machine
because it is so radically different.

Career wise I usually stay middle of the road and shun radical
technologies. I put too much at risk with each project to spend time
too far out on the bleeding edge so I have made several choices that
are "close to center" in that I've picked Grails and Eclipse RCP
knowing that if the edge moves away from them radically they will be
at the center of the pack long enough to pay off. For example Grails
is based on Spring which is heavily influencing Application Server
design so any time spent there will be valuable later things like MVC,
IoC, and Plugins are standard ideas. RCP is built on OSGi which is
probably not going anywhere... and will allow me to learn how to write
Eclipse plugins. Eclipse is a mainstream IDE for many languages and
that means I could potentially give back into the developer community
of any technology if I know it.

JBoss Seam is neat, I've done a demo project in it... but I must be
stupid because I don't "get it" or maybe Seam is like Eclipse RCP you
have to "think right" to get it to work well. JSF and EJB3 are nice
but take too long to turn around a project in... maybe this is a
tooling problem? Maybe I need to pay enough money to get shown the
magic handshakes that make it work well. Problem is I'm broke...
mentally taxed... and tired of learning to do things when all I want
to do is just get something done _damn_ it.

And that's where I'm at today. This time last year I was "ordered" to
look at BPEL and a host of other buzzword technologies. I spent six
months with them and found that for the most part these are all hard
to learn and hard to understand. They looked shiny and for a long time
I believed a lot of the hype. But, in real practice of building and
maintaining software... many time software that is ugly, poorly
designed, or otherwise just crap to deal with... I've found that only
two or three tools really are worth sticking to and really any help.
For me that has been Groovy and Grails and the tools they are built
on.

My verdict is still out on the best way to do desktop applications in
Java but I can say that so far nothing really holds the promise of an
all encompassing solution that will work well. Eclipse comes close but
RCP is a pain to learn and doesn't tolerate discovery mode learning
very well. That's a problem for widespread adoption. JavaFX promises
to support learning by discovery but it's not ready today. Flex is
building a following but I worry about Flex becoming a "Cold Fusion"
type community.

To sum up:

I like Groovy, Grails, Hibernate3 and JPA.
I chose Eclipse RCP but I don't like it.

I think the new vendor lock-in strategy is to provide you with tools
that are "open source" but you can only use with thousands of dollars
in training and license fees. And, I think that strategy will "Cold
Fusion"-ize many of these communities... but maybe that's what they
want? After all, the extreme opposite of that kind of vendor lock-in
is probably something like Perl and no vendor seems to be able to make
money at that game.

Note see the PLEAC for a jump start on Groovy:
http://pleac.sourceforge.net/

Obviously, I'm an old-hand C/C++/Perl programmer so I found the PLEAC
very helpful. YMMV.


On Jan 7, 2008 11:31 AM, Tim Jowers <[email protected]> wrote:
>
> Anyone have input into a Java code generator for quickly putting a database
> on the web?  The design mantra is vanilla Java code and KISS. Right now I am
> using JDBC metadata to produce a Data Access Object, Value Object (aka Data
> Transfer Object), Business Object, and Session Bean (inherits from BO). My
> goal is not to reinvent the wheel in O-R mapping but to make something very
> simple. KISS. I guess the industry trends are toward frameworks like
> AquaLogic or Rails/Grails but this generator simply creates vanilla Java
> code so it may be edited by a skilled programmer.
>
> What are the main issues with code generators? Feedback desired.
> 1. Generated code is unmaintainable. Yes. Seen that many times! Generated
> code cannot be customized. So, for now, I'm created quite simply Java code
> with no special techniques. Even 1.4 compliant (no 1.5 language enhancements
> are being used).
> 2. Does not fit our framework. E.g. one client is using WebLogic 8.1 which
> has source-annotated-comments which pre-dates Java annotations. For them I
> might customize the code to be able to generate webservices and EJB's with
> the old BEA WebLogic way of doing things. They are considering moving to WLS
> 10 or maybe JBoss 4.2. The code is vanilla Java code so the programmer can
> edit the generated code as needed.
> 3. Round-tripping. How to generate the code a second time. The present
> design I'm advocating is to extend the base class (BO) and edit the new
> class. This way the generated code does not conflict with manually changed
> code. Any other ideas?
>
>
> What are the main issues with O-R mapping/mappers? Feedback desired.
> 1. No support for complex relationships. E.g XMLBeans had no capability to
> manage two tables/two object types. I'm using FK and PK metadata to
> generated the VO's. I have methods for "shallow" (just the table to object)
> and "deep" (all related tables  to a hierarchy of objects).
> 2. No support for n-to-m relationships. I saw in the Grails presentation
> they can create tables based on relational keywords in the script class.
> Conversely, I think the n-to-m relationships can be separated into three
> categories such as a lookup table (picklist), an n-to-several, and a true
> n-to-many. I'm working on defining these further as the real interest is how
> they are rendered graphically. I have some db investigation code to make
> estimates on these.
> 3. Does not create a good GUI. I think this is really the main part. A smart
> user could edit a database directly, but a dumb user needs calendar and
> other controls plus a workflow to make them productive. I presently am
> rendering in JSP/HTML and in Flex. I'm  also thinking about how to make a
> workflow builder as the workflow objects seems apparent from the
> relationships.
> 4. No support for ad hoc queries. I'm supporting ad-hoc queries by the
> creation of a new BO. Internally the VO's which correspond to the tables
> used int he query are used.
>
> A few other problems I've run into are:
> 1. Corporate databases are often not normalized. Lots of examples.
> 2. Database constraints are sometimes not defined so not available in
> metadata.
>
> So far the result is I've been able to make JSP/HTML websites very quickly.
> My personal style is I tend to hijack the JSP code and use it in custom
> ways. E.g. http://www.gouno.com/ really is very custom HTML/DHTML/JavaScript
> but uses the basic Java generated code on the back end.
>
> My other consideration is what GUI framework to support next. I've added
> support for REST, JSP/HTML, and some for Flex. I'm wondering what is the
> most popular AJAX framework? DOJO? And also for some reason would like to do
> a GTK interface since it it a native framework and runs on the major OS's.
> Thoughts?
>
> Thanks for your feedback,
> Tim Jowers
>
>
>
>
> _______________________________________________
> Juglist mailing list
> [email protected]
> http://trijug.org/mailman/listinfo/juglist_trijug.org
>
>



--
/** Shawn.Hartsock http://hartsock.blogspot.com/  //*/



-- 
/** Shawn.Hartsock http://hartsock.blogspot.com/  //*/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.