本文整理汇总了Java中org.hibernate.FlushMode类的典型用法代码示例。如果您正苦于以下问题:Java FlushMode类的具体用法?Java FlushMode怎么用?Java FlushMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FlushMode类属于org.hibernate包,在下文中一共展示了FlushMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beforeCommit
import org.hibernate.FlushMode; //导入依赖的package包/类
@Override
public void beforeCommit(boolean readOnly) throws DataAccessException {
if (!readOnly) {
Session session = getCurrentSession();
// Read-write transaction -> flush the Hibernate Session.
// Further check: only flush when not FlushMode.MANUAL.
if (!session.getFlushMode().equals(FlushMode.MANUAL)) {
try {
SessionFactoryUtils.logger.debug("Flushing Hibernate Session on transaction synchronization");
session.flush();
}
catch (HibernateException ex) {
throw SessionFactoryUtils.convertHibernateAccessException(ex);
}
}
}
}
示例2: beforeCommit
import org.hibernate.FlushMode; //导入依赖的package包/类
public void beforeCommit(boolean readOnly) throws DataAccessException {
if (!readOnly) {
Session session = getCurrentSession();
// Read-write transaction -> flush the Hibernate Session.
// Further check: only flush when not FlushMode.MANUAL.
if (!FlushMode.isManualFlushMode(session.getFlushMode())) {
try {
logger.debug("Flushing Hibernate Session on transaction synchronization");
session.flush();
} catch (HibernateException ex) {
throw SessionFactoryUtils
.convertHibernateAccessException(ex);
}
}
}
}
示例3: prepareTransaction
import org.hibernate.FlushMode; //导入依赖的package包/类
@Override
public Object prepareTransaction(EntityManager entityManager, boolean readOnly, String name)
throws PersistenceException {
Session session = getSession(entityManager);
FlushMode flushMode = session.getFlushMode();
FlushMode previousFlushMode = null;
if (readOnly) {
// We should suppress flushing for a read-only transaction.
session.setFlushMode(FlushMode.MANUAL);
previousFlushMode = flushMode;
}
else {
// We need AUTO or COMMIT for a non-read-only transaction.
if (flushMode.lessThan(FlushMode.COMMIT)) {
session.setFlushMode(FlushMode.AUTO);
previousFlushMode = flushMode;
}
}
return new SessionTransactionData(session, previousFlushMode);
}
示例4: beforeCommit
import org.hibernate.FlushMode; //导入依赖的package包/类
@Override
public void beforeCommit(boolean readOnly) throws DataAccessException {
if (!readOnly) {
Session session = getCurrentSession();
// Read-write transaction -> flush the Hibernate Session.
// Further check: only flush when not FlushMode.NEVER/MANUAL.
if (!session.getFlushMode().lessThan(FlushMode.COMMIT)) {
try {
SessionFactoryUtils.logger.debug("Flushing Hibernate Session on transaction synchronization");
session.flush();
}
catch (HibernateException ex) {
throw translateException(ex);
}
}
}
}
示例5: prepareForCommit
import org.hibernate.FlushMode; //导入依赖的package包/类
@Override
protected void prepareForCommit(DefaultTransactionStatus status) {
if (this.earlyFlushBeforeCommit && status.isNewTransaction()) {
HibernateTransactionObject txObject = (HibernateTransactionObject) status.getTransaction();
Session session = txObject.getSessionHolder().getSession();
if (!session.getFlushMode().lessThan(FlushMode.COMMIT)) {
logger.debug("Performing an early flush for Hibernate transaction");
try {
session.flush();
}
catch (HibernateException ex) {
throw convertHibernateAccessException(ex);
}
finally {
session.setFlushMode(FlushMode.MANUAL);
}
}
}
}
示例6: getFlushMode
import org.hibernate.FlushMode; //导入依赖的package包/类
private static FlushMode getFlushMode(FlushModeType flushModeType) {
FlushMode flushMode;
switch ( flushModeType ) {
case ALWAYS:
flushMode = FlushMode.ALWAYS;
break;
case AUTO:
flushMode = FlushMode.AUTO;
break;
case COMMIT:
flushMode = FlushMode.COMMIT;
break;
case NEVER:
flushMode = FlushMode.MANUAL;
break;
case MANUAL:
flushMode = FlushMode.MANUAL;
break;
case PERSISTENCE_CONTEXT:
flushMode = null;
break;
default:
throw new AssertionFailure( "Unknown flushModeType: " + flushModeType );
}
return flushMode;
}
示例7: getFlushMode
import org.hibernate.FlushMode; //导入依赖的package包/类
private static FlushMode getFlushMode(AnnotationInstance[] hints, String element, String query) {
String val = getString( hints, element );
if ( val == null ) {
return null;
}
if ( val.equalsIgnoreCase( FlushMode.ALWAYS.toString() ) ) {
return FlushMode.ALWAYS;
}
else if ( val.equalsIgnoreCase( FlushMode.AUTO.toString() ) ) {
return FlushMode.AUTO;
}
else if ( val.equalsIgnoreCase( FlushMode.COMMIT.toString() ) ) {
return FlushMode.COMMIT;
}
else if ( val.equalsIgnoreCase( FlushMode.NEVER.toString() ) ) {
return FlushMode.MANUAL;
}
else if ( val.equalsIgnoreCase( FlushMode.MANUAL.toString() ) ) {
return FlushMode.MANUAL;
}
else {
throw new AnnotationException( "Unknown FlushMode in hint: " + query + ":" + element );
}
}
示例8: load
import org.hibernate.FlushMode; //导入依赖的package包/类
@Override
public Object load(Serializable id, Object optionalObject, SessionImplementor session) {
LOG.debugf( "Loading entity: %s using named query: %s", persister.getEntityName(), queryName );
// IMPL NOTE: essentially we perform the named query (which loads the entity into the PC), and then
// do an internal lookup of the entity from the PC.
final AbstractQueryImpl query = (AbstractQueryImpl) session.getNamedQuery( queryName );
if ( query.hasNamedParameters() ) {
query.setParameter( query.getNamedParameters()[0], id, persister.getIdentifierType() );
}
else {
query.setParameter( 0, id, persister.getIdentifierType() );
}
query.setOptionalId( id );
query.setOptionalEntityName( persister.getEntityName() );
query.setOptionalObject( optionalObject );
query.setFlushMode( FlushMode.MANUAL );
query.list();
// now look up the object we are really interested in!
// (this lets us correctly handle proxies and multi-row or multi-column queries)
return session.getPersistenceContext().getEntity( session.generateEntityKey( id, persister ) );
}
示例9: initialize
import org.hibernate.FlushMode; //导入依赖的package包/类
public void initialize(Serializable key, SessionImplementor session)
throws HibernateException {
LOG.debugf("Initializing collection: %s using named query: %s", persister.getRole(), queryName);
//TODO: is there a more elegant way than downcasting?
AbstractQueryImpl query = (AbstractQueryImpl) session.getNamedSQLQuery(queryName);
if ( query.getNamedParameters().length>0 ) {
query.setParameter(
query.getNamedParameters()[0],
key,
persister.getKeyType()
);
}
else {
query.setParameter( 0, key, persister.getKeyType() );
}
query.setCollectionKey( key )
.setFlushMode( FlushMode.MANUAL )
.list();
}
示例10: findSameDepartmentInSession
import org.hibernate.FlushMode; //导入依赖的package包/类
public Department findSameDepartmentInSession(Long newSessionId, org.hibernate.Session hibSession){
if (newSessionId == null){
return(null);
}
Department newDept = Department.findByDeptCode(this.getDeptCode(), newSessionId, hibSession);
if (newDept == null && this.getExternalUniqueId() != null){
// if a department wasn't found and an external uniqueid exists for this
// department check to see if the new term has a department that matches
// the external unique id
List l = hibSession.
createCriteria(Department.class).
add(Restrictions.eq("externalUniqueId",this.getExternalUniqueId())).
add(Restrictions.eq("session.uniqueId", newSessionId)).
setFlushMode(FlushMode.MANUAL).
setCacheable(true).list();
if (l.size() == 1){
newDept = (Department) l.get(0);
}
}
return(newDept);
}
示例11: findByPuidDepartmentId
import org.hibernate.FlushMode; //导入依赖的package包/类
public static DepartmentalInstructor findByPuidDepartmentId(String puid, Long deptId, org.hibernate.Session hibSession) {
try {
return (DepartmentalInstructor)hibSession.
createQuery("select d from DepartmentalInstructor d where d.externalUniqueId=:puid and d.department.uniqueId=:deptId").
setString("puid", puid).
setLong("deptId",deptId.longValue()).
setCacheable(true).
setFlushMode(FlushMode.MANUAL).
uniqueResult();
} catch (NonUniqueResultException e) {
Debug.warning("There are two or more instructors with puid "+puid+" for department "+deptId+" -- returning the first one.");
return (DepartmentalInstructor)hibSession.
createQuery("select d from DepartmentalInstructor d where d.externalUniqueId=:puid and d.department.uniqueId=:deptId").
setString("puid", puid).
setLong("deptId",deptId.longValue()).
setCacheable(true).
setFlushMode(FlushMode.MANUAL).
list().get(0);
}
}
示例12: load
import org.hibernate.FlushMode; //导入依赖的package包/类
public void load() throws Exception {
ApplicationProperties.setSessionId(iSessionId);
org.hibernate.Session hibSession = null;
Transaction tx = null;
try {
hibSession = TimetableManagerDAO.getInstance().createNewSession();
hibSession.setCacheMode(CacheMode.IGNORE);
hibSession.setFlushMode(FlushMode.COMMIT);
tx = hibSession.beginTransaction();
load(hibSession);
tx.commit();
} catch (Exception e) {
iProgress.fatal("Unable to load input data, reason: " + e.getMessage(), e);
tx.rollback();
} finally {
// here we need to close the session since this code may run in a separate thread
if (hibSession != null && hibSession.isOpen()) hibSession.close();
}
}
示例13: load
import org.hibernate.FlushMode; //导入依赖的package包/类
public void load() {
ApplicationProperties.setSessionId(iSessionId);
org.hibernate.Session hibSession = null;
Transaction tx = null;
try {
hibSession = TimetableManagerDAO.getInstance().getSession();
hibSession.setCacheMode(CacheMode.IGNORE);
hibSession.setFlushMode(FlushMode.COMMIT);
tx = hibSession.beginTransaction();
load(hibSession);
tx.commit();
} catch (Exception e) {
iProgress.message(msglevel("loadFailed", Progress.MSGLEVEL_FATAL), "Unable to load input data, reason:"+e.getMessage(),e);
tx.rollback();
} finally {
// here we need to close the session since this code may run in a separate thread
if (hibSession!=null && hibSession.isOpen()) hibSession.close();
}
}
示例14: findRoom
import org.hibernate.FlushMode; //导入依赖的package包/类
private Room findRoom(String buildingAbbv, String roomNumber){
Room room = null;
if (room == null) {
List rooms = this.
getHibSession().
createQuery("select distinct r from Room as r where r.roomNumber=:roomNbr and r.building.abbreviation = :building").
setString("building", buildingAbbv).
setString("roomNbr", roomNumber).
setCacheable(true).
setFlushMode(FlushMode.MANUAL).
list();
if (rooms != null && rooms.size() > 0){
room = (Room) rooms.iterator().next();
}
}
return(room);
}
示例15: prepareFlushMode
import org.hibernate.FlushMode; //导入依赖的package包/类
protected FlushMode prepareFlushMode(Session session, boolean readOnly) throws PersistenceException {
FlushMode flushMode = session.getFlushMode();
if (readOnly) {
// We should suppress flushing for a read-only transaction.
if (!flushMode.equals(FlushMode.MANUAL)) {
session.setFlushMode(FlushMode.MANUAL);
return flushMode;
}
}
else {
// We need AUTO or COMMIT for a non-read-only transaction.
if (flushMode.lessThan(FlushMode.COMMIT)) {
session.setFlushMode(FlushMode.AUTO);
return flushMode;
}
}
// No FlushMode change needed...
return null;
}