當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。