本文整理汇总了Java中org.hibernate.Session.createCriteria方法的典型用法代码示例。如果您正苦于以下问题:Java Session.createCriteria方法的具体用法?Java Session.createCriteria怎么用?Java Session.createCriteria使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.Session
的用法示例。
在下文中一共展示了Session.createCriteria方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNewsInfoByConditionAndPage
import org.hibernate.Session; //导入方法依赖的package包/类
/**
* 根据条件查询指定新闻
*/
@Override
public List<?> getNewsInfoByConditionAndPage(NewsInfo condition, int page, int pageSize) {
Session session = SessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(NewsInfo.class);
if (condition != null) {
if (condition.getTopic() != null && condition.getTopic().getId() != null ) {
criteria.add(Restrictions.eq("topic.id", condition.getTopic().getId()));
}
if (condition.getTitle() != null && !"".equals(condition.getTitle())) {
criteria.add(Restrictions.like("title", condition.getTitle(), MatchMode.ANYWHERE));
}
}
criteria.setFirstResult(pageSize * (page - 1));
criteria.setMaxResults(pageSize);
criteria.addOrder(Order.desc("createDate"));
return criteria.list();
}
示例2: getByMarketApp
import org.hibernate.Session; //导入方法依赖的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;
}
示例3: getAllPromotees
import org.hibernate.Session; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<String> getAllPromotees(){
Session session = HibernateUtil.getSession();
List<String> promotees = new ArrayList<>();
Criteria criteria;
try {
criteria = session.createCriteria(User.class);
promotees = criteria.add(Restrictions.ge("avgScore", 70.0))
.add(Restrictions.like("approved", true))
.setProjection(Projections.property("username")).list();
}
catch(HibernateException he) {
he.printStackTrace();
}finally {
session.close();
}
if(promotees.isEmpty()) {
promotees = null;
}
return promotees;
}
示例4: getDepartmentsList
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public List<Department> getDepartmentsList() {
logger.info("Запрос к базе на чтение списка всех отделов");
List<Department> dhList;
Session session = getSession();
try{
Criteria crit = session.
createCriteria(Department.class);
dhList = crit.list();
}catch (HibernateException e){
logger.error(e.getStackTrace());
throw new MyRuntimeException(StuffExceptions.DATABASE_ERROR);
}
return dhList;
}
示例5: searchByTitle
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public Pager<Book> searchByTitle(String title, int pageNo, int pageSize) {
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(Book.class);
criteria.add(Restrictions.like("bookTitle", "%"+title+"%"));
long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue();
criteria.setProjection(null);
// criteria.addOrder(Order.desc("clickTimes"));
criteria.setFirstResult((pageNo - 1) * pageSize);
criteria.setMaxResults(pageSize);
List<Book> results = criteria.list();
System.out.println(results.size()+"-------数据多少");
Pager<Book> page=new Pager<Book>(pageSize, pageNo, recordTotal, results);
return page;
}
示例6: fetchProcessDefinition
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
protected InputStream fetchProcessDefinition(WorkflowLocation workflowLocation) throws WorkflowLoaderException {
String processDefinition = null;
Session session = null;
Transaction transaction = null;
if(sessionFactory == null)
throw new WorkflowLoaderException("'sessionFactory' has not been defined for HibernateLoader");
try {
session = sessionFactory.openSession();
transaction = session.beginTransaction();
Criteria criteria = session.createCriteria(HibernateProcessDescription.class);
criteria.add(Restrictions.eq("workflowName", workflowLocation.location));
HibernateProcessDescription hpd = (HibernateProcessDescription)criteria.uniqueResult();
if(hpd != null)
processDefinition = hpd.getContent();
transaction.commit();
} catch(HibernateException hibernateException) {
throw new WorkflowLoaderException(hibernateException);
} finally {
if (transaction != null && transaction.isActive())
transaction.rollback();
if (session != null)
session.close();
}
if(processDefinition == null)
throw new WorkflowLoaderException("Process definition '" + workflowLocation.location + "' not found");
return new ByteArrayInputStream(processDefinition.getBytes());
}
示例7: listForDownloads
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public List<App> listForDownloads(Session session, int currentPage, int pageSize) {
ProjectionList proList = Projections.projectionList();
proList.add(Projections.property("id"));
proList.add(Projections.property("pkname"));
proList.add(Projections.property("marketName"));
Criteria cri = session.createCriteria(App.class);
cri.setProjection(proList);
cri.setMaxResults(pageSize);
cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
// 先全部更新.
// cri.add(Restrictions.or(Restrictions.ltProperty("realDownload",
// "lastDayDownload"),
// Restrictions.ne("deltaDownload", 0)));
List<Object[]> list = HibernateHelper.list(cri);
List<App> apps = null;
if (list != null) {
apps = new ArrayList<App>(list.size());
for (Object[] obj : list) {
App e = new App();
e.setId((Integer) obj[0]);
e.setPkname((String) obj[1]);
e.setMarketName((String) obj[2]);
apps.add(e);
}
list.clear();
}
return apps;
}
示例8: getQuizComments
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public List<Comment> getQuizComments(int quizId) {
List<Comment> comments = new ArrayList<>();
Session session = HibernateUtil.getSession();
Criteria criteria = null;
Quiz q = null;
Query query = null;
StudyGuide sg = null;
String hql = "FROM StudyGuide WHERE studyGuideId = :id";
try {
criteria = session.createCriteria(Quiz.class);
q = (Quiz)criteria.add(Restrictions.like("quizId", quizId)).uniqueResult();
comments = q.getComments();
}
catch(HibernateException he) {
he.printStackTrace();
}
if(comments.isEmpty()) {
return null;
}
return comments;
}
示例9: get
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public MarketApp get(Session session, String marketName, String pkname) {
Criteria cri = session.createCriteria(MarketApp.class);
cri.add(Restrictions.eq("pkname", pkname));
cri.add(Restrictions.eq("marketName", marketName));
cri.setCacheable(false);
Object o = cri.uniqueResult();
if (o != null) {
return (MarketApp) o;
}
return null;
}
示例10: getOfficialSigSha1
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public String getOfficialSigSha1(Session session, String pkname) {
Projection officialSigSha1 = Projections.property("officialSigSha1");
Criteria cri = session.createCriteria(App.class);
cri.setProjection(officialSigSha1);
cri.add(Restrictions.eq("pkname", pkname));
cri.add(Restrictions.isNotNull("officialSigSha1"));
List<String> list = HibernateHelper.list(cri);
if (list != null && !list.isEmpty()) {
return list.get(0);
}
return null;
}
示例11: getByManyId
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public MarketApp getByManyId(Session sess, String marketName, Integer appIdOfMarket, int apkIdOfMarket) {
Criteria cri = sess.createCriteria(MarketApp.class);
if (appIdOfMarket != null && appIdOfMarket.intValue() > 0) {
cri.add(Restrictions.eq("appId", appIdOfMarket));
}
cri.add(Restrictions.eq("apkId", apkIdOfMarket));
cri.add(Restrictions.eq("marketName", marketName));
cri.setCacheable(false);
Object o = cri.uniqueResult();
if (o != null) {
return (MarketApp) o;
}
return null;
}
示例12: getAppByPackageName
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public App getAppByPackageName(Session sess, String pkname) {
Criteria cri = sess.createCriteria(App.class);
cri.add(Restrictions.eq("pkname", pkname));
Object o = cri.uniqueResult();
if (o != null) {
return (App) o;
}
return null;
}
示例13: listLogByUserPage
import org.hibernate.Session; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Pager<SysLog> listLogByUserPage(int userId, int pageNo, int pageSize) {
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(SysLog.class);
criteria.add(Restrictions.eq("user.id", userId));
long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue();
criteria.setProjection(null);
criteria.addOrder(Order.desc("time"));
criteria.setFirstResult((pageNo - 1) * pageSize);
criteria.setMaxResults(pageSize);
List<SysLog> results = criteria.list();
return new Pager<SysLog>(pageSize, pageNo, recordTotal, results);
}
示例14: listLogAllByPage
import org.hibernate.Session; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Pager<SysLog> listLogAllByPage(int pageNo, int pageSize) {
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(SysLog.class);
long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue();
criteria.setProjection(null);
criteria.addOrder(Order.desc("time"));
criteria.setFirstResult((pageNo - 1) * pageSize);
criteria.setMaxResults(pageSize);
List<SysLog> results = criteria.list();
return new Pager<SysLog>(pageSize, pageNo, recordTotal, results);
}
示例15: count
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public long count(Session session) {
Criteria cri = session.createCriteria(App.class);
cri.add(Restrictions.eq("hidden", false));
cri.setProjection(Projections.count("id"));
Object o = cri.uniqueResult();
return ((Long) o).longValue();
}