Menu

Expressions and Improved JavaDocs in 0.9.6

0.9.6 is out and it includes the final pieces for expressions.

Expressions are designed to cover the harder comparisons that QDT.permittedValues methods don't cover.

They are inspired by the Java 8 stream framework so every expression method produces a new expression. This sounds complicated but it's a well known technique and easy to write code with.

To start an expression use the DBRow column( ) method or the appropriate Expressions value( ) method. After that the methods you can use will be available to you:

marq.column(marq.uidMarque).plus(2).minus(4).bracket().times(6).bracket().dividedBy(3)

The column method creates a expression appropriate to the field, in this case a NumberExpression, and each method call creates a new expression of the appropriate class.

To use an expression drop it into the addCondition() method in DBQuery.

However to add the above expression to your DBQuery you'll need to get a BooleanExpression as every condition is a test between 2 or more expressions. The above expression is included as:

 query.addCondition(marq.column(marq.uidMarque).plus(2).minus(4).bracket().times(6).bracket().dividedBy(3).is(-2)));

Some expressions need to start with a literal value and the best way to get the expression is to use the static value( ) method provide in each of the expression classes

StringExpression.value("V").append(nameValue.replace("BMW","")
NumberExpression.value(5).dividedBy(marque.column(marque.uidMarque))
DateExpression.value(lastTuesday).is(marque.column(marque.creationDate))

Expressions also provide access to builtin database functions like CURRENT_USER and SYSDATE. They are available as static methods on the expression class similar to their return type.

marq.name.permittedValues(StringExpression.currentUser());

The last example also shows you can use expressions with QDTs directly.


JavaDocs have been improved for all of the nz.co.gregs.dbvolution classes. It felt like a herculean effort and produced several process and bug fixes, so I hope they're good :)

Posted by Gregory Graham 2014-01-31 Labels: JavaDocs Expressions StringExpression NumberExpression DateExpression database functions CURRENT_USER SYSDATE addCondition

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.