PikaORM

PikaORM

PikaORM is a simple ORM for Java, designed for the Montana State University Databases class. It follows the ActiveRecord pattern, mapping java classes to database tables. It features a fluent query API, validation, life-cycle callbacks and allows you to drop to raw SQL if you need to.

Pika does not use config files or annotations.

Documentation

Sample Code

Todo.java
// ActiveRecord style classes map to tables, e.g. `todos`  
public class Todo extends PikaBean {
    private String title;
    private String description;
    private Boolean completed = false;

    public Todo() {}

    public void setTitle(String title)              { this.title = title; }
    public void setDescription(String description)  { this.description = description; }
    //  etc...

    // A standard typed entry point for queries against Todos
    public static PikaClassFinder<Todo> find() {
        return find(Todo.class);
    }

    // simple validation mechanism
    @Override
    protected void validation() {
        require("title");
    }
}


PikaORM orm = new PikaORM("jdbc:sqlite:app.db") // connect to a database
        .makeDefaultORM()                       // make this the standard connection
        .withMigrations(new AppMigrations())    // migrations keep your schema up to date
        .applyMigrations();

// PikaBeans support simple CRUD
Todo todo = new Todo();
todo.setTitle("Read the docs");
todo.setDescription("Finish the PikaORM guide");
todo.saveOrThrow();

// A nice fluent API for querying
Todo first = Todo.find().byId(1);
PikaList<Todo> active = Todo.find()
        .where("completed = :done", "done", false)
        .fetchList(); // convert to a list for in-memory work

// Drop down to raw SQL when you want to
PikaList<Todo> rows = orm.select("SELECT * FROM todos", Todo.class).fetchList();