Skip to content

Commit 9f030fa

Browse files
committed
feat(database): add GenerateEntityAction for PL/SQL to Java for design new workflow
Add a new action, GenerateEntityAction, to convert PL/SQL code to Java entity. This action is available when editing a file with the Oracle PL/SQL dialect. It uses a template to render the Java entity code based on the selected PL/SQL code. The rendered code is then displayed in a prompter for further handling. This feature enables users to easily generate Java entities from PL/SQL code, facilitating the migration process.
1 parent 563e88b commit 9f030fa

File tree

5 files changed

+96
-4
lines changed

5 files changed

+96
-4
lines changed

CHANGELOG.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1-
# [](https://github.com/unit-mesh/auto-dev/compare/v1.5.4...v) (2024-01-19)
1+
# [](https://github.com/unit-mesh/auto-dev/compare/v1.5.5...v) (2024-01-21)
22

33
## [Unreleased]
44

5+
## [1.5.5](https://github.com/unit-mesh/auto-dev/compare/v1.5.4...v[1.5.5]) (2024-01-21)
6+
7+
### Bug Fixes
8+
- **java:** add Java language check in AutoCrudAction ([6669b4b](https://github.com/unit-mesh/auto-dev/commit/6669b4ba8cfa142805760eb894e59ca6a765753b))
9+
- **llm:** add trailing slash to customOpenAiHost && fixed [#77](https://github.com/unit-mesh/auto-dev/issues/77) ([f68d124](https://github.com/unit-mesh/auto-dev/commit/f68d12431e5ed774ec22f6acbaaa33810e72f4a8))
10+
- **test:** add check for now writing test service [#78](https://github.com/unit-mesh/auto-dev/issues/78) ([a4b0d04](https://github.com/unit-mesh/auto-dev/commit/a4b0d04c285a1c702af0d55cc11953fb67beb8ad))
11+
12+
### Features
13+
- **database:** add SQL living documentation support ([08c82bd](https://github.com/unit-mesh/auto-dev/commit/08c82bdd6865bfb824e8008a845335ddf013ebb2))
14+
- **database:** improve finding nearest SQL definition ([6e95d47](https://github.com/unit-mesh/auto-dev/commit/6e95d47186cccadc981369172ceb9ebcf09da9ea))
15+
- **docs:** add basic PL/SQL implementation ([478f1d9](https://github.com/unit-mesh/auto-dev/commit/478f1d9bab7f2347ac34bbc9cdfd0b627e1919e9))
16+
- **java:** add detectLanguageLevel function ([6f7b156](https://github.com/unit-mesh/auto-dev/commit/6f7b156bd6d28ba7fef67f5f21654d948e86501b))
17+
- **provider:** add language level detection ([8cd2584](https://github.com/unit-mesh/auto-dev/commit/8cd25842513a7fb7e999ae2df7b93d9aa01cb326))
18+
- **rust:** add support for EnumContext ([d58b435](https://github.com/unit-mesh/auto-dev/commit/d58b435ddc6bc6e6c5cc0dedca1f0f6bb6efd341))
19+
- **scala:** add ScalaClassContextBuilder and test case ([98ef74f](https://github.com/unit-mesh/auto-dev/commit/98ef74fc68b21399f0e6b58e90f81ffb63dd282d))
20+
- **sql:** add functionality to update living documentation ([c99b21d](https://github.com/unit-mesh/auto-dev/commit/c99b21d09d42532fffd601e82c0d0a41dda88f61))
21+
522
## [1.5.4](https://github.com/unit-mesh/auto-dev/compare/v1.5.3...v[1.5.4]) (2024-01-19)
623

724
### Bug Fixes
@@ -904,7 +921,8 @@
904921
- update for configure ([1eb22b8](https://github.com/unit-mesh/auto-dev/commit/1eb22b8a0dfb9aa6a379aa6fb05dd93bf07c05af))
905922
- use single binding ([9092752](https://github.com/unit-mesh/auto-dev/commit/9092752a4a79ff64d062e089137f427a83db3988))
906923

907-
[Unreleased]: https://github.com/unit-mesh/auto-dev/compare/v1.5.4...HEAD
924+
[Unreleased]: https://github.com/unit-mesh/auto-dev/compare/v1.5.5...HEAD
925+
[1.5.5]: https://github.com/unit-mesh/auto-dev/compare/v1.5.4...v1.5.5
908926
[1.5.4]: https://github.com/unit-mesh/auto-dev/compare/v1.5.3...v1.5.4
909927
[1.5.3]: https://github.com/unit-mesh/auto-dev/compare/v1.5.2...v1.5.3
910928
[1.5.2]: https://github.com/unit-mesh/auto-dev/compare/v1.4.4...v1.5.2

exts/database/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
# Database Extensions
22

3-
This directory contains extensions that are specific to a database.
3+
This directory contains extensions that are specific to a database.
44

55
- Generate SQL DDL for a database from a schema
66

77
Or others?
88

9+
## Usecases: PL/SQL to Java
10+
11+
1. Generate Repository from PL/SQL code
12+
2. Generate Entity from PL/SQL code
13+
3. Generate Service from PL/SQL code
14+
- Create test cases for the service
15+
4. Generate Java code from PL/SQL code
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package cc.unitmesh.database.actions
2+
3+
import cc.unitmesh.devti.gui.sendToChatWindow
4+
import cc.unitmesh.devti.intentions.action.base.AbstractChatIntention
5+
import cc.unitmesh.devti.provider.ContextPrompter
6+
import cc.unitmesh.devti.template.TemplateRender
7+
import com.intellij.openapi.diagnostic.logger
8+
import com.intellij.openapi.editor.Editor
9+
import com.intellij.openapi.project.Project
10+
import com.intellij.psi.PsiFile
11+
import com.intellij.sql.dialects.oracle.OraDialect
12+
13+
class GenerateEntityAction : AbstractChatIntention() {
14+
private val logger = logger<GenerateEntityAction>()
15+
16+
override fun priority() = 901
17+
18+
override fun getFamilyName(): String = "Generate Java Entity"
19+
20+
override fun getText(): String = "Generate Java Entity"
21+
22+
override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?): Boolean {
23+
if (editor == null || file == null) return false
24+
return file.language is OraDialect
25+
}
26+
27+
28+
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
29+
if (editor == null || file == null) return
30+
val selectedText = editor.selectionModel.selectedText ?: return
31+
32+
val templateRender = TemplateRender("genius/migration")
33+
val template = templateRender.getTemplate("gen-entity.vm")
34+
templateRender.context = GenEntityContext(
35+
lang = file.language.displayName ?: "",
36+
sql = selectedText,
37+
)
38+
val prompter = templateRender.renderTemplate(template)
39+
40+
logger.info("Prompt: $prompter")
41+
42+
sendToChatWindow(project, getActionType()) { panel, service ->
43+
service.handlePromptAndResponse(panel, object : ContextPrompter() {
44+
override fun displayPrompt(): String = prompter
45+
override fun requestPrompt(): String = prompter
46+
}, null, false)
47+
}
48+
}
49+
}
50+
51+
data class GenEntityContext(
52+
val lang: String = "",
53+
var sql: String = "",
54+
)

exts/database/src/main/resources/cc.unitmesh.database.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
</dependencies>
66

77
<extensions defaultExtensionNs="cc.unitmesh">
8-
<!-- -->
8+
<autoDevIntention>
9+
<className>cc.unitmesh.database.actions.GenerateEntityAction</className>
10+
<bundleName>messages.AutoDevBundle</bundleName>
11+
<categoryKey>intention.category.llm</categoryKey>
12+
</autoDevIntention>
13+
914
<livingDocumentation
1015
language="SQL"
1116
implementationClass="cc.unitmesh.database.provider.SqlLivingDocumentationProvider"/>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
You are a professional application migration programmer. Based on following Oracle PL/SQL code to Java entity,
2+
just need to convert the code to Java entity, no need to write any code logic.
3+
4+
```${context.lang}
5+
${context.sql}
6+
```
7+
8+

0 commit comments

Comments
 (0)