本文整理汇总了Java中org.hibernate.Transaction.isActive方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.isActive方法的具体用法?Java Transaction.isActive怎么用?Java Transaction.isActive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.Transaction
的用法示例。
在下文中一共展示了Transaction.isActive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getKeys
import org.hibernate.Transaction; //导入方法依赖的package包/类
public Collection<String> getKeys(Long piid, String prefix, Type type) {
if( piid == null)
throw new PersistentVarsException("Could not find keys for 'null' piid");
Session session = null;
Transaction transaction = null;
Collection<String> list = null;
try {
session = sessionFactory.openSession();
transaction = session.beginTransaction();
list = getKeysImpl(session, piid, prefix, type);
transaction.commit();
} catch (HibernateException hibernateException) {
throw new PersistentVarsException("HibernatePropertySet.getKeys: " + hibernateException.getMessage());
} finally {
if (transaction != null && transaction.isActive())
transaction.rollback();
if (session != null)
session.close();
}
return list;
}
示例2: save
import org.hibernate.Transaction; //导入方法依赖的package包/类
public void save(HibernatePersistentVarsItem item) {
if( item == null)
throw new PersistentVarsException("Could not save 'null' PropertyItem");
Session session = null;
Transaction transaction = null;
try {
session = this.sessionFactory.openSession();
transaction = session.beginTransaction();
session.saveOrUpdate(item);
session.flush();
transaction.commit();
} catch (HibernateException hibernateException) {
throw new PersistentVarsException("Could not save key '" + item.getKey() + "':" + hibernateException.getMessage());
} finally {
if (transaction != null && transaction.isActive())
transaction.rollback();
if (session != null)
session.close();
}
}
示例3: findByKey
import org.hibernate.Transaction; //导入方法依赖的package包/类
public HibernatePersistentVarsItem findByKey(Long piid, String key) {
if( piid == null)
throw new PersistentVarsException("Could not find property for 'null' piid");
if( key == null)
throw new PersistentVarsException("Could not find property for 'null' key");
Session session = null;
Transaction transaction = null;
HibernatePersistentVarsItem item = null;
try {
session = sessionFactory.openSession();
transaction = session.beginTransaction();
item = getItem(session, piid, key);
session.flush();
transaction.commit();
} catch (HibernateException hibernateException) {
throw new PersistentVarsException("Could not find key '" + key + "': " + hibernateException.getMessage());
} finally {
if (transaction != null && transaction.isActive())
transaction.rollback();
if (session != null)
session.close();
}
return item;
}
示例4: remove
import org.hibernate.Transaction; //导入方法依赖的package包/类
public void remove(Long piid, String key) {
if( piid == null)
throw new PersistentVarsException("Could not remove property for 'null' piid");
if( key == null)
throw new PersistentVarsException("Could not remove property with 'null' key");
Session session = null;
Transaction transaction = null;
try {
session = this.sessionFactory.openSession();
transaction = session.beginTransaction();
session.delete(getItem(session, piid, key));
session.flush();
transaction.commit();
} catch (HibernateException hibernateException) {
throw new PersistentVarsException("Could not remove key '" + key + "': " + hibernateException.getMessage());
} finally {
if (transaction != null && transaction.isActive())
transaction.rollback();
if (session != null)
session.close();
}
}
示例5: findCurrentSteps
import org.hibernate.Transaction; //导入方法依赖的package包/类
public List<Step> findCurrentSteps(final long entryId) throws WorkflowStoreException {
Session session = null;
Transaction transaction = null;
List<Step> steps = null;
try {
session = sessionFactory.openSession();
transaction = session.beginTransaction();
steps = loadEntry(session, entryId).getCurrentSteps();
transaction.commit();
} catch (HibernateException hibernateException) {
throw new WorkflowStoreException(hibernateException);
} finally {
if (transaction != null && transaction.isActive())
transaction.rollback();
if (session != null)
session.close();
}
return steps;
}
示例6: findProcessInstance
import org.hibernate.Transaction; //导入方法依赖的package包/类
public ProcessInstance findProcessInstance(long entryId) throws WorkflowStoreException {
Session session = null;
Transaction transaction = null;
ProcessInstance workflowEntry = null;
try {
session = sessionFactory.openSession();
transaction = session.beginTransaction();
workflowEntry = loadEntry(session, entryId);
transaction.commit();
} catch (HibernateException hibernateException) {
throw new WorkflowStoreException(hibernateException);
} finally {
if (transaction != null && transaction.isActive())
transaction.rollback();
if (session != null)
session.close();
}
return workflowEntry;
}
示例7: findHistorySteps
import org.hibernate.Transaction; //导入方法依赖的package包/类
public List<Step> findHistorySteps(final long entryId) throws WorkflowStoreException {
Session session = null;
Transaction transaction = null;
List<Step> steps = null;
try {
session = sessionFactory.openSession();
transaction = session.beginTransaction();
steps = loadEntry(session, entryId).getHistorySteps();
transaction.commit();
} catch (HibernateException hibernateException) {
throw new WorkflowStoreException(hibernateException);
} finally {
if (transaction != null && transaction.isActive())
transaction.rollback();
if (session != null)
session.close();
}
return steps;
}
示例8: fetchProcessDefinition
import org.hibernate.Transaction; //导入方法依赖的package包/类
@Override
protected InputStream fetchProcessDefinition(WorkflowLocation workflowLocation) throws WorkflowLoaderException {
String processDefinition = null;
Session session = null;
Transaction transaction = null;
if(sessionFactory == null)
throw new WorkflowLoaderException("'sessionFactory' has not been defined for HibernateLoader");
try {
session = sessionFactory.openSession();
transaction = session.beginTransaction();
Criteria criteria = session.createCriteria(HibernateProcessDescription.class);
criteria.add(Restrictions.eq("workflowName", workflowLocation.location));
HibernateProcessDescription hpd = (HibernateProcessDescription)criteria.uniqueResult();
if(hpd != null)
processDefinition = hpd.getContent();
transaction.commit();
} catch(HibernateException hibernateException) {
throw new WorkflowLoaderException(hibernateException);
} finally {
if (transaction != null && transaction.isActive())
transaction.rollback();
if (session != null)
session.close();
}
if(processDefinition == null)
throw new WorkflowLoaderException("Process definition '" + workflowLocation.location + "' not found");
return new ByteArrayInputStream(processDefinition.getBytes());
}
示例9: isTransactionInProgress
import org.hibernate.Transaction; //导入方法依赖的package包/类
@Override
public boolean isTransactionInProgress(
JDBCContext jdbcContext, Context transactionContext, Transaction transaction) {
return (transaction != null && transaction.isActive()) ||
TransactionSynchronizationManager.isActualTransactionActive();
}
示例10: deleteSessionById
import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
* @param id
* @throws HibernateException
*/
public static void deleteSessionById(Long id) throws HibernateException {
org.hibernate.Session hibSession = new SessionDAO().getSession();
Transaction tx = null;
try {
tx = hibSession.beginTransaction();
for (Iterator i=hibSession.createQuery("from Location where session.uniqueId = :sessionId").setLong("sessionId", id).iterate();i.hasNext();) {
Location loc = (Location)i.next();
loc.getFeatures().clear();
loc.getRoomGroups().clear();
hibSession.update(loc);
}
/*
for (Iterator i=hibSession.createQuery("from Exam where session.uniqueId=:sessionId").setLong("sessionId", id).iterate();i.hasNext();) {
Exam x = (Exam)i.next();
for (Iterator j=x.getConflicts().iterator();j.hasNext();) {
ExamConflict conf = (ExamConflict)j.next();
hibSession.delete(conf);
j.remove();
}
hibSession.update(x);
}
*/
hibSession.flush();
hibSession.createQuery(
"delete DistributionPref p where p.owner in (select s from Session s where s.uniqueId=:sessionId)").
setLong("sessionId", id).
executeUpdate();
hibSession.createQuery(
"delete InstructionalOffering o where o.session.uniqueId=:sessionId").
setLong("sessionId", id).
executeUpdate();
hibSession.createQuery(
"delete Department d where d.session.uniqueId=:sessionId").
setLong("sessionId", id).
executeUpdate();
hibSession.createQuery(
"delete Session s where s.uniqueId=:sessionId").
setLong("sessionId", id).
executeUpdate();
String[] a = { "DistributionPref", "RoomPref", "RoomGroupPref", "RoomFeaturePref", "BuildingPref", "TimePref", "DatePatternPref", "ExamPeriodPref" };
for (String str : a) {
hibSession.createQuery(
"delete " + str + " p where owner not in (from PreferenceGroup)").
executeUpdate();
}
deleteObjects(
hibSession,
"ExamConflict",
hibSession.createQuery("select x.uniqueId from ExamConflict x where x.exams is empty").iterate()
);
tx.commit();
} catch (HibernateException e) {
try {
if (tx!=null && tx.isActive()) tx.rollback();
} catch (Exception e1) { }
throw e;
}
HibernateUtil.clearCache();
}
示例11: rollForwardInstructionalOffering
import org.hibernate.Transaction; //导入方法依赖的package包/类
public void rollForwardInstructionalOffering(InstructionalOffering fromInstructionalOffering, Session fromSession, Session toSession){
InstructionalOfferingDAO ioDao = new InstructionalOfferingDAO();
org.hibernate.Session hibSession = ioDao.getSession();
iLog.info("Rolling " + fromInstructionalOffering.getCourseNameWithTitle());
Transaction trns = null;
try {
if (hibSession.getTransaction()==null || !hibSession.getTransaction().isActive())
trns = hibSession.beginTransaction();
InstructionalOffering toInstructionalOffering = findToInstructionalOffering(fromInstructionalOffering, toSession, hibSession);
if (toInstructionalOffering == null){
return;
}
if (toInstructionalOffering.getInstrOfferingConfigs() != null && toInstructionalOffering.getInstrOfferingConfigs().size() > 0){
toInstructionalOffering.getInstrOfferingConfigs().clear();
}
toInstructionalOffering.setNotOffered(fromInstructionalOffering.isNotOffered());
toInstructionalOffering.setUniqueIdRolledForwardFrom(fromInstructionalOffering.getUniqueId());
InstrOfferingConfig fromInstrOffrConfig = null;
InstrOfferingConfig toInstrOffrConfig = null;
if (fromInstructionalOffering.getInstrOfferingConfigs() != null && fromInstructionalOffering.getInstrOfferingConfigs().size() > 0){
List<InstrOfferingConfig> fromInstrOffrConfigs = new ArrayList<InstrOfferingConfig>(fromInstructionalOffering.getInstrOfferingConfigs());
Collections.sort(fromInstrOffrConfigs, new InstrOfferingConfigComparator(null));
for (Iterator it = fromInstrOffrConfigs.iterator(); it.hasNext();){
fromInstrOffrConfig = (InstrOfferingConfig) it.next();
toInstrOffrConfig = new InstrOfferingConfig();
toInstrOffrConfig.setLimit(fromInstrOffrConfig.getLimit());
toInstrOffrConfig.setInstructionalOffering(toInstructionalOffering);
toInstrOffrConfig.setName(fromInstrOffrConfig.getName());
toInstrOffrConfig.setUnlimitedEnrollment(fromInstrOffrConfig.isUnlimitedEnrollment());
toInstrOffrConfig.setUniqueIdRolledForwardFrom(fromInstrOffrConfig.getUniqueId());
toInstrOffrConfig.setClassDurationType(fromInstrOffrConfig.getClassDurationType());
toInstrOffrConfig.setInstructionalMethod(fromInstrOffrConfig.getInstructionalMethod());
toInstructionalOffering.addToinstrOfferingConfigs(toInstrOffrConfig);
hibSession.saveOrUpdate(toInstrOffrConfig);
hibSession.update(toInstructionalOffering);
rollForwardSchedSubpartsForAConfig(fromInstrOffrConfig, toInstrOffrConfig, hibSession, toSession);
hibSession.update(toInstructionalOffering);
}
}
if (trns != null && trns.isActive()) {
trns.commit();
}
hibSession.flush();
hibSession.evict(toInstructionalOffering);
hibSession.evict(fromInstructionalOffering);
} catch (Exception e){
iLog.error("Failed to roll " + fromInstructionalOffering.getCourseName(), e);
if (trns != null){
if (trns.isActive()){
trns.rollback();
}
}
}
}
示例12: doDelete
import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
* Delete distribution pref
* @param distPrefId
*/
private void doDelete(HttpServletRequest request, String distPrefId) {
Transaction tx = null;
sessionContext.checkPermission(distPrefId, "DistributionPref", Right.ExaminationDistributionPreferenceDelete);
try {
DistributionPrefDAO dpDao = new DistributionPrefDAO();
org.hibernate.Session hibSession = dpDao.getSession();
tx = hibSession.getTransaction();
if (tx==null || !tx.isActive())
tx = hibSession.beginTransaction();
HashSet relatedExams = new HashSet();
DistributionPref dp = dpDao.get(new Long(distPrefId));
PreferenceGroup owner = (PreferenceGroup) dp.getOwner();
owner.getPreferences().remove(dp);
for (Iterator i=dp.getDistributionObjects().iterator();i.hasNext();) {
DistributionObject dObj = (DistributionObject)i.next();
PreferenceGroup pg = dObj.getPrefGroup();
relatedExams.add(pg);
pg.getDistributionObjects().remove(dObj);
hibSession.saveOrUpdate(pg);
}
hibSession.delete(dp);
hibSession.saveOrUpdate(owner);
for (Iterator i=relatedExams.iterator();i.hasNext();) {
Exam exam = (Exam)i.next();
ChangeLog.addChange(
hibSession,
sessionContext,
exam,
ChangeLog.Source.DIST_PREF_EDIT,
ChangeLog.Operation.DELETE,
exam.firstSubjectArea(),
exam.firstDepartment());
}
if (tx!=null && tx.isActive())
tx.commit();
hibSession.flush();
hibSession.refresh(owner);
}
catch (Exception e) {
Debug.error(e);
if (tx!=null && tx.isActive())
tx.rollback();
}
}
示例13: deleteRoomFeature
import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws HibernateException
*/
public ActionForward deleteRoomFeature(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
RoomFeatureEditForm roomFeatureEditForm = (RoomFeatureEditForm) form;
Long id = new Long(roomFeatureEditForm.getId());
RoomFeatureDAO rdao = new RoomFeatureDAO();
org.hibernate.Session hibSession = rdao.getSession();
Transaction tx = null;
try {
tx = hibSession.beginTransaction();
RoomFeature rf = rdao.get(id, hibSession);
if (rf != null) {
sessionContext.checkPermission(rf, rf instanceof GlobalRoomFeature ? Right.GlobalRoomFeatureDelete : Right.DepartmenalRoomFeatureDelete);
ChangeLog.addChange(
hibSession,
sessionContext,
rf,
ChangeLog.Source.ROOM_FEATURE_EDIT,
ChangeLog.Operation.DELETE,
null,
(rf instanceof DepartmentRoomFeature?((DepartmentRoomFeature)rf).getDepartment():null));
for (Iterator i=rf.getRooms().iterator();i.hasNext();) {
Location loc = (Location)i.next();
loc.getFeatures().remove(rf);
hibSession.save(loc);
}
for (RoomFeaturePref p: (List<RoomFeaturePref>)hibSession.createQuery("from RoomFeaturePref p where p.roomFeature.uniqueId = :id")
.setLong("id", id).list()) {
p.getOwner().getPreferences().remove(p);
hibSession.delete(p);
hibSession.saveOrUpdate(p.getOwner());
}
hibSession.delete(rf);
}
tx.commit();
} catch (Exception e) {
if (tx!=null && tx.isActive()) tx.rollback();
throw e;
}
roomFeatureEditForm.setDeptCode((String)sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom));
return mapping.findForward("showRoomFeatureList");
}
示例14: doDelete
import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
* Delete distribution pref
* @param distPrefId
*/
private void doDelete(HttpServletRequest request, String distPrefId) {
/*
String query = "delete DistributionPref dp where dp.uniqueId=:distPrefId";
Query q = hibSession.createQuery(query);
q.setLong("distPrefId", Long.parseLong(distPrefId));
q.executeUpdate();
*/
Transaction tx = null;
try {
DistributionPrefDAO dpDao = new DistributionPrefDAO();
org.hibernate.Session hibSession = dpDao.getSession();
tx = hibSession.getTransaction();
if (tx==null || !tx.isActive())
tx = hibSession.beginTransaction();
HashSet relatedInstructionalOfferings = new HashSet();
DistributionPref dp = dpDao.get(new Long(distPrefId));
sessionContext.checkPermission(dp, Right.DistributionPreferenceDelete);
Department dept = (Department) dp.getOwner();
dept.getPreferences().remove(dp);
for (Iterator i=dp.getDistributionObjects().iterator();i.hasNext();) {
DistributionObject dObj = (DistributionObject)i.next();
PreferenceGroup pg = dObj.getPrefGroup();
relatedInstructionalOfferings.add((pg instanceof Class_ ?((Class_)pg).getSchedulingSubpart():(SchedulingSubpart)pg).getInstrOfferingConfig().getInstructionalOffering());
pg.getDistributionObjects().remove(dObj);
hibSession.saveOrUpdate(pg);
}
hibSession.delete(dp);
hibSession.saveOrUpdate(dept);
List<Long> changedOfferingIds = new ArrayList<Long>();
for (Iterator i=relatedInstructionalOfferings.iterator();i.hasNext();) {
InstructionalOffering io = (InstructionalOffering)i.next();
ChangeLog.addChange(
hibSession,
sessionContext,
io,
ChangeLog.Source.DIST_PREF_EDIT,
ChangeLog.Operation.DELETE,
io.getControllingCourseOffering().getSubjectArea(),
null);
if (permissionOfferingLockNeeded.check(sessionContext.getUser(), io))
changedOfferingIds.add(io.getUniqueId());
}
if (!changedOfferingIds.isEmpty())
StudentSectioningQueue.offeringChanged(hibSession, sessionContext.getUser(), sessionContext.getUser().getCurrentAcademicSessionId(), changedOfferingIds);
if (tx!=null && tx.isActive())
tx.commit();
hibSession.flush();
hibSession.refresh(dept);
}
catch (Exception e) {
Debug.error(e);
if (tx!=null && tx.isActive())
tx.rollback();
}
}
示例15: deleteRoomGroup
import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward deleteRoomGroup(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
RoomGroupEditForm roomGroupEditForm = (RoomGroupEditForm) form;
Long id = new Long(roomGroupEditForm.getId());
RoomGroupDAO rgdao = new RoomGroupDAO();
org.hibernate.Session hibSession = rgdao.getSession();
Transaction tx = null;
try {
tx = hibSession.beginTransaction();
RoomGroup rg = rgdao.get(id, hibSession);
if (rg != null) {
sessionContext.checkPermission(rg, rg.isGlobal() ? Right.GlobalRoomGroupDelete : Right.DepartmenalRoomGroupDelete);
ChangeLog.addChange(
hibSession,
sessionContext,
rg,
ChangeLog.Source.ROOM_GROUP_EDIT,
ChangeLog.Operation.DELETE,
null,
rg.getDepartment());
Collection rooms = rg.getRooms();
//remove roomGroup from room
for (Iterator iter = rooms.iterator(); iter.hasNext();) {
Location r = (Location) iter.next();
Collection roomGroups = r.getRoomGroups();
roomGroups.remove(rg);
hibSession.saveOrUpdate(r);
}
for (RoomGroupPref p: (List<RoomGroupPref>)hibSession.createQuery("from RoomGroupPref p where p.roomGroup.uniqueId = :id")
.setLong("id", id).list()) {
p.getOwner().getPreferences().remove(p);
hibSession.delete(p);
hibSession.saveOrUpdate(p.getOwner());
}
hibSession.delete(rg);
}
tx.commit();
} catch (Exception e) {
Debug.error(e);
try {
if(tx!=null && tx.isActive())
tx.rollback();
}
catch (Exception e1) { }
throw e;
}
return mapping.findForward("showRoomGroupList");
}