22
ActiveJDBC gets support for H2 database
1 Comment · Posted by Igor Polevoy in Uncategorized
Until recently, ActiveJDBC supported three databases: MySQL, Oracle and PostgreSQL. However, being a true open source project, ActiveJDBC welcomes suggestions and contributions from the community. Recent collaboration with a developer Phil Suh resulted in adding support for a new database: H2. H2 is an important database because of number of reasons, such as: it is implemented in Java, meaning that installation can be done on any OS, it is also fast, super friendly, but more interestingly, it can run in the embedded mode.
Now, developers using ActiveJDBC can use H2 in a standard client/server mode, or they can also choose to run it in embedded mode.
Most development was done by Phil, and integration done by me.
enjoy
Igor
ActiveJDBC · ActiveRecord · database · H2 · JDBC
16
Introducing ActiveWeb – framework for rapid web development in Java
3 Comments · Posted by Igor Polevoy in Web Development
A day has come for all good men (pat on the shoulder)… to announce ActiveWeb. For those who do not know what this is, ActiveWeb is a Java framework for rapid development of web applications. The reasons why I developed it are many, but dis-satisfaction with the current (bizarre) state of affairs in Java is a main one. On the one hand, the number of Java Web frameworks is mind boggling, on the other, each and every one of them is weird one way or another. Unfortunately they all suffer from a few common deficiencies:
- They usually solve only one problem
- They need to be integrated with one another
- Mostly do not support TDD/BDD
- Mostly not full stack
I’m sure there is more, but these are first that come to mind. Let me pick one after another:
- They usually solve only one problem
Lets say we choose JSF. This is a standard proposed by Sun based on the design by Craig R. McClanahan – the same guy who in 1998 – 1999 architected Struts 1. While JSP seems an improvement ove Struts 1, there are certain problems this technology has:
- JSF generates HTML, an pretty ugly one too. Asking an HTML designer to make a JSF page look pixel perfect is asking impossible.
- JSF serves a component state in HTML (taxing Internet traffic) or server (allocating RAM)
- JSF does not solves only one problem: accepting a request and rendering.
Unfortunately JSF has become a “standard” and there are many Java shops that fight it on a daily basis.
- They need to be integrated with one another
Since in a typical web project (even the simplest one), you have many standard requirements, you need more than one framework integrated together. For example, Struts + Spring + Hibernate + Log4J… or RichFaces + Seam + Hibernate…. or [insert your stack here].
As you can see, it would be nice to push the button and have a complete working hello world project integrated all in one: View technology, Stuff in the middle, DB access (and a good on at that), first class testing support, logging, monitoring, security, etc.
These are all the things we need for web applications, and support exists in a variety of different frameworks. Unfortunately they are all disparate, and require a significant effort to integrate together before you can even write your first Hello World.
- Mostly do not support TDD/BDD
When I learned Ruby on Rails, I was surprised by many things, but the biggest surprise came from integrated framework for testing of all aspects of a web application. This seemingly simple concept blew me away. While Java is a general purpose language and it has a lot of support for general programming, I’m yet to see a decent testing framework that is also integrated with a web framework… and which has also been developed specifically for web applications. For example, in a regular Java project it is usually numbingly hard to write a simple test that would allow to simulate a web request, invoke some tested functionality, allow the application to generate data in DB, and HTML by the view and then verify that the data in DB is correct and the structure and content of HTML are correct as well. One would think, that this is the most basic of requirements for a web development framework, but unfortunately this is non-existent in the Java world.
- Mostly not full stack
Most Java web frameworks are not full stack. What does this mean? In a typical web project there are many requirements:
- Need to render view
- Need to write business logic
- Need to save to DB
- Need to manage transactions/security
- Need to log to files
- Need to write tests
- … add your need here
Unfortunately, most frameworks only solve #1. There are however a few notable exceptions, such as JBoss Seam, Play Framework and Grails. The disadvantage with Seam is mostly that it centered around JBoss technologies and JBoss server, but the biggest problem IMHO is a marriage of Seam and JSF. This means difficult HTML to work with, potential scalability problems, ugly URLs, non-REST requests, etc. Grails is almost an exact copy of Ruby on Rails but for Groovy language. As such, Grails has all the implementations of a great web development framework. However, developers looking at Grails need to make a choice to switch to another language. Groovy is similar to Java in syntax, but has dynamic language features like those in Ruby. While learning Groovy is easier than learning Ruby for a Java developer, picking Grails still means switching to a different language. The third choice is Play Framework. What can I say.. this is a great framework and I’m surprised it is not as popular as I thought it could/should be. I discovered Play! half way through development of ActiveWeb, and found that there are many similarities. These similarities are mostly because both Play and ActiveWeb chose Ruby on Rails as a model to be replicated in Java. Both ActiveWeb and Play have their merits (I will write a blog on differences one day), and Java developers now have two choices to be a lot more productive while sticking with Java language.
Whew! If you got here, I take my hat off!
The ActiveWeb has a new home as of a couple of weeks ago, and documentation will be coming in the following days/weeks. The new home is on Google Code: http://code.google.com/p/activeweb/
Enjoy,
Igor
.
23
JSON gods have been appeased!
No comments · Posted by Igor Polevoy in ActiveJDBC, ActiveRecord, java, ORM
ActiveJDBC gets built in JSON generation, here is a simple example:
Person p = (Person)Person.findById(1); String xml = p.toJson(true);
will generate this:
{
"type":"activejdbc.test_models.Person",
"id":"1",
"updated_at":"2011-02-23 22:18:11.0",
"graduation_date":"1954-12-01",
"name":"John",
"dob":"1934-12-01",
"last_name":"Smith",
"created_at":"2011-02-23 22:18:11.0"
}
The functionality is quite similar to that of the toXml() method, and more options are available, including specifying what attributes you want, pretty/ugly formats and inclusion of children. for more information, look here: GenerationOfJson
enjoy,
igor
Active Record · ActiveRecord · java · JDBC · JSON · ORM
11
Collect statistics on your queries in ActiveJDBC
No comments · Posted by Igor Polevoy in Uncategorized
ActiveJDBC has had a truly little hidden(till now) gem for reporting on query performance. It is called Statistics Queue. If configured, it will collect statistical information on queries executed and then make it available for reporting. We built a simple UI page that helps us see all the queries recorded in the queue. This page makes it easy to sort all queries by total, average, minimum and maximum times they took to execute. The API to get the reporting is simple:
Liststatistics = Registry.instance().getStatisticsQueue().getReportSortedBy("avg");
The argument for the method getReportSortedBy("avg") can be either one of these: “total”, “avg”, “min”, “max”, “count”, which makes this easy to sort your queries any way you like.
This tool helps to get to the bottom of performance problems.
For more information, take a look at Statistics Reporting page.
Happy coding
Igor
No tags
9
ActiveJDBC gets XML generation
3 Comments · Posted by Igor Polevoy in ActiveJDBC, ActiveRecord, java, Open Source, ORM
While development on this project is an ongoing effort, I do not always have time to blog about new functionality. However, XML generation is something that is really useful for REST Web services. Having this built directly into the ORM layer spares additional programming, reliance on new dependency and in general promotes the light weight style of development. I also tried to ensure that the API themselves are lightweight. Here is an example:
Person p = Person.findById(1); String xml = p.toXml(2, true);
This is simple and self – explanatory. The first parameter is a number of spaces to use for indentation, and second – whether to pre-pend the XML declaration.
Of course there is more to it than meets the eye. The LazyList also got the same method, allowing to convert a list of models into XML.
For more information, please refer to:
http://code.google.com/p/activejdbc/wiki/GenerationOfXml
Happy coding!
No tags
25
ActiveJDBC Validations go I18N!
No comments · Posted by Igor Polevoy in ActiveJDBC, ActiveRecord, java, ORM
A few days ago I added new functionality to AJ – something that bothered me for some time. This has to do with the validation framework. The original implementation had a rather simplistic approach where you just attached a validation message to a validation declaration like so:
public class Temperature extends Model{
static{
validateRange("temp", 10, 2000).message("Temperature is outside the limit");
}
}
However, this is good for a simple English – only apps, but certainly insufficient for other languages. So, I rolled up my sleeves and extended these features to provide real internationalization based on Java Resource Bundles.
This new feature allows to enter a resource bundle key instead of a phrase like this:
public class Temperature extends Model{
static{
validateRange("temp", 10, 2000).message("temperature.outside.limits");
}
}
All you need to do is to provide localized (.. or localised
) property files, as usual in Java:
#activejdbc_messages.properties:
temperature.outside.limits = Temperature is outside acceptable limits, while it needs to be between {0} and {1} for user: {2}
and then voilà, you can get your localized message:
String user = "Tom";
Temperature temp = new Temperature();
if(!temp.save()){
String message = temp.errors().get("temp", user);
System.out.println(message);// prints: Temperature is outside acceptable limits, while it needs to be between 10 and 2000 for user: Tom
}
The code above uses default locale (en, US).
As you can see, the first two parameters in the message were filled out by the validator, while the third one was provided on the fly. This function is called “Split Parameters”, and was suggested for implementation by Evan Leonard.
If you used a German bundle:
#activejdbc_messages_de_DE.properties:
temperature.outside.limits = Die Temperatur liegt außerhalb akzeptabler Grenzen, während es sein muss zwischen {0} und {1}
… and the way to get this message is to provide a locale to the errors(locale) method:
Temperature temp = new Temperature();
temp.set("temp", 5000);
if(!temp.save()){
String message = temp.errors(new Locale("de", "DE")).get(temp); //<<<=== provide locale
System.out.println(message);// prints: Die Temperatur liegt außerhalb akzeptabler Grenzen, während es sein muss zwischen 10 und 2000
}
I also ensured that the new implementation is backwards compatible. If it does not find a key in the bundle, it will print the passed in message verbatim.
For more in this, follow to ActiveJDBC Validations
Happy coding!
ActiveRecord · JDBC · ORM
24
CJUG presentation went well, with healthy attendance
No comments · Posted by Igor Polevoy in ActiveJDBC, java, Open Source, Uncategorized
This finally happened, I posted the slides on the project page:
CJUG presentation on ActiveJDBC at Thoughworks.
There was a full house, and the presentation took longer than planned b/c people were asking a lot of questions.
Could this be that Java world is really ready for a new ORM? I hope so.
The Google Groups support forum is pretty busy now days, check this out:
ActiveJDBC Forum
Cheers!
ActiveRecord · JDBC · ORM
11
CJUG accepted proposal for a presentation
No comments · Posted by Igor Polevoy in Uncategorized
CJUG – the Chicago Java User Group accepted my offer for a presentation on ActiveJDBC (ActiveRecord for Java).
Presentation will take place on August 17th, at Thoughtworks. Details are here:
http://www.cjug.org/Wiki.jsp?page=2010.08.17.downtown
Those wishing to attend, can RSVP here:
http://gathers.us/events/cjug-activejdbc
See ya there!
igor
No tags
I started to go a bit more aggressively regarding documentation, and added a few more pages covering core functionality:
http://code.google.com/p/activejdbc/wiki/Features
I should be almost done in the coming week
cheers,
Igor
No tags
28
ActiveJDBC documentation started to get shaped
No comments · Posted by Igor Polevoy in ActiveJDBC, java
I started to publish documentation for ActiveJDBC, the first article on One to Many relationship. It can be located here:
http://code.google.com/p/activejdbc/wiki/OneToManyAssociation
In the coming days – weeks I will publish documentation for all ActiveJDBC features.
Happy coding!
igor
ActiveRecord · java · ORM
