org.codehaus.groovy.grails.orm.hibernate.metaclass
Class AbstractSavePersistentMethod

java.lang.Object
  extended by org.codehaus.groovy.grails.commons.metaclass.AbstractDynamicMethodInvocation
      extended by org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractDynamicPersistentMethod
          extended by org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractSavePersistentMethod
All Implemented Interfaces:
DynamicMethodInvocation
Direct Known Subclasses:
MergePersistentMethod, SavePersistentMethod

public abstract class AbstractSavePersistentMethod
extends AbstractDynamicPersistentMethod

Abstract class for different implementations that perform saving to implement

Since:
0.3
Author:
Graeme Rocher

Constructor Summary
AbstractSavePersistentMethod(java.util.regex.Pattern pattern, org.hibernate.SessionFactory sessionFactory, java.lang.ClassLoader classLoader, GrailsApplication application)
           
 
Method Summary
protected  java.lang.Object doInvokeInternal(java.lang.Object target, java.lang.Object[] arguments)
           
protected  java.lang.Object handleValidationError(java.lang.Object target, org.springframework.validation.Errors errors)
          This method willl set the save() method will set the flush mode to manual.
protected abstract  java.lang.Object performInsert(java.lang.Object target, boolean shouldFlush)
          Subclasses should override and perform an insert operation, flushing the session if the second argument is true
protected abstract  java.lang.Object performSave(java.lang.Object target, boolean shouldFlush)
          Subclasses should override and perform a save operation, flushing the session if the second argument is true
protected  void setErrorsOnInstance(java.lang.Object target, org.springframework.validation.Errors errors)
          Associates the Errors object on the instance
 
Methods inherited from class org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractDynamicPersistentMethod
getHibernateTemplate, invoke
 
Methods inherited from class org.codehaus.groovy.grails.commons.metaclass.AbstractDynamicMethodInvocation
getPattern, isMethodMatch, setPattern
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSavePersistentMethod

public AbstractSavePersistentMethod(java.util.regex.Pattern pattern,
                                    org.hibernate.SessionFactory sessionFactory,
                                    java.lang.ClassLoader classLoader,
                                    GrailsApplication application)
Method Detail

doInvokeInternal

protected java.lang.Object doInvokeInternal(java.lang.Object target,
                                            java.lang.Object[] arguments)
Specified by:
doInvokeInternal in class AbstractDynamicPersistentMethod

handleValidationError

protected java.lang.Object handleValidationError(java.lang.Object target,
                                                 org.springframework.validation.Errors errors)
This method willl set the save() method will set the flush mode to manual. What this does is ensure that the database changes are not persisted to the database if a validation error occurs. If save() is called again and validation passes the code will check if there is a manual flush mode and flush manually if necessary

Parameters:
target - The target object that failed validation
errors - The Errors instance
Returns:
This method will return null signaling a validation failure

setErrorsOnInstance

protected void setErrorsOnInstance(java.lang.Object target,
                                   org.springframework.validation.Errors errors)
Associates the Errors object on the instance

Parameters:
target - The target instance
errors - The Errors object

performSave

protected abstract java.lang.Object performSave(java.lang.Object target,
                                                boolean shouldFlush)
Subclasses should override and perform a save operation, flushing the session if the second argument is true

Parameters:
target - The target object to save
shouldFlush - Whether to flush
Returns:
The target object

performInsert

protected abstract java.lang.Object performInsert(java.lang.Object target,
                                                  boolean shouldFlush)
Subclasses should override and perform an insert operation, flushing the session if the second argument is true

Parameters:
target - The target object to save
shouldFlush - Whether to flush
Returns:
The target object


Copyright (c) 2005-2006 The Grails project