本文整理匯總了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);
}