Grails Configuration

Automated Business Logic is designed to minimize and eliminate coding changes required to specify business logic.




Grails Configuration


You can configure an existing project to use Automated Business Logic using the procedures described in the sub-sections below.  You can further explore these settings with the Example described in the following section.



Configure your DataSource
Automated Business Logic operates by handling Gorm events.  This is activated by adding the following line to your conf/DataSource.groovy file as shown in the screen shot above:

hibernate.current_session_context_class = 'com.autobizlogic.abl.session.LogicThreadLocalSessionContext'


Properties files

Your ABLConfig.properties file needs to be present in the class path. Typically, the easiest way to do this is to put it in the src/java directory, but there are many other ways to do this.

ABLConfig.properties needs one modification:

currentSessionContextClass = org.springframework.orm.hibernate3.SpringSessionContext

You can copy the properties files from the BusLogicIntroGrails project into yours.  They do not require alteration, but you can configure them as described here.

You will also want to copy the file ABL_logging.properties in the same directory. This will allow you to configure logging in a detailed and precise way, and it will avoid a harmless but scary-looking exception at startup.

Business Logic jar


As shown at the right, copy the following your unzipped distribution to your projects' lib folder:
autobizlogic_xxx.jar
Proper javassist version
commons-jexl







Logic Classes

You can build your Business Logic Components in Groovy, as shown in the screen shot above.

Being transactional

Your transactional business logic will of course only be invoked in the context of transactions, so you must ensure that all activity is bracketed by transactions.One easy way to do this is to add the @Transactional annotation (more specifically org.springframework.transaction.annotation.Transactional) to your controller objects. Your service objects will by default be transactional, which works fine here. You can also do this programmatically, or by using the transactional dependency injection. This is a vast topic, which is thankfully covered in Grails documentation (see here for programmatic transactions, and here for more details on Spring transactions).Any activity that is not bracketed within a transaction will not invoke any transactional business logic.

Example

The download zip contains the elements of a Grails project.  Proceed as described in Grails Demo Installation.  You can investigate the resultant Grails project.

You can then introduce business logic into your own projects.  Note you can start very simply: just configure and declare some simple logic - perhaps a multi-attribute constraint, or an auditing rule.


Trouble Shooting

javassist version

If you see an exception along the lines of:

org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [save] of controller [buslogicdemograils.CustomerController$$EnhancerByCGLIB$$a17473ab]  caused exception: Runtime error executing action

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

at java.lang.Thread.run(Thread.java:680)

Caused by: org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Runtime error executing action

... 3 more

Caused by: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoSuchMethodError: javassist.util.proxy.ProxyFactory.isProxyClass(Ljava/lang/Class;)Z

... 3 more

Caused by: java.lang.NoSuchMethodError: javassist.util.proxy.ProxyFactory.isProxyClass(Ljava/lang/Class;)Z

at com.autobizlogic.abl.businesslogicadapter.persistence.hibernate.HibernateMetaUtil.getEntityClassForBean(HibernateMetaUtil.java:237)

at com.autobizlogic.abl.businesslogicadapter.persistence.hibernate.HibernateMetaUtil.attributeIsTransient(HibernateMetaUtil.java:282)

at com.autobizlogic.abl.businesslogicadapter.persistence.ObjectStateFactory.createObjectStateForState(ObjectStateFactory.java:142)

at com.autobizlogic.abl.businesslogicadapter.persistence.ObjectStateFactory.createObjectStateForState(ObjectStateFactory.java:32)


that's a sign that you're using the wrong version of javassist. Copy javassist into your lib directory -- need 3.12.



Comments