Exemplo n.º 1
0
  public synchronized AppModule deploy(final AppModule appModule) throws OpenEJBException {

    final Set<String> abstractSchemaNames = new HashSet<String>();
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
      for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
        if (isCmpEntity(bean)) {
          final EntityBean entity = (EntityBean) bean;
          final String name = entity.getAbstractSchemaName();
          if (name != null) {
            abstractSchemaNames.add(name);
          }
        }
      }
    }

    final Map<String, String> contextData = new HashMap<String, String>();
    contextData.put("appId", appModule.getModuleId());

    for (final EjbModule ejbModule : appModule.getEjbModules()) {
      contextData.put("ejbJarId", ejbModule.getModuleId());
      deploy(ejbModule, contextData, abstractSchemaNames);
    }
    contextData.clear();
    return appModule;
  }
Exemplo n.º 2
0
  private EjbModule deploy(
      final EjbModule ejbModule,
      final Map<String, String> contextData,
      final Set<String> abstractSchemaNames)
      throws OpenEJBException {
    contextData.put("moduleId", ejbModule.getModuleId());
    contextData.put("moduleUri", ejbModule.getModuleUri().toString());

    final OpenejbJar openejbJar;
    if (ejbModule.getOpenejbJar() != null) {
      openejbJar = ejbModule.getOpenejbJar();
    } else {
      openejbJar = new OpenejbJar();
      ejbModule.setOpenejbJar(openejbJar);
    }

    StringTemplate deploymentIdTemplate = this.deploymentIdTemplate;
    if (openejbJar.getProperties().containsKey(DEPLOYMENT_ID_FORMAT)) {
      final String format = openejbJar.getProperties().getProperty(DEPLOYMENT_ID_FORMAT);
      logger.info("Using " + DEPLOYMENT_ID_FORMAT + " '" + format + "'");
      deploymentIdTemplate = new StringTemplate(format);
    }

    for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
      StringTemplate template = deploymentIdTemplate;

      final org.apache.openejb.api.EjbDeployment annotation =
          getEjbDeploymentAnnotation(ejbModule, bean);

      EjbDeployment ejbDeployment = openejbJar.getDeploymentsByEjbName().get(bean.getEjbName());
      if (ejbDeployment == null) {

        ejbDeployment = new EjbDeployment();

        ejbDeployment.setEjbName(bean.getEjbName());

        if (annotation != null && isDefined(annotation.id())) {
          template = new StringTemplate(annotation.id());
          ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
        } else {
          ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
          if (!(bean instanceof ManagedBean) || !((ManagedBean) bean).isHidden()) {
            logger.info(
                "Auto-deploying ejb "
                    + bean.getEjbName()
                    + ": EjbDeployment(deployment-id="
                    + ejbDeployment.getDeploymentId()
                    + ")");
          }
        }

        openejbJar.getEjbDeployment().add(ejbDeployment);
      } else if (ejbDeployment.getDeploymentId() == null) {
        if (annotation != null && isDefined(annotation.id())) {
          template = new StringTemplate(annotation.id());
          ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
        } else {
          ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
          logger.info(
              "Auto-assigning deployment-id for ejb "
                  + bean.getEjbName()
                  + ": EjbDeployment(deployment-id="
                  + ejbDeployment.getDeploymentId()
                  + ")");
        }
      }

      if (ejbDeployment.getContainerId() == null
          && annotation != null
          && isDefined(annotation.container())) {
        ejbDeployment.setContainerId(annotation.container());
      }

      if (isCmpEntity(bean)) {
        final EntityBean entity = (EntityBean) bean;
        if (entity.getAbstractSchemaName() == null) {
          String abstractSchemaName = bean.getEjbName().trim().replaceAll("[ \\t\\n\\r-]+", "_");

          // The AbstractSchemaName must be unique, we should check that it is
          if (abstractSchemaNames.contains(abstractSchemaName)) {
            int i = 2;
            while (abstractSchemaNames.contains(abstractSchemaName + i)) {
              i++;
            }
            abstractSchemaName = abstractSchemaName + i;
          }

          abstractSchemaNames.add(abstractSchemaName);
          entity.setAbstractSchemaName(abstractSchemaName);
        }
      }
    }

    return ejbModule;
  }
Exemplo n.º 3
0
  private EnterpriseBeanInfo initEntityBean(final EntityBean e, final Map m)
      throws OpenEJBException {
    final EntityBeanInfo bean = new EntityBeanInfo();

    final EjbDeployment d = (EjbDeployment) m.get(e.getEjbName());
    if (d == null) {
      throw new OpenEJBException(
          "No deployment information in openejb-jar.xml for bean "
              + e.getEjbName()
              + ". Please redeploy the jar");
    }
    bean.ejbDeploymentId = d.getDeploymentId();
    bean.containerId = d.getContainerId();

    final Icon icon = e.getIcon();
    bean.largeIcon = icon == null ? null : icon.getLargeIcon();
    bean.smallIcon = icon == null ? null : icon.getSmallIcon();
    bean.description = e.getDescription();
    bean.displayName = e.getDisplayName();
    bean.ejbClass = e.getEjbClass();
    bean.abstractSchemaName = e.getAbstractSchemaName();
    bean.ejbName = e.getEjbName();
    bean.home = e.getHome();
    bean.remote = e.getRemote();
    bean.localHome = e.getLocalHome();
    bean.local = e.getLocal();
    bean.transactionType = "Container";

    bean.primKeyClass = e.getPrimKeyClass();
    bean.primKeyField = e.getPrimkeyField();
    bean.persistenceType = e.getPersistenceType().toString();
    bean.reentrant = String.valueOf(e.getReentrant());
    bean.properties.putAll(d.getProperties());

    final CmpVersion cmpVersion = e.getCmpVersion();
    if (e.getPersistenceType() == PersistenceType.CONTAINER) {
      if (cmpVersion != null && cmpVersion == CmpVersion.CMP1) {
        bean.cmpVersion = 1;
      } else {
        bean.cmpVersion = 2;
      }
    }

    final List<CmpField> cmpFields = e.getCmpField();
    for (final CmpField cmpField : cmpFields) {
      bean.cmpFieldNames.add(cmpField.getFieldName());
    }

    if (bean.persistenceType.equalsIgnoreCase("Container")) {
      for (final Query q : e.getQuery()) {
        final QueryInfo query = new QueryInfo();
        query.queryStatement = q.getEjbQl().trim();

        final MethodInfo method = new MethodInfo();
        method.ejbName = bean.ejbName;
        method.className = "*";

        final QueryMethod qm = q.getQueryMethod();
        method.methodName = qm.getMethodName();
        if (qm.getMethodParams() != null) {
          method.methodParams = qm.getMethodParams().getMethodParam();
        }
        query.method = method;
        final ResultTypeMapping resultType = q.getResultTypeMapping();
        if (ResultTypeMapping.REMOTE.equals(resultType)) {
          query.remoteResultType = true;
        }
        bean.queries.add(query);
      }

      for (final org.apache.openejb.jee.oejb3.Query q : d.getQuery()) {
        final QueryInfo query = new QueryInfo();
        query.description = q.getDescription();
        query.queryStatement = q.getObjectQl().trim();

        final MethodInfo method = new MethodInfo();
        method.ejbName = bean.ejbName;
        method.className = "*";
        final org.apache.openejb.jee.oejb3.QueryMethod qm = q.getQueryMethod();
        method.methodName = qm.getMethodName();
        if (qm.getMethodParams() != null) {
          method.methodParams = qm.getMethodParams().getMethodParam();
        }
        query.method = method;
        bean.queries.add(query);
      }
    }
    return bean;
  }