Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch '2.2.x'

  • Loading branch information...
commit b2808b968475b4179a2142f0030d85ec7a591a3c 2 parents 32d2f45 + 7ac9b65
@jeffbrown jeffbrown authored
View
2  ...ibernate/src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/cfg/ColumnConfig.groovy
@@ -30,6 +30,8 @@ class ColumnConfig {
int length = -1
int precision = -1
int scale = -1
+ String defaultValue
+ String comment
String toString() {
"column[name:$name, index:$index, unique:$unique, length:$length, precision:$precision, scale:$scale]"
View
9 ...nate/src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/cfg/GrailsDomainBinder.java
@@ -1813,6 +1813,10 @@ protected static void createClassProperties(GrailsDomainClass domainClass, Persi
Mapping gormMapping = getMapping(domainClass.getClazz());
+ if (gormMapping != null) {
+ table.setComment(gormMapping.getComment());
+ }
+
for (GrailsDomainClassProperty currentGrailsProp : persistentProperties) {
// if its inherited skip
@@ -2683,6 +2687,11 @@ private static void bindSimpleValue(String type, SimpleValue simpleValue, boolea
private static void bindColumn(GrailsDomainClassProperty property, GrailsDomainClassProperty parentProperty,
Column column, ColumnConfig cc, String path, Table table, String sessionFactoryBeanName) {
+ if (cc != null) {
+ column.setComment(cc.getComment());
+ column.setDefaultValue(cc.getDefaultValue());
+ }
+
Class<?> userType = getUserType(property);
String columnName = getColumnNameForPropertyAndPath(property, path, cc, sessionFactoryBeanName);
if ((property.isAssociation() || property.isBasicCollectionType()) && userType == null) {
View
6 ...c/main/groovy/org/codehaus/groovy/grails/orm/hibernate/cfg/HibernateMappingBuilder.groovy
@@ -422,6 +422,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.defaultValue) cc.defaultValue = namedArgs.defaultValue
+ if (namedArgs.comment) cc.comment = namedArgs.comment
cc.length = namedArgs["length"] ?: -1
cc.precision = namedArgs["precision"] ?: -1
cc.scale = namedArgs["scale"] ?: -1
@@ -537,6 +539,10 @@ class HibernateMappingBuilder {
mapping.datasources = names
}
+ void comment(String comment) {
+ mapping.comment = comment
+ }
+
void methodMissing(String name, args) {
if ('user-type' == name && args && (args[0] instanceof Map)) {
hibernateCustomUserType(args[0])
View
7 grails-hibernate/src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/cfg/Mapping.groovy
@@ -114,7 +114,7 @@ class Mapping {
ColumnConfig discriminatorColumn
/**
- * Obtains a ColumnConfig object for the given name
+ * Obtains a PropertyConfig object for the given name
*/
PropertyConfig getPropertyConfig(String name) { columns[name] }
@@ -143,4 +143,9 @@ class Mapping {
* @return the datasource names
*/
List<String> datasources = [GrailsDomainClassProperty.DEFAULT_DATA_SOURCE]
+
+ /**
+ * DDL comment.
+ */
+ String comment
}
View
32 .../test/groovy/org/codehaus/groovy/grails/orm/hibernate/HibernateMappingBuilderTests.groovy
@@ -737,4 +737,36 @@ class HibernateMappingBuilderTests extends GroovyTestCase {
assertTrue mapping.getPropertyConfig('firstName').updateable
assertFalse mapping.getPropertyConfig('lastName').updateable
}
+
+ void testDefaultValue() {
+ def builder = new HibernateMappingBuilder("Foo")
+ def mapping = builder.evaluate {
+ comment 'wahoo'
+ name comment: 'bar'
+ foo defaultValue: '5'
+ }
+ assertEquals '5', mapping.getPropertyConfig('foo').columns[0].defaultValue
+ assertNull mapping.getPropertyConfig('name').columns[0].defaultValue
+ }
+
+ void testColumnComment() {
+ def builder = new HibernateMappingBuilder("Foo")
+ def mapping = builder.evaluate {
+ comment 'wahoo'
+ name comment: 'bar'
+ foo defaultValue: '5'
+ }
+ assertEquals 'bar', mapping.getPropertyConfig('name').columns[0].comment
+ assertNull mapping.getPropertyConfig('foo').columns[0].comment
+ }
+
+ void testTableComment() {
+ def builder = new HibernateMappingBuilder("Foo")
+ def mapping = builder.evaluate {
+ comment 'wahoo'
+ name comment: 'bar'
+ foo defaultValue: '5'
+ }
+ assertEquals 'wahoo', mapping.comment
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.