4/03/2009

Empire-db: Type-safe query builder

I found a new database access framework named Empire-db in the Apache Incubator.

A most important feature of Empire-db which I think is a type-safe query builder. See a following example from Empire-db's web site.

// Create a command object
DBCommand cmd = db.createCommand();
// Select columns
cmd.select(EMP.EMPLOYEE_ID);
cmd.select(EMP.LASTNAME.append(", ").append(EMP.FIRSTNAME).as("NAME"));
cmd.select(DEP.NAME.as("DEPARTMENT"));
// Join tables
cmd.join  (DEP.DEPARTMENT_ID, EMP.DEPARTMENT_ID);
// Set constraints
cmd.where(EMP.LASTNAME.likeUpper("Foo%"));
cmd.where(EMP.RETIRED.is(false));
// Set order
cmd.orderBy(EMP.LASTNAME);
cmd.orderBy(EMP.FIRSTNAME); 
This feature is very useful at the software development projects which face many changes of database schema. Because compilation errors are caused by changes of database schema. We can fix these errors completely and surely soon.