List of usage examples for org.hibernate StatelessSession createCriteria
@Deprecated Criteria createCriteria(Class persistentClass);
From source file:org.openspaces.persistency.hibernate.StatelessHibernateExternalDataSource.java
License:Open Source License
protected boolean exists(BulkItem bulkItem, StatelessSession session) { Criteria criteria = null;//from www .jav a 2 s .c o m switch (bulkItem.getOperation()) { case BulkItem.REMOVE: case BulkItem.WRITE: case BulkItem.UPDATE: Object entry = bulkItem.getItem(); criteria = session.createCriteria(entry.getClass().getName()); ClassMetadata classMetaData = getSessionFactory().getClassMetadata(entry.getClass()); criteria.add(Restrictions.idEq(classMetaData.getIdentifier(entry))); criteria.setProjection(Projections.rowCount()); return ((Number) criteria.uniqueResult()).intValue() > 0; case BulkItem.PARTIAL_UPDATE: criteria = session.createCriteria(bulkItem.getTypeName()); criteria.add(Restrictions.idEq(bulkItem.getIdPropertyValue())); criteria.setProjection(Projections.rowCount()); return ((Number) criteria.uniqueResult()).intValue() > 0; default: return false; } }
From source file:org.openspaces.persistency.hibernate.StatelessHibernateSpaceSynchronizationEndpoint.java
License:Open Source License
private boolean exists(DataSyncOperation dataSyncOperation, StatelessSession session) { Criteria criteria = null;/*w ww. j a v a 2 s .c o m*/ switch (dataSyncOperation.getDataSyncOperationType()) { case REMOVE: case WRITE: case UPDATE: if (!dataSyncOperation.supportsDataAsObject()) return false; Object entry = dataSyncOperation.getDataAsObject(); criteria = session.createCriteria(entry.getClass().getName()); ClassMetadata classMetaData = getSessionFactory().getClassMetadata(entry.getClass()); criteria.add(Restrictions.idEq(classMetaData.getIdentifier(entry))); criteria.setProjection(Projections.rowCount()); return ((Number) criteria.uniqueResult()).intValue() > 0; case PARTIAL_UPDATE: if (!dataSyncOperation.supportsGetTypeDescriptor()) return false; SpaceTypeDescriptor typeDescriptor = dataSyncOperation.getTypeDescriptor(); criteria = session.createCriteria(typeDescriptor.getTypeName()); criteria.add(Restrictions.idEq(typeDescriptor.getIdPropertyName())); criteria.setProjection(Projections.rowCount()); return ((Number) criteria.uniqueResult()).intValue() > 0; default: return false; } }
From source file:vault.queryrouter.models.dao.JobQueueDAO.java
License:Apache License
public static int getProcessingQuery(StatelessSession session, int tenantMppdbId) { int counter = 0; Criteria criteria = session.createCriteria(TenantUpdateJob.class); criteria.add(Expression.eq("status", TenantUpdateJobStatus.Processing.toString())); criteria.add(Expression.or(Expression.eq("action", "tenant_mppdb_data_movement"), Expression.eq("action", "mppdb_copy"))); criteria.add(Expression.eq("tenantMppdbId", tenantMppdbId)); Iterator updateJobs = criteria.list().iterator(); if (updateJobs != null) { while (updateJobs.hasNext()) { updateJobs.next();//ww w . j av a2 s . c o m counter++; } } return counter; }
From source file:vault.queryrouter.models.dao.JobQueueDAO.java
License:Apache License
public static TenantUpdateJob getPendingQueryLock(StatelessSession session, String workerId) throws Exception { try {/* w w w . j a v a 2 s . c o 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.MPPDBDAO.java
License:Apache License
public static List<MPPDB> getMppdbs(StatelessSession session, int tenantMppdbGroupId) { //Find out the mmpdb_id which belongs to the current tenant group Criteria criteria = session.createCriteria(MPPDB.class); criteria.add(Expression.eq("tenantMppdbGroupId", tenantMppdbGroupId)); return (List<MPPDB>) criteria.list(); }
From source file:vault.queryrouter.models.dao.MPPDBDAO.java
License:Apache License
public static String getMppdbId(StatelessSession session, String mppdbIp) { String mppdbId = null;/*www . j av a 2 s . c o m*/ Criteria criteria = session.createCriteria(MPPDB.class); criteria.add(Expression.eq("mppdbIp", mppdbIp)); Iterator mppdbs = criteria.list().iterator(); while (mppdbs.hasNext()) { MPPDB mppdb = (MPPDB) mppdbs.next(); mppdbId = mppdb.getMppdbId(); } return mppdbId; }
From source file:vault.queryrouter.models.dao.QueryDAO.java
License:Apache License
public static Query getQuery(StatelessSession session, String queryId) throws Exception { Query query = null;// w w w . ja v a 2s . c o m try { Criteria criteria = session.createCriteria(Query.class); criteria.add(Expression.eq("queryId", queryId)); query = (Query) criteria.uniqueResult(); } catch (Exception e) { logger.error("Failed to get Query", e); throw e; } return query; }
From source file:vault.queryrouter.models.dao.QueryDAO.java
License:Apache License
public static int getProcessingQuerySum(StatelessSession session, String mppdbId) { try {//from w w w . j av a 2 s . c om int count = 0; //Find out the query log record where end_time is null Criteria criteria = session.createCriteria(Query.class); criteria.add(Expression.eq("queryStatus", QueryLogStatus.Processing.toString())); criteria.add(Expression.eq("mppdbId", mppdbId)); Iterator query = criteria.list().iterator(); while (query.hasNext()) { query.next(); count++; } return count; } catch (Exception e) { logger.error("Can't get the sum of processing query", e); throw e; } }
From source file:vault.queryrouter.models.dao.UserDAO.java
License:Apache License
public static User getUser(StatelessSession session, int tenantMppdbId, String userName, String password) throws InvalidTenantMPPDBUsernameAndPassword { try {/*from ww w . j a va 2 s . co m*/ Criteria criteria = session.createCriteria(User.class); criteria.add(Expression.eq("userName", userName)); criteria.add(Expression.eq("tenantMppdbId", tenantMppdbId)); criteria.add(Expression.eq("password", password)); List<User> users = criteria.list(); if (users.size() == 0) { throw new InvalidTenantMPPDBUsernameAndPassword(); } return users.get(0); } catch (Exception e) { logger.error("Fail to get User id", e); throw e; } }
From source file:vault.queryrouter.models.dao.UserDAO.java
License:Apache License
public static Iterator getUserList(StatelessSession session, int tenantMppdbId) { //Find out the mmpdb_id which belongs to the current tenant group Criteria criteria = session.createCriteria(User.class); criteria.add(Expression.eq("tenantMppdbId", tenantMppdbId)); Iterator users = criteria.list().iterator(); return users; }