Reputation: 9584
I am unable to run some basic groovy code with abstraction. I have read thru this link and auto generated pojos and rest controllers from Data Grip.
Simple code snippet of what I tried
class abstract AGenerate {
abstract def getPackageName() ;
abstract def getFileSuffix() ;
abstract def generateClassFiles()
abstract def generate(output, className, fields) ;
def typeMapping = [
(~/(?i)int/) : "Integer",
(~/(?i)bigint/) : "Long",
(~/(?i)float/): "Double", : "Float",
(~/(?i)double|decimal|real/) : "Double",
(~/(?i)datetime|timestamp/) : "java.sql.Timestamp",
(~/(?i)date/) : "java.sql.Date",
(~/(?i)time/) : "java.sql.Time",
(~/(?i)/) : "String"
]
...
package com.companyname.autogenerate ;
import com.intellij.database.model.DasTable
import com.intellij.database.model.ObjectKind
import com.intellij.database.util.Case
import com.intellij.database.util.DasUtil
FILES.chooseDirectoryAndSave("Choose directory", "Choose where to store generated files") { dir ->
SELECTION.filter { it instanceof DasTable && it.getKind() == ObjectKind.TABLE }.each { generateFolderFromTable(it, dir) }
}
class GenerateEntityClass extends AGenerate {
def getFileSuffix() {
return "Entity.java"
}
def getPackageName() {
return "com.sample;" ;
}
...
Notice I have defined a super class AGenerate and then child classes GenerateEntityClass, I get a error when try to run AutoGenerate at the import line itself
import com.intellij.database.model.DasTable
import com.intellij.database.model.ObjectKind
import com.mycompany.autogenerate.GenerateEntityClass
def GenerateEntityClass entityClass = new GenerateEntityClass();
FILES.chooseDirectoryAndSave("Choose directory", "Choose where to store generated files") { dir ->
SELECTION.filter { it instanceof DasTable && it.getKind() == ObjectKind.TABLE }.each { entityClass.generateFolderFromTable(it, dir) }
}
I get an error
12:06 AM AutoGenerate.groovy: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script24.groovy: 4: unable to resolve class com.companyname.autogenerate.GenerateEntityClass @ line 4, column 1. import com.companyname.autogenerate.GenerateEntityClass;
Edit: Folder Structure Project
-->scripts
----->AutoGenerate.groovy (call this from DataGrip)
----->com
-------->companyname
----------->autogenerate
-------------->AGenerate.groovy
-------------->GenerateEntityClass.groovy
-->src
Upvotes: 0
Views: 683
Reputation: 9584
For some reason abstractions dont work. So I just separated the scripts in different files (ones that change and ones that done) and used a bash script to concat. For now this should work. Until someone answers this in a better way this works.
Upvotes: 0