Skip to content

Instantly share code, notes, and snippets.

@benek
Created December 11, 2012 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benek/4254610 to your computer and use it in GitHub Desktop.
Save benek/4254610 to your computer and use it in GitHub Desktop.
Generate Java fields from database column names
/**
* Author: Javier Alberto Ramirez Hernandez
* Date: 03/12/12
* Time: 10:39
* SintelTI.mx
*/
def basePath = '/base/path'
def convertLine(String line) {
def convertedLine = ''
line.tokenize('_').eachWithIndex { token, index ->
convertedLine += (index == 0) ? token.toLowerCase() : token.toLowerCase().capitalize()
}
convertedLine
}
new File(basePath).eachFile { file ->
def mappedFile = new File(basePath + file.name + '_mapping')
file.eachLine { line ->
mappedFile << "@Column(name=\"$line\")\n"
mappedFile << 'private String ' + convertLine(line) + ';\n'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment