ActiveRecord is to Ruby on Rails as Active Objects is to Java. Ideally it would be called AwesomeObjects. At last, persisting data for your Java web application is not all xml, POJOS, EJBs and did I mention xml? I don't hate xml but I find configuring your application extremely inefficient after working with other frameworks that utilize convention over configuration. Why do I have to specifiy a log4j properties file, hibernate persistance.xml configuration. And there's soooo many options of how to develop: JPA, Wicket, OJB, Spring, Struts, Torque, Cayenne, Jaxor, TJDO, JDBM, pBeans, JPOX, Simple ORM, Ibatis, XORM, Speedo, Smyle, PAT, LiDO, JDO, IntelliBO, KodoJDO, Hamlets, Faces, RIFE, Shale, Sling, Stripes, Vaadin, Poopdeck (okay, I just made that one up). Point is that It can be a real headache to develop a Java web app. Furthermore, why do I have to create my POJOs and SQL for my database? Why can't a framework just create my data objects, along with nice RESTful CRUD operations for each. Why, crow, why?! So at least for the moment, finding ActiveObjects is lemonade to quench my thirst for answers. The documentation is lacking for ActiveObject but I was able to get it working quite easily. As soon as I saw the interface annotations for this library, I knew it would be a blast working with - assuming the pesticides had been spread around the source code e.g. no bugs. The website can be found here: http://java.net/projects/activeobjects/pages/Home Below I have an example on how to use Active Objects. Let us assume our web application has the concept of "templates" which we want to persist in the database. Templates can have questions, instances and permissions (those are all just interfaces too). As you can see below we just define java interfaces with get and set methods. You don't implement the methods, just define them for reflection by AO. Also every interface will have a getID() method inherited from the parent Entity class. You can also add any annotations to describe any more specific mappings between your Java interface, other interfaces and also types for the database table. For example, below I use @OneToMany and @SQLType(Types.CLOB). I had attempted to use Active Objects with a Blackboard Building Block (also called a B2), but the Blackboard API didn't seem to want to give me a proper information on how to connect to the database (Bb v 9.1.7). Therefore I never actually got around to using this code, but I'll share it with you since you're already here. And I wanna give a big shout out to Peter Fokkinga's since I'm using his DbUtils class which can be found here. So how would we use this Database class? Assuming the virtual installation worked consistently, below is an example using Spring with controller request mappings of how to do an edit and update. If I come onto any projects that need a standalone website I would like to combine the Grails or Play! framework and use ActiveObjects for the Model part of the MVC framework - resulting in sheer Java bad-ass-ery. I know Java is a huge language and web frameworks only covers a small part of it's ability; however, I really like the idea of Java becoming a competitor for simple turnkey web apps, the same ones that can be made in a short time using the conventions of CakePHP, Zend, Django and Rails. Developing in Play! and ActiveObjects is just plain easier. I don't imagine that JEE, ContextFactories and extensive xml configurations are just going to magically disappear (you know job security and all that), but this is the age of designing RESTful web services and shunning away the complexities of CORBA and even SOAP. I'm sure in ten years, something new will be along to lay rest to REST (sorry I couldn't resist) but for now, the general consensus seems to be that web applications should be very simple to develop and maintain, i.e. wham, bam, thank you mam. Comments Comments are closed. | Kelt DockinsDeafie, geekie, techie, chewie (Likes)Professional Resume
|



RSS Feed