hi,
i'm implementing a sequence block behind a session facade to serve as a primary key generator for other entities (imitating a database auto-increment column). i want to name each sequence according to the entity
ejb it serves, without passing a
string if possible.
i have the ejbCreate method of each entity bean obtain an instance of the sequence's session facade bean, which issues it a new integral primary key. the session ejb looks up the correct number based on the name of the sequence, so the sequence name needs to be passed from the client entity that is requesting the new primary key doesn't it?
i thought i remembered reading somewhere that a method's client (the class calling the method) can be looked up and referenced without passing the client itself as an argument. if this is possible, i'd like to do that instead, i.e.:
1.) EntityEJB calls the getPrimaryKey() method on a Stateless Session EJB.
2.) getPrimaryKey() *somehow* retrieves a reference to the EntityEJB, even though an instance of it was not passed as an argument.
3.) getPrimaryKey uses this *magic* reference to call getClass().getName() and get the EntityEJB's class name as a String.
4.) getPrimaryKey uses this String to either create a new sequence or findByPrimaryKey and return the next number in the sequence.
i'd rather not hard-code the String name of each sequence into its respective EntityEJB if this can be retrieved automatically. i'd also like to avoid doing a getPrimaryKey(this), since the facade bean will work with different entities and i don't want my entities to polymorph at all.
if anyone knows how i can get the name of the class that called a method, from within the method itself, without passing an instance of the class as an argument, please let me know. Thanks!