From 7641ec42b797b24a1487b3205b592edcb43d786e Mon Sep 17 00:00:00 2001 From: Vladimir Orany Date: Thu, 29 Jul 2021 12:09:20 +0200 Subject: [PATCH] generating enums only on demand (#21) --- .../generator/MicronautDataGenerator.groovy | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/subprojects/micronaut-grails-jpa-generator/src/main/groovy/com/agorapulse/micronaut/grails/jpa/generator/MicronautDataGenerator.groovy b/subprojects/micronaut-grails-jpa-generator/src/main/groovy/com/agorapulse/micronaut/grails/jpa/generator/MicronautDataGenerator.groovy index dcf67b80..204c5362 100644 --- a/subprojects/micronaut-grails-jpa-generator/src/main/groovy/com/agorapulse/micronaut/grails/jpa/generator/MicronautDataGenerator.groovy +++ b/subprojects/micronaut-grails-jpa-generator/src/main/groovy/com/agorapulse/micronaut/grails/jpa/generator/MicronautDataGenerator.groovy @@ -64,7 +64,7 @@ abstract class MicronautDataGenerator { } @SuppressWarnings('NestedForLoop') - int generate(File root, String packageSuffix = '.model') { + int generate(File root, String packageSuffix = '.model', boolean generateEnums = false) { Collection entities = datastore.mappingContext.persistentEntities Collection entityClasses = entities*.javaClass entities.each { PersistentEntity entity -> @@ -78,17 +78,19 @@ abstract class MicronautDataGenerator { repositoryFile.text = generateRepository(entity, packageSuffix) } - List requiredEnums = [] - for (PersistentEntity entity in datastore.mappingContext.persistentEntities) { - for (PersistentProperty property in entity.persistentProperties) { - if (property.type.enum) { - requiredEnums.add(property.type) + if (generateEnums) { + List requiredEnums = [] + for (PersistentEntity entity in datastore.mappingContext.persistentEntities) { + for (PersistentProperty property in entity.persistentProperties) { + if (property.type.enum) { + requiredEnums.add(property.type) + } } } - } - requiredEnums.each { Class enumType -> - copyEnum(root, enumType) + requiredEnums.each { Class enumType -> + copyEnum(root, enumType) + } } return entities.size()