use of jakarta.ejb.FinderException in project tomee by apache.
the class BasicBmpBean method ejbFindByPrimaryKey.
/**
* Maps to BasicBmpHome.findByPrimaryKey
*
* @param primaryKey
* @return
* @throws jakarta.ejb.FinderException
* @see BasicBmpHome#sum
*/
public Integer ejbFindByPrimaryKey(final Integer primaryKey) throws jakarta.ejb.FinderException {
boolean found = false;
try {
final InitialContext jndiContext = new InitialContext();
final DataSource ds = (DataSource) jndiContext.lookup("java:comp/env/jdbc/basic/entityDatabase");
final Connection con = ds.getConnection();
try {
final PreparedStatement stmt = con.prepareStatement("select * from entity where id = ?");
try {
stmt.setInt(1, primaryKey.intValue());
found = stmt.executeQuery().next();
} finally {
stmt.close();
}
} finally {
con.close();
}
} catch (final Exception e) {
throw new FinderException("FindByPrimaryKey failed");
}
if (found)
return primaryKey;
else
throw new jakarta.ejb.ObjectNotFoundException();
}
Aggregations