Created
December 11, 2012 00:20
-
-
Save benek/4254610 to your computer and use it in GitHub Desktop.
Generate Java fields from database column names
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
/** | |
* 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