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


Java CacheMode类代码示例

本文整理汇总了Java中org.hibernate.CacheMode的典型用法代码示例。如果您正苦于以下问题:Java CacheMode类的具体用法?Java CacheMode怎么用?Java CacheMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CacheMode类属于org.hibernate包,在下文中一共展示了CacheMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCacheMode

import org.hibernate.CacheMode; //导入依赖的package包/类
private static CacheMode getCacheMode(CacheModeType cacheModeType) {
	switch ( cacheModeType ) {
		case GET:
			return CacheMode.GET;
		case IGNORE:
			return CacheMode.IGNORE;
		case NORMAL:
			return CacheMode.NORMAL;
		case PUT:
			return CacheMode.PUT;
		case REFRESH:
			return CacheMode.REFRESH;
		default:
			throw new AssertionFailure( "Unknown cacheModeType: " + cacheModeType );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:QueryBinder.java

示例2: getCacheMode

import org.hibernate.CacheMode; //导入依赖的package包/类
private static CacheMode getCacheMode(AnnotationInstance[] hints, String element, String query) {
	String val = getString( hints, element );
	if ( val == null ) {
		return null;
	}
	if ( val.equalsIgnoreCase( CacheMode.GET.toString() ) ) {
		return CacheMode.GET;
	}
	if ( val.equalsIgnoreCase( CacheMode.IGNORE.toString() ) ) {
		return CacheMode.IGNORE;
	}
	if ( val.equalsIgnoreCase( CacheMode.NORMAL.toString() ) ) {
		return CacheMode.NORMAL;
	}
	if ( val.equalsIgnoreCase( CacheMode.PUT.toString() ) ) {
		return CacheMode.PUT;
	}
	if ( val.equalsIgnoreCase( CacheMode.REFRESH.toString() ) ) {
		return CacheMode.REFRESH;
	}
	throw new AnnotationException( "Unknown CacheMode in hint: " + query + ":" + element );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:QueryBinder.java

示例3: cascadeBeforeDelete

import org.hibernate.CacheMode; //导入依赖的package包/类
protected void cascadeBeforeDelete(
		EventSource session,
		EntityPersister persister,
		Object entity,
		EntityEntry entityEntry,
		Set transientEntities) throws HibernateException {

	CacheMode cacheMode = session.getCacheMode();
	session.setCacheMode( CacheMode.GET );
	session.getPersistenceContext().incrementCascadeLevel();
	try {
		// cascade-delete to collections BEFORE the collection owner is deleted
		new Cascade( CascadingActions.DELETE, CascadePoint.AFTER_INSERT_BEFORE_DELETE, session ).cascade(
				persister,
				entity,
				transientEntities
		);
	}
	finally {
		session.getPersistenceContext().decrementCascadeLevel();
		session.setCacheMode( cacheMode );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:DefaultDeleteEventListener.java

示例4: cascadeAfterDelete

import org.hibernate.CacheMode; //导入依赖的package包/类
protected void cascadeAfterDelete(
		EventSource session,
		EntityPersister persister,
		Object entity,
		Set transientEntities) throws HibernateException {

	CacheMode cacheMode = session.getCacheMode();
	session.setCacheMode( CacheMode.GET );
	session.getPersistenceContext().incrementCascadeLevel();
	try {
		// cascade-delete to many-to-one AFTER the parent was deleted
		new Cascade( CascadingActions.DELETE, CascadePoint.BEFORE_INSERT_AFTER_DELETE, session ).cascade(
				persister,
				entity,
				transientEntities
		);
	}
	finally {
		session.getPersistenceContext().decrementCascadeLevel();
		session.setCacheMode( cacheMode );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:DefaultDeleteEventListener.java

示例5: AbstractApiHelper

import org.hibernate.CacheMode; //导入依赖的package包/类
public AbstractApiHelper(HttpServletRequest request, HttpServletResponse response, SessionContext context, CacheMode cacheMode) {
	iRequest = request;
	iResponse = response;
	iContext = context;
	iCacheMode = cacheMode;

	// select academic session if needed
	UserContext user = (iContext == null ? null : iContext.getUser());
	Long sessionId = getAcademicSessionId();
	if (user != null && sessionId != null && !sessionId.equals(user.getCurrentAcademicSessionId())) {
		String role = (user.getCurrentAuthority() == null ? null : user.getCurrentAuthority().getRole());
		if (getParameter("role") != null) role = getParameter("role");
		UserAuthority best = null;
		for (UserAuthority authority: user.getAuthorities()) {
			if (authority.getAcademicSession() != null && authority.getAcademicSession().getQualifierId().equals(sessionId)) {
				if (best == null || authority.getRole().equals(role)) best = authority;
			}
		}
		if (best != null) user.setCurrentAuthority(best);
	}
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:22,代码来源:AbstractApiHelper.java

示例6: load

import org.hibernate.CacheMode; //导入依赖的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

示例7: load

import org.hibernate.CacheMode; //导入依赖的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

示例8: NamedQueryDefinition

import org.hibernate.CacheMode; //导入依赖的package包/类
public NamedQueryDefinition(
		String query,
		boolean cacheable,
		String cacheRegion,
		Integer timeout,
		Integer fetchSize,
		FlushMode flushMode,
		CacheMode cacheMode,
		boolean readOnly,
		String comment,
		Map parameterTypes
) {
	this.query = query;
	this.cacheable = cacheable;
	this.cacheRegion = cacheRegion;
	this.timeout = timeout;
	this.fetchSize = fetchSize;
	this.flushMode = flushMode;
	this.parameterTypes = parameterTypes;
	this.cacheMode = cacheMode;
	this.readOnly = readOnly;
	this.comment = comment;
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:24,代码来源:NamedQueryDefinition.java

示例9: cascadeBeforeDelete

import org.hibernate.CacheMode; //导入依赖的package包/类
protected void cascadeBeforeDelete(
		EventSource session,
		EntityPersister persister,
		Object entity,
		EntityEntry entityEntry,
		Set transientEntities) throws HibernateException {

	CacheMode cacheMode = session.getCacheMode();
	session.setCacheMode( CacheMode.GET );
	session.getPersistenceContext().incrementCascadeLevel();
	try {
		// cascade-delete to collections BEFORE the collection owner is deleted
		new Cascade( CascadingAction.DELETE, Cascade.AFTER_INSERT_BEFORE_DELETE, session )
				.cascade( persister, entity, transientEntities );
	}
	finally {
		session.getPersistenceContext().decrementCascadeLevel();
		session.setCacheMode( cacheMode );
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:21,代码来源:DefaultDeleteEventListener.java

示例10: cascadeAfterDelete

import org.hibernate.CacheMode; //导入依赖的package包/类
protected void cascadeAfterDelete(
		EventSource session,
		EntityPersister persister,
		Object entity,
		Set transientEntities) throws HibernateException {

	CacheMode cacheMode = session.getCacheMode();
	session.setCacheMode( CacheMode.GET );
	session.getPersistenceContext().incrementCascadeLevel();
	try {
		// cascade-delete to many-to-one AFTER the parent was deleted
		new Cascade( CascadingAction.DELETE, Cascade.BEFORE_INSERT_AFTER_DELETE, session )
				.cascade( persister, entity, transientEntities );
	}
	finally {
		session.getPersistenceContext().decrementCascadeLevel();
		session.setCacheMode( cacheMode );
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:20,代码来源:DefaultDeleteEventListener.java

示例11: reindexClasses

import org.hibernate.CacheMode; //导入依赖的package包/类
protected void reindexClasses(FullTextEntityManager fullTextEntityManager, Set<Class<?>> entityClasses)
		throws InterruptedException {
	int batchSize = propertyService.get(HIBERNATE_SEARCH_REINDEX_BATCH_SIZE);
	int loadThreads = propertyService.get(HIBERNATE_SEARCH_REINDEX_LOAD_THREADS);
	
	if (LOGGER.isInfoEnabled()) {
		LOGGER.info("Targets for indexing job: {}", entityClasses);
	}
	
	for (Class<?> clazz : entityClasses) {
		ProgressMonitor progressMonitor = new ProgressMonitor();
		Thread t = new Thread(progressMonitor);
		LOGGER.info(String.format("Reindexing %1$s.", clazz));
		t.start();
		MassIndexer indexer = fullTextEntityManager.createIndexer(clazz);
		indexer.batchSizeToLoadObjects(batchSize)
				.threadsToLoadObjects(loadThreads)
				.cacheMode(CacheMode.NORMAL)
				.progressMonitor(progressMonitor)
				.startAndWait();
		progressMonitor.stop();
		t.interrupt();
		LOGGER.info(String.format("Reindexing %1$s done.", clazz));
	}
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:26,代码来源:HibernateSearchDaoImpl.java

示例12: getUserProfiles

import org.hibernate.CacheMode; //导入依赖的package包/类
/**
	 * {@inheritDoc}
	 */
public List<UserProfile> getUserProfiles(final int start, final int count) {
	
	//get fields directly from the sakaiperson table and use Transformers.aliasToBean to transform into UserProfile pojo
	//the idea is we *dont* want a SakaiPerson object
	HibernateCallback<List<UserProfile>> hcb = session -> {
           Query q = session.getNamedQuery(QUERY_GET_SAKAI_PERSON);
           //see scalars in the hbm
           q.setFirstResult(start);
           q.setMaxResults(count);
           q.setResultTransformer(Transformers.aliasToBean(UserProfile.class));
           q.setCacheMode(CacheMode.GET);
           return q.list();
       };
  	
  	return getHibernateTemplate().execute(hcb);
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:20,代码来源:ProfileDaoImpl.java

示例13: runStatefulHql

import org.hibernate.CacheMode; //导入依赖的package包/类
private static void runStatefulHql() throws Exception {
  Stopwatch watch = Stopwatch.createStarted();
  Session session = sessionFactory.openSession();
  try {
    session.getTransaction().begin();
    @SuppressWarnings("unchecked")
    List<Driver> list = 
      session.createQuery("select d from Driver d LEFT JOIN FETCH d.cars c")
      .setCacheable(true)
      .setCacheMode(CacheMode.NORMAL).list();
    for (Driver entry : list) {
      LOG.info("Entry " + entry.getId());
    }
    session.getTransaction().commit();
  } catch (Exception ex) {
    session.getTransaction().rollback();
    throw ex;
  } finally {
    session.close();
  }
  LOG.info("StatefulHql:=" + watch.toString());
}
 
开发者ID:AndreasKl,项目名称:java-classic-playground,代码行数:23,代码来源:Program.java

示例14: runStatefulCriteria

import org.hibernate.CacheMode; //导入依赖的package包/类
private static void runStatefulCriteria() throws Exception {
  Stopwatch watch = Stopwatch.createStarted();
  Session session = sessionFactory.openSession();
  try {
    session.getTransaction().begin();
    @SuppressWarnings("unchecked")
    List<Driver> list = 
      session
        .createCriteria(Driver.class)
        .setFetchMode("cars", FetchMode.JOIN)
        .setCacheable(true)
        .setCacheMode(CacheMode.NORMAL)
        .list();
    for (Driver entry : list) {
      LOG.info("Entry " + entry.getId());
    }
    session.getTransaction().commit();
  } catch (Exception ex) {
    session.getTransaction().rollback();
    throw ex;
  } finally {
    session.close();
  }
  LOG.info("StatefulCriteria:=" + watch.toString());
}
 
开发者ID:AndreasKl,项目名称:java-classic-playground,代码行数:26,代码来源:Program.java

示例15: getResultListFromHibernate

import org.hibernate.CacheMode; //导入依赖的package包/类
/**
 * Execute Hibernate criteria query and return a scrollable result set.
 * 
 * @param criteria
 *            Hibernate criteria
 * @return scrollable result set
 * @see https://jira.chpc.utah.edu/browse/FUR-1274
 */
@HibernateExecutor
private ScrollableResults getResultListFromHibernate(final GenericCriteria criteria)
{
	ScrollableResults results = null;
	// Need to use INSENSITIVE scroll-mode per FUR-1300 and
	// http://www.coderanch.com/t/301684/JDBC/java/Unsupported-syntax-refreshRow
	final ScrollMode scrollMode = ScrollMode.SCROLL_INSENSITIVE;
	try
	{
		results = criteria.setCacheMode(CacheMode.IGNORE).scroll(scrollMode);
	}
	catch (final HibernateException e)
	{
		log.error("An exception occurred while scrolling results", e);
	}

	// Normally we won't know up-front the size of a streaming result set. But for
	// easier debugging of the subsequent paging sub-chain, print out the size of the
	// list because we know it already in this case.
	if (log.isDebugEnabled())
	{
		log.debug("Result set = " + StringUtil.getNullSafeToString(results));
	}
	return results;
}
 
开发者ID:openfurther,项目名称:further-open-core,代码行数:34,代码来源:HibernateCriteriaScrollableResultsExecutor.java


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