use of jakarta.ejb.FinderException in project tomee by apache.
the class JpaCmpEngine method executeUpdateQuery.
public int executeUpdateQuery(final BeanContext beanContext, final String signature, Object[] args) throws FinderException {
final EntityManager entityManager = getEntityManager(beanContext);
Query query = createNamedQuery(entityManager, signature);
if (query == null) {
final int parenIndex = signature.indexOf('(');
if (parenIndex > 0) {
final String shortName = signature.substring(0, parenIndex);
query = createNamedQuery(entityManager, shortName);
}
if (query == null) {
throw new FinderException("No query defined for method " + signature);
}
}
// process args
if (args == null) {
args = NO_ARGS;
}
for (int i = 0; i < args.length; i++) {
Object arg = args[i];
// ejb proxies need to be swapped out for real instance classes
if (arg instanceof EJBObject) {
arg = Cmp2Util.getEntityBean((EJBObject) arg);
}
if (arg instanceof EJBLocalObject) {
arg = Cmp2Util.getEntityBean((EJBLocalObject) arg);
}
query.setParameter(i + 1, arg);
}
final int result = query.executeUpdate();
return result;
}
use of jakarta.ejb.FinderException in project tomee by apache.
the class EjbSelect method execute_boolean.
public static boolean execute_boolean(final Object obj, final String methodSignature, final Object... args) throws FinderException {
final BeanContext beanContext = (BeanContext) obj;
final Container container = beanContext.getContainer();
if (!(container instanceof CmpContainer)) {
throw new FinderException("Deployment is not connected to a CmpContainer " + beanContext.getDeploymentID());
}
final CmpContainer cmpContainer = (CmpContainer) container;
final Boolean result = (Boolean) cmpContainer.select(beanContext, methodSignature, "byte", args);
return result;
}
use of jakarta.ejb.FinderException in project tomee by apache.
the class EjbSelect method execute_int.
public static int execute_int(final Object obj, final String methodSignature, final Object... args) throws FinderException {
final BeanContext beanContext = (BeanContext) obj;
final Container container = beanContext.getContainer();
if (!(container instanceof CmpContainer)) {
throw new FinderException("Deployment is not connected to a CmpContainer " + beanContext.getDeploymentID());
}
final CmpContainer cmpContainer = (CmpContainer) container;
final Number result = (Number) cmpContainer.select(beanContext, methodSignature, "int", args);
return result.intValue();
}
use of jakarta.ejb.FinderException in project tomee by apache.
the class EjbSelect method execute_double.
public static double execute_double(final Object obj, final String methodSignature, final Object... args) throws FinderException {
final BeanContext beanContext = (BeanContext) obj;
final Container container = beanContext.getContainer();
if (!(container instanceof CmpContainer)) {
throw new FinderException("Deployment is not connected to a CmpContainer " + beanContext.getDeploymentID());
}
final CmpContainer cmpContainer = (CmpContainer) container;
final Number result = (Number) cmpContainer.select(beanContext, methodSignature, "double", args);
return result.doubleValue();
}
use of jakarta.ejb.FinderException in project tomee by apache.
the class BasicBmp2DataSourcesBean method ejbFindByPrimaryKey.
/**
* Maps to BasicBmp2DataSourcesHome.findByPrimaryKey
*
* @param primaryKey
* @return Integer
* @throws jakarta.ejb.FinderException
*/
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