Code Monkey home page Code Monkey logo

rosetta's Introduction

Rosetta Build Status

Overview

Rosetta is a Java library that leverages Jackson to take the pain out of mapping objects to/from the DB, designed to integrate seamlessly with jDBI. Jackson is extremely fast, endlessly configurable, and already used by many Java webapps.

Rosetta isn't an ORM. It doesn't silently read and write to your database, validate input, or manage connections. It does two things:

  1. Binds Java objects to query parameters using a jDBI BindingAnnotation
  2. Maps query results back to Java objects using a jDBI ResultSetMapperFactory

Usage

To use with jDBI on Maven-based projects, add the following dependency:

<dependency>
  <groupId>com.hubspot.rosetta</groupId>
  <artifactId>RosettaJdbi</artifactId>
  <version>3.11.0</version>
</dependency>

Binding

You can bind JDBI arguments in your DAO using @BindWithRosetta.

public interface MyDAO {
  @SqlUpdate("UPDATE my_table SET name = :name, type = :type WHERE id = :id")
  void update(@BindWithRosetta MyRow obj);
}

@BindWithRosetta behaves like jDBI's @BindBean, but it converts the object to a tree using Jackson which lets you use all the Jackson annotations you know and love to customize the representation. It's also generally more robust - it supports the not-quite-standard naming conventions, enums, fluent setters, nested objects (with dot-notation), getters without fields, etc.

Mapping

To register Rosetta globally for mapping, you can add it to your DBI like so:

dbi.registerMapper(new RosettaMapperFactory());

Or to test it out on a single DAO you would do:

@RegisterMapperFactory(RosettaMapperFactory.class)
public interface MyDAO { /* ... */ }

Or to use in combination with a Handle: (same idea to register on a Query)

handle.registerMapper(new RosettaMapperFactory());

Advanced Features

For a list of advanced features, see here

rosetta's People

Contributors

hs-jenkins-bot avatar jhaber avatar ldriscoll avatar mattastica avatar tdavis avatar tpetr avatar

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.