Created
March 2, 2017 08:33
-
-
Save jneira/13dcc70210bc19e5a588e4d61a8fc3ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.codehaus.groovy.grails.commons.GrailsClassUtils | |
import org.codehaus.groovy.grails.commons.GrailsDomainClass | |
import org.codehaus.groovy.grails.commons.GrailsDomainClassProperty | |
import org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration | |
import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration; | |
import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder | |
import org.codehaus.groovy.grails.orm.hibernate.cfg.HibernateMappingBuilder | |
import org.codehaus.groovy.grails.orm.hibernate.cfg.Mapping | |
import org.codehaus.groovy.grails.plugins.support.aware.GrailsApplicationAware | |
import org.hibernate.MappingException; | |
import org.hibernate.mapping.JoinedSubclass; | |
import org.hibernate.mapping.PersistentClass; | |
import org.hibernate.mapping.RootClass; | |
import org.junit.internal.matchers.Each | |
import groovy.lang.Closure | |
import entidad.Entidad | |
import java.util.Iterator; | |
import java.util.concurrent.ConcurrentHashMap.Values | |
class MyGrailsDomainConfiguration extends DefaultGrailsDomainConfiguration implements GrailsApplicationAware{ | |
private static final long serialVersionUID = 1; | |
private boolean alreadyProcessed = false; | |
def grailsApplication | |
@Override | |
void secondPassCompile() throws MappingException { | |
fixRootMapping() | |
super.secondPassCompile(); | |
createJoinedSubclassesFK() | |
} | |
boolean rootMappingFixed=false | |
def fixRootMapping() { | |
if (!rootMappingFixed) { | |
Object o = Entidad.mappings | |
HibernateMappingBuilder builder = new HibernateMappingBuilder(Entidad.class.name) | |
Mapping m = builder.evaluate((Closure<?>) o,grailsApplication) | |
GrailsDomainBinder.MAPPING_CACHE.put(Entidad.class, m) | |
rootMappingFixed=true | |
} | |
} | |
boolean joinedSubclassesFKCreated=false | |
def createJoinedSubclassesFK() { | |
if (!joinedSubclassesFKCreated) { | |
classes.values().each { clazz -> | |
if (clazz instanceof RootClass) { | |
if (clazz.hasSubclasses()) { | |
clazz.subclassIterator.each { subclass -> | |
if (subclass instanceof JoinedSubclass) { | |
subclass.createForeignKey(); | |
secondPassCompileForeignKeys(subclass.table,new HashSet()) | |
} | |
} | |
} | |
} | |
} | |
joinedSubclassesFKCreated=true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment