`
xgbjmxn
  • 浏览: 268697 次
  • 性别: Icon_minigender_1
  • 来自: 新乡
社区版块
存档分类
最新评论

jbpm4.1得到Session

    博客分类:
  • jbpm
阅读更多

jbpm4.1得到Session
开启事务
并执行SQL操作

--------------------------------------------------------------------------------------------------------
package testProcess.basic;

import javax.annotation.Resource;

import junit.framework.TestCase;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.TaskService;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
// @ContextConfiguration(locations = { "classpath:applicationContext.xml" })
@ContextConfiguration(locations = { "/jbpm4/spring/applicationContext.xml" })
public class BasicTestProcess extends TestCase {
@Resource(name = "processEngine")
private ProcessEngine processEngine;

public RepositoryService repositoryService = null;

public ExecutionService executionService = null;

public TaskService taskService = null;
private static final Log log = LogFactory.getLog(BasicTestProcess.class);

protected void setUp() throws Exception {
   repositoryService = this.getProcessEngines().getRepositoryService();

   executionService = this.getProcessEngines().getExecutionService();

   taskService = this.getProcessEngines().getTaskService();
}

public ProcessEngine getProcessEngines() {

   return this.processEngine;
}
}

--------------------------------------------------------------------------------------------------------
package testProcess.del;

import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.jbpm.api.cmd.Environment;
import org.jbpm.pvm.internal.env.EnvironmentFactory;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
import org.jbpm.pvm.internal.hibernate.DbSessionImpl;
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.session.DbSession;
import org.junit.Test;

import testProcess.basic.BasicTestProcess;

public class Hibernate extends BasicTestProcess {

private static final String STRING = null;

@Test
public void jbpm4_1_Session_SQL_Detele() {
   EnvironmentFactory environmentFactory = (EnvironmentFactory) this
     .getProcessEngines();

   Environment environment = environmentFactory.openEnvironment();
   try {

    EnvironmentImpl environmentImpl = (EnvironmentImpl) environment;
    DbSessionImpl dbSession = (DbSessionImpl) environmentImpl
      .getFromCurrent(DbSession.class);

    // 得到Session
    Session session = dbSession.getSession();
    Transaction tx = session.beginTransaction();
    // 业务操作开始

    ExecutionImpl customer = (ExecutionImpl) session.get(
      ExecutionImpl.class, new Long(32));

    session.delete(customer);
    // 业务操作结束
    tx.commit();

   } catch (Exception ex) {

    ex.printStackTrace();
   }

   finally {

   }

   System.out.println("END");
}

@Test
public void jbpm4_1_Session_SQL_Query() {

   EnvironmentFactory environmentFactory = (EnvironmentFactory) this
     .getProcessEngines();

   Environment environment = environmentFactory.openEnvironment();
   try {

    EnvironmentImpl environmentImpl = (EnvironmentImpl) environment;
    DbSessionImpl dbSession = (DbSessionImpl) environmentImpl
      .getFromCurrent(DbSession.class);

    // 得到Session

    Session session = dbSession.getSession();
    Transaction tx = session.beginTransaction();
    // 业务操作开始
    String sql = "SELECT * FROM jbpmdb.jbpm4_execution j";

    Query query = session.createSQLQuery(sql).addScalar("DBID_",
      org.hibernate.Hibernate.STRING).addScalar("ACTIVITYNAME_",
      org.hibernate.Hibernate.STRING);

    //
    List list = query.list();
    Iterator iter = list.iterator();
    while (iter.hasNext()) {
     Object[] o = (Object[]) iter.next();
     String str = (String) o[0];
     String str1 = (String) o[1];
     System.out.println(str);
     System.out.println(str1);
    }
    // 业务操作结束

    tx.commit();

   } catch (Exception ex) {

    ex.printStackTrace();
   }

   finally {

   }

   System.out.println("END");
}
}

分享到:
评论

相关推荐

    jbpm6.0 入门(很有权威)

    加入 jBPM 社区可以获得技术支持和交流经验的机会。 ##### 2.5 源码 jBPM 的源代码开放给公众,开发者可以自行编译或贡献代码。 - **许可证**:Apache License 2.0 - **源代码**:可在 GitHub 或其他代码仓库获取...

    JBPM5权威指南

    4.1 jBPM API 16 4.11 Knowledge Base 17 4.12 会话 17 4.13 事件 19 4.2. Knowledge-based API 21 第五章 核心引擎:基础 21 5.1 创建一个流程 21 5.1.1 Eclipse BPMN2.0图形编辑器插件 22 5.1.2 使用XML定义流程 ...

    jBPM User Guide Version 6.1.1-SNAPSHOT

    介绍了jBPM API的使用,包括知识库(KnowledgeBase)、会话(Session)、相关键(Correlation Key)、相关属性(Correlation Properties)和事件(Events)。 #### 4.2 基于知识的API(Knowledge-based API) 说明...

    jbpm6_用户手册

    #### 4.1 jBPM API 核心API是jBPM的基础,提供了与jBPM核心引擎交互的接口。 ##### 4.1.1 KnowledgeBase 知识库用于管理业务知识,包括流程定义和规则。 ##### 4.1.2 Session 会话对象允许用户与jBPM引擎交互,...

    JBoss Seam 工作原理、seam和hibernate的范例、RESTFul的seam、seam-gen起步、seam组件、配置组件、jsf,jboss、标签、PDF、注解等等

    1.4. Seam 和jBPM:待办事项列表(todo list)示例..................................................................................................... 32 1.4.1. 理解代码....................................

Global site tag (gtag.js) - Google Analytics