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


Java Example类代码示例

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


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

示例1: findByExample

import org.hibernate.criterion.Example; //导入依赖的package包/类
@Override
public <T> List<T> findByExample(
		final String entityName, final T exampleEntity, final int firstResult, final int maxResults)
		throws DataAccessException {

	Assert.notNull(exampleEntity, "Example entity must not be null");
	return executeWithNativeSession(new HibernateCallback<List<T>>() {
		@Override
		@SuppressWarnings("unchecked")
		public List<T> doInHibernate(Session session) throws HibernateException {
			Criteria executableCriteria = (entityName != null ?
					session.createCriteria(entityName) : session.createCriteria(exampleEntity.getClass()));
			executableCriteria.add(Example.create(exampleEntity));
			prepareCriteria(executableCriteria);
			if (firstResult >= 0) {
				executableCriteria.setFirstResult(firstResult);
			}
			if (maxResults > 0) {
				executableCriteria.setMaxResults(maxResults);
			}
			return executableCriteria.list();
		}
	});
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:HibernateTemplate.java

示例2: doFindByExample

import org.hibernate.criterion.Example; //导入依赖的package包/类
public <T> List<T> doFindByExample(final String entityName, final T exampleEntity, final int firstResult,
    final int maxResults) {
if (exampleEntity == null) {
    throw new IllegalArgumentException("Example entity must not be null");
}

Criteria executableCriteria = (entityName != null ? getSession().createCriteria(entityName)
	: getSession().createCriteria(exampleEntity.getClass()));
executableCriteria.add(Example.create(exampleEntity));
if (firstResult >= 0) {
    executableCriteria.setFirstResult(firstResult);
}
if (maxResults > 0) {
    executableCriteria.setMaxResults(maxResults);
}
return executableCriteria.list();
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:LAMSBaseDAO.java

示例3: findByExample

import org.hibernate.criterion.Example; //导入依赖的package包/类
public <T> List<T> findByExample(final String entityName, final T exampleEntity, final int firstResult,
    final int maxResults) {

if (exampleEntity == null) {
    throw new IllegalArgumentException("Example entity must not be null");
}

Criteria executableCriteria = (entityName != null ? getSession().createCriteria(entityName)
	: getSession().createCriteria(exampleEntity.getClass()));
executableCriteria.add(Example.create(exampleEntity));
if (firstResult >= 0) {
    executableCriteria.setFirstResult(firstResult);
}
if (maxResults > 0) {
    executableCriteria.setMaxResults(maxResults);
}
return executableCriteria.list();
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:LAMSBaseDAO.java

示例4: getByMarketApp

import org.hibernate.criterion.Example; //导入依赖的package包/类
@Override
public CatalogConvertor getByMarketApp(Session sess, String marketName, short catalog, int subCatalog) {
    Criteria cri = sess.createCriteria(CatalogConvertor.class);
    CatalogConvertor catalogConvertor = new CatalogConvertor();
    catalogConvertor.setMarketName(marketName);
    catalogConvertor.setCatalog(catalog);
    catalogConvertor.setSubCatalog(subCatalog);
    Example example = Example.create(catalogConvertor);
    example.excludeZeroes();
    cri.add(example);

    Object o = cri.uniqueResult();
    if (o != null) {
        catalogConvertor = (CatalogConvertor) o;
    }
    return catalogConvertor;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:18,代码来源:CatalogConvertorDaoImpl.java

示例5: findByExample

import org.hibernate.criterion.Example; //导入依赖的package包/类
public List findByExample(Secuserrole instance) {
	Session session = getSession();
	logger.debug("finding Secuserrole instance by example");
	try {
		List results = session.createCriteria(
				"com.quatro.model.security.Secuserrole").add(
				Example.create(instance)).list();
		logger.debug("find by example successful, result size: "
				+ results.size());
		return results;
	} catch (RuntimeException re) {
		logger.error("find by example failed", re);
		throw re;
	} finally {
		this.releaseSession(session);
	}
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:18,代码来源:SecuserroleDao.java

示例6: findByExample

import org.hibernate.criterion.Example; //导入依赖的package包/类
public List findByExample(SecProviderDao instance) {
	logger.debug("finding Provider instance by example");
	Session session = getSession();
	try {
		List results = session.createCriteria(
				"com.quatro.model.security.SecProvider").add(
				Example.create(instance)).list();
		logger.debug("find by example successful, result size: "
				+ results.size());
		return results;
	} catch (RuntimeException re) {
		logger.error("find by example failed", re);
		throw re;
	} finally {
		this.releaseSession(session);
	}
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:18,代码来源:SecProviderDao.java

示例7: testQBE

import org.hibernate.criterion.Example; //导入依赖的package包/类
@Test
public void testQBE() {
	Session session = sessionFactory.getCurrentSession();
	session.beginTransaction();

	Topic topicExample = new Topic();
	topicExample.setTitle("Category4%");
	Example example = Example.create(
		topicExample).ignoreCase().enableLike();

	Criteria criteria = session.createCriteria(Topic.class)
							.add(Restrictions.like("title", "%topic7"))
							.add(example)
							;

	for (Object object : criteria.list()) {
		Topic topic = (Topic)object;

		System.out.println(topic);
	}
}
 
开发者ID:bejondshao,项目名称:personal,代码行数:22,代码来源:QBETest.java

示例8: testSimpleQBE

import org.hibernate.criterion.Example; //导入依赖的package包/类
public void testSimpleQBE() throws Exception {
	deleteData();
    initData();

    Session s = openSession();

    Transaction t = s.beginTransaction();
    Componentizable master = getMaster("hibernate", "open sourc%", "open source1");
    Criteria crit = s.createCriteria(Componentizable.class);
    Example ex = Example.create(master).enableLike();
    crit.add(ex);
    List result = crit.list();
    assertNotNull(result);
    assertEquals(1, result.size());

    t.commit();
    s.close();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:19,代码来源:QueryByExampleTest.java

示例9: testJunctionNotExpressionQBE

import org.hibernate.criterion.Example; //导入依赖的package包/类
public void testJunctionNotExpressionQBE() throws Exception {
    deleteData();
    initData();
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Componentizable master = getMaster("hibernate", null, "ope%");
    Criteria crit = s.createCriteria(Componentizable.class);
    Example ex = Example.create(master).enableLike();

    crit.add(Expression.or(Expression.not(ex), ex));

    List result = crit.list();
    assertNotNull(result);
    assertEquals(2, result.size());
    t.commit();
    s.close();

}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:19,代码来源:QueryByExampleTest.java

示例10: searchByExample

import org.hibernate.criterion.Example; //导入依赖的package包/类
@Override
public Page<Taxon> searchByExample(Taxon example, boolean ignoreCase,
		boolean useLike) {
	Example criterion = Example.create(example);
	if(ignoreCase) {
		criterion.ignoreCase();
	}
	if(useLike) {
		criterion.enableLike();
	}
	Criteria criteria = getSession().createCriteria(Taxon.class);
	criteria.add(criterion);
	List<Taxon> results = (List<Taxon>) criteria.list();
	Page<Taxon> page = new DefaultPageImpl<Taxon>(results.size(), null, null, results, null);
	return page;
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:17,代码来源:TaxonDaoImpl.java

示例11: findByExample

import org.hibernate.criterion.Example; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<T> findByExample(T exampleInstance, String... excludeProperty) {
	try {
		Criteria crit = getSession().createCriteria(getPersistentClass());
		Example example = Example.create(exampleInstance);
		for (String exclude : excludeProperty) {
			example.excludeProperty(exclude);
		}
		crit.add(example);
		return crit.list();
	} catch (Exception e) {
		// e.printStackTrace();
		getTransaction().rollback();
		return null;
	}
}
 
开发者ID:schogini,项目名称:jVoiD,代码行数:18,代码来源:GenericHibernateDAO.java

示例12: countByExample

import org.hibernate.criterion.Example; //导入依赖的package包/类
/**
 * @Title: countByExample
 * @Description: 根据模型统计
 * @param @param entityBean
 * @param @return
 * @return int
 */
public <T> int countByExample(final T obj) {
	return (Integer) getHibernateTemplate().executeWithNativeSession(new HibernateCallback<Integer>() {
		public Integer doInHibernate(Session s) throws HibernateException, SQLException {
			// 组装属性
			Criteria criteria = s.createCriteria(obj.getClass()).setProjection(Projections.projectionList().add(Projections.rowCount()))
					.add(Example.create(obj));
			if (getHibernateTemplate().isCacheQueries()) {
				criteria.setCacheable(true);
				if (getHibernateTemplate().getQueryCacheRegion() != null)
					criteria.setCacheRegion(getHibernateTemplate().getQueryCacheRegion());
			}
			if (getHibernateTemplate().getFetchSize() > 0)
				criteria.setFetchSize(getHibernateTemplate().getFetchSize());
			if (getHibernateTemplate().getMaxResults() > 0)
				criteria.setMaxResults(getHibernateTemplate().getMaxResults());
			SessionFactoryUtils.applyTransactionTimeout(criteria, getSessionFactory());
			return (Integer) criteria.uniqueResult();
		}
	});
}
 
开发者ID:liuling07,项目名称:QiQuYingServer,代码行数:28,代码来源:BaseDAO.java

示例13: findByExample

import org.hibernate.criterion.Example; //导入依赖的package包/类
/**
 * Execute a query based on a given example entity object.
 * 
 * @param entityName the name of the persistent entity
 * @param exampleEntity an instance of the desired entity, serving as example for "query-by-example"
 * @param firstResult the index of the first result object to be retrieved (numbered from 0)
 * @param maxResults the maximum number of result objects to retrieve (or <=0 for no limit)
 * @return a {@link List} containing 0 or more persistent instances
 * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
 * @see org.hibernate.criterion.Example#create(Object)
 * @see org.hibernate.Criteria#setFirstResult(int)
 * @see org.hibernate.Criteria#setMaxResults(int)
 */
@SuppressWarnings("unchecked")
@Override
public List<Object> findByExample(final String entityName, final Object exampleEntity, final int firstResult, final int max) throws DataAccessException {
	Assert.notNull(exampleEntity, "Example entity must not be null");
	return executeWithNativeSession(session -> {
		Criteria executableCriteria = (entityName != null ? session.createCriteria(entityName) : session.createCriteria(exampleEntity.getClass()));
		executableCriteria.add(Example.create(exampleEntity));
		prepareCriteria(executableCriteria);
		if (firstResult >= 0) {
			executableCriteria.setFirstResult(firstResult);
		}
		if (max > 0) {
			executableCriteria.setMaxResults(max);
		}
		return executableCriteria.list();
	});
}
 
开发者ID:jurgendl,项目名称:hql-builder,代码行数:31,代码来源:HibernateTemplate.java

示例14: findByExampleHbn

import org.hibernate.criterion.Example; //导入依赖的package包/类
private List<ExerciseGroup> findByExampleHbn(ExerciseGroup instance, Session session) {
  log.debug("finding ExerciseGroup instance by example");
  try {
    if (session != null) {
      Criteria criteria = session.createCriteria("de.uniwue.info6.database.map.ExerciseGroup");
      criteria.add(Example.create(instance));
      if (instance.getScenario() != null) {
        criteria.createAlias("scenario", "sc")
        .add(Restrictions.eq("sc.id", instance.getScenario().getId()));
      }

      @SuppressWarnings("unchecked")
      List<ExerciseGroup> results = criteria.list();

      log.debug("find by example successful, result size: " + results.size());
      return results;
    }
    return null;
  } catch (RuntimeException re) {
    log.error("find by example failed", re);
    throw re;
  }
}
 
开发者ID:UniversityOfWuerzburg-ChairCompSciVI,项目名称:ueps,代码行数:24,代码来源:ExerciseGroupDao.java

示例15: findByExampleHbn

import org.hibernate.criterion.Example; //导入依赖的package包/类
private List<SolutionQuery> findByExampleHbn(SolutionQuery instance, Session session) {
	log.debug("finding SolutionQuery instance by example");
	try {
		Criteria criteria = session.createCriteria("de.uniwue.info6.database.map.SolutionQuery");
		criteria.add(Example.create(instance));
		if (instance.getExercise() != null) {
			criteria.createAlias("exercise", "e").add(Restrictions.eq("e.id", instance.getExercise().getId()));
		}

		@SuppressWarnings("unchecked")
		List<SolutionQuery> results = criteria.list();
		log.debug("find by example successful, result size: " + results.size());
		return results;
	} catch (RuntimeException re) {
		log.error("find by example failed", re);
		throw re;
	}
}
 
开发者ID:UniversityOfWuerzburg-ChairCompSciVI,项目名称:ueps,代码行数:19,代码来源:SolutionQueryDao.java


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