|
Project Information
Links
|
IntroductionActiveJDBC is a Java implementation of Active Record design pattern. It was inspired by ActiveRecord ORM from Ruby on Rails. For more information on features of ActiveJDBC, see the Features page.
FeaturesPlease, follow this link: Features NewsMarch 20 2012 - ActiveWeb and ActiveJDBC were presented to the Software Craftsmanship McHenry County - got great reception. Part of the presentation was to build a simple live application with test coverage. January 25 2012 - Support for Microsoft SQL Server was added. This brings the number of databases supported by ActiveJDBC to 5: MySQL, PostgreSQL, Oracle, H2, MS SQLServer. Kudos to John Richardson for this contribution. Support of MS SQLServer includes both Microsoft and TDS drivers. January 3 2012 - I did a presentation at Groupon Geekfest on ActiveWeb and ActiveJDBC: http://geekfest.gathers.us/events/geekfest-activeweb-and-activejdbc. It was very well received. Some reactions from Ruby developers were: "I'd die to have this when I did Java", as well as help in developing support for Microsoft SQLServer September 18 2011 - A new caching provider has been integrated into the project: EHCache. This was done because it seems that OSCache, however good of a project, is retired by OpenSymphony. August 10 2011 - Dear community, we are preparing for a first formal release of ActiveJDBC and publishing it to the Maven Central. In preparations, we upgraded the version from 1.1-SNAPSHOT to 1.2-SNAPSHOT and also moved all classes from package: activejdbc to package: org.javalite.activejdbc We also moved group artifact from: activejdbc to: org.javalite.activejdbc All these superficial changes are required by Sonatype to publish to the Maven Central. We apologize for the temporary inconvenience, but this change is something we did not anticipate. However, with ActiveWeb following the suit, it too will be released under org.javalite group ID and package. The old repository you are using for 1.1-SNAPSHOT: http://ipsolutionsdev.com/snapshots/ will stay untouched indefinitely, so you can upgrade to 1.2-SNAPSHOT at any time in the future, if you can wait till a fixed release 1.2 will be published to Maven Central (~ 2 weeks) The new repository we are publishing snapshots is hosted by Sonatype: https://oss.sonatype.org/content/repositories/snapshots/org/javalite/ July 20 2011 Made JavaDoc accessible: http://ipsolutionsdev.com/activejdbc/ May 22 2011 Phil Suh added support for H2 Database February 23 2011 Added a long awaited generation of JSON into classes Model and LazyList, for more information navigate to GenerationOfJson January 12 2011 ActiveJDBC now has ability to load metadata on demand - when a database is first accessed. This means that in cases when a system has more than one database, their metadata is not loaded up all at once. This gives more flexibility because you do not need to have all connections available in places where you only need one. November 9 2010 ActiveJDBC now has ability to generate stock XML from models and lists of models. Follow this link for more information: GenerationOfXml September 28 2010 ActiveJDBC validations framework has been extended to take in dynamic parameters, and reflect internationalized messages. For more information, take a look at Validations September 7 2010 All artifacts from this project are published to a new snapshot repository: http://ipsolutionsdev.com/snapshots/. August 18 2010: Well, it did finally happen: yesterday I ran a presentation on ActibeJDBC at Thoughtworks. Attendance was at healthy 25 people, and all were engaged and asked a lot of questions. To those attended: thank you for interest in the framework, your questions and suggestions! This proves once again that there is room for a new Java ORM system. If you'd like to get the presentation slides, follow this link: https://activejdbc.googlecode.com/svn/trunk/doc/activejdbc-cjug.pdf. happy coding! August 11 2010: Chicago Java User Group accepted my proposal for a presentation on ActiveJDBC. Thoughtworks will be hosting it on August 17th. July 19 2010: ActiveJDBC sources are published on Google Code under Apache 2.0 License. Design principles
Programming modelFor 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 how to use it: How to queryQuerying is easy: 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");Paging through dataList<Employee> people = Employee.where("department = ? and hire_date > ? ", "IT", hireDate)
.offset(21)
.limit(10)
.orderBy("hire_date asc");This query will ensure that the returned result set will start at the 21st record and will return only 10 records, according to the "orderBy". The ActiveJDBC has a built in facility for various database flavors and it will generate appropriate SQL statement that is specific for a DB (Oracle, MySQL, etc) and is efficient. It will not fetch all records, starting with 1. Creating new recordsThere are several ways to do this, and the simplest is: Person p = new Person();
p.set("name", "Marilyn");
p.set("last_name", "Monroe");
p.set("dob", "1935-12-06");
p.saveIt();There is also a shorthand version of doing the same: new Person().set("name", "Marilyn").set("last_name", "Monroe").set("dob", "1935-12-06").saveIt();and yet another one : Person.createIt("name", "Marilyn", "last_name", "Monroe", "dob", "1935-12-06");Updating a single recordEmployee e = Employee.findFirst("first_name = ?", "John");
e.set("last_name", "Steinbeck").saveIt();deleting a recordEmployee e = Employee.findFirst("first_name = ?", "John");
e.delete();For more detailed information, look at the Features page How to downloadIf you are using Maven, add these repositories to your pom: <repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Plugin Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>sonatype-nexus-plugin-snapshots</id>
<name>Sonatype Nexus Plugin Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
If you are not using Maven, you can pull down the latest from here: https://oss.sonatype.org/content/repositories/snapshots/org/javalite/ Current version is: 1.2-SNAPSHOT. How to buildCheck the project out from SVN: svn checkout http://activejdbc.googlecode.com/svn/trunk/ activejdbc Navigate to the project directory: cd activejdbc Execute this command at the root of the project (provided you have Maven installed): mvn clean install -Dmaven.test.skip=true Note: you need to disable tests because the build would fail if you do not have databases configured for testing. What ActiveJDBC is not
Getting StartedPlease, follow this link: Getting Started Supported databasesCurrently ActiveJDBC supports MySQL, PostgreSQL, Oracle, H2 and MS SQLServer SupportPlease, post your questions here: http://groups.google.com/group/activejdbc-group Frequently Asked QuestionsWant to contribute?Please consider these steps:
Once you are comfortable with code, please request a branch created for your feature. You will be made a contributor on the project, and will commit your code to a branch. We will examine code and it all checks, we will merge the code to trunk, and make it official. Please consider these requirements:
We welcome your help, contributions and suggestions. |