本文整理汇总了Java中org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException类的典型用法代码示例。如果您正苦于以下问题:Java HibernateOptimisticLockingFailureException类的具体用法?Java HibernateOptimisticLockingFailureException怎么用?Java HibernateOptimisticLockingFailureException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HibernateOptimisticLockingFailureException类属于org.springframework.orm.hibernate3包,在下文中一共展示了HibernateOptimisticLockingFailureException类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAndIncrement
import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException; //导入依赖的package包/类
@Override
@Transactional(propagation = Propagation.MANDATORY)
public long getAndIncrement(final String key)
{
return (Long) getHibernateTemplate().execute(new HibernateCallback()
{
@Override
public Object doInHibernate(Session session)
{
Query query = session.createQuery("FROM SystemConfig sc WHERE sc.key = :key").setParameter("key", key)
.setLockMode("sc", LockMode.UPGRADE_NOWAIT);
while( true )
{
try
{
SystemConfig sc = (SystemConfig) query.uniqueResult();
Long v = Long.valueOf(sc.getValue());
sc.setValue(Long.toString(v.longValue() + 1));
session.update(sc);
session.flush();
return v;
}
catch( HibernateOptimisticLockingFailureException e )
{
// Sleep for a little bit and keep trying
try
{
Thread.sleep(50);
}
catch( InterruptedException e1 )
{
// Ignore
}
}
}
}
});
}
示例2: processSave
import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException; //导入依赖的package包/类
@Override
protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) {
TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI);
try {
targetInstanceManager.save(ti);
if (ti.getState().equals(TargetInstance.STATE_PAUSED)) {
// Send the updated profile to the harvester.
harvestCoordinator.updateProfileOverrides(ti);
}
}
catch (HibernateOptimisticLockingFailureException e) {
if (log.isErrorEnabled()) {
log.error("Failed to save target instance. " + e.getMessage(), e);
}
throw new WCTRuntimeException("The target instance " + ti.getJobName() + " could not be saved as it has been modified by another user or the system.");
}
finally {
unbindContext(req);
}
try {
ModelAndView mav = queueController.showForm(req ,res, errors);
mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("targetInstance.saved", new Object[] { ti.getTarget().getName() + " ("+ ti.getOid().toString() + ")" }, Locale.getDefault()));
return mav;
}
catch(Exception ex) {
throw new WCTRuntimeException("Failed to load queue controller", ex);
}
}
示例3: handle
import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException; //导入依赖的package包/类
@Override
protected ModelAndView handle(HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) throws Exception {
ProfileListCommand command = (ProfileListCommand) comm;
req.getSession().setAttribute(ProfileListController.SESSION_KEY_SHOW_INACTIVE, command.isShowInactive());
if(command.getActionCommand().equals(ProfileListCommand.ACTION_LIST))
{
String defaultAgency = (String)req.getSession().getAttribute(ProfileListController.SESSION_AGENCY_FILTER);
if(defaultAgency == null)
{
defaultAgency = AuthUtil.getRemoteUserObject().getAgency().getName();
}
command.setDefaultAgency(defaultAgency);
}
else if(command.getActionCommand().equals(ProfileListCommand.ACTION_FILTER))
{
req.getSession().setAttribute(ProfileListController.SESSION_AGENCY_FILTER, command.getDefaultAgency());
}
else if(command.getActionCommand().equals(ProfileListCommand.ACTION_IMPORT))
{
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) req;
CommonsMultipartFile uploadedFile = (CommonsMultipartFile) multipartRequest.getFile("sourceFile");
Profile profile = new Profile();
profile.setProfile( new String(uploadedFile.getBytes()) );
Date now = new Date();
profile.setName("Profile Imported on "+now.toString());
profile.setDescription("Imported");
String importAgency = req.getParameter("importAgency");
if(importAgency == null || importAgency.trim().equals("")) {
profile.setOwningAgency(AuthUtil.getRemoteUserObject().getAgency());
} else {
long agencyOid = Long.parseLong(importAgency);
Agency agency = agencyUserManager.getAgencyByOid(agencyOid);
profile.setOwningAgency(agency);
}
// Save to the database
try {
profileManager.saveOrUpdate(profile);
}
catch (HibernateOptimisticLockingFailureException e) {
Object[] vals = new Object[] {profile.getName(), profile.getOwningAgency().getName()};
errors.reject("profile.modified", vals, "profile has been modified by another user.");
}
return new ModelAndView("redirect:/curator/profiles/list.html");
}
ModelAndView mav = getView(command);
mav.addObject(Constants.GBL_CMD_DATA, command);
return mav;
}