sql-reader-lib

GitHub Repo stars GitHub issues GitHub last commit JitPack

Introduction

This project was created for study purposes, but also to be used for public or private projects. My plan is to keep it up to date and working in the best possible way, but for that I need the help of the community. If you encounter any problems, report by clicking here.

Hooking into

You can get the latest version available on JitPack.

Gradle

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    compileOnly 'com.github.eokasta:sql-reader-lib:VERSION'
}

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
    
<dependency>
    <groupId>com.github.eokasta</groupId>
    <artifactId>sql-reader-lib</artifactId>
    <version>VERSION</version>
</dependency>

Examples

Main

private final ReaderAdapterMap readerAdapterMap = new ReaderAdapterMap(); /* If you want to create adapters */
private final ResultSetReader resultSetReader = new ResultSetReader(readerAdapterMap /* If you want to create adapters */);

private void registerAdapters() {
  readerAdapterMap.registerAdapter(
    String.class /* Type received */,
    ACoolClass.class /* Return type */,
    new ACoolClassAdapter() /* ReaderAdapter implemented */
  );
}

private AHappyClass parse(ResultSet resultSet) {
  return resultSetReader.parseSafe(
    resultSet /* ResultSet with query return values */,
    AHappyClass.class /* Class type to parse */
  ); /* Returns the instance of the AHappyClass class with the assigned attribute values */
}

Adapter class

public class ACoolClassAdapter implements ReaderAdapter<ACoolClass> {

  @Override
  public ACoolClass parse(Object object) {
    return /* Returns the ACoolClass instance */;
  }

}

Object class

Example one

@ReadClass /* All attributes present in the class will receive their due values, except those that contain @IgnoreField */
public class AHappyClass {
  
  private String name;
  private int age;
  @IgnoreField /* This attribute will not receive any value when it is instantiated by ResultSetReader */
  private Double balance;
  private ACoolClass coolClass;
  
  public AHappyClass() { } /* If there is a constructor with parameters, an overload must be made with another constructor without parameters */
  
}

Example two

/* It is no longer necessary to use @IgnoreField in this type of example */
public class AHappyClass {
  
  @ReadField /* All attributes that contain @ReadField will receive values when they are instantiated by ResultSetReader */
  private String name;
  @ReadField
  private int age;
  private Double balance;
  @ReadField
  private ACoolClass coolClass;
  
  public AHappyClass() { } /* If there is a constructor with parameters, an overload must be made with another constructor without parameters */
  
}

For more examples, click here.