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
Community moderators have prevented the ability to post new answers.
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.
Hausoon, is there any way to remove all children objects (data)?
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Huasoon.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you hausoon, that is a BIG HELP :)
And very well written :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.