Tag Archives: Java

Backbase launches Ajax Struts Edition

Being a big Java fan I am very excited that Backbase has announced a Struts Version of its popular Library.
“This newest edition of our Backbase AJAX software can revitalize business-critical Struts applications without compromising the reliability of the existing applications,” says Jouk Pleiter, CEO of Backbase, “Global 2000 companies and other large organizations will see an almost immediate return on investment.”
Along with the well known Backbase functionality you also get a taglib which allows you to add this functionality to your existing applications. [via AjaxWorld]
Did you like this? Share it:

I’m back

I haven’t posted much lately, because I had my exam session, but it’s finally and completely over and done. Now there has been a lot of activity on my favorite topic, Ajax, lately and I had a hard time keeping up with all the news that from Ajaxian, and many others. Especially the discussion on wether graphical drawing is a good thing for the client side has some interesting points:

Client side drawing is possible thanks to many possible implementations but it has neither a good standardized API nor is it very reliable.

On the other hand a nicely written article on the concepts of REST and Ajax has caught my eye:
Javaâ„¢ Servlet’s HttpSession API provides an example of this strain. HttpSession lets you associate session state with a particular user. This API seems deceptively simple to novice developers. Indeed, it appears that you can store any object in HttpSession and pull it out without ever coding any special lookup logic yourself. But as you start putting more objects in HttpSession, you start to notice that your application server uses more and more memory and processing resources. Soon you decide that you need to deploy your application in a clustered environment to help with growing resource needs. Then you realize that for HttpSession to work in a clustered environment, each object must implement Java’s Serializable interface so that session data can be transmitted between servers in a clustered environment. Then you must decide whether or not your application server should persist session data in the case of a shutdown/restart cycle. Soon you begin to question whether violating the client-stateless-server constraint was such a good idea after all. (Actually, many developers are ignorant of this constraint.)
But more on this in a separate Post :)

So this is about it to catch a bit up with the present, after hammering my head against all those Analysis and Linear Algebra Books, sorry if it is a bit superficial, but hey, there is just too much to write about now to dwell in the past.

Technorati Tags: , , ,

»crosslinked«

Did you like this? Share it:

Setting up HSQL and Hibernate for Unit tests

I know, this sounds a bit too specific to really bother you but since it’s a nice thing to do, and I use it really often during development I thought I’d share it with you.

The scenario

You are developing an application where you heavily rely on a database and want it to be tested during your unit tests. In my case I have an application that uses Hibernate that is connected to an Oracle database for it’s data persistence. Now I want to write some Unit Tests, using JUnit, to see wether all works fine and my objects get serialized and restored correctly. Usually I would have to set up another database with my structure and then test it on that, but JUnit explicitly discourages this as it requires you to setup the same environment on all machines that will test the code.

The solution

The solution is HSQLDB. HSQLDB is the leading SQL relational database engine written in Java. It has a JDBC driver and supports a rich subset of ANSI-92 SQL (BNF tree format) plus SQL 99 and 2003 enhancements. Along many other features it can also run in a memory resident mode, that will keep all of its data in memory and it is lost after the execution finishes. At first sight this may seem a useless feature, but think about what exactly you need when running unit tests: a simple to set up database, that is freshly instantiated with every run. And HSQL is easy to set up, in fact so easy that a single line makes all the difference.
So what once was my hibernate configuration file:
 
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC 
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@hostname:1526:orcl</property>
        <property name="connection.username">username</property>
        <property name="connection.password">password</property>
        <property name="connection.pool_size">10</property>
        <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
        <property name="current_session_context_class">thread</property>
        <property name="cache.provider_class">org.hibernate.cache.SwarmCacheProvider</property>
        <property name="show_sql">true</property>
        <mapping resource="events/Event.hbm.xml">
    </mapping>
</session-factory>
</hibernate-configuration>
Now becomes this:
 
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC 
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
 
<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="connection.url">jdbc:hsqldb:mem:somename</property>
        <property name="connection.username">sa</property>
        <property name="connection.password"></property>
        <property name="connection.pool_size">1</property>
 
        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
 
        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>
 
        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
 
        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
 
        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">create</property>
 
        <mapping resource="events/Event.hbm.xml">
    </mapping>
</session-factory>
</hibernate-configuration>
Special attention is needed with the connection.url property and the hbm2ddl.auto property which tell hibernate to use a memory resident HSQL Database and to create the database structure at startup, which is exactly what we need for our Unit-Tests. Now for this to run you only need to include the HSQLDB Jar in your classpath and everything will run as it used to, only that it is much easier to test in a new environment, thus making it perfect for continouuous integration.
To sum it all up here are the steps to migrate to HSQL for testing:
  1. Add HSQLDB to your classpath
  2. Set the driverclass to org.hsqldb.jdbcDriver
  3. Set the dialect to org.hibernate.dialect.HSQLDialect
  4. Set the database URL to jdbc:hsqldb:mem:somename
  5. Run your tests :)




powered by performancing firefox

Did you like this? Share it:

JavaScript Persisten Object Notation (JSPON)

Some days old but still great news: Kris Zyp has written up an RFC for JSPON, a Notation for persisting objects over JSON. In “classical” JSON you have no way to reference the same object in different places (in fact there is no way to tell that two objects are actually the same) which leads to data redundancy. JSPON uses a similar approach to Java and DWR, every object that is being transferred gets an object id, which uniquely identifies it.
In order to identify JSON objects, a po$id field should be set to associate an “id” with the object. By identifying an object, it can now be referenced by id. The id field should be a string. For example:
{"po$id" : "34",
"myField" : "value"
"myChild": {"po$id" : "23"}
}
The advantages of this are easily spotted: you can now reference the same object multiple times, make cyclic relations and much much more. Especially the fact that we eliminate to repeat objects multiple time helps reducing communication size and therefore speed it up (a lot ^^).

Basic JSON does not support object referencing.  Therefore the following object (“obj”) could not be serialized with JSON:

var obj={};
var obj2 = {"foo": "val", "bar" : 4};
obj.field1 = obj2;
obj.field2 = obj2;

With JSON there is no way to communicate the fact that both field1 and field2 point to the same object. The best JSON could do is to make a copy of the serialization of obj2 for each field, but this does not effectively communicate that it is the same object and if you set obj.field1.foo = “newValue”, that obj.field2.foo should return “newValue”.  With JSPON this referenced can be communicated:

var obj={"po$id": "1", 
"field1": {"po$id": "2", "foo": "val", "bar": 4},
"field2": {"po$id": "2"}}
The RFC also defines some more advanced things such as lazy loading capabilities (po$ready), distributed object management (po$sourceURL), object versioning (po$version) and array and wrapper objects.

It’s really an interesting read and if it really becomes standard it may improve both speed and usability. Hopefully it is included in some of the popular libraries soon.
aaa


Technorati Tags: , , ,
Did you like this? Share it:

Ajax based login using Acegi

Sanjiv Jivan just wrote a nice article on how to implement an Ajax enabled login system with Spring. I think it might be usefull ^^
Acegi is an extremely powerful Spring module for Authentication and Authorization and has almost become a defacto for web based applications built using Spring. Ajax based applications are getting hotter by the day and having a nice inplace Ajax based login page can improve coolness of your app and make it more Web 2.0′ish. However implementing an Ajax-Acegi based login does require a little extra work because based on the J2EE spec, when a user tries to login, they are redirected back to the login page if the credentials are invalid or redirected to the success page on successful authentication.

Read the full article here.
Technorati Tags: , , ,
Did you like this? Share it: