Reputation: 247
Creating mysql table from Grails domain class does not generates table and column name in Uppercase letters. table names are created in lowercase . Even when doing reverse-engineer with table names in uppercase letters the domain class is generated in lowercase only. How to created table with table and column name in uppercase ?
Upvotes: 1
Views: 1414
Reputation: 2939
I agree with Burt, You can add also the following code to change the generated column name in database to upper case by overriding the other methods
public String propertyToColumnName(String propertyName) {
return super.propertyToColumnName(propertyName).toUpperCase();
}
public String columnName(String columnName) {
return super.columnName(columnName).toUpperCase();
}
public String joinKeyColumnName(String joinedColumn, String joinedTable) {
return super.joinKeyColumnName( joinedColumn, joinedTable ).toUpperCase();
}
public String foreignKeyColumnName(String propertyName, String propertyEntityName, String propertyTableName, String referencedColumnName) {
return super.foreignKeyColumnName(propertyName, propertyEntityName, propertyTableName, referencedColumnName).toUpperCase();
}
public String logicalColumnName(String columnName, String propertyName) {
return super.logicalColumnName(columnName, propertyName).toUpperCase();
}
public String logicalCollectionColumnName(String columnName, String propertyName, String referencedColumn) {
return logicalCollectionColumnName(columnName, propertyName, referencedColumn).toUpperCase();
}
Upvotes: 0
Reputation: 75681
You can customize table names with a custom NamingStrategy
. By default Grails uses an ImprovedNamingStrategy
but you can use your as described in the docs: http://grails.org/doc/latest/guide/GORM.html#customNamingStrategy
This subclass of ImprovedNamingStrategy
will generate uppercase names:
package com.foo.bar
import org.hibernate.cfg.ImprovedNamingStrategy
class UppercaseNamingStrategy extends ImprovedNamingStrategy {
private static final long serialVersionUID = 1
String classToTableName(String className) {
super.classToTableName(className).toUpperCase()
}
String collectionTableName(String ownerEntity, String ownerEntityTable, String associatedEntity, String associatedEntityTable, String propertyName) {
super.collectionTableName(ownerEntity, ownerEntityTable, associatedEntity, associatedEntityTable, propertyName).toUpperCase()
}
String logicalCollectionTableName(String tableName, String ownerEntityTable, String associatedEntityTable, String propertyName) {
super.logicalCollectionTableName(tableName, ownerEntityTable, associatedEntityTable, propertyName).toUpperCase()
}
String tableName(String tableName) {
super.tableName(tableName).toUpperCase()
}
}
Specify it in DataSource.groovy
in the hibernate
block:
hibernate {
...
naming_strategy = com.foo.bar.UppercaseNamingStrategy
}
Upvotes: 3