-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
11 deletions.
There are no files selected for viewing
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
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
52 changes: 52 additions & 0 deletions
52
src/main/kotlin/eu/vendeli/jooq/generator/ExtendedKotlinJooqGenerator.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package eu.vendeli.jooq.generator | ||
|
||
import org.jooq.codegen.GeneratorStrategy | ||
import org.jooq.codegen.KotlinGenerator | ||
import org.jooq.impl.DAOImpl | ||
import org.jooq.meta.TableDefinition | ||
import org.jooq.tools.JooqLogger | ||
import java.io.File | ||
import java.io.IOException | ||
|
||
class ExtendedKotlinJooqGenerator : KotlinGenerator() { | ||
private val logger: JooqLogger = JooqLogger.getLogger(ExtendedKotlinJooqGenerator::class.java) | ||
|
||
override fun generateDao(table: TableDefinition) { | ||
super.generateDao(table) | ||
|
||
File("$targetDirectory/DAOExtendedImpl.kt").takeIf { | ||
!it.exists() | ||
}?.also { targetFile -> | ||
targetFile.createNewFile() | ||
javaClass.classLoader.getResource("DAOExtendedImpl.kt")!!.openStream().use { | ||
targetFile.writeBytes(it.readBytes()) | ||
} | ||
} | ||
|
||
val file = getFile(table, GeneratorStrategy.Mode.DAO) | ||
if (file.exists()) { | ||
try { | ||
var fileContent = file.readBytes().toString(Charsets.UTF_8) | ||
|
||
fileContent = fileContent.replace( | ||
"import org.jooq.impl.DAOImpl\n", | ||
"import org.springframework.beans.factory.annotation.Autowired\n", | ||
) | ||
fileContent = fileContent.replace( | ||
" : " + DAOImpl::class.java.getSimpleName(), | ||
" : eu.vendeli.jooq.impl.DAOExtendedImpl", | ||
) | ||
|
||
if (generateSpringAnnotations()) { | ||
val dslContextSetting = ") {\n\t@Autowired\n\tfun setCfg(configuration: Configuration) {\n\t\t" + | ||
"super.setConfiguration(configuration)\n\t}" | ||
fileContent = fileContent.replace(") {", dslContextSetting) | ||
} | ||
|
||
file.writeBytes(fileContent.toByteArray()) | ||
} catch (e: IOException) { | ||
logger.error("generateDao error: {}", file.absolutePath, e) | ||
} | ||
} | ||
} | ||
} |
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