jbpm4.1得到Session
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");
}
}
猜你喜欢
转载自xgbjmxn.iteye.com/blog/1108424
今日推荐
周排行