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


Java Session.createQuery方法代码示例

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


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

示例1: updateAppHistory4indeToIndexed

import org.hibernate.Session; //导入方法依赖的package包/类
/**
 * 更新 状态到数据库,仅针对 appStatus 为 1(add) 2(update) 更新索引 ,
 */
@Override
public int updateAppHistory4indeToIndexed(List<Integer> appIds) {
    String hql = "update AppHistory4Index set indexStatus=1,lastIndexTime=:lastIndexTime where (appStatus=1 or appStatus=2) and appId in (:appIds)";

    Session session = null;
    try {
        session = this.sessions.openSession();
        Query query = session.createQuery(hql);
        query.setParameterList("appIds", appIds);
        query.setTimestamp("lastIndexTime", new Date());

        return query.executeUpdate();
    } catch (Exception e) {
        logger.error("error:", e);
        return 0;
    } finally {
        if (session != null && session.isOpen()) {
            session.flush();
            session.clear();
            session.close();
        }
    }

}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:28,代码来源:AppHistory4IndexDaoImpl.java

示例2: deleteMark

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public int deleteMark(int user_id, int img_id) {
	Session session = HibernateUtils.getSession(); //生成session实例
    Transaction tx = session.beginTransaction();  //创建transaction实例 
    int temp = 0;
    try {  
    	String hql = "delete from Mark where user_id  = ? and img_id = ?"; 
    	Query query = session.createQuery(hql);
    	query.setInteger(0, user_id);
    	query.setInteger(1, img_id);
    	temp = query.executeUpdate(); 
    	tx.commit();            //提交事务  
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();   
	}finally {
	  HibernateUtils.closeSession();  //关闭Session实例
	} 
    return temp; 
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:21,代码来源:MarkService.java

示例3: getByIds

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public List<MarketApp> getByIds(Session session, List<Integer> ids) {
    StringBuilder queryString = new StringBuilder("from MarketApp where id in (:ids)");
    Query q = session.createQuery(queryString.toString());
    q.setParameterList("ids", ids);
    List<MarketApp> list = HibernateHelper.list(q);
    return list;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:9,代码来源:MarketAppDaoImpl.java

示例4: updateWeekDownload

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public int updateWeekDownload(Session session, int id) {
    String hql = "update App set LastWeekDelta =RealDownload - LastWeekDownload , LastWeekDownload = RealDownload where id = :id";
    Query query = session.createQuery(hql);
    query.setParameter("id", id);
    return query.executeUpdate();
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:8,代码来源:AppDaoImpl.java

示例5: deleteByMarketApps

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public int deleteByMarketApps(Session session, List<Integer> marketAppIds) {
    String hql = "delete App where marketAppId in (:marketAppIds)";
    Query query = session.createQuery(hql);
    query.setParameterList("marketAppIds", marketAppIds);
    return query.executeUpdate();
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:8,代码来源:AppDaoImpl.java

示例6: checkCredential

import org.hibernate.Session; //导入方法依赖的package包/类
/**
    * Checks whether a user can login to this workspace. The Credential must include the password.
    */
   @Override
   public boolean checkCredential(ICredentials credential, IWorkspace workspace) throws RepositoryRuntimeException {
if (log.isDebugEnabled()) {
    log.debug("Checking credential " + credential + " for workspace " + workspace);
}
if ((credential == null) || (workspace == null) || (workspace.getWorkspaceId() == null)) {
    return false;
}

Session hibernateSession = getSessionFactory().getCurrentSession();
Query query = hibernateSession.createQuery(CredentialDAO.CHECK_CREDENTIAL_WITH_WORKSPACE);
query.setString(0, credential.getName());
query.setString(1, String.valueOf(credential.getPassword()));
query.setLong(2, workspace.getWorkspaceId());

Long count = (Long) query.uniqueResult();
if (count > 2) {
    log.warn("More than one credential found for workspace " + workspace.getWorkspaceId() + " and credential "
	    + credential.getName());
}

return count > 0;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:CredentialDAO.java

示例7: addBorrower

import org.hibernate.Session; //导入方法依赖的package包/类
/**
 * Add Borrower
 */
public RestResponse addBorrower(Borrower borrower) {

	RestResponse response = new RestResponse();
	Session session = this.sessionFactory.openSession();
	Transaction transaction = (Transaction) session.beginTransaction();

	String queryString = "from Borrower where ssn=:ssn";
	Query query = session.createQuery(queryString);
	query.setString("ssn", borrower.getSsn());
	Object object = query.uniqueResult();

	if (object != null) {
		response.setError("Account already exists");
		response.setSuccess(false);

	} else {

		session.persist(borrower);
		transaction.commit();

		query = session.createQuery(queryString);
		query.setString("ssn", borrower.getSsn());
		object = query.uniqueResult();

		Borrower borrower2 = (Borrower) object;
		response.setSuccess(true);
		response.setResult(String.valueOf(borrower2.getCardId()));
	}

	session.close();

	return response;

}
 
开发者ID:axd164330,项目名称:Library,代码行数:38,代码来源:LibraryServicesImpl.java

示例8: updateDayDownload

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public int updateDayDownload(Session session, int id) {
    String hql = "update App set LastDayDelta =RealDownload - LastDayDownload , LastDayDownload = RealDownload where id = :id";
    Query query = session.createQuery(hql);
    query.setParameter("id", id);
    return query.executeUpdate();
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:8,代码来源:AppDaoImpl.java

示例9: countAppsOfDropMarket

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public long countAppsOfDropMarket(Session session, String marketName) {
    Query query = session.createQuery("select count(id) from App  where marketName = :marketName");
    query.setParameter("marketName", marketName);
    Object o = query.uniqueResult();
    return Long.valueOf(o.toString());
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:8,代码来源:AppDaoImpl.java

示例10: getStudyGuideComments

import org.hibernate.Session; //导入方法依赖的package包/类
/**
 * Gets the comments associated with a study guide
 * 
 * @param id for study guide
 * 
 * @return list of comments
 * 
 */
@Override
public List<CommentSG> getStudyGuideComments(int guideId) {
	List<CommentSG> comments = new ArrayList<>();
	Session session = HibernateUtil.getSession();
	Query query = null;
	StudyGuide sg = null;
	String hql = "FROM StudyGuide WHERE studyGuideId = :id";
	
	try {
		query = session.createQuery(hql);
		query.setParameter("id", guideId);
		
		sg = (StudyGuide)query.uniqueResult();
		
		comments = sg.getComments();
	}
	catch(HibernateException he) {
		he.printStackTrace();
	}
	
	if(comments.isEmpty()) {
		return null;
	}
	
	return comments;
}
 
开发者ID:grantleymorrison,项目名称:FlashBoard,代码行数:35,代码来源:StudyGuideDaoImpl.java

示例11: contains

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public boolean contains(String userKey) {
    if (userKey == null) {
        return false;
    }
    
    String hql = "SELECT COUNT(*) FROM KeyBean WHERE userKey = :userKey";
    
    Session session = sessionFactory.getCurrentSession();
    Query query = session.createQuery(hql);
    query.setString("userKey", userKey);
    
    return ((Long) query.uniqueResult()) > 0L;
}
 
开发者ID:by-syk,项目名称:SchTtableServer,代码行数:15,代码来源:KeyDaoImpl.java

示例12: findByHql

import org.hibernate.Session; //导入方法依赖的package包/类
public <T> List<T> findByHql(String hql, Object[] vals, int from_id, int len) {
	Session session = hibernateTemplate.getSessionFactory().openSession();
	org.hibernate.Transaction tx = session.beginTransaction(); 
	
	Query query = session.createQuery(hql);
	if(vals != null) {
		for(int i=0;i<vals.length;i++) {
			if(vals[i] instanceof Integer) {
				query.setInteger(i, (Integer)vals[i]);
			} else {
				query.setString(i, vals[i].toString());
			}
		}
	}
	
	if(len>0) {
		query.setFirstResult(from_id);
		query.setMaxResults(len);
	}
	
	try {
		tx.commit();
		return query.list();
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();
		return null;
	} finally {
		session.close(); 
	}
	
}
 
开发者ID:lrxzl,项目名称:djpt,代码行数:33,代码来源:DaoImpl.java

示例13: updateIncrementDownload

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public int updateIncrementDownload(Session session, int id, int delta) {
    String queryString = "update App set realDownload = realDownload + :delta , downloadrank = realDownload +deltaDownload where id = :id";
    Query q = session.createQuery(queryString);
    q.setParameter("id", id);
    q.setParameter("delta", delta);
    return q.executeUpdate();
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:9,代码来源:AppDaoImpl.java

示例14: isPlaceExists

import org.hibernate.Session; //导入方法依赖的package包/类
synchronized public static boolean isPlaceExists(String desc)
{
         int chk=0;
         sf=Logic.getSf();
         Session s = null;
         List<String> lst=new ArrayList<String> ();
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("select pl_id from Places pl where pl.pl_desc=:pldesc");
                qry.setParameter("pldesc", desc);
                lst=qry.getResultList();
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                          System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
            if(chk==0)
            {
                  if (lst.isEmpty())
                  {
                        return (false);
                  }
                  else
                  {
                       return (true);
                  }
            }
            else
            {
                 return (true);
            }
}
 
开发者ID:Tejas07PSK,项目名称:EBwn2_ForOpenShift,代码行数:44,代码来源:Validate.java

示例15: updateUserPhone

import org.hibernate.Session; //导入方法依赖的package包/类
synchronized public static boolean updateUserPhone(String ... vals)
{
         int chk=0;
         int nor=0;
         sf=Logic.getSf();
         Session s = null;
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("update UserDetails ud set ud.mob_no=:mobno where ud.usr_id=:uid");
                qry.setParameter("uid", vals[0]);
                qry.setParameter("mobno", vals[1]);
                nor=qry.executeUpdate();
                System.out.println("No. Of rows updated="+nor);
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                         System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
            if(chk==0)
            {
                 if(nor!=0)
                 {
                      return (true);
                 }
                 else
                 {
                      return (false);
                 }
            }
            else
            {
                 return (false);
            }
}
 
开发者ID:Tejas07PSK,项目名称:maven_EWorld_OpenShift,代码行数:46,代码来源:Update.java


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