Skip to content

Commit

Permalink
fix for GRAILS-11310 "Implement hibernate Column Transformers in Doma…
Browse files Browse the repository at this point in the history
…in classes"
  • Loading branch information
graemerocher committed Apr 29, 2014
1 parent c092e42 commit 96ce446
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2734,6 +2734,8 @@ protected void bindColumn(GrailsDomainClassProperty property, GrailsDomainClassP
if (cc != null) {
column.setComment(cc.getComment());
column.setDefaultValue(cc.getDefaultValue());
column.setCustomRead(cc.getRead());
column.setCustomWrite(cc.getWrite());
}

Class<?> userType = getUserType(property);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class ColumnConfig {
int scale = -1
String defaultValue
String comment
String read
String write

String toString() {
"column[name:$name, index:$index, unique:$unique, length:$length, precision:$precision, scale:$scale]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ class HibernateMappingBuilder {
if (namedArgs["enumType"]) cc.enumType = namedArgs["enumType"]
if (namedArgs["index"]) cc.index = namedArgs["index"]
if (namedArgs["unique"]) cc.unique = namedArgs["unique"]
if (namedArgs["read"]) cc.read = namedArgs["read"]
if (namedArgs["write"]) cc.write = namedArgs["write"]
if (namedArgs.defaultValue) cc.defaultValue = namedArgs.defaultValue
if (namedArgs.comment) cc.comment = namedArgs.comment
cc.length = namedArgs["length"] ?: -1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package grails.gorm.tests

import grails.persistence.Entity

/**
* Created by graemerocher on 29/04/14.
*/
class CustomColumnReadWriteSpec extends GormDatastoreSpec{

void "Test custom read and write mapping"() {
when:"An entity with a custom read write is saved"
Name name = new Name(name:"bob").save()
session.clear()
name = Name.get(name.id)

then:"the custom read write were used"
name.name == 'BOBBOB'
}

@Override
List getDomainClasses() {
[Name]
}
}

@Entity
class Name {
Long id
Long version

String name

static mapping = {
name write:'UPPER(?)', read:'REPEAT(name, 2)'
}
}

0 comments on commit 96ce446

Please sign in to comment.