An open API service indexing awesome lists of open source software.

https://github.com/yadickson/autoplsp

Maven plugin for generate Java classes from SP DataBase
https://github.com/yadickson/autoplsp

database java maven-plugin oracle-database

Last synced: 6 months ago
JSON representation

Maven plugin for generate Java classes from SP DataBase

Awesome Lists containing this project

README

          

# Maven Auto PLSQL/SP Generator Plugin

![version](https://img.shields.io/github/v/release/yadickson/autoplsp?style=flat-square)
![license](https://img.shields.io/github/license/yadickson/autoplsp?style=flat-square)
[![build](https://img.shields.io/github/actions/workflow/status/yadickson/autoplsp/maven.yml?branch=master&style=flat-square)](https://github.com/yadickson/autoplsp/actions/workflows/maven.yml)
![tests](https://img.shields.io/endpoint?style=flat-square&url=https%3A%2F%2Fgist.githubusercontent.com%2Fyadickson%2F2edc636fc2ff6aff4b056d455f3290be%2Fraw%2Fautoplsp-junit-tests.json)
![coverage](https://img.shields.io/endpoint?style=flat-square&url=https%3A%2F%2Fgist.githubusercontent.com%2Fyadickson%2F2edc636fc2ff6aff4b056d455f3290be%2Fraw%2Fautoplsp-jacoco-coverage.json)
[![Central OSSRH][oss-nexus-image]][oss-nexus-url]
[![Central Maven][central-image]][central-url]

Maven plugin to generate Java classes from StoredProcedure and Functions in Database

[Examples](https://github.com/yadickson/autoplsp-examples)

## Support

- Oracle DataBase 11g and 12c
- Basic PostgresSQL
- Basic SQL Server (Tested 2017, Driver jTDS)
- Java >= 8
- Spring Framework >= 4
- Auto package name detection
- Configuration file generation for Spring
- Use output parameters to evaluate process
- Transaction annotation
- Command line for all parameters
- JsonNonNull support
- Parameter IN builder support
- Disable documentation generation
- JUnit5 support

## Oracle

- Procedures
- Functions
- Numerics (NUMBER, DECIMAL, INTEGER, FLOAT, REAL, DEC, INT, SMALLINT, BINARY_DOUBLE, BINARY_FLOAT)
- Texts (CHAR, NCHAR, VARCHAR, VARCHAR2, NVARCHAR2)
- Lobs (CLOB, NCLOB, BLOB)
- Time (DATE, TIMESTAMP)
- ROWID and UROWID
- REF CURSOR (only output)
- TYPE OBJECT (only input)
- TYPE TABLE [NATIVE] (only input)
- TYPE TABLE [TYPE OBJECT] (only input)

## PostgresSQL

- Procedures
- Functions
- Numerics (INTEGER, REAL)
- Texts (TEXT, CHARACTER)
- Working in progress

## SQL Server

- Procedures
- Functions
- Numerics (INT, BIGINT, SMALLINT, TINYINT, DECIMAL, NUMERIC, FLOAT, REAL, BIT, MONEY, SMALLMONEY)
- Texts (CHAR, NCHAR, VARCHAR, NVARCHAR, TEXT, NTEXT)
- Binaries (BINARY, VARBINARY, IMAGE)
- Time (DATE, TIME, DATETIME, DATETIME2, DATETIMEOFFSET, SMALLDATETIME)
- REF CURSOR (Not supported)
- Working in progress

## POM properties

```xml

1.7
1.7
UTF-8

```

## POM dependencies

```xml

org.springframework
spring-core
5.3.26
provided

org.springframework
spring-context
5.3.26
provided

org.springframework
spring-jdbc
5.3.26
provided

org.slf4j
log4j-over-slf4j
1.7.36
provided

javax.annotation
javax.annotation-api
1.3.2
provided

commons-lang
commons-lang
2.6
provided

org.junit.jupiter
junit-jupiter-api
5.8.2
test

org.junit.jupiter
junit-jupiter-engine
5.8.2
test

org.junit.vintage
junit-vintage-engine
5.8.2
test

org.junit.jupiter
junit-jupiter-params
5.8.2
test

org.mockito
mockito-core
4.6.1
test

org.mockito
mockito-junit-jupiter
4.6.1
test

```
## Oracle
```xml

com.oracle.database.jdbc
ojdbc8
23.2.0.0
provided

```
## PostgreSQL
```xml

org.postgresql
postgresql
42.1.4
provided

```
## SQL Server
```xml

net.sourceforge.jtds
jtds
1.3.1
provided

```

## POM plugin config

```xml

com.github.yadickson
autoplsp
...



generator




...
...
...
...
...DataSource
...JdbcTemplate
JDBC/...
Object
Array
...
...
...
...
...
...
...
...
...
true/false
true/false
true/false
true/false
true/false
junit4/junit5
true/false
true/false
true/false
true/false
true/false

...
...


...
...


...
...


...
...


...
...




...driver..
..driver..
..version..

```

### driver (required)

JDBC Driver class name, examples:

```
oracle.jdbc.driver.OracleDriver
```
```
org.postgresql.Driver
```
```
net.sourceforge.jtds.jdbc.Driver
```

### connectionString (required)

Database connection string, examples:

```
jdbc:oracle:thin:@${host}:${port}:${db}
```
```
jdbc:postgresql://${host}:${port}/${db}
```
```
jdbc:jtds:sqlserver://${host}:${port}/${db}
```

### user (required)

Database username

### pass (required)

Database password

### javaDataSourceName (required)

Datasource stereotype name

### javaJdbcTemplateName (optional, default jdbcTemplate)

JdbcTemplate stereotype name

### jndiDataSourceName (required)

Datasource JNDI name

### outputConfigFileName (optional)

Default value **${project.artifactId}-context.xml**

### outParameterCode (optional - default value OUT_RETURN_CODE)

Output parameter code to evaluate process.

If code is Zero (O), **OK**

If code is not Zero (0), **throw SQLException (OUT_RETURN_MSG, null, OUT_RETURN_CODE)**

### outParameterMessage (optional - default value OUT_RETURN_MSG)

Output parameter message.

### javaPackageName (required)

Package name for Java classes

### jsonNonNull (optional - default value false) (since 1.7.12)

Add @JsonInclude(JsonInclude.Include.NON_NULL) annotation.

### includes -> include sp (optional, default .*)

Regular expression to include procedure and functions names, example SP_YES.*

### excludes -> exclude sp (optional, default none)

Regular expression to exclude procedure and functions names, example SP_NOT.*

### resultset -> resultset (optional, default .*)

Regular expression to find resultset on procedure and functions names, example SP_YES.*

### test (true/false) (default false)

Include test folder and test classes

### junit (junit4/junit5) (default junit5)

Include junit configuration

### header (true/false) (default true)

Add header documentation class

### documentation (true/false) (default true)

Add documentation classes

### builder (true/false) (default false)

Include builder parameters only for IN

### lombok (true/false) (default false)

Include lombok definitions

### serialization (true/false)

Add serialization class support

# Command line support

> mvn clean package -Dautoplsp.driver=... -Dautoplsp.connectionString=... -Dautoplsp.user=... -Dautoplsp.pass=... -Dautoplsp.=...

## POM Basic Configuration (include all procedure and function)

```xml

com.github.yadickson
autoplsp
...



generator


...
...
...
...
...DataSource
JDBC/...
...





...driver..
..driver..
..version..

```

## POM Basic Configuration (include one procedure)

```xml

com.github.yadickson
autoplsp
...



generator


...
...
...
...
...DataSource
JDBC/...
...
...

SP_ADD_VALUES






...driver..
..driver..
..version..

```

## POM Basic Configuration (include two procedures)

```xml

com.github.yadickson
autoplsp
...



generator


...
...
...
...
...DataSource
JDBC/...
...
...

SP_ADD_VALUES
SP_SUB_VALUES






...driver..
..driver..
..version..

```

## POM Basic Configuration (exclude one procedure)

```xml

com.github.yadickson
autoplsp
...



generator


...
...
...
...
...DataSource
JDBC/...
...
...

SP_DIV_VALUES






...driver..
..driver..
..version..

```

# How to evaluate result code

**Examples**

```sql
CREATE OR REPLACE PROCEDURE SP_PROCEDURE
(
OUT_P_CODE OUT NUMBER,
OUR_P_MSG OUT VARCHAR2
)
AS
BEGIN

NULL;

END SP_PROCEDURE;
```
```sql
CREATE OR REPLACE FUNCTION FN_FUNCTION
(
OUT_P_CODE OUT NUMBER,
OUR_P_MSG OUT VARCHAR2
)
RETURN NUMBER
AS
BEGIN

RETURN 0;

END FN_FUNCTION;
```

# Build project

```bash
mvn clean package install
```

# Configuration file generated

**spring/database/[outputConfigFileName]**

```xml











```

# Configuration in the parent project

Add import resource in *root-context.xml*

```xml

...

```

# Transaction annotation example

```Java
@Service
public class CustomServiceImpl implements CustomService {

...

@Transactional(rollbackFor = CustomException.class)
@Override
public Long customMethod() throws CustomException {
dao1.execute(...);
dao2.execute(...);
}
}

```

# Example with unit test and persistence into src folder

```

com.github.yadickson
autoplsp
1.8.0

oracle.jdbc.driver.OracleDriver
...
...
...
...
plsql
src/main/java
src/main/resources
.
.
false
false
false
true
false
true
junit5
true
true
false
false
true



...
...
...



```

# Run command line to persistence into src folder

```
$ mvn clean autoplsp:generator -Dautoplsp.user=... -Dautoplsp.pass=... -Dautoplsp.connectionString=jdbc:oracle:thin:@...:...:...
```

# Run test

```
$ mvn test
```

[oss-nexus-image]: https://img.shields.io/nexus/r/https/oss.sonatype.org/com.github.yadickson/autoplsp.svg
[oss-nexus-url]: https://oss.sonatype.org/#nexus-search;quick~autoplsp

[central-image]: https://maven-badges.herokuapp.com/maven-central/com.github.yadickson/autoplsp/badge.svg
[central-url]: https://maven-badges.herokuapp.com/maven-central/com.github.yadickson/autoplsp