2 Replies Latest reply on Nov 2, 2010 7:36 PM by jfaath

    raiseAsynchronousEvent and db persistence

    jhedden.jhedden.opsource.net

      So Im not sure why this persists:


      events.raiseEvent("createTicket", selectedId);



      yet this doesnt:


      events.raiseAsynchronousEvent("createTicket", selectedId);



      This is SLSB. submitProcess() is relevant method:



      @Stateless
      @Name("activationManager")
      @Restrict("#{identity.loggedIn}")
      public class ActivationManagerAction implements ActivationManager {
      
          @Logger 
          private Log log;
          
          @In
          private EntityManager entityManager;
          
          @In
          private Events events;
          
          @In
          private Order order;
      
          @In(required = false)
          @Out(required = false, scope = ScopeType.PAGE)
          private Environment environment;
      
          @In(required = false) 
          @Out(required = false, scope = ScopeType.PAGE)
          private EnvironmentActivationProcess process;
      
          @RequestParameter
          private Integer optionId;
      
          @RequestParameter
          private Integer selectedId;
      
          @In
          private NavController navController;
      
          /**
           * Method to load all processes for an Env.
           * @param environmentId Integer
           */
          @Begin(flushMode = FlushModeType.MANUAL, join = true)
          public void getProcessDashboard(Integer environmentId) {
              for (Environment env : order.getEnvironmentList()) {
                  if (env.getId().equals(environmentId)) {
                      environment = entityManager.find(Environment.class, env.getId());
                      entityManager.refresh(environment);
                  }
              }
              navController.activation();
          }
      
          /**
           * Method to add a process.
           */
          public void addProcess() {
              ActivationProcess option = entityManager.find(ActivationProcess.class, optionId);
              entityManager.refresh(option);
              process = new EnvironmentActivationProcess();
              process.setActivationProcess(option);
              process.setEnvironment(environment);
              environment.addProcess(process);
              entityManager.persist(process);
              entityManager.flush();
          }
          
          /**
           * Method to delete a process.
           */
          public void deleteProcess() {
              process = entityManager.find(EnvironmentActivationProcess.class, selectedId);
              entityManager.refresh(process);
              environment.removeEnvironmentActivationProcess(process);
              entityManager.remove(process);
              entityManager.flush();
              FacesUtil.addInfoMessage("Option successfully removed.");
          }
          
          /**
           * Submit a process for RealOps to pickup.
           */
          public void submitProcess() {
              events.raiseAsynchronousEvent("createTicket", selectedId);
              FacesUtil.addInfoMessage("Process successfully submitted.");
          }
      
          /**
           * Method to load a process.
           */
          public void loadProcess() { 
              process = entityManager.find(EnvironmentActivationProcess.class, selectedId);
              entityManager.refresh(process);
          }
      
          /**
           * Method to load an env.
           */
          public void loadEnvironment() { 
              environment = entityManager.find(Environment.class, environment.getId());
              entityManager.refresh(environment);
          }
      
          /**
           * Method to save a process.
           */
          public void saveProcess() {
              entityManager.merge(process);
              entityManager.flush();
              FacesUtil.addInfoMessage("Manual process is now valid.");
          }
      }



      This is the Observer, which in turn accesses a WS and then persists results:


      @Name("ticketObserver")
      public class TicketObserver {
          
          @Logger 
          private Log log;
      
          @In
          private EntityManager entityManager;
          
          /**
           * Creates RNT Ticket.
           * @param id Integer
           */
          @SuppressWarnings("unused")
          @Observer("createTicket")
          public void createTicket(Integer id) {
              EnvironmentActivationProcess process = entityManager.find(EnvironmentActivationProcess.class, id);
              entityManager.refresh(process);
              process.setSubmitProcess(true);
              String rntTicketId = null;
              
              try {
                  Integer serviceId = process.getActivationProcess().getId();
                  TicketService service = TicketServiceFactory.getService(serviceId); 
                  service.createRNTTicket(process);
              } catch (GeneralServiceException e) {
                  log.error("Exception creating ticket");
                  e.printStackTrace();
              }
              
              entityManager.merge(process);
              entityManager.flush();
          }
      }



      persistence.xml:


      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Persistence deployment descriptor for dev profile -->
      <persistence xmlns="http://java.sun.com/xml/ns/persistence" 
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
                   version="1.0">
                   
         <persistence-unit name="ooord" transaction-type="JTA">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:/ooordDatasource</jta-data-source>
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
               <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/ooordEntityManagerFactory"/>
               <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
            </properties>
         </persistence-unit>
          
      </persistence>



      and finally components.xml :


      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
                  xmlns:core="http://jboss.com/products/seam/core"
                  xmlns:persistence="http://jboss.com/products/seam/persistence"
                  xmlns:drools="http://jboss.com/products/seam/drools"
                  xmlns:bpm="http://jboss.com/products/seam/bpm"
                  xmlns:security="http://jboss.com/products/seam/security"
                  xmlns:mail="http://jboss.com/products/seam/mail"
                  xmlns:framework="http://jboss.com/products/seam/framework"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:web="http://jboss.com/products/seam/web"
                  xmlns:spring="http://jboss.com/products/seam/spring"
                  xmlns:transaction="http://jboss.com/products/seam/transaction"
                  xsi:schemaLocation=
                      "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd 
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd 
                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.0.xsd
                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd
                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd
                       http://jboss.com/products/seam/framework http://jboss.com/products/seam/framework-2.0.xsd
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd
                       http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.0.xsd
                       http://jboss.com/products/seam/spring http://jboss.com/products/seam/spring-2.0.xsd
                       http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.0.xsd">
      
          <core:init debug="@debug@" jndi-pattern="@jndiPattern@" />
          
          <core:transactionListener/>
          
          <transaction:ejb-transaction/>
           
          <core:manager concurrent-request-timeout="10000" conversation-timeout="3600000" conversation-id-parameter="cid"/>
         
          <web:multipart-filter url-pattern="*.seam" max-request-size="10000000" create-temp-files="true" disabled="false" />
         
          <web:context-filter url-pattern="/order/file/*"/>
         
          <security:identity security-rules="#{securityRules}" authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
         
          <mail:mail-session host="localhost" port="25"/> 
          
          <persistence:managed-persistence-context name="entityManager" auto-create="true" 
              persistence-unit-jndi-name="java:/ooordEntityManagerFactory"/>
              
          <spring:context-loader>
              <spring:config-locations>
                  <value>classpath*:beanRefFactory.xml</value>
              </spring:config-locations>
          </spring:context-loader> 
        
          <event type="org.jboss.seam.security.notLoggedIn">
             <action execute="#{redirect.captureCurrentView}"/>
          </event>
          <event type="org.jboss.seam.security.loginSuccessful">
             <action execute="#{redirect.returnToCapturedView}"/>
          </event>
          
          <!--             
          <bpm:jbpm> 
              <bpm:process-definitions>
                  <value>orderManagement.jpdl.xml</value>
              </bpm:process-definitions> 
              <bpm:pageflow-definitions>
                  <value>orderFlow.jpdl.xml</value>
              </bpm:pageflow-definitions>
          </bpm:jbpm>
          -->
         
          <!-- Drools -->
          <drools:rule-base name="securityRules">
             <drools:rule-files>
                 <value>/security.drl</value>
             </drools:rule-files>
          </drools:rule-base>
            
          <drools:rule-base name="saveOrderRules">
             <drools:rule-files>
                 <value>/saveOrderRules.drl</value>
             </drools:rule-files>
          </drools:rule-base>
         
          <drools:managed-working-memory name="saveOrderWM" auto-create="true" rule-base="#{saveOrderRules}"/>
         
          <drools:rule-base name="orderEmailRules">
             <drools:rule-files>
                 <value>/orderEmailRules.drl</value>
             </drools:rule-files>
          </drools:rule-base>
         
          <drools:managed-working-memory name="orderEmailWM" auto-create="true" rule-base="#{orderEmailRules}"/>
          
          <!-- Framework Queries -->
          <framework:entity-home name="activationProcessHome" entity-class="net.opsource.ooord.model.ActivationProcess"/>
          <factory name="activationProcess" value="#{activationProcessHome.instance}"/>
          <framework:entity-query name="activationProcesses" ejbql="select a from ActivationProcess a" />
         
          <framework:entity-home name="dataCenterHome" entity-class="net.opsource.ooord.model.DataCenter"/>
          <factory name="dataCenter" value="#{dataCenterHome.instance}"/>
          <framework:entity-query name="dataCenters" ejbql="select d from DataCenter d" />
          
          <framework:entity-home name="databaseHome" entity-class="net.opsource.ooord.model.Database"/>
          <factory name="database" value="#{databaseHome.instance}"/>
          <framework:entity-query name="databases" ejbql="select d from Database d" order="d.type"/>
         
          <framework:entity-home name="databaseVersionHome" entity-class="net.opsource.ooord.model.DatabaseVersion"/>
          <factory name="databaseVersion" value="#{databaseVersionHome.instance}"/>
          <framework:entity-query name="databaseVersions" ejbql="select d from DatabaseVersion d">
             <framework:restrictions>           
                 <value>d.database = #{server.database}</value>
             </framework:restrictions>
          </framework:entity-query>
         
          <framework:entity-home name="databaseOptionHome" entity-class="net.opsource.ooord.model.DatabaseOption"/>
          <factory name="databaseOption" value="#{databaseOptionHome.instance}"/>
          <framework:entity-query name="databaseOptions1" ejbql="select d from DatabaseOption d where d.optionLevel = 1">
             <framework:restrictions>        
                 <value>d.database = #{server.database}</value>
             </framework:restrictions>
          </framework:entity-query>
          <framework:entity-query name="databaseOptions2" ejbql="select d from DatabaseOption d where d.optionLevel = 2">
             <framework:restrictions>        
                 <value>d.database = #{server.database}</value>
             </framework:restrictions>
          </framework:entity-query>
                 
      </components>



      Ive tried everything from @Transactional to @TransactionAttribute to using:


      <spring:transaction platform-transaction-manager="#{txManager}" join-transaction="true" conversation-context-required="false" />
      <bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager" />



      Ive obviously got some sort of knowledge gap.