ActiveObjects provides an object-relational mapping tool that allows developers to work with database entities as objects. It implements the Active Record pattern, where each entity class maps to a database table with properties mapping to columns. The ActiveObjects service handles persisting object state changes to the database. Plugins can use it by importing the ActiveObjects component and declaring entity classes to have their data stored in the product's database for transparent backup/restore.
4. Agenda
• What is ActiveObjects?
• Example
• Using it in your plugins
• Resources
3
5. What is ActiveObjects?
• Implements the Active Record pattern
• Models an object (entity) as a database table:
• Object class name is the table name
• Object field names are column names
• Any single object instance is one row
• Exposes state methods -- persist object changes to
database 4
7. ActiveObjects EntityManager
import com.atlassian.activeobjects.external.ActiveObjects as
ao;
// create an active object
Page page = ao.create(Page.class);
// retrieve an object from the DB by primary key
Page dbPage = ao.get(Page.class, 843);
// update the object
page.setTitle(“new title”);
// save the object, persisting properties to DB
page.save();
// make it go away 6
ao.delete(page);
8. More interesting things
// count all pages
int totalPages = ao.count(Page.class);
// find and retrieve all pages as objects
Page[] allPages = ao.find(Page.class);
// find pages based on title
Page[] filteredPages = ao.find(Page.class,
Query.select().where(“title ~ ?”, “Documentation”));
// migrate DB schema based on updated object
Task dbMigrationTask = new PluginUpgradeTask() {
ao.migrate(Page.class, BlogPost.class, Issue.class);
}
7
9. “ But I'm losing my edge to better-looking people
with better ideas and more talent.
”
And they're actually really, really nice.
LCD Soundsystem,
articulating our #1 fear
8
10. ActiveObjects details
• Open source project on java.net
• Packaged as plugin for Atlassian products
• ActiveObjects services imported as components
• Currently supports JIRA and Confluence
• Bundled in JIRA 4.4, Confluence 4.0
9
11. Ego: Integration with
Atlassian products
• Uses the same DB the product uses; no additional
configuration
• Transparent backup/restore
• Tables are backed up/restored by same process as rest of
product
• Each plugin client has a private table “space”
• Plugins can’t share tables; use components instead 10
12. ActiveObjects in your plugin
<component-import key="ao" name="Active Objects service"
interface="com.atlassian.activeobjects.external.ActiveObjects"
>
<description>Component to access Active Objects
functionality from the plugin</description>
</component-import>
<ao key="ao-module">
<description>The module configuring the Active Objects
service used by this plugin</description>
<entity>com.atlassian.summit.Page</entity>
</ao> 11
13. ActiveObjects in your plugin
<dependency>
<groupId>com.atlassian.activeobjects</groupId>
<artifactId>activeobjects-plugin</artifactId>
<version>0.9.7</version>
<scope>provided</scope>
</dependency>
12