GithubHelp home page GithubHelp logo

indabaconsultores / dbcallcdi Goto Github PK

View Code? Open in Web Editor NEW
0.0 5.0 1.0 156 KB

CDI Extension for calling DB Stored Procedures

License: GNU Lesser General Public License v3.0

Java 99.73% PLpgSQL 0.27%
cdi-extension cdi stored-procedures lgpl hibernate deltaspike

dbcallcdi's Introduction

Travis-CI Sonarcloud SonarCloud Technical Debt SonarCloud Coverage

DB Call CDI Extension (LGPL)

A CDI Extension to call stored procedures or database functions declaratively using hibernate.

Feel free to use this library as you wish, make sure to quote the LGPL in all used sources.

Using this project

Include Maven dependency on your pom.xml

<dependency>
	<groupId>es.indaba</groupId>
	<artifactId>DbCallCDI</artifactId>
	<version>1.8</version>
</dependency>

Define your CDI Bean as an interface. The implementation will be provided by the CDI extension:

@ApplicationScoped
public interface DBTester {

  @StoredProcedure("CALL echoProc(?,?)")
  @StoredProcedureResult({ @FieldResult(name = "value", position = 2) })
  @DatabaseCall
  public ProcedureResult<String> callEchoAsProcedure(@StoredProcedureParameter(1) String name) throws Exception;

}

The extension interprets the following annotations in order to build a call to a database stored procedures.

  • DatabaseCall defines that this method should be processed as a stored procedure call
  • StoredProcedure defines the database call expression
  • StoredProcedureResult defines the mapping of the output values retrieved from the stored procedure call and the returning object properties
  • StoredProcedureParameter identifies the stored procedure input parameters

Executing db call:

The interface is injected as a normal CDI bean

@Inject
private DBTester dbTester;
...
ProcedureResult<String> result = dbTester.callEchoAsProcedure(testVal);

The returning type looks like this

public class ProcedureResult<T> {

	private T value;

	public T getValue() {
		return value;
	}

	public void setValue(T value) {
		this.value = value;
	}
}

Using EntityManager Qualifier

@ApplicationScoped
public interface DBTester {

  @StoredProcedure("CALL echoProc(?,?)")
  @StoredProcedureResult({ @FieldResult(name = "value", position = 2) })
  @DatabaseCall(qualifier=MyDatabase.class)
  public ProcedureResult<String> callEchoAsProcedure(@StoredProcedureParameter(1) String name) throws Exception;

}

Check tests for detailed use.

References

Contribute

Pull requests are welcomed!!

dbcallcdi's People

Contributors

dependabot[bot] avatar jjrodrig avatar jurkiri avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

jjrodrig

dbcallcdi's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.