Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Help with Active Objects

James Star
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2012

Hello,

I have begun working with Active Objects. And I need to know how to do 2 things.

1. How do I update an existing entry where name is LIKE "abc"

2. How do I retrieve an existing entry where name is LIKE "abc"

Other questions if I have to use query, is how do I find the table, columns, or even use select?

Started on this tut, but looking for more examples: https://developer.atlassian.com/display/AO/Getting+Started+with+Active+Objects#GettingStartedwithActiveObjects-Creatingyourfirstentity

Thanks,

James

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

7 votes
Answer accepted
Akeles
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2012

Hi James,

Using the https://developer.atlassian.com/display/AO/Getting+Started+with+Active+Objects#GettingStartedwithActiveObjects-Creatingyourfirstentity as an eexample.

The TODO class is a table which the table name is prefixed by AO_XXXXX in the database (becoming AO_XXXX_TODO)

The column names are DESCRIPTION and COMPLETE.

To execute a select, you need something like

ao.find(TODO.class, "DESCRIPTION like ?", abc);

https://developer.atlassian.com/display/AO/Finding+Entities

To update entity, you need to retrieve the records as Entity objects and then update using the mutator method and then calling the save() to persist the changes.

It will look something like

ao.executeInTransaction(new TransactionCallback<Void>() 
{
   @Override
   public Void doInTransaction()
   {
      for (Todo todo : ao.find(Todo.class, "DESCRIPTION like ?", "abc")) 
      {
         todo.setDescription("updated");
         todo.save();
      }
      return null;
   }
});

Hope it helps.

James Star
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 4, 2012

Hausoon, is there any way to remove all children objects (data)?

Thank you.

4 votes
Akeles
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 6, 2012

Hi James,

You can remove the objects by calling delete() after retreiving the objects as follows:

ao.executeInTransaction(new TransactionCallback<Void>() 
{
   @Override
   public Void doInTransaction()
   {
      for (Todo todo : ao.find(Todo.class, "DESCRIPTION like ?", "abc")) 
      {
         todo.delete();
      }
      return null;
   }
});

Details are at https://developer.atlassian.com/display/AO/Deleting+Entities

James Star
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 7, 2012

Thank you Huasoon.

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 8, 2012

Nice answers! (both of them!)

0 votes
James Star
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 4, 2012

Thank you hausoon, that is a BIG HELP :)

And very well written :)

TAGS
AUG Leaders

Atlassian Community Events