• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB-QL

 
Aleks V. Pascoal
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fellows,
I'm having problemas using EJB 2.0, CMP. The plan is to use find methods to all my searchs in the database. But:
1) find methods returns EJBObject's or Collection of those, so i have to encapsulate then into Value Objects to pass up, to the presentation layer. Who's responsability is this?
2) EJB-QL don't allow me to use LIKE expression's. My first idea was to use ejbHome methods to execute SQL directly. But than, they wil return VO's and Collection of then. So in the same class i'll have to types of search methods very distinct, i didn't like it.

Any suggestions?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read page 230 of spec for you 2nd Q.

11.2.7.9 Like expressions
The syntax for the use of the comparison operator [NOT] LIKE in a conditional expression is as follows:
single_valued_path_expression [NOT] LIKE pattern-value [ESCAPE escape-character]
The single_valued_path_expression must have a String value. The pattern-value is a string literal in
which an underscore (_) stands for any single character, a percent (%) character stands for any sequence
of characters (including the empty sequence), and all other characters stand for themselves. The
optional escape-characteris a single character string literal and is used to escape the special meaning of
the underscore and percent characters in pattern-value.
Examples are:
� address.phone LIKE �12%3� is true for �123� �12993� and false for �1234�
� asentence.word LIKE �l_se� is true for �lose� and false for �loose�
� aword.underscored LIKE �\_%� ESCAPE �\� is true for �_foo� and false for �bar�
� address.phone NOT LIKE �12%3� is false for �123� and �12993� and true for �1234�
If the value of the single_valued_path_expression is NULL, the value of the LIKE expression is
unknown.


1) find methods returns EJBObject's or Collection of those, so i have to encapsulate then into Value Objects to pass up, to the presentation layer. Who's responsability is this?

Define a method in component interface to return value objects. Write a session bean which does the find , get the collection, naviagtes through it and gets value object.
 
Aleks V. Pascoal
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry... i didn't explain it rigth. I want to use LIKE with input parameter.
 
Wildson Luz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aleks,
follow this example:
"SELECT DISTINCT OBJECT(c) FROM Ojb c WHERE LOCATE(?1,c.field) > 0"
where ?1 is the first input parameter in your FIND function.
It's all rigth in JBOSS.
my regards,
Wildson
 
Mikalai Zaikin
Ranch Hand
Posts: 3371
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wildson,
What a nice solution !
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is the solution is proprietary.
 
Mikalai Zaikin
Ranch Hand
Posts: 3371
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any proprietary solutions in this query.
Isn't it allowed to have input parameters in LOCATE(S,S)?
Please, point what's wrong with this style ?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry.. I forgot that Locate was a function.
 
Wildson Luz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fellows,
it must function in all app servers since it's in the especification. LOCATE is a function defined in EJBQL.
Wildson
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic