本文整理汇总了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();
}
}
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
示例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());
}
示例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;
}
示例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;
}
示例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();
}
}
示例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();
}
示例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);
}
}
示例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);
}
}