List of usage examples for org.hibernate StatelessSession update
void update(Object entity);
From source file:org.openspaces.persistency.hibernate.StatelessHibernateSpaceSynchronizationEndpoint.java
License:Open Source License
private void executeUpdate(StatelessSession session, DataSyncOperation dataSyncOperation) { if (!dataSyncOperation.supportsDataAsObject()) return;/*from w w w .ja v a 2s . c o m*/ Object entry = dataSyncOperation.getDataAsObject(); if (logger.isTraceEnabled()) { logger.trace("[Optimistic UPDATE] Update Entry [" + entry + "]"); } session.update(entry); }
From source file:vault.queryrouter.models.dao.JobQueueDAO.java
License:Apache License
public static TenantUpdateJob getPendingQueryLock(StatelessSession session, String workerId) throws Exception { try {// ww w. j a v a 2 s.co m session.getTransaction().begin(); //Update the pending query(order by last_touch_timestamp) status from pending to processing String hql = "UPDATE TenantUpdateJob set status= '" + TenantUpdateJobStatus.Processing.toString() + "', workerId = '" + workerId + "' WHERE status='" + TenantUpdateJobStatus.Pending.toString() + "' AND type ='" + TenantUpdateJobType.queryrouter.toString() + "' ORDER BY lastTouchTime LIMIT 1"; org.hibernate.Query query = session.createQuery(hql); int result = query.executeUpdate(); session.getTransaction().commit(); //Pending query exists and the status changes from "Pending" to "Processing" if (result != 0) { //Find the processing query by the thread(workerId) Criteria criteria = session.createCriteria(TenantUpdateJob.class); criteria.add(Expression.eq("workerId", workerId.toString())); criteria.add(Expression.eq("status", TenantUpdateJobStatus.Processing.toString())); TenantUpdateJob pendingQueueCandidate = (TenantUpdateJob) criteria.uniqueResult(); Query q = QueryDAO.getQuery(session, pendingQueueCandidate.getQueryId()); //Check the availability of the processing Query that could be actual processed //If the number of conflictQuery is more than 0 which means the processing query conflicts with the another processing query(e.g.move_tenant_mppdb_data) int conflictQuery = JobQueueDAO.getProcessingQuery(session, q.getTenantMppdbId()); //No conflict query -> Return the query(TenantUpdateJob Object) if (conflictQuery == 0) { return pendingQueueCandidate; } //Conflict query exists -> Status of the processing query turn back to "Pending" and the last_touch_timestamp will be updated else { try { session.getTransaction().begin(); TenantUpdateJob jq = (TenantUpdateJob) session.get(TenantUpdateJob.class, pendingQueueCandidate.getJobQueueId()); jq.setStatus(TenantUpdateJobStatus.Pending.toString()); jq.setWorkerId(""); session.update(jq); session.getTransaction().commit(); } catch (HibernateException e) { logger.error("Exception: ", e); if (session.getTransaction() != null) session.getTransaction().rollback(); e.printStackTrace(); } return null; } } //No pending query exists else { return null; } } catch (Exception e) { logger.error(e.toString()); throw e; } }
From source file:vault.queryrouter.models.dao.QueryDAO.java
License:Apache License
public static void updateQueryLog(StatelessSession session, String QuerylogID, Timestamp endTime, QueryLogStatus queryStatus) {//from w w w .jav a2 s .co m Query query = (Query) session.get(Query.class, QuerylogID); query.setEndTime(endTime); query.setQueryStatus(queryStatus.toString()); session.update(query); }
From source file:vault.queryrouter.models.dao.QueryDAO.java
License:Apache License
public static void updateQueryLogWithError(StatelessSession session, String QuerylogID, Timestamp endTime, String errorMessage) {/*w w w. j av a 2s.c om*/ Query query = (Query) session.get(Query.class, QuerylogID); query.setEndTime(endTime); query.setQueryStatus(QueryLogStatus.Failure.toString()); query.setErrorMessage(errorMessage); session.update(query); }
From source file:vn.edu.vnu.uet.fit.model.GenericModel.java
public void update(T entity) throws JDBCException, Exception { StatelessSession session = HibernateUtil.getSessionFactory().openStatelessSession(); Transaction trans = session.getTransaction(); try {//from w ww . j a va 2s . c om trans.begin(); session.update(entity); trans.commit(); } catch (JDBCException ex) { trans.rollback(); throw ex; } catch (Exception ex) { trans.rollback(); throw ex; } session.close(); }