List of usage examples for org.hibernate Criteria setReadOnly
public Criteria setReadOnly(boolean readOnly);
From source file:com.eucalyptus.objectstorage.metadata.DbObjectMetadataManagerImpl.java
License:Open Source License
@Override public PaginatedResult<ObjectEntity> listUploads(Bucket bucket, int maxUploads, String prefix, String delimiter, String keyMarker, String uploadIdMarker) throws Exception { try (TransactionResource trans = Entities.transactionFor(ObjectEntity.class)) { PaginatedResult<ObjectEntity> result = new PaginatedResult<ObjectEntity>(); HashSet<String> commonPrefixes = new HashSet<String>(); // Include zero since 'istruncated' is still valid if (maxUploads >= 0) { final int queryStrideSize = maxUploads + 1; ObjectEntity searchObj = new ObjectEntity(); searchObj.withBucket(bucket); //This doesn't actually filter, but do it anyway searchObj.withState(ObjectState.mpu_pending); Criteria objCriteria = Entities.createCriteria(ObjectEntity.class); objCriteria.setReadOnly(true); objCriteria.setFetchSize(queryStrideSize); objCriteria.add(Example.create(searchObj)); objCriteria.addOrder(Order.asc("objectKey")); objCriteria.setMaxResults(queryStrideSize); if (!Strings.isNullOrEmpty(keyMarker)) { objCriteria.add(Restrictions.gt("objectKey", keyMarker)); } else { keyMarker = ""; }/*from w ww. j a v a 2 s . c o m*/ if (!Strings.isNullOrEmpty(uploadIdMarker)) { objCriteria.add(Restrictions.gt("uploadId", uploadIdMarker)); } else { uploadIdMarker = ""; } if (!Strings.isNullOrEmpty(prefix)) { objCriteria.add(Restrictions.like("objectKey", prefix, MatchMode.START)); } else { prefix = ""; } //Be sure to add the bucket restriction last objCriteria = getSearchByBucket(objCriteria, bucket); // Ensure not null. if (Strings.isNullOrEmpty(delimiter)) { delimiter = ""; } List<ObjectEntity> objectInfos = null; int resultKeyCount = 0; String[] parts = null; String prefixString = null; boolean useDelimiter = !Strings.isNullOrEmpty(delimiter); int pages = 0; // Iterate over result sets of size maxkeys + 1 since // commonPrefixes collapse the list, we may examine many more // records than maxkeys + 1 do { parts = null; prefixString = null; // Skip ahead the next page of 'queryStrideSize' results. objCriteria.setFirstResult(pages++ * queryStrideSize); objectInfos = (List<ObjectEntity>) objCriteria.list(); if (objectInfos == null) { // nothing to do. break; } for (ObjectEntity objectRecord : objectInfos) { if (useDelimiter) { // Check if it will get aggregated as a commonprefix parts = objectRecord.getObjectKey().substring(prefix.length()).split(delimiter); if (parts.length > 1) { prefixString = prefix + parts[0] + delimiter; if (!prefixString.equals(keyMarker) && !commonPrefixes.contains(prefixString)) { if (resultKeyCount == maxUploads) { // This is a new record, so we know // we're truncating if this is true result.setIsTruncated(true); resultKeyCount++; break; } else { // Add it to the common prefix set commonPrefixes.add(prefixString); result.setLastEntry(prefixString); // count the unique commonprefix as a // single return entry resultKeyCount++; } } else { // Already have this prefix, so skip } continue; } } if (resultKeyCount == maxUploads) { // This is a new (non-commonprefix) record, so // we know we're truncating result.setIsTruncated(true); resultKeyCount++; break; } result.getEntityList().add(objectRecord); result.setLastEntry(objectRecord); resultKeyCount++; } if (resultKeyCount <= maxUploads && objectInfos.size() <= maxUploads) { break; } } while (resultKeyCount <= maxUploads); // Sort the prefixes from the hashtable and add to the reply if (commonPrefixes != null) { result.getCommonPrefixes().addAll(commonPrefixes); Collections.sort(result.getCommonPrefixes()); } } else { throw new IllegalArgumentException("max uploads must be positive integer"); } return result; } catch (Exception e) { LOG.error("Error generating paginated multipart upload list for bucket " + bucket.getBucketName(), e); throw e; } }
From source file:com.eucalyptus.objectstorage.metadata.DbObjectMetadataManagerImpl.java
License:Open Source License
@Override public List<ObjectEntity> lookupObjectVersions(Bucket bucket, String objectKey, int numResults) throws Exception { ObjectEntity searchObj = new ObjectEntity().withBucket(bucket).withState(ObjectState.extant) .withKey(objectKey);//from ww w . j av a2s. c o m List<ObjectEntity> objectInfos = null; try (TransactionResource tran = Entities.transactionFor(ObjectEntity.class)) { Criteria objCriteria = Entities.createCriteria(ObjectEntity.class); objCriteria.setMaxResults(numResults); objCriteria.setReadOnly(true); objCriteria.add(Example.create(searchObj)); objCriteria.addOrder(Order.desc("objectModifiedTimestamp")); objCriteria = getSearchByBucket(objCriteria, bucket); objectInfos = objCriteria.list(); tran.commit(); } catch (Exception ex) { LOG.warn("exception caught while retrieving all versions of object " + objectKey + " in bucket " + bucket.getBucketName()); throw ex; } return objectInfos; }
From source file:com.eucalyptus.objectstorage.metadata.DbObjectMetadataManagerImpl.java
License:Open Source License
@Override public PaginatedResult<ObjectEntity> listVersionsPaginated(final Bucket bucket, int maxEntries, String prefix, String delimiter, String fromKeyMarker, String fromVersionId, boolean latestOnly) throws Exception { EntityTransaction db = Entities.get(ObjectEntity.class); try {/*from w w w .j av a 2 s . c o m*/ PaginatedResult<ObjectEntity> result = new PaginatedResult<ObjectEntity>(); HashSet<String> commonPrefixes = new HashSet<String>(); // Include zero since 'istruncated' is still valid if (maxEntries >= 0) { final int queryStrideSize = maxEntries + 1; ObjectEntity searchObj = new ObjectEntity().withBucket(bucket).withState(ObjectState.extant); // Return latest version, so exclude delete markers as well. // This makes listVersion act like listObjects if (latestOnly) { searchObj.setIsLatest(true); searchObj.setIsDeleteMarker(false); } Criteria objCriteria = Entities.createCriteria(ObjectEntity.class); objCriteria.setReadOnly(true); objCriteria.setFetchSize(queryStrideSize); objCriteria.add(Example.create(searchObj)); objCriteria.addOrder(Order.asc("objectKey")); objCriteria.addOrder(Order.desc("objectModifiedTimestamp")); objCriteria.setMaxResults(queryStrideSize); if (!Strings.isNullOrEmpty(fromKeyMarker)) { if (!Strings.isNullOrEmpty(fromVersionId)) { // Look for the key that matches the key-marker and version-id-marker ObjectEntity searchObject = new ObjectEntity(bucket, fromKeyMarker, fromVersionId); ObjectEntity matchingObject = null; try { matchingObject = Entities.uniqueResult(searchObject); if (matchingObject == null || matchingObject.getObjectModifiedTimestamp() == null) { throw new NoSuchKeyException(bucket.getBucketName() + "/" + fromKeyMarker + "?versionId=" + fromVersionId); } } catch (Exception e) { LOG.warn("No matching object found for key-marker=" + fromKeyMarker + " and version-id-marker=" + fromVersionId); throw new NoSuchKeyException( bucket.getBucketName() + "/" + fromKeyMarker + "?versionId=" + fromVersionId); } // The result set should be exclusive of the key with the key-marker version-id-marker pair. Look for keys that chronologically // follow the version-id-marker for the given key-marker and also the keys that follow the key-marker. objCriteria.add(Restrictions.or( Restrictions.and(Restrictions.eq("objectKey", fromKeyMarker), Restrictions.lt("objectModifiedTimestamp", matchingObject.getObjectModifiedTimestamp())), Restrictions.gt("objectKey", fromKeyMarker))); } else { // No version-id-marker, just set the criteria the key-marker objCriteria.add(Restrictions.gt("objectKey", fromKeyMarker)); } } else { // No criteria to be set } if (!Strings.isNullOrEmpty(prefix)) { objCriteria.add(Restrictions.like("objectKey", prefix, MatchMode.START)); } else { prefix = ""; } objCriteria = getSearchByBucket(objCriteria, bucket); // Ensure not null. if (Strings.isNullOrEmpty(delimiter)) { delimiter = ""; } List<ObjectEntity> objectInfos = null; int resultKeyCount = 0; String[] parts = null; String prefixString = null; boolean useDelimiter = !Strings.isNullOrEmpty(delimiter); int pages = 0; // Iterate over result sets of size maxkeys + 1 since // commonPrefixes collapse the list, we may examine many more // records than maxkeys + 1 do { parts = null; prefixString = null; // Skip ahead the next page of 'queryStrideSize' results. objCriteria.setFirstResult(pages++ * queryStrideSize); objectInfos = (List<ObjectEntity>) objCriteria.list(); if (objectInfos == null) { // nothing to do. break; } for (ObjectEntity objectRecord : objectInfos) { if (useDelimiter) { // Check if it will get aggregated as a commonprefix parts = objectRecord.getObjectKey().substring(prefix.length()).split(delimiter); if (parts.length > 1) { prefixString = prefix + parts[0] + delimiter; if (!prefixString.equals(fromKeyMarker) && !commonPrefixes.contains(prefixString)) { if (resultKeyCount == maxEntries) { // This is a new record, so we know // we're truncating if this is true result.setIsTruncated(true); resultKeyCount++; break; } else { // Add it to the common prefix set commonPrefixes.add(prefixString); result.setLastEntry(prefixString); // count the unique commonprefix as a // single return entry resultKeyCount++; } } else { // Already have this prefix, so skip } continue; } } if (resultKeyCount == maxEntries) { // This is a new (non-commonprefix) record, so // we know we're truncating result.setIsTruncated(true); resultKeyCount++; break; } result.getEntityList().add(objectRecord); result.setLastEntry(objectRecord); resultKeyCount++; } if (resultKeyCount <= maxEntries && objectInfos.size() <= maxEntries) { break; } } while (resultKeyCount <= maxEntries); // Sort the prefixes from the hashtable and add to the reply if (commonPrefixes != null) { result.getCommonPrefixes().addAll(commonPrefixes); Collections.sort(result.getCommonPrefixes()); } } else { throw new IllegalArgumentException("MaxKeys must be positive integer"); } return result; } catch (Exception e) { LOG.error("Error generating paginated object list of bucket " + bucket.getBucketName(), e); throw e; } finally { db.rollback(); } }
From source file:com.eucalyptus.objectstorage.metadata.DbObjectMetadataManagerImpl.java
License:Open Source License
@Override public long countValid(Bucket bucket) throws Exception { try (TransactionResource trans = Entities.transactionFor(ObjectEntity.class)) { /*Criteria queryCriteria = Entities.createCriteria(ObjectEntity.class); queryCriteria.add(Restrictions.eq("state", ObjectState.extant)) .createCriteria("bucket").add(Restrictions.eq("naturalId", bucket.getNaturalId()))*/ Criteria queryCriteria = Entities.createCriteria(ObjectEntity.class) .add(Restrictions.eq("state", ObjectState.extant)).setProjection(Projections.rowCount()); queryCriteria = getSearchByBucket(queryCriteria, bucket); queryCriteria.setReadOnly(true); final Number count = (Number) queryCriteria.uniqueResult(); trans.commit();/*from w ww .j a v a 2 s .c o m*/ return count.longValue(); } catch (Throwable e) { LOG.error("Error getting object count for bucket " + bucket.getBucketName(), e); throw new Exception(e); } }
From source file:com.eucalyptus.objectstorage.metadata.DbObjectMetadataManagerImpl.java
License:Open Source License
@Override public long getTotalSize(Bucket bucket) throws Exception { try (TransactionResource trans = Entities.transactionFor(ObjectEntity.class)) { Criteria queryCriteria = Entities.createCriteria(ObjectEntity.class) .add(Restrictions.or(Restrictions.eq("state", ObjectState.creating), Restrictions.eq("state", ObjectState.extant))) .setProjection(Projections.sum("size")); if (bucket != null) { queryCriteria = getSearchByBucket(queryCriteria, bucket); }// w ww.j ava 2s . com queryCriteria.setReadOnly(true); final Number count = (Number) queryCriteria.uniqueResult(); return count == null ? 0 : count.longValue(); } catch (Throwable e) { LOG.error("Error getting object total size for " + (bucket == null ? "all buckets" : "bucket " + bucket.getBucketName()), e); throw new Exception(e); } }
From source file:com.eucalyptus.objectstorage.WalrusManager.java
License:Open Source License
private boolean bucketHasSnapshots(String bucketName) throws Exception { EntityWrapper<WalrusSnapshotInfo> dbSnap = null; try {//from w w w. ja v a2s. com dbSnap = EntityWrapper.get(WalrusSnapshotInfo.class); WalrusSnapshotInfo walrusSnapInfo = new WalrusSnapshotInfo(); walrusSnapInfo.setSnapshotBucket(bucketName); Criteria snapCount = dbSnap.createCriteria(WalrusSnapshotInfo.class).add(Example.create(walrusSnapInfo)) .setProjection(Projections.rowCount()); snapCount.setReadOnly(true); Long rowCount = (Long) snapCount.uniqueResult(); dbSnap.rollback(); if (rowCount != null && rowCount.longValue() > 0) { return true; } return false; } catch (Exception e) { if (dbSnap != null) { dbSnap.rollback(); } throw e; } }
From source file:com.eucalyptus.walrus.WalrusFSManager.java
License:Open Source License
private String getMultipartData(ObjectInfo objectInfo, GetObjectType request, GetObjectResponseType response) throws WalrusException { //get all parts PartInfo searchPart = new PartInfo(request.getBucket(), request.getKey()); searchPart.setCleanup(false);//from ww w.ja v a 2s . c o m searchPart.setUploadId(objectInfo.getUploadId()); List<PartInfo> parts; EntityTransaction db = Entities.get(PartInfo.class); try { Criteria partCriteria = Entities.createCriteria(PartInfo.class); partCriteria.setReadOnly(true); partCriteria.add(Example.create(searchPart)); partCriteria.add(Restrictions.isNotNull("partNumber")); partCriteria.addOrder(Order.asc("partNumber")); parts = partCriteria.list(); if (parts.size() == 0) { throw new InternalErrorException( "No parts found corresponding to uploadId: " + objectInfo.getUploadId()); } } finally { db.rollback(); } if (request.getInlineData()) { if ((objectInfo.getSize() * 4) > WalrusProperties.MAX_INLINE_DATA_SIZE) { throw new InlineDataTooLargeException(request.getBucket() + "/" + request.getKey()); } String base64Data = ""; for (PartInfo part : parts) { byte[] bytes = new byte[102400]; int bytesRead = 0, offset = 0; try { FileIO fileIO = storageManager.prepareForRead(part.getBucketName(), part.getObjectName()); while ((bytesRead = fileIO.read(offset)) > 0) { ByteBuffer buffer = fileIO.getBuffer(); if (buffer != null) { buffer.get(bytes, 0, bytesRead); base64Data += new String(bytes, 0, bytesRead); offset += bytesRead; } } fileIO.finish(); } catch (Exception e) { LOG.error(e, e); throw new InternalErrorException(e); } } return Hashes.base64encode(base64Data); } else { response.setHasStreamingData(true); // support for large objects storageManager.getMultipartObject(response, parts, request.getIsCompressed()); return null; } }
From source file:com.jubination.model.dao.CallAPIMessageDAOImpl.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = true) public Long fetchEntitySize(String fromDate, String toDate, String type) { System.out.println("*******com.jubination.model.dao.CallAPIMessageDAOImpl.fetchEntitySize()"); Long size = 0l;/*from w ww.j a va 2s . c o m*/ switch (type) { case "Total": System.out.println("*****Case - Total"); session = getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "Busy": System.out.println("*****Case - Busy"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("Status", "busy", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "Failed": System.out.println("*****Case - Failed"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("Status", "failed", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "NoAnswer": System.out.println("*****Case - NoAnswer"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("Status", "no-answer", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "RequestedCallBack": System.out.println("*****Case - RequestedCallBack"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("TrackStatus", "requested for callback", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "GreetingsHangUp": System.out.println("*****Case - GreetingsHangUp"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("CallType", "trans", MatchMode.ANYWHERE)); criteria.add(Restrictions.like("Status", "completed", MatchMode.ANYWHERE)); criteria.add(Restrictions.isNull("TrackStatus")); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "HangUpOnConnect": System.out.println("*****Case - HangUpOnConnect"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("TrackStatus", "did not speak", MatchMode.ANYWHERE)); criteria.add(Restrictions.like("CallType", "client-hangup", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "MissCall": System.out.println("*****Case - MissCall"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("TrackStatus", "did not speak", MatchMode.ANYWHERE)); criteria.add(Restrictions.like("CallType", "incomplete", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "Spoke": System.out.println("*****Case - Spoke"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("TrackStatus", "spoke", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; } return size; }
From source file:com.jubination.model.dao.CallAPIMessageDAOImpl.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = true) public Long fetchEntitySize(String date, String type) { System.out.println("*******com.jubination.model.dao.CallAPIMessageDAOImpl.fetchEntitySize()"); Long size = 0l;//from w ww . j a v a 2s. c om switch (type) { case "Total": System.out.println("*****Case - Total"); session = getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "Busy": System.out.println("*****Case - Busy"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("Status", "busy", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "Failed": System.out.println("*****Case - Failed"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("Status", "failed", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "NoAnswer": System.out.println("*****Case - NoAnswer"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("Status", "no-answer", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "RequestedCallBack": System.out.println("*****Case - RequestedCallBack"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("TrackStatus", "requested for callback", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "GreetingsHangUp": System.out.println("*****Case - GreetingsHangUp"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("CallType", "trans", MatchMode.ANYWHERE)); criteria.add(Restrictions.like("Status", "completed", MatchMode.ANYWHERE)); criteria.add(Restrictions.isNull("TrackStatus")); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "HangUpOnConnect": System.out.println("*****Case - HangUpOnConnect"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("TrackStatus", "did not speak", MatchMode.ANYWHERE)); criteria.add(Restrictions.like("CallType", "client-hangup", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "MissCall": System.out.println("*****Case - MissCall"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("TrackStatus", "did not speak", MatchMode.ANYWHERE)); criteria.add(Restrictions.like("CallType", "incomplete", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "Spoke": System.out.println("*****Case - Spoke"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("TrackStatus", "spoke", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; } return size; }
From source file:com.zapangtrainer.model.dao.ClientDAOImpl.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = true) public Object readInnerProperty(String type, String paramId, String calType) { String average = null;/* www . ja v a 2 s.c o m*/ List<Reply> list = null; switch (type) { case "rating": session = getSessionFactory().openSession(); Criteria criteria = session.createCriteria(Reply.class, "reply"); criteria.createAlias("reply.client", "client"); criteria.setReadOnly(true); Calendar cal = Calendar.getInstance(); String date0 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.DATE, -1); String date1 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.DATE, -1); String date2 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.DATE, -1); String date3 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.DATE, -1); String date4 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.DATE, -1); String date5 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.DATE, -1); String date6 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); criteria.add(Restrictions.or(Restrictions.eq("client.date", date0), Restrictions.or(Restrictions.eq("client.date", date1), Restrictions.or(Restrictions.eq("client.date", date2), Restrictions.or(Restrictions.eq("client.date", date3), Restrictions.or(Restrictions.eq("client.date", date4), Restrictions.or( Restrictions.eq("client.date", date5), Restrictions.or(Restrictions.eq("client.date", date6))))))))); criteria.add(Restrictions.eq("reply.question", paramId)); criteria.add(Restrictions.eq("reply.type", type)); criteria.add(Restrictions.ne("reply.answer", "0")); criteria.setResultTransformer(criteria.DISTINCT_ROOT_ENTITY); list = (List<Reply>) criteria.list(); Float value = 0.0f; for (Reply val : list) { if (val.getAnswer() != null && !val.getAnswer().equals("")) { value += Float.parseFloat(val.getAnswer()); } } value /= list.size(); average = value.toString(); case "descriptive": case "options": case "binary": default: } return average; }