Wednesday, May 13, 2015

Falling in Love with activeWeb and activeJDBC Frameworks (or why I'll never J2E again)


CrossMyPath, the iGIS system, was originally developed using J2E technolgies, DAO layers of anotated POJOs following the repository pattern and EclipseLink hosted in TomEE. At the time it seemed like the sexy new stuff.  But three months in there were problems. Conflicts deep in EclipseLink and TomEE began to surface that were not resolvable and then a long slew of tech evaluations later I started getting worn out. I also was trying to find a solution for GUI designing and autogenning my entities like Linq for Entities on the Msquish side and again just wasn't quite getting there.

The worst part of J2E and it's always been the worst part was the long click to clunk cycle to update code on the server (forgetting JRebel and other such) and moreover the horrific exception swallowing that was going on. Instead, it was just piles of gibberish exceptions with nothing you could use to resolve the problem. That violated some deep rule of coding for me and I wondered just WHO were the programmers that allowed such things to happen. J2E took the right path with J2E 5 and simplified annotations based get up quickly approach. But the deployment  model and inter-vendor issues were still rife and annoying. Sure you could go whole Oracle and do a bit better but you'd miss a lot of the exciting new stuff.

So I scrounged around. People were using Ruby on Rails EVERYWHERE I mean almost as much as PHP (CRAP!). OK PHP just isn't object oriented and while you CAN make web sites with it, I've never seen anything BIG that was maintainable for this very reason.  I looked at Ruby. But it's RUBY for chrissakes! ICK! It wasn't that I couldn't learn Ruby. But non compiled non typed languages give me the willies. And there has to be a performance hit. So then there's Grails. The java Rails for the rest of us. But when I looked at it all and the docs somehow it just seemed big and unfriendly. Not the lean MVC framework. What about Sails? Its great, but wheres the ORM tooling? and on it went.

Then at 5am one night I ran into Igor. Yes thats his name. "Here is ActiveWeb. Watch the 5 min video"  and ... there was no video.  5 minute quick tutorial to Active Web. I clicked. Nope nothing there either. grrr. So then I said OKOK I'll just look at the docs. Let's see. And the docs were ...  amazing. Amazing in that it was so simple, so brief you've never seen anything quite like it. About 12 pages on ActiveJDBC (the db orm to java stuff) and another 12 on the web framework. Each page might have another 4 to ten sections.

It wasn't the framework per se that was so inviting, but the GOALS of the framework. Igor was saying HEY why doesn't this stuff just WORK for chrissakes. Why do I have to specify out a POJO or DAO if my DB already has all that.  Granted, having every datamember to annotate with validations is useful, but you can do that in activeweb if you wish. but if you don't wish, its so much faster.

In fact, it's a strict MVC approach, but creating a Model for a new table is as simple as copying the six lines of code from another model file and then just changing the class and table name. Poof done. What? How can this be done? What if you have One to Manies?  If you want the child "many" tables included, simply refer to them using a column named Child_id and poof its included. For a many to many you do have to specify the endpoints but its just 2 lines.

The secret is that ActiveWeb has an inspection process so that each time it saves it embeds class information about the database tables directly into your models class files. Brilliant. Now yes, everyone grumbles a bit on the config of this but after an hour or two and reading you get it solved.

Now you can fly with the click to clunk being 6 seconds for code compile and inspection on a fairly large project, 5 seconds for Tomcat to recognize that theres a code change and 2 seconds for Tomcat to reload. Magic. I'll take 12 seconds over 120 seconds any time. And that was it. I could never again easily go forward on J2E.

Wait what about entities and caching that J2E supports? It's available by adding a cache annotation to your model and poof it uses Memcache. What about complex transactions? OK, here its not as robust and flexible as J2E but I wasn't building a banking application so it really wasn't necessary. And like Hibernate you can specify how agressively to load (with default being lazy loading).

One gotcha is freemarker ('so you can automate your tests of the frontend' says Igor). And really all you need to know is how to do an ifdef, how to load a partial page, and how to bring in and reference a variable. If you want to go deep into freemarker it's your business but I just use the basics. The rest is tooled around JQuery (and if need be a more robust beast like Angular or KnockoutJs).

And some of the best is the REST support and how easy it is to link up AJAX calls with all default routes.  The MVC calls follow simple naming so that by default the controllers index() method is called (you can specify/direct to others) and then that calls the template with the same name as controllermethod.

The framework supports translation and also specifying different data for dev and production and test setups.

They have support for managing links to controllers with their LinkTo keyword which also support inserting returned HTML or JSON into your page. Building a full REST controller with CRUD is fairly simple with all CRUD paths being by convention of the framework and mapping to your controller. So follow the convention, and all your REST functions just work without having to code paths anywhere. Cool!

But why FreeMarker templates. Ugh Freemarker! Igor points out that it was hard to write regression tests with JSPs and that FreeMarker made that much simpler. I'm not sure I followed WHY but ok I'll just nod and someday I'll figure out more details. Still the amount you have to use freemarker other than if then else and loading partials (of html) and iterations doesn't take very long, and if you want to go deeper that's up to you.

There is always a learning curve, but you really can wing it and just search around the groups or docs for the next piece you need. Oh and that intro video is now there along with the 5 minute getting started. It's coming along. Apparently Igor has been using this framework on many large projects so it's really a work of love and to make for him what the other frameworks should be. And I support that.

ActiveWeb and ActiveJDBC can be found at http://www.javalite.org

No comments:

Post a Comment