use of javax.ejb.FinderException in project tomee by apache.
the class JpaCmpEngine method queryBeans.
public List<Object> queryBeans(final ThreadContext callContext, final Method queryMethod, final Object[] args) throws FinderException {
final BeanContext deploymentInfo = callContext.getBeanContext();
final EntityManager entityManager = getEntityManager(deploymentInfo);
final StringBuilder queryName = new StringBuilder();
queryName.append(deploymentInfo.getAbstractSchemaName()).append(".").append(queryMethod.getName());
final String shortName = queryName.toString();
if (queryMethod.getParameterTypes().length > 0) {
queryName.append('(');
boolean first = true;
for (final Class<?> parameterType : queryMethod.getParameterTypes()) {
if (!first) {
queryName.append(',');
}
queryName.append(parameterType.getCanonicalName());
first = false;
}
queryName.append(')');
}
final String fullName = queryName.toString();
Query query = createNamedQuery(entityManager, fullName);
if (query == null) {
query = createNamedQuery(entityManager, shortName);
if (query == null) {
throw new FinderException("No query defined for method " + fullName);
}
}
return executeSelectQuery(query, args);
}
use of javax.ejb.FinderException in project tomee by apache.
the class BasicBmp2DataSourcesBean method ejbFindByPrimaryKey.
/**
* Maps to BasicBmp2DataSourcesHome.findByPrimaryKey
*
* @param primaryKey
* @return Integer
* @throws javax.ejb.FinderException
*/
public Integer ejbFindByPrimaryKey(final Integer primaryKey) throws javax.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 javax.ejb.ObjectNotFoundException();
}
use of javax.ejb.FinderException in project tomee by apache.
the class BasicBmpBean method ejbFindByPrimaryKey.
/**
* Maps to BasicBmpHome.findByPrimaryKey
*
* @param primaryKey
* @return
* @throws javax.ejb.FinderException
* @see BasicBmpHome#sum
*/
public Integer ejbFindByPrimaryKey(final Integer primaryKey) throws javax.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 javax.ejb.ObjectNotFoundException();
}
use of javax.ejb.FinderException in project Payara by payara.
the class TimerWrapper method getSchedule.
public ScheduleExpression getSchedule() throws java.lang.IllegalStateException, javax.ejb.NoSuchObjectLocalException, javax.ejb.EJBException {
checkCallPermission();
ScheduleExpression schedule;
if (!isCalendarTimer()) {
throw new IllegalStateException("Only allowed for calendar-based timers");
}
try {
schedule = timerService_.getScheduleExpression(timerId_);
} catch (FinderException fe) {
throw new NoSuchObjectLocalException("timer no longer exists", fe);
}
return schedule;
}
Aggregations