|
|
|
|||||
|
Ice and Object Persistence
Hi, I'm really new to ICE and have some problems understanding some things.
Anyway, here's the scenario: I have a little application which stores books and authors in an object oriented database. Now, I already have the model, and the beans (Author.java and Book.java) This works well from a pure java approach. Nonetheless I want to be able to use these objects with a c++ program too. Here's where ICE comes into the game. Now, Author and Book don't really have anything special to them. Their attributes are strings and booleans. All of them can be correctly mapped to c++. So my questions are: - What's the best approach on this case? - Should I generate interfaces or classes or tie classes or what? - The database exists, so I can't create new Objects, I must use the ones I already have... Is that possible? - How would my ICE file would look like? - How can I use a hypothetical AuthorPrx to manage the existing Author? - Is this possible? Thanks ![]() |
|
|||||
|
I'll try to be more specific tomorrow...
But part of the problem is that the database is already in use, there's already a model and I have to adapt slice to it. Right now I'm a little bit stuck as of how should I interact with the database. See, normally I would have something like: Code:
public class Author public String getName()... public void setName()... public List<Book> getBooks()... public void setBooks(List<Books> books)... ... Code:
... public void save()... public void delete()... public List<Author> get(Author author)... Code:
sequence<Author> AuthorSeq;
class Author {
...
idempotent AuthorSeq get(Author* a);
}
Then another question arises... How should I implement the queries? - idempotent AuthorSeq getAuthor(Author* a); - idempotent void getAuthor(Author* a, out AuthorSeq); - sequence<Author*> AuthorSeq; idempotent AuthorSeq getAuthor(Author* a); - sequence<Author*> AuthorSeq; idempotent void getAuthor(Author* a, out AuthorSeq); There's where I begin getting lost! How do I get my list of Authors? Note.- All my "sequences<Type>" are mapped to java.util.list<E>... I just didn't write that on the code to make it a little bit smaller. ![]() |
|
||||||
|
It looks to me like you are quite confused about the difference between pass by proxy, and pass by value. I would recommend reading my article "Proxies" in http://www.zeroc.com/newsletter/issue23.pdf. You might also want to look in more detail about the Ice object model in the Ice manual.
Code:
public void save()... public void delete()... public List<Author> get(Author author)... Code:
interface Book
{
};
sequence<Book*> BookPrxSeq;
interface Library
{
sequence<BookPrxSeq> getBookByAuthor(string author);
};
|
|
|||||
|
Read your article
It did help me, now I know that there's no problem at all --and in fact makes a lot more sense-- to return proxies on my queries. So, in my "finder" interface, I can define something like:Code:
interface Finder {
idempotent AuthorPrxSeq getAuthors(Author* a);
}
Code:
sequence<Author*> AuthorPrxSeq; Code:
class Author {
idempotent String getName();
idempotent String getLastName();
idempotent BookPrxSeq getBooks();
idempotent void setName(String name);
idempotent void setLastName(String lastName);
idempotent void setBooks(BookPrxSeq books);
}
Code:
sequence<Book*> BookPrxSeq; Last edited by gurito : 09-16-2008 at 05:04 AM. |
|
|||||
|
YaY! It works!
I don't know if it's the best way to do it though... So, anyway, in my servant code I created a new Author ice-object: Code:
Author author = new AuthorI(); Code:
AuthorPrx prx = AuthorPrxHelper.checkedCast(adapter.addWithUUID(author)); YAY!Thanks for all your help! I'll keep in touch (Surely I'll have more and more questions) |
|
||||||
|
Glad to hear you are getting along with your project!
What you should probably do is use a servant id that is representative of the database object (for example, use the database id), and then use a default servant. This allows you do use a single servant instance for all database objects of a given type. I would also encourage you to design your interfaces in such a way as to not require multiple invocations to get your object data. This is a very good way to get bad performance. For example, in your above interface you have: Code:
class Author {
idempotent String getName();
idempotent String getLastName();
idempotent BookPrxSeq getBooks();
idempotent void setName(String name);
idempotent void setLastName(String lastName);
idempotent void setBooks(BookPrxSeq books);
}
Code:
struct AuthorDesc {
string name;
string lastName;
BookPrxSeq books
};
class Author {
AuthorDesc describe();
idempotent void setName(String name);
idempotent void setLastName(String lastName);
idempotent void setBooks(BookPrxSeq books);
};
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Object* add(Object servant, Identity id),can the servant be static object? | russule | Help Center | 2 | 06-23-2007 08:19 AM |
| [icePHP] 'persistence' question | g00fy | Help Center | 2 | 06-23-2006 02:23 AM |
| Can persistence to Ice application be used other database, such as mysql? | richardma | Help Center | 1 | 12-21-2005 04:12 AM |
| Object Factories and object initialisation | Nis Baggesen | Help Center | 1 | 09-30-2004 08:40 AM |
| Object serialization in ICE | shantanu_k06 | Help Center | 4 | 02-17-2004 02:00 PM |