/LightWeightSQLWrapper

Library which let you connect faster and easier to a databases.

Primary LanguageJavaApache License 2.0Apache-2.0

Lightweight SQL wrapper

Lightweight mysql driver wrapper which let you connect faster and easier to an existing database.

If your project is built with Maven add following to your pom file:

<dependency>
    <groupId>com.vladimanaev</groupId>
    <artifactId>lightweight-sql-wrapper</artifactId>
    <version>2.5</version>
</dependency>

If your project is built with Gradle add following to your gradle setting file:

compile 'com.vladimanaev:lightweight-sql-wrapper:2.5'

Dependencies

<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<version>6.0.2</version>
</dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-dbcp2</artifactId>
    <version>2.1.1</version>
</dependency>

Example

//result object class example
public class TestResultObj {

    @ColumnDetails(name = "test_column")
    private String column;

}

// code example

//initialize once
DriverManagerWrapperImpl driverManagerWrapper = DriverManagerWrapperImpl.createDefaultConnectionPool("db_url", "test_user", "password");
MySQLConnector mySQLConnector = new MySQLConnector(driverManagerWrapper);

//on each query do following
Query query = new Query("SELECT test_column FROM somewhere WHERE everything_is_good = ?");
query.addParameter("true", JDBCType.BOOLEAN);

List<TestResultObj> testResultObjs = mySQLConnector.getConnection().executeSelectQuery(TestResultObj.class,
                                                                                       TestResultObj::new, (f) -> {
    ColumnDetails annotation = f.getAnnotation(ColumnDetails.class);
    return annotation != null ? annotation.name() : null;
}, query);