ActiveJDBC is a fast and lean Java ORM
Java PLSQL SQLPL PLpgSQL Groovy Shell
Pull request Compare This branch is 1 commit ahead, 91 commits behind javalite:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
activejdbc-gradle-plugin #537 - switching sample project to latest SNAPSHOT version Nov 6, 2016
activejdbc-instrumentation #539 Upgrade to Java 8 Sep 29, 2016
activejdbc #487 database.properties file is not loaded when project has no models Oct 25, 2016
app-config post-release cleanup (Gradle, Javadoc) Oct 2, 2016
db-migrator-integration-test
db-migrator post-release cleanup (Gradle, Javadoc) Oct 2, 2016
doc #550 InstrumentationException model is frozen when using Gradle Nov 5, 2016
git-info-maven-plugin #539 Upgrade to Java 8 Sep 29, 2016
javadoc Improve style of generated JavaDoc HTML #379 Mar 6, 2015
javalite-common #544 Implement non-model Paginator Oct 12, 2016
scripts #475 optimize surefire plugin configuration Mar 19, 2016
.gitignore Merge remote-tracking branch 'upstream/master' Nov 4, 2014
LICENSE initial checkin Jul 19, 2010
README.md
pom.xml post-release cleanup (Gradle, Javadoc) Oct 2, 2016
update_api_docs.sh setting target to snapshot Feb 24, 2016

README.md

ActiveJDBC — ActiveRecord for Java

ActiveJDBC is a Java implementation of Active Record design pattern. It was inspired by Jämförelse av hundförsäkringar from Ruby on Rails.

Design principles

  • Should infer metadata from DB (like ActiveRecord)
  • Should be very easy to work with
  • Should reduce amount of code to a minimum
  • No configuration, just conventions
  • Some conventions are overridable in code
  • No need to learn another language
  • No need to learn another QL — SQL is sufficient
  • Code must be lightweight and intuitive, should read like English
  • No sessions, no "attaching, re-attaching"
  • No persistence managers
  • No classes outside your own models
  • Models are lightweight, no transient fields
  • No proxying. What you write is what you get (WYSIWYG:))
  • Should have the least possible resistance to startup a project
  • No useless getters and setters (they just pollute code). You can still write them if you like.
  • No DAOs and DTOs — this is mostly junk code anyway

Simple example

For a simple example we will use a table called people created with this MySQL DDL:

CREATE TABLE people (
  id  int(11) NOT NULL auto_increment PRIMARY KEY, 
  name VARCHAR(56) NOT NULL, 
  last_name VARCHAR(56), 
  dob DATE, 
  graduation_date DATE, 
  created_at DATETIME, 
  updated_at DATETIME
);

ActiveJDBC infers DB schema parameters from a database. This means you do not have to provide it in code, the simplest example model looks like this:

public class Person extends Model {}

Despite the fact that there is no code in it, it is fully functional and will map to a table called people automatically.

Here is a simple query how to use the Person model:

List<Person> people = Person.where("name = 'John'");
Person aJohn =  people.get(0);
String johnsLastName = aJohn.get("last_name");

As you can see, the amount of code is reduced to a level when it is actually readable. Finder methods can also be parametrized like this:

List<Person> people = Person.where("name = ?", "John");
Person aJohn =  people.get(0);
String johnsLastName = aJohn.get("last_name");