本文整理汇总了Java中org.hibernate.Query.setLockMode方法的典型用法代码示例。如果您正苦于以下问题:Java Query.setLockMode方法的具体用法?Java Query.setLockMode怎么用?Java Query.setLockMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.Query
的用法示例。
在下文中一共展示了Query.setLockMode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.hibernate.Query; //导入方法依赖的package包/类
@Transactional
public String process(String code, Date date) {
if (code == null) {
throw new IllegalArgumentException("code is null");
}
if (date == null) {
throw new IllegalArgumentException("date is null");
}
code = code.trim().toUpperCase();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
Date targetDate = calendar.getTime();
String hql = "from SequenceInfo where code=?";
Query query = sequenceInfoManager.createQuery(hql, code);
query.setLockMode("SequenceInfo", LockMode.WRITE);
SequenceInfo sequenceInfo = (SequenceInfo) query.setFirstResult(0)
.setMaxResults(1).uniqueResult();
int sequence = 0;
if (sequenceInfo == null) {
sequenceInfo = new SequenceInfo();
sequenceInfo.setCode(code);
sequenceInfo.setValue(1);
sequenceInfo.setUpdateDate(targetDate);
} else {
Date updateDate = sequenceInfo.getUpdateDate();
if (updateDate == null) {
sequenceInfo.setUpdateDate(targetDate);
sequenceInfo.setValue(1);
} else if (updateDate.before(targetDate)) {
sequenceInfo.setUpdateDate(targetDate);
sequenceInfo.setValue(1);
} else {
sequenceInfo.setValue(sequenceInfo.getValue() + 1);
}
}
sequenceInfoManager.save(sequenceInfo);
sequence = sequenceInfo.getValue();
if (sequence >= 100000) {
throw new IllegalStateException(sequence
+ " is larger than 100000, cannot process it.");
}
// sequence += 100000;
// String code = Integer.toString(sequence).substring(1);
// return code;
return Integer.toString(sequence);
}