Using ActiveObjects in Atlassian Plugins

3,971 views
3,749 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,971
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
15
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Using ActiveObjects in Atlassian Plugins

    1. 1. Using ActiveObjects inAtlassian PluginsWe don’t like databases either.Ben SpeakmonDeveloper Relations, Atlassian 2
    2. 2. Agenda• What is ActiveObjects?• Example• Using it in your plugins• Resources 3
    3. 3. 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
    4. 4. Entity objectsimport net.java.ao.Entity; // adds getID() for primary keypublic interface Page extends Entity { String getTitle(); void setTitle(String title); ContentWrapper getBody(); void setBody(ContentWrapper content);} 5
    5. 5. ActiveObjects EntityManagerimport com.atlassian.activeobjects.external.ActiveObjects asao;// create an active objectPage page = ao.create(Page.class);// retrieve an object from the DB by primary keyPage dbPage = ao.get(Page.class, 843);// update the objectpage.setTitle(“new title”);// save the object, persisting properties to DBpage.save();// make it go away 6ao.delete(page);
    6. 6. More interesting things// count all pagesint totalPages = ao.count(Page.class);// find and retrieve all pages as objectsPage[] allPages = ao.find(Page.class);// find pages based on titlePage[] filteredPages = ao.find(Page.class, Query.select().where(“title ~ ?”, “Documentation”));// migrate DB schema based on updated objectTask dbMigrationTask = new PluginUpgradeTask() { ao.migrate(Page.class, BlogPost.class, Issue.class);} 7
    7. 7. “ But Im losing my edge to better-looking people with better ideas and more talent. ” And theyre actually really, really nice. LCD Soundsystem, articulating our #1 fear 8
    8. 8. 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
    9. 9. Ego: Integration withAtlassian 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
    10. 10. ActiveObjects in your plugin<component-import key="ao" name="Active Objects service"interface="com.atlassian.activeobjects.external.ActiveObjects">  <description>Component to access Active Objectsfunctionality from the plugin</description></component-import><ao key="ao-module">  <description>The module configuring the Active Objectsservice used by this plugin</description>  <entity>com.atlassian.summit.Page</entity></ao> 11
    11. 11. ActiveObjects in your plugin<dependency>  <groupId>com.atlassian.activeobjects</groupId>  <artifactId>activeobjects-plugin</artifactId>  <version>0.9.7</version>  <scope>provided</scope></dependency> 12
    12. 12. Wrap-up• In-depth tutorial: atlss.in/AOGettingStarted• Documentation: atlss.in/AODocumentation• Plugin SDK: atlss.in/PluginSDK 13

    ×