当前位置: 首页>>代码示例>>Java>>正文


Java FlushMode类代码示例

本文整理汇总了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);
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:SpringSessionSynchronization.java

示例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);
            }
        }
    }
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:18,代码来源:SpringSessionSynchronization.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:HibernateJpaDialect.java

示例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);
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:SpringSessionSynchronization.java

示例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);
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:HibernateTransactionManager.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:QueryBinder.java

示例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 );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:QueryBinder.java

示例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 ) );

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:NamedQueryLoader.java

示例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();

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:NamedQueryCollectionInitializer.java

示例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);
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:23,代码来源:Department.java

示例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);
	}
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:21,代码来源:DepartmentalInstructor.java

示例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();
	}
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:23,代码来源:InstructorSchedulingDatabaseLoader.java

示例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();
	}
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:23,代码来源:TimetableDatabaseLoader.java

示例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);
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:18,代码来源:EventImport.java

示例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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:HibernateJpaDialect.java


注:本文中的org.hibernate.FlushMode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。