Saturday, October 08, 2011

Groovy Support in ADF

Groovy Support in ADF

Groovy is as an agile dynamic language, Oracle JDeveloper and Oracle ADF 11g introduce support for the Groovy scripting language, allowing you Groovy expressions to be used in attribute validation and as a source for attribute values Groovy need to have a minimum java version 1.5.Groovy comes into its own is within Oracle ADF Business Components is helping to bridge the gap between Oracle ADF's declarative business logic,Groovy supports 99% of java syntax it's so easy to paste some java code into groovey programs

 

Oracle ADF provides a number of different declarative points into which you can drop Groovy code:

 

• Values for view and entity objects attributes
• Validation rules on entity object attributes
• Expressions for error messages Oracle White Paper-Introduction to Groovy support in JDeveloper and Oracle ADF 11g.
• Values for view object bind variables
• View object transient attribute validation


Groovy Expressions in ADF Business Components View Objects

 

ADF Business Components view objects also provide the ability to use Groovy expressions. As with entity objects, view objects can support:
• Referencing attributes in the same view object
• Referencing attributes in other view objects
• Transient attribute validation Oracle White Paper-Introduction to Groovy support in JDeveloper and Oracle ADF 11g.
• Referencing methods in the Java class that backs the view object
• Referencing built in calls such as sum and min
View objects also allow Groovy expressions to be used in bind variables

.

Things to be aware of

 

· Semicolons are optional. Use them if you like (though you must use them to put several statements on one line).

· the return keyword is optional.

· You can use this keyword inside static methods (which refers to this class).

· Methods and classes are public by default.

· Protected in Groovy has the same meaning as protected in Java, i.e. you can have friends in the same package and derived classes can also see protected members.

· Inner classes are not supported at the moment. In most cases you can use Closures instead.

· The throws clause in a method signature is not checked by the Groovy compiler, because there is no difference between checked and unchecked exceptions.

· You will not get compile errors like you would in Java for using undefined members or passing arguments of the wrong type.

Some Examples:

Java code

 

class  HelloWorld {

private final Thing thing = new Thing ( ) ;

   {

          thing.doSomething ( ) ;

   }

}

 

Groovy Code

class HelloWorld {

private final thing = new Thing ( )

{

      thing.doSomething ( )

}

}

Semicolons is optional in Groovy

 

A = 10

println x

 

A = new java.util.Date()

println A

 

A = -3.1499392

println A

 

A = false

println A

 

A= "Hi"

println A

println is equalant to System.out.println

 

 

The first line java import tells to groovy the full name of sql object 

The second line creates SQL DB connection and stores in variable
Third line calls "eachRow" Method of sql and passing two parameters


1.Query String is first param
2.printing some sql result values
The closure the fields of "it" are accessed in two different ways. The first is as a simple field reference, accessing the id field of it. The second is the included Groovy expression mentioned above

 

Who will Benefit


Who don't already know java and who don't want learn java they can use Groovy to use power of JVM and Development kit while programming


conclusion

 

Java is Groovy,Groovy is Java


1.99% java code supports Groovy
2.Groovy supports JSR 175 annotation same as Java
3.Increases developer productivity by reducing scaffolding code when developing web, GUI ,database or console applications
4.Compiles straight to Java byte code so you can use it anywhere you can use Java

 

 

Source from: http://groovy.codehaus.org and oracle.com

1 comment: