📄 defaultsessionowner.java
字号:
package com.ttdev.customerCRUD;
import org.apache.hivemind.*;
import org.hibernate.*;
public class DefaultSessionOwner implements SessionOwner, Discardable {
private SessionCreator creator;
private Session session;
private Transaction tx;
private boolean isToRollback;
public Session getSession() {
if (session == null) {
session = creator.createSession();
if (tx == null) {
tx = session.beginTransaction();
isToRollback = false;
}
}
return session;
}
public void threadDidDiscardService() {
if (session != null) {
try {
endTransaction();
} finally {
session.close();
session = null;
}
}
}
public void setSessionCreator(SessionCreator creator) {
this.creator = creator;
}
public void setToRollback() {
isToRollback = true;
}
public void endTransaction() {
if (tx != null) {
try {
if (isToRollback) {
tx.rollback();
} else {
tx.commit();
}
} catch (RuntimeException e) {
tx.rollback();
throw e;
} finally {
tx = null;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -