Last updated by sshucker 2 years ago
Install the plugin with the command:
grails install-plugin extended-gorm-mappings
Last updated by burtbeckwith 4 months ago
Introduction
This plugin adds extra options to the
mapping closure in GORM domain classes. It includes a few mappings with the plugin, but it also provides the infrastructure for you to easily add mapping extensions in your own code.
Built-in mappings
| Mapping | Data Type | Description |
|---|
| insertable | boolean | controls whether this column is included in INSERT statements |
| updateable | boolean | controls whether this column is included in UPDATE statements |
| formula | string | provides a SQL formula to be used in SELECT statements instead of binding this field to a database column. Implicitly makes the column read-only |
| | | Example: firstOrderDate formula: "(select min(o.creation_date) from Orders o where o.customer_id = id)" |
Version history
| Version | Changes |
|---|
| 0.3 | Insertable:false and Formula mappings now add a nullable:true constraint so you're not forced to enter a value you can't save. Formula mappings will no longer create a column if you're generating schema. Schema generation for Insertable:false mappings will no longer create columns as NOT NULL |
| 0.2 | Upgraded for grails 1.1.x |
| 0.1 | Initial release for grails 1.0.x |
How it works
Grails builds a
Configuration and then uses that Configuration to create a
SessionFactory. This plugin extends grail's ConfigurableLocalSessionFactoryBean and modifies the hibernate Configuration just before the SessionFactory is built.
Creating your own mappings
Rather than hardcode a list of mapping extensions, this plugin queries the application context for any beans that implement the interface
package org.riskfactor.grails.gorm;import org.hibernate.mapping.Property;public interface GormExtension {
void extend(GrailsDomainClass domainClass, Property prop, Object setting);
String getKey();
}
When the plugin finds
key in a domain object's mapping closure, it will pass the associated value as the
setting argument to the
extend method. The
prop argument is the hibernate
Property that grails has constructed to map the column. In your
extend method, you modify this property. You'll need some familiarity with the org.hibernate.mapping package to make this work, but you can look at the included GormExtensions for examples.
Last updated by admin 3 years ago
Last updated by admin 3 years ago