tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thiago Veronezi <thi...@veronezi.org>
Subject Re: Oberride @NamedNativeQuery
Date Tue, 02 Nov 2010 13:55:23 GMT
Hmmm...
My advice is to try to get rid anything that could break your portability.
If thats not possible here, you can use your DAO (or EAO if you like) layer
to manage the query, setting a "resource" as your query string.

Example:
***************************************************
@Stateless
@Local(IUserEAO.class)
public class UserEAO extends AbstractDb<User> implements IUserEAO {

@EJB
private IRoleEAO iroleeao;

//YOUR QUERY CAN BE AN INJECTABLE RESOURCE
@Resource
private String findUserQuery;

@Override
protected Class<User> getEntityClass() {
return User.class;
}

@RolesAllowed( { "ROLE_ADMIN", "ROLE_SYSTEM" })
@Override
public User create(RoleType type, String account, String realName, String
password) {
User user = new User();

if (account == null || "".equals(account.trim()) || realName == null
|| "".equals(realName.trim()) || password == null
|| "".equals(password.trim())) {
final Map<String, String> params = new HashMap<String, String>();
params.put("account", account);
params.put("realName", realName);
params.put("password", password);
throw new SystemException("Invalid data: " + params);
}

user.setAccount(account.toLowerCase());
user.setRealName(realName);
user.setPassword(password);
user = super.create(user);

if(RoleType.ROLE_ADMIN.equals(type)) {
iroleeao.addUser(RoleType.ROLE_USER.name(), user);
}
iroleeao.addUser(type.name(), user);
return user;
}

@Override
public User findByAccount(String account) {
//THEN YOU CAN USE YOUR QUERY HERE
return super.findUniqueByQuery(this.findUserQuery,
new NamedParam("paccount", account));
}
}
***************************************************

To override the value of "findUserQuery", you can user this feature...`
http://openejb.apache.org/3.0/alternate-descriptors.html

[]s,
Thiago.

On Tue, Nov 2, 2010 at 9:22 AM, typhoon <sd10046@lanet.lv> wrote:

>
> Hi all,
>
> I'm using @NamedNativeQuery in entity bean, but it's database specific and
> as a result can't be used in unit tests. Therefore my question is - can we
> override named query or other entity bean's attributes somehow for
> execution
> in unit tests?
>
> Regards,
> ty
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Oberride-NamedNativeQuery-tp3023685p3023685.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message