Example #1
0
  private Object findByPrimaryKey(
      final Method callMethod,
      final Object[] args,
      final ThreadContext callContext,
      final InterfaceType interfaceType)
      throws OpenEJBException {
    final BeanContext beanContext = callContext.getBeanContext();

    final TransactionPolicy txPolicy =
        createTransactionPolicy(
            beanContext.getTransactionType(callMethod, interfaceType), callContext);

    try {
      final EntityBean bean = (EntityBean) cmpEngine.loadBean(callContext, args[0]);
      if (bean == null) {
        throw new ObjectNotFoundException(beanContext.getDeploymentID() + " : " + args[0]);
      }

      // rebuild the primary key
      final KeyGenerator kg = beanContext.getKeyGenerator();
      final Object primaryKey = kg.getPrimaryKey(bean);

      // create a new ProxyInfo based on the deployment info and primary key
      return new ProxyInfo(beanContext, primaryKey);
    } catch (final FinderException fe) {
      handleApplicationException(txPolicy, fe, false);
    } catch (final Throwable e) { // handle reflection exception
      handleSystemException(txPolicy, e, callContext);
    } finally {
      afterInvoke(txPolicy, callContext);
    }
    throw new AssertionError("Should not get here");
  }
Example #2
0
  private ThreadContext createThreadContext(final EntityBean entityBean) {
    if (entityBean == null) {
      throw new NullPointerException("entityBean is null");
    }

    final BeanContext beanContext = getBeanContextByClass(entityBean.getClass());
    final KeyGenerator keyGenerator = beanContext.getKeyGenerator();
    final Object primaryKey = keyGenerator.getPrimaryKey(entityBean);

    return new ThreadContext(beanContext, primaryKey);
  }
Example #3
0
  private Object findEJBObject(
      final Method callMethod,
      final Object[] args,
      final ThreadContext callContext,
      final InterfaceType interfaceType)
      throws OpenEJBException {
    final BeanContext beanContext = callContext.getBeanContext();

    final TransactionPolicy txPolicy =
        createTransactionPolicy(
            beanContext.getTransactionType(callMethod, interfaceType), callContext);

    try {
      final List<Object> results = cmpEngine.queryBeans(callContext, callMethod, args);

      final KeyGenerator kg = beanContext.getKeyGenerator();

      // The following block of code is responsible for returning ProxyInfo object(s) for each
      // matching entity bean found by the query.  If its a multi-value find operation a Vector
      // of ProxyInfo objects will be returned. If its a single-value find operation then a
      // single ProxyInfo object is returned.
      if (callMethod.getReturnType() == Collection.class
          || callMethod.getReturnType() == Enumeration.class) {
        final List<ProxyInfo> proxies = new ArrayList<ProxyInfo>();
        for (final Object value : results) {
          final EntityBean bean = (EntityBean) value;

          if (value == null) {
            proxies.add(null);
          } else {
            // get the primary key
            final Object primaryKey = kg.getPrimaryKey(bean);

            // create a new ProxyInfo based on the deployment info and primary key and add it to the
            // vector
            proxies.add(new ProxyInfo(beanContext, primaryKey));
          }
        }
        if (callMethod.getReturnType() == Enumeration.class) {
          return new Enumerator(proxies);
        } else {
          return proxies;
        }
      } else {
        if (results.size() != 1) {
          throw new ObjectNotFoundException(
              "A Enteprise bean with deployment_id = "
                  + beanContext.getDeploymentID()
                  + (args != null && args.length >= 1 ? " and primarykey = " + args[0] : "")
                  + " Does not exist");
        }

        // create a new ProxyInfo based on the deployment info and primary key
        final EntityBean bean = (EntityBean) results.get(0);
        if (bean == null) {
          return null;
        } else {
          final Object primaryKey = kg.getPrimaryKey(bean);
          return new ProxyInfo(beanContext, primaryKey);
        }
      }
    } catch (final FinderException fe) {
      handleApplicationException(txPolicy, fe, false);
    } catch (final Throwable e) { // handle reflection exception
      handleSystemException(txPolicy, e, callContext);
    } finally {
      afterInvoke(txPolicy, callContext);
    }
    throw new AssertionError("Should not get here");
  }