Giter Site home page Giter Site logo

japper's Introduction

Japper

Build Status

Japper is a JDBC mapper which can handle a JDBC ResultSet and convert* it to a given class (Entity). The mapper does not have any other dependency.

Getting started

Japper is partly using javax.persistence Annotations in order to do the mapping. It is not implementing the jpa specifications.

  • Add the dependency of japper to your project (TODO)
  • Add javax.persistence dependency

The code usage is like the following:

ResultSet resultSet = ...;
Person person = Mapper.into(Person.class).map(resultSet);
@NoArgsConstructor
public class PersonEntity {
  @Transient
  private String notDatabaseRelevant;
  @Column(name = "last_name")
  private String sureName;
  @Convert(converter = ObjectToStringConverter.class)
  private Object actualAString;
}

public class ObjectToStringConverter implements AttributeConverter<Object, String> { ... }

Be aware that the entity needs a default constructor in order to be instantiated. This means either lombok`s @NoArgsConstructor or a default constructor by hand.

Spring JDBC Template

jdbcTemplate.query("select * from person", (rs, rowNum) -> Mapper.into(Person.class).map(rs))

Naming Conventions

The naming convention is jpa like, means that camel case variables inside the entity are getting converted to database columns with underscore:

 +-----------+-----------+
 | Entity    | Database  |
 +-----------+-----------+
 | sureName  | sure_name |
 +-----------+-----------+
 | SureName  | sure_name |
 +-----------+-----------+
 | SURE_NAME | sure_name |
 +-----------+-----------+
 | SURENAME  | surename  |
 +-----------+-----------+
 

Keep in mind that the ResultSet specification states that it is case insensitive, so it does not matter if the column name is upper or lower case.

Supported Annotations

  • javax.persistence.Transient: If the variable should not be taken into account at all
  • javax.persistence.Column: Used to specify a different name as the database column (if the name attribute is empty the annotation is ignored)
  • javax.persistence.Convert: Converter if the datatype should be changed from the database into the entity class. A converter has to have the converter attribute present.

Java 8 DateTime Api

The mapper supports the DateTime Api for

  • LocalDateTime
  • LocalDate

If there is the need of others which are not implemented yet, feel free to use a converter (shown above).

Built With

  • Java
  • Gradle

Authors

  • Simon Schober - Initial Work

License

This project is licensed under the MIT License - see the LICENSE.MD file for details

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.