added jpa entity generator

This commit is contained in:
Niclas Thobaben 2021-09-18 14:26:51 +02:00
parent c29498eb96
commit 0e617b6fdc
2 changed files with 6 additions and 8 deletions

View file

@ -12,7 +12,7 @@ module.exports = {
model.dir = model.package.replace(/\./g, '/')
model.fields = model.fields.map(field => {
field.name = utils.camelcase(field.name)
field.type = javaType.mapJavaType(field.type, namespace)
field.type = javaType.mapJavaType(field.type, namespace, 'Entity')
if(field.type.fullQualifiedName && field.type.fullQualifiedName.includes('models')) {
field.type.fullQualifiedName = field.type.fullQualifiedName.replace('models', 'db')

View file

@ -50,19 +50,17 @@ const SUPPORTED_TYPES = {
}
function getCustomType(type, namespace) {
console.log("====== CUSTOM: " + type)
function getCustomType(type, namespace, suffix) {
let match = LAST_ELEMENT_REGEX.exec(type)
let name = ''
let importstatement = null
if(match) {
name = utils.pascalcase(match[2])
importstatement = `${match[1].replace('enums', 'models')}.${name}`
importstatement = `${match[1].replace('enums', 'models')}.${name}${suffix}`
}else {
name = utils.pascalcase(type)
importstatement = `${namespace}.models.${name}`
importstatement = `${namespace}.models.${name}${suffix}`
}
return {
@ -86,9 +84,9 @@ function mapCollection(type) {
}
module.exports = {
mapJavaType: (type, namespace) => {
mapJavaType: (type, namespace, suffix) => {
const baseType = COLLECTION_REGEX.exec(type)[1]
let javaType = SUPPORTED_TYPES[baseType] || getCustomType(baseType, namespace)
let javaType = SUPPORTED_TYPES[baseType] || getCustomType(baseType, namespace, suffix)
if(type.startsWith('[')) {
javaType = mapCollection(javaType);