Question

I'm having a problem with active objects library (https://java.net/projects/activeobjects/pages/Home).

Let's say i have ao entity like this:

@Implementation(PersonImpl.class)
interface Person extends Entity{

    public String getName();

    public String setName();
}

And the implementation class of this entity :

class PersonImpl {

    private Person person;

    public PersonImpl(Person person){
        this.person = person;
    }

    public String getName(){
       if( isTodayIsMonday() )
           return "I hate monday";
       else
           return person.getName();
    }
}

Problem is in PersonImpl class. Because of person.getName() I get infinite recursion (impl class is always invoked). How can I skip invoking implementation (in PersonImpl class) and just get name from database?

Was it helpful?

Solution

According to http://www.javalobby.org/articles/activeobjects/ , ActiveObjects automatically avoids this problem by examining the call stack:

"We can use this to check for the defined implementation one step up on the stack. If we find that it initiated the method call, we'll skip the re-invocation of the defined implementation and actually execute the method call normally. Thus, any calls to an entity from its defined implementation will skip any implementation logic, avoiding recursion."

OTHER TIPS

private String getMyName(boolean isMonday) {
  if (isMonday) {
    return "I hate Monday";
  }
  return person.getName();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top