The normal way of doing this is by implementing several finder methods, and
let a session bean do the entity querying..

For searching on names with wildchars just do:

  query = "$name like $1"

this will actually serve as several finder methods (see examples under).

  findByName("Bob");

This will return the same as the =.

  findByName("Bo%");

This will return all matching records for Bo* and so on.

You can even do this:
  findByName("Bo% %mi%th%");

Nifty :)..

For the other stuff you have to add more finder methods. Or make it a bean
managed persistance bean where you can toy around with the finder methods as
you like :)

Btw, important notice is: all findermethods implemented using like has to
return Collection not remote interface.

Have fun, hope this helps better :)

Klaus Myrseth





-----Opprinnelig melding-----
Fra: Nick Newman [mailto:[EMAIL PROTECTED]]
Sendt: 12. september 2000 22:23
Til: Orion-Interest
Emne: RE: Specifying finder-methods (full query)


At 08:57 PM 9/12/00 +0200, you wrote:
>Thanks for the reaction (also Nick). I realize now the potential security 
>problems by allowing full
>specification of SQL on the client. 
>
>Unfortunately the "Bob" example does not solve my problem. I managed to 
>implement that example.
>That is where I came from. From there I tried to continue to implement a 
>Query By Example frame and
>that's where I got stuck.
>
>Something like this:
>Say you have a table with products and you would like to create a flexible 
>query frame for those
>products to run queries like all products for which the stock is low and 
>which are purchased from comp
>xyz, or all products from categorie abc with names like %nic%.
>
>With specifying the query in orion-ejb-jar I came as far as either 
>specifying a fixed name / number or
>you can use another fixed operator, e.g. '>' or LIKE. Due to generated the 
>quotes I could not let the client
>generate the selection part of the where clause. You get roughly the same 
>error as when generating the
>whole statement.
>
>Probably you can write some ?Session? Bean that will query direct on the 
>database returning a collection
>of primary keys, but for some reason that does not sound like music to me.

Hi Frank,

I apologise that my earlier reply was a bit off the mark.  I hadn't read
the whole email carefully enough to realize exactly what it was that you
wanted to do.

So far as I know, the accepted solution to your problem is exactly the one
you tend to reject; using a stateless session bean to perform the direct
SQL queries for you.  I agree that this sounds a little unsatisfactory.
After all, shouldn't the entity bean do everything to do with the entities?

A slightly more elegant solution may arrive when EJB 2.0 is fully
implemented.  In EJB 2.0 the home interface of an EJB can also define
arbitrary (non-finder, non-create) methods.  That may be a more logical
place to put a home-grown finder perhaps?

Nick

Reply via email to