Skip to content

baudoliver7/jdbc-toolset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EO principles respected here DevOps By Rultor.com We recommend IntelliJ IDEA

Javadoc License codecov Hits-of-Code Maven Central PDD status

A toolset for Jdbc

There is some tools:

DataSourceWrap and ConnectionWrap

We give some wrappers to easily decorate DataSource and Connection.

public final MyDataSource extends DataSourceWrap {
    
    public MyDataSource(final DataSource origin) {
        super(origin);
    }
}

public final MyConnection extends ConnectionWrap {

    public MyConnection(final Connection origin) {
        super(origin)
    }
}

LockedConnection

Sometimes, you don't want some pieces of code to close your connection after use. So, to prevent them to close your connection, you can decorate it with LockedConnection before give them like this:

new LockedConnection(
    connection
)

LocalLockedDataSource

Sometimes, you are in situations where you want to use only one connection during the current thread and be sure that all modifications are taken into account only when you decide to explicitly commit them. Then, LocalLockedDataSource is your friend in such case. Just decorate your datasource like this :

try (final Connection connection = datasource.getConnection()) {
    final DataSource uds = new LocalLockedDataSource(
        datasource, connection
    );
    final Connection conn1 = uds.getConnection();
    // We do here some operations with our connection.
    // After that, we attempt to commit and close it.
        conn1.commit(); // no effect
        conn1.close(); // no effect
        ...
    // Somewhere else in the same thread, we want a connection
    // to do another operations.
    final Connection conn2 = uds.getConnection(); // we get here the current connection
        ...
        ...
    // We choose now to commit all changes.
    // For that, we should use connection that is stored in the local thread `cthread`.
        cthread.get().commit();
};

Use it in your project

If you're using Maven, you should add it to your pom.xml dependencies like this:

<dependency>
    <groupId>com.baudoliver7</groupId>
    <artifactId>jdbc-toolset</artifactId>
    <version><!-- latest version --></version>
</dependency>

How to contribute

Fork repository, make changes, send us a pull request. We will review your changes and apply them to the master branch shortly, provided they don't violate our quality standards. To avoid frustration, before sending us your pull request please run full Maven build:

mvn clean install -Pqulice

Keep in mind that JDK 8 and Maven 3.1.0 are the lowest versions you may use.

Got questions ?

If you have questions or general suggestions, don't hesitate to submit a new Github issue.