Java Code Examples for org.hibernate.Query#executeUpdate()

The following examples show how to use org.hibernate.Query#executeUpdate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimingDAO.java    From pikatimer with GNU General Public License v3.0 7 votes vote down vote up
public void createDefaultTimingLocations() {
    
    blockingClearAll();
    
    Session s=HibernateUtil.getSessionFactory().getCurrentSession();
    s.beginTransaction();
    // sql to set the name and date
    Query query = s.createSQLQuery("INSERT into TIMING_LOCATION (TIMING_LOCATION_ID, TIMING_LOCATION_NAME) values (:id, :name)");
    query.setParameter("id", 1);
    query.setParameter("name", "Start");
    query.executeUpdate();
    query.setParameter("id", 2);
    query.setParameter("name", "Finish");
    query.executeUpdate();            
    s.getTransaction().commit();
    
    // Thread.dumpStack(); // who called this?
    refreshTimingLocationList();
}
 
Example 2
Source File: LockTokenDAO.java    From document-management-system with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Remove
 */
public static void delete(String user, String token) throws DatabaseException {
	log.debug("delete({}, {})", user, token);
	String qs = "delete from LockToken lt where lt.user=:user and lt.token=:token";
	Session session = null;
	Transaction tx = null;

	try {
		session = HibernateUtil.getSessionFactory().openSession();
		tx = session.beginTransaction();
		Query q = session.createQuery(qs);
		q.setString("user", user);
		q.setString("token", token);
		q.executeUpdate();
		HibernateUtil.commit(tx);
	} catch (HibernateException e) {
		HibernateUtil.rollback(tx);
		throw new DatabaseException(e.getMessage(), e);
	} finally {
		HibernateUtil.close(session);
	}

	log.debug("delete: void");
}
 
Example 3
Source File: DBQueryUtil.java    From kardio with Apache License 2.0 6 votes vote down vote up
/**
 * Update the k8s_pods_containers table with number of Pods&Containers
 * @param envId
 * @param compName
 * @param numOfPods
 * @param parentCompName
 * @param numOfCont
 */
public static void updatePodsAndContainers(final int envId, String compName, int numOfPods, String parentCompName, int numOfCont){
	final java.sql.Date todayDate = new java.sql.Date(Calendar.getInstance().getTimeInMillis());;
	final int compId = getComponentId(compName, parentCompName);
	if(compId == 0){
		logger.info("Component Name = " + compName + "; Parent Component Name = " + parentCompName + "; is not available in the DB");
		return;
	}
	Session session = HibernateConfig.getSessionFactory().getCurrentSession();
	Transaction txn = session.beginTransaction();
	Query query = session.createQuery(HQLConstants.UPDATE_K8S_PODS_CONT_DETAILS);
	query.setInteger("totalPods", numOfPods);
	query.setInteger("totalContainers", numOfCont);
	query.setLong("compId", compId);
	query.setLong("environmentId", envId);
	query.setDate("stsDate", todayDate);
	query.executeUpdate();
	txn.commit();
}
 
Example 4
Source File: SignInfoDAO.java    From CoolSignIn with Apache License 2.0 6 votes vote down vote up
public boolean updateSingle(int id,String signDetail, int signTimes, String lastSignPhoto){
	Session session = getSession();
	session.beginTransaction();
	String hqlString="update SignInfo  set signDetail=:signDetail , signTimes=:signTimes , lastSignPhoto=:lastSignPhoto where signID=:id";
	Query query = session.createQuery(hqlString);
	query.setString("signDetail", signDetail);
	query.setInteger("signTimes", signTimes);
	query.setString("lastSignPhoto", lastSignPhoto);
	query.setInteger("id", id);
	try {
		query.executeUpdate();
		session.getTransaction().commit();
		return true;
	} catch (Exception e) {
		log.debug("update signInfo fail!! ");
		e.printStackTrace();
		return false;
	}
	
}
 
Example 5
Source File: DBQueryUtil.java    From kardio with Apache License 2.0 5 votes vote down vote up
/**
 * Update the tps_service table with latest tps values. 
 * 
 */
public static void updateTpsService(final int envId, int componentId, float tpsVaule, float latencyValue){
	Session session = HibernateConfig.getSessionFactory().getCurrentSession();
	Transaction txn = session.beginTransaction();
	Query query = session.createQuery(HQLConstants.UPDATE_TPS_SERVICE_DETAILS);
	query.setFloat("tpsVaule", tpsVaule);
	query.setFloat("latencyValue", latencyValue);
	query.setTimestamp("lastUpdateDate", new java.sql.Timestamp(System.currentTimeMillis()));
	query.setLong("compId", componentId);
	query.setLong("environmentId", envId);
	query.executeUpdate();
	txn.commit();
}
 
Example 6
Source File: HostDao.java    From yeti with MIT License 5 votes vote down vote up
public void deleteHost(String hostName, int footprintId) {
    String hql = "delete from Host where name = :hostName and footprint.id = :footprintId";
    Query query = HibernateUtil.getSession().createQuery(hql);
    query.setParameter("hostName", hostName);
    query.setParameter("footprintId", footprintId);
    query.executeUpdate();
}
 
Example 7
Source File: NotificationEventDao.java    From olat with Apache License 2.0 5 votes vote down vote up
@Retryable
@Transactional(propagation = Propagation.REQUIRES_NEW)
public int updateEventsByIds(Set<Long> ids, NotificationEvent.Status status) {
    Query query = genericDao.getNamedQuery(NotificationEvent.UPDATE_EVENT_STATUS_BY_IDS);
    query.setParameterList(NotificationEvent.IDS_PARAM, ids);
    query.setParameter(NotificationEvent.EVENT_STATUS_PARAM, status);
    return query.executeUpdate();
}
 
Example 8
Source File: AssessmentGradingFacadeQueries.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public boolean markMediaForConversion(final List<Long> mediaIds) {
    final HibernateCallback<Integer> hcb = session -> {
        Query q = session.createQuery("UPDATE MediaData SET location = 'CONVERTING' WHERE id in (:ids)");
        q.setParameterList("ids", mediaIds);
        return q.executeUpdate();
    };
    return getHibernateTemplate().execute(hcb).equals(mediaIds.size());
}
 
Example 9
Source File: MessageBundleServiceImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Transactional
public int revertAll(final String locale) {
   Query query = sessionFactory.getCurrentSession().createQuery("update MessageBundleProperty set value = null where locale = :locale");
   query.setString("locale", locale);

    try {
        return query.executeUpdate();
    } catch (Exception e) {
        log.warn("Cound not revert all MessageBundleProperty's " + e.getMessage(), e);
        return 0;
    }
}
 
Example 10
Source File: ChatManagerImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Resets the passed context's default channel
 *
 */
protected void resetPlacementDefaultChannel(String context, String placement) {
    Session session = null;

    try {
        session = getSessionFactory().getCurrentSession();
        Query query = session.createSQLQuery("update CHAT2_CHANNEL c set c.placementDefaultChannel = :channel, c.PLACEMENT_ID = NULL WHERE c.context = :context and c.PLACEMENT_ID = :placement");
        query.setBoolean("channel", false);
        query.setString("context", context);
        query.setString("placement", placement);
        query.executeUpdate();
    } catch(Exception e) {
        log.warn(e.getMessage());
    }
}
 
Example 11
Source File: TestDb.java    From megatron-java with Apache License 2.0 5 votes vote down vote up
private static void truncateAllTables() {
    Query q = session.createSQLQuery("truncate ip_range");
    q.executeUpdate();
    q = session.createSQLQuery("truncate ip_range");
    q.executeUpdate();
    q = session.createSQLQuery("truncate additional_item");
    q.executeUpdate();
    q = session.createSQLQuery("truncate asn");
    q.executeUpdate();
    q = session.createSQLQuery("truncate domain_name");
    q.executeUpdate();
    q = session.createSQLQuery("truncate entry_type");
    q.executeUpdate();
    q = session.createSQLQuery("truncate free_text");
    q.executeUpdate();
    q = session.createSQLQuery("truncate ip_range");
    q.executeUpdate();
    q = session.createSQLQuery("truncate job");
    q.executeUpdate();
    q = session.createSQLQuery("truncate job_type");
    q.executeUpdate();
    q = session.createSQLQuery("truncate log_entry");
    q.executeUpdate();
    q = session.createSQLQuery("truncate mail_job");
    q.executeUpdate();
    q = session.createSQLQuery("truncate mail_job_log_entry_mapping");
    q.executeUpdate();
    q = session.createSQLQuery("truncate organization");
    q.executeUpdate();
    q = session.createSQLQuery("truncate original_log_entry");
    q.executeUpdate();
    q = session.createSQLQuery("truncate prio");
    q.executeUpdate();
}
 
Example 12
Source File: AssessmentGradingFacadeQueries.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public boolean markMediaForConversion(final List<Long> mediaIds) {
    final HibernateCallback<Integer> hcb = session -> {
        Query q = session.createQuery("UPDATE MediaData SET location = 'CONVERTING' WHERE id in (:ids)");
        q.setParameterList("ids", mediaIds);
        return q.executeUpdate();
    };
    return getHibernateTemplate().execute(hcb).equals(mediaIds.size());
}
 
Example 13
Source File: ContentCountDaoImpl.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public int freshCacheToDB(Ehcache cache) {
	List<Integer> keys = cache.getKeys();
	if (keys.size() <= 0) {
		return 0;
	}
	Element e;
	Integer views;
	int i = 0;
	String hql = "update ContentCount bean"
			+ " set bean.views=bean.views+:views"
			+ ",bean.viewsMonth=bean.viewsMonth+:views"
			+ ",bean.viewsWeek=bean.viewsWeek+:views"
			+ ",bean.viewsDay=bean.viewsDay+:views" + " where bean.id=:id";
	Query query = getSession().createQuery(hql);
	for (Integer id : keys) {
		e = cache.get(id);
		if (e != null) {
			views = (Integer) e.getValue();
			if (views != null) {
				query.setParameter("views", views);
				query.setParameter("id", id);
				i += query.executeUpdate();
			}
		}
	}
	return i;
}
 
Example 14
Source File: LowFunctionalityDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Erase low functionality.
 *
 * @param aLowFunctionality
 *            the a low functionality
 * @param profile
 *            the profile
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.analiticalmodel.functionalitytree.dao.ILowFunctionalityDAO#eraseLowFunctionality(it.eng.spagobi.analiticalmodel.functionalitytree.bo.LowFunctionality,
 *      it.eng.spago.security.IEngUserProfile)
 */
@Override
public void eraseLowFunctionality(LowFunctionality aLowFunctionality, IEngUserProfile profile) throws EMFUserError {
	logger.debug("IN");
	Session aSession = null;
	Transaction tx = null;
	try {
		if (hasChild(aLowFunctionality.getId())) {
			HashMap params = new HashMap();
			params.put(PAGE, "BIObjectsPage");
			// params.put(SpagoBIConstants.ACTOR,
			// SpagoBIConstants.ADMIN_ACTOR);
			params.put(SpagoBIConstants.OPERATION, SpagoBIConstants.FUNCTIONALITIES_OPERATION);
			throw new EMFUserError(EMFErrorSeverity.ERROR, 1000, new Vector(), params);
		}
		aSession = getSession();
		tx = aSession.beginTransaction();
		SbiFunctions hibFunct = (SbiFunctions) aSession.load(SbiFunctions.class, aLowFunctionality.getId());
		Set oldRoles = hibFunct.getSbiFuncRoles();
		Iterator iterOldRoles = oldRoles.iterator();
		while (iterOldRoles.hasNext()) {
			SbiFuncRole role = (SbiFuncRole) iterOldRoles.next();
			aSession.delete(role);
		}

		// update prog column in other functions
		// String hqlUpdateProg =
		// "update SbiFunctions s set s.prog = (s.prog - 1) where s.prog > "
		// + hibFunct.getProg() + " and s.parentFunct.functId = " +
		// hibFunct.getParentFunct().getFunctId();
		if (hibFunct.getParentFunct() != null) {
			String hqlUpdateProg = "update SbiFunctions s set s.prog = (s.prog - 1) where s.prog > ? " + " and s.parentFunct.functId = ?";
			Query query = aSession.createQuery(hqlUpdateProg);
			query.setInteger(0, hibFunct.getProg().intValue());
			query.setInteger(1, hibFunct.getParentFunct().getFunctId().intValue());
			query.executeUpdate();
		}

		aSession.delete(hibFunct);

		tx.commit();
	} catch (HibernateException he) {
		logger.error("HibernateException", he);

		if (tx != null)
			tx.rollback();

		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);

	} catch (EMFUserError emfue) {
		if (tx != null)
			tx.rollback();
		throw emfue;
	} catch (Exception e) {
		logException(e);
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		if (aSession != null)
			if (aSession != null) {
				if (aSession.isOpen()) {
					aSession.close();
					logger.debug("The [eraseLowFunctionality] occurs. LowFunctionality cache will be cleaned.");
					this.clearCache();
				}
				logger.debug("OUT");
			}
	}
}
 
Example 15
Source File: LecturerCourseDao.java    From olat with Apache License 2.0 4 votes vote down vote up
public void deleteByLecturerIds(List<Long> lecturerIds) {
    Query query = genericDao.getNamedQuery(LecturerCourse.DELETE_LECTURERS_BY_LECTURER_IDS);
    query.setParameterList("lecturerIds", lecturerIds);
    query.executeUpdate();
}
 
Example 16
Source File: CourseDao.java    From olat with Apache License 2.0 4 votes vote down vote up
public void disableSynchronization(Long courseId) {
    Query query = genericDao.getNamedQuery(Course.DISABLE_SYNCHRONIZATION);
    query.setParameter("courseId", courseId);
    query.executeUpdate();
}
 
Example 17
Source File: BaseDaoImpl.java    From SpringCloud with Apache License 2.0 4 votes vote down vote up
public void UpdateByHql(String hql, Object[] args) {
    Query query = getSession().createQuery(hql);
    setParameter(query, args);
    query.executeUpdate();
}
 
Example 18
Source File: CourseDao.java    From olat with Apache License 2.0 4 votes vote down vote up
public void deleteResourceableId(Long resourceableId) {
    Query query = genericDao.getNamedQuery(Course.DELETE_RESOURCEABLE_ID);
    query.setParameter("resId", resourceableId);
    query.executeUpdate();
}
 
Example 19
Source File: GenericBaseCommonDao.java    From jeecg with Apache License 2.0 2 votes vote down vote up
/**
 * 通过sql更新记录
 *
 * @param <T>
 * @param query
 * @return
 */
public int updateBySqlString(final String query) {

	Query querys = getSession().createSQLQuery(query);
	return querys.executeUpdate();
}
 
Example 20
Source File: GenericBaseCommonDao.java    From jeecg with Apache License 2.0 2 votes vote down vote up
/**
 * 执行HQL语句操作更新
 *
 * @param hql
 * @return
 */
public Integer executeHql(String hql) {
	Query q = getSession().createQuery(hql);
	return q.executeUpdate();
}