Java Code Examples for org.hibernate.Query.setInteger()

The following are Jave code examples for showing how to use setInteger() of the org.hibernate.Query class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ImageClassify   File: ConstantService.java   View Source Code Vote up 8 votes
@Override
public boolean updateValueOfKey(Constant constant) { 
		Session session = HibernateUtils.getSession();
		 Transaction tx = session.beginTransaction();
		 boolean isUpdate = false;
		 try {
			Query query = session.createQuery("update Constant c set c.value =? where c.id = ?");  
		    query.setString(0,constant.getValue());
		    query.setInteger(1, constant.getId()); 
			int temp = query.executeUpdate();  
			tx.commit();
			if (temp>0) {
				isUpdate = true;
			}
		} catch (Exception e) {
			 e.printStackTrace();
			 tx.rollback();
		}finally {
			HibernateUtils.closeSession();
		}   
		 return isUpdate;
}
 
Example 2
Project: sjk   File: AppHistory4IndexDaoImpl.java   View Source Code Vote up 6 votes
@Override
public int updateAppStatus2Del(Integer id) {
    Session session = null;

    try {
        session = this.sessions.openSession();
        //
        String hql = "update AppHistory4Index set appStatus=3,indexStatus=-1,lastOpTime=:lastOpTime where appId =:appId";
        Query query = session.createQuery(hql);
        query.setInteger("appId", id);
        query.setTimestamp("lastOpTime", 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();
        }
    }
}
 
Example 3
Project: ImageClassify   File: MarkService.java   View Source Code Vote up 6 votes
@Override
public boolean updateMark(Mark mark) {
	Session session = HibernateUtils.getSession();
	 Transaction tx = session.beginTransaction();
	 try {
		Query query = session.createQuery("update Mark m set m.mark_accuracy =? where m.user_id = ? and m.img_id = ?");  
	    query.setString(0, mark.getMark_accuracy());
	    query.setInteger(1, mark.getUser_id());
	    query.setInteger(2, mark.getImg_id()); 
		query.executeUpdate();  
		tx.commit();
		return true;
	} catch (Exception e) {
		 e.printStackTrace();
		 tx.rollback();
		 return false;
	}finally {
		HibernateUtils.closeSession();
	} 
}
 
Example 4
Project: ImageClassify   File: UserService.java   View Source Code Vote up 6 votes
@Override
public boolean updateAccuracy(User user) {
	Session session = HibernateUtils.getSession();
	 Transaction tx = session.beginTransaction();
	 try {
		Query query = session.createQuery("update User u set u.accuracy =? where u.user_id = ?");  
	    query.setString(0, user.getAccuracy());
	    query.setInteger(1, user.getUser_id()); 
		query.executeUpdate();  
		tx.commit();
		return true;
	} catch (Exception e) {
		 e.printStackTrace();
		 tx.rollback();
		 return false;
	}finally {
		HibernateUtils.closeSession();
	}  
}
 
Example 5
Project: ImageClassify   File: InterestService.java   View Source Code Vote up 6 votes
@Override
public int deleteInterests(int user_id) {  
			Session session = HibernateUtils.getSession(); //生成session实例
		    Transaction tx = session.beginTransaction();  //创建transaction实例 
		    int temp = 0;
		    try {  
		    	String hql = "delete from Interest where user_id  =  ?"; 
		    	Query query = session.createQuery(hql);
		    	query.setInteger(0, user_id);  
		    	temp = query.executeUpdate(); 
		    	tx.commit();            //提交事务  
			} catch (Exception e) {
				e.printStackTrace();
				tx.rollback();   
			}finally {
			  HibernateUtils.closeSession();  //关闭Session实例
			} 
		    return temp;
}
 
Example 6
Project: ImageClassify   File: InterestService.java   View Source Code Vote up 6 votes
@Override
public int deleteInterest(int user_id, int category_id) {
	Session session = HibernateUtils.getSession(); //生成session实例
    Transaction tx = session.beginTransaction();  //创建transaction实例 
    int temp = 0;
    try {  
    	String hql = "delete from Interest where user_id  = ? and category_id = ?"; 
    	Query query = session.createQuery(hql);
    	query.setInteger(0, user_id);  
    	query.setInteger(1, category_id);
    	temp = query.executeUpdate(); 
    	tx.commit();            //提交事务  
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();   
	}finally {
	  HibernateUtils.closeSession();  //关闭Session实例
	} 
    return temp;
}
 
Example 7
Project: sjk   File: MarketAppDaoImpl.java   View Source Code Vote up 6 votes
@Override
public int deleteByPK(Session sess, int id) {
    Query query = sess.createQuery("delete from MarketApp where id=:id");
    query.setInteger("id", id);
    int rows = query.executeUpdate();
    return rows;
}
 
Example 8
Project: sjk   File: AppDaoImpl.java   View Source Code Vote up 5 votes
@Override
public int deleteByMarketApp(Session sess, int foreignKey) {
    Query query = sess.createQuery("delete from App where marketAppId=:marketAppId");
    query.setInteger("marketAppId", foreignKey);
    int rows = query.executeUpdate();
    return rows;
}
 
Example 9
Project: sjk   File: MonUserChannelAppDaoImpl.java   View Source Code Vote up 5 votes
@Override
public MonUserChannelApp getChannelApp(String marketName, Integer apkId) {
    Query query = getSession().createQuery(
            "from MonUserChannelApp m where  m.apkId=:apkId  and m.marketName=:marketName ");
    query.setString("marketName", marketName);
    query.setInteger("apkId", apkId);
    List<MonUserChannelApp> list = HibernateHelper.list(query);
    if (list == null || list.size() == 0) {
        return null;
    } else {
        return list.get(0);
    }
}
 
Example 10
Project: sdudoc   File: LogDaoImpl.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
@Override
public List<SysLog> listLogByUserId(int userId) {
	String sql = "from SysLog where user.id=:userId";
	Session session = sessionFactory.getCurrentSession();
	Query query = session.createQuery(sql);
	query.setInteger("userId", userId);
	List<SysLog> sysLogs = query.list();
	return sysLogs;
}
 
Example 11
Project: lams   File: OrganisationDAO.java   View Source Code Vote up 5 votes
@Override
   public int getCountCoursesByParentCourseAndTypeAndState(Integer parentOrgId, Integer typeId, Integer stateId,
    String searchString) {
Query query = getSession().createQuery(OrganisationDAO.GET_COUNT_COURSES_BY_PARENT_TYPE_STATE);
query.setInteger("parentOrgId", parentOrgId);
query.setInteger("typeId", typeId);
query.setInteger("stateId", stateId);
// support for custom search from a toolbar
searchString = searchString == null ? "" : searchString;
query.setString("searchString", searchString);

return ((Number) query.uniqueResult()).intValue();
   }
 
Example 12
Project: sdudoc   File: CollectDaoImpl.java   View Source Code Vote up 5 votes
@Override
public Collect getCollectByBook$User(int bookId, int userId) {
	String sql = "from Collect where bookId=:bookId and userId=:userId";
	Session session = sessionFactory.getCurrentSession();
	Query query = session.createQuery(sql);
	query.setInteger("bookId", bookId);
	query.setInteger("userId", userId);
	List<Collect> collects = query.list();
	if(collects.size() == 0)
		return null;
	return collects.get(0);
}
 
Example 13
Project: lams   File: OrganisationDAO.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
   @Override
   public List<Organisation> getPagedCourses(Integer parentOrgId, Integer typeId, Integer stateId, int page, int size,
    String sortBy, String sortOrder, String searchString) {
String sortByParam = "o.name";
switch (sortBy) {
    case "id":
	sortByParam = "o.organisationId";
	break;
    case "name":
	sortByParam = "o.name";
	break;
    case "code":
	sortByParam = "o.code";
	break;
    case "description":
	sortByParam = "o.createDate";
	break;
}

Query query = getSession().createQuery(OrganisationDAO.GET_PAGED_COURSES + sortByParam + " " + sortOrder);
query.setInteger("typeId", typeId);
query.setInteger("stateId", stateId);
query.setInteger("parentOrgId", parentOrgId);
// support for custom search from a toolbar
searchString = searchString == null ? "" : searchString;
query.setString("searchString", searchString);
query.setFirstResult(page * size);
query.setMaxResults(size);
return query.list();
   }
 
Example 14
Project: sjk   File: SysDictionaryDaoImpl.java   View Source Code Vote up 5 votes
@Override
public int updateDicValue(Integer id, Integer intValue) {
    String hql = "update SysDictionary set IntValue =:intValue where id =:id";
    Query query = getSession().createQuery(hql);
    query.setInteger("intValue", intValue);
    query.setInteger("id", id);
    return query.executeUpdate();
}
 
Example 15
Project: sjk   File: MetroDaoImpl.java   View Source Code Vote up 5 votes
@Override
public int delete(int id) {
    Query query = getSession().createQuery("delete from Metro where id=:id");
    query.setInteger("id", id);
    int rows = query.executeUpdate();
    return rows;
}
 
Example 16
Project: lams   File: LessonDAO.java   View Source Code Vote up 5 votes
/**
    * @see org.lamsfoundation.lams.lesson.dao.ILessonDAO#getLessonsByOrgAndUserWithCompletedFlag(Integer, Integer,
    *      boolean)
    */
   @Override
   public List getLessonsByGroupAndUser(Integer userId, Integer orgId) {
Query query = getSession().getNamedQuery("lessonsByOrgAndUserWithChildOrgs");
query.setInteger("userId", userId.intValue());
query.setInteger("orgId", orgId.intValue());
List result = query.list();
return result;
   }
 
Example 17
Project: sjk   File: MoFeaturedDaoImpl.java   View Source Code Vote up 5 votes
@Override
public int delete(int id) {
    Query query = getSession().createQuery("delete from MoFeatured where id=:id");
    query.setInteger("id", id);
    int rows = query.executeUpdate();
    return rows;
}
 
Example 18
Project: djpt   File: DaoImpl.java   View Source Code Vote up 5 votes
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(); 
	}
	
}
 
Example 19
Project: sjk   File: AppDaoImpl.java   View Source Code Vote up 5 votes
@Override
public int updateAudit(List<Integer> ids, int status) {
    String hql = "update App set status =:status where id in (:ids)";
    Query query = getSession().createQuery(hql);
    query.setParameterList("ids", ids);
    query.setInteger("status", status);
    return query.executeUpdate();
}
 
Example 20
Project: sjk   File: MarketAppDaoImpl.java   View Source Code Vote up 5 votes
@Override
public int deleteByPK(Session sess, int id) {
    Query query = sess.createQuery("delete from MarketApp where id=:id");
    query.setInteger("id", id);
    int rows = query.executeUpdate();
    return rows;
}