Skip to content

Commit

Permalink
Merged fix for GRAILS-4344 which also fixes GRAILS-5426 "HibernatePlu…
Browse files Browse the repository at this point in the history
…ginSupport.#addValidationMethods(...) is reason of memory leak"
  • Loading branch information
graemerocher committed Nov 25, 2009
1 parent 0adcf81 commit d1b78f7
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
Expand Up @@ -135,6 +135,9 @@ class ClosureEventTriggeringInterceptor extends SaveOrUpdateEventListener implem
entity."$property.name" = now
}

if(!entity.validate(deepValidate:false)) {
result = true
}
return result
}

Expand Down
Expand Up @@ -33,7 +33,7 @@ class DomainClassGrailsPlugin {

def version = grails.util.GrailsUtil.getGrailsVersion()
def dependsOn = [i18n:version]
def loadAfter = ['hibernate', 'controllers']
def loadAfter = ['controllers']

def doWithSpring = {
for(dc in application.domainClasses) {
Expand Down
Expand Up @@ -394,14 +394,6 @@ Try using Grails' default cache provider: 'org.hibernate.cache.OSCacheProvider'"
Validator validator = ctx.containsBean("${dc.fullName}Validator") ? ctx.getBean("${dc.fullName}Validator") : null
def validateMethod = new ValidatePersistentMethod(sessionFactory, application.classLoader, application,validator)

MetaProperty originalPropertiesProperty = metaClass.getMetaProperty("properties")
metaClass.setProperties = {Object o ->
originalPropertiesProperty.setProperty delegate, o
if(delegate.hasErrors()) {
GrailsHibernateUtil.setObjectToReadyOnly delegate,sessionFactory
}
}

metaClass.validate = {->
validateMethod.invoke(delegate, "validate", [] as Object[])
}
Expand Down
@@ -0,0 +1,63 @@
package org.codehaus.groovy.grails.orm.hibernate
/**
* @author Graeme Rocher
* @since 1.1
*/

public class DoNotPersistInvalidObjectTests extends AbstractGrailsHibernateTests{

protected void onSetUp() {
gcl.parseClass('''
import grails.persistence.*
@Entity
class DoNotPersist {
String name
static constraints = {
name size:1..5
}
}
''')
}


void testDoNoPersistInvalidInstanceUsingDirtyChecking() {
def testDomain = ga.getDomainClass("DoNotPersist").clazz

def t = testDomain.newInstance(name:"bob")

assertNotNull "should have saved test instance",t.save(flush:true)

session.clear()

t = testDomain.get(1)
t.name = "fartooolong"

session.flush()
session.clear()

t = testDomain.get(1)
assertEquals "bob", t.name
}

void testPersistValidInstanceUsingDirtyChecking() {
def testDomain = ga.getDomainClass("DoNotPersist").clazz

def t = testDomain.newInstance(name:"bob")

assertNotNull "should have saved test instance",t.save(flush:true)

session.clear()

t = testDomain.get(1)
t.name = "fred"

session.flush()
session.clear()

t = testDomain.get(1)
assertEquals "fred", t.name
}

}

0 comments on commit d1b78f7

Please sign in to comment.