public int getNonPlacedStudentCount() { Utility.logFile(Constant.METHOD_ENTER + Utility.getCurrentMethodName(1) + "(StatisticsManagerImpl)", null, Constant.LOGTYPE_INFO); DetachedCriteria subCriteria = DetachedCriteria.For <Entity_PlacementDetails>("placedObj"); subCriteria.Add(Restrictions.EqProperty("placedObj.studentId", "student.studentId")); subCriteria.SetProjection(Projections.Distinct(Projections.Property("placedObj.studentId"))); DetachedCriteria mainCriteria = DetachedCriteria.For <Entity_Student>("student"); mainCriteria.SetProjection(Projections.Count(Projections.Distinct(Projections.Property("student.studentId")))); mainCriteria.Add(Subqueries.NotExists(subCriteria)); mainCriteria.Add(Restrictions.Eq("student.myConfigObj.currentBatch", Common.loggedUser.myConfigObj.currentBatch)); mainCriteria.Add(Restrictions.Eq("student.myConfigObj.currentDegree", Common.loggedUser.myConfigObj.currentDegree)); IList list = persistence.findByCriteria(mainCriteria); if (list != null && list.Count > 0) { return(Convert.ToInt32(list[0])); } else { return(0); } }
public List <Entity_Staff> getUnusedUsersList() { Utility.logFile(Constant.METHOD_ENTER + Utility.getCurrentMethodName(1) + "(StaffManagerImpl)", null, Constant.LOGTYPE_INFO); DetachedCriteria mainCriteria = DetachedCriteria.For <Entity_Staff>("staff"); DetachedCriteria subCriteria1 = DetachedCriteria.For <Entity_Notification>("notificationObj"); subCriteria1.Add(Restrictions.EqProperty("notificationObj.staffId", "staff.staffId")); subCriteria1.SetProjection(Projections.Distinct(Projections.Property("notificationObj.staffId"))); DetachedCriteria subCriteria2 = DetachedCriteria.For <Entity_UserNotification>("userNotificationObj"); subCriteria2.Add(Restrictions.EqProperty("userNotificationObj.staffId", "staff.staffId")); subCriteria2.SetProjection(Projections.Distinct(Projections.Property("userNotificationObj.staffId"))); mainCriteria.Add(Subqueries.NotExists(subCriteria1)); mainCriteria.Add(Subqueries.NotExists(subCriteria2)); mainCriteria.Add(Restrictions.Gt("staffId", Convert.ToInt64(Common.adminId))); IList list = persistence.findByCriteria(mainCriteria); if (list != null && list.Count > 0) { return(list.Cast <Entity_Staff>().ToList()); } else { return(null); } }
public int getNotificationCount() { Utility.logFile(Constant.METHOD_ENTER + Utility.getCurrentMethodName(1) + "(NotificationManagerImpl)", null, Constant.LOGTYPE_INFO); DetachedCriteria mainCriteria = DetachedCriteria.For <Entity_Notification>("notification"); mainCriteria.Add(Restrictions.Eq("notification.myConfigObj.currentBatch", Common.loggedUser.myConfigObj.currentBatch)); mainCriteria.Add(Restrictions.Eq("notification.myConfigObj.currentDegree", Common.loggedUser.myConfigObj.currentDegree)); mainCriteria.SetProjection(Projections.Count("notification.notificationId")); DetachedCriteria subCriteria = DetachedCriteria.For <Entity_UserNotification>("userNotification"); subCriteria.Add(Restrictions.EqProperty("userNotification.notificationId", "notification.notificationId")); subCriteria.Add(Restrictions.Eq("userNotification.staffId", Common.loggedUser.staffId)); subCriteria.SetProjection(Projections.Distinct(Projections.Property("userNotification.notificationId"))); mainCriteria.Add(Subqueries.NotExists(subCriteria)); IList list = persistence.findByCriteria(mainCriteria); if (list != null && list.Count > 0) { return(Convert.ToInt32(list[0])); } else { return(0); } }
/// <summary> /// Compiles this <see cref="IsExpression" /> into a <see cref="ICriterion" /> instance. /// </summary> /// <param name="subquery"> /// The subquery to filter. /// </param> /// <returns> /// The compiled <see cref="ICriterion" /> instance. /// </returns> public virtual ICriterion Compile(DetachedCriteria subquery) { if (Negated) { return(Subqueries.Exists(subquery)); } return(Subqueries.NotExists(subquery)); }
public IList <Photo> ListOrphaned() { return(Registry.Session.CreateCriteria <Photo>("photo") .Add(Subqueries.NotExists( DetachedCriteria.For <PhotoReferenceBase>("reference") .SetProjection(Projections.Id()) .Add(Property.ForName("reference.Photo.Id").EqProperty("photo.Id")) )).List <Photo>()); }
public void UntypedSubqueriesCriterion() { ICriteria expected = CreateTestCriteria(typeof(Person)) .Add(Subqueries.Exists(DetachedCriteriaChild)) .Add(Subqueries.NotExists(DetachedCriteriaChild)); var actual = CreateTestQueryOver <Person>() .And(Subqueries.WhereExists(DetachedQueryOverChild)) .And(Subqueries.WhereNotExists(DetachedQueryOverChild)); AssertCriteriaAreEqual(expected, actual); }
public IDictionary <string, IList <Entity_Student> > filteredStudentList(MyCriteria notifyCriteria) { Utility.logFile(Constant.METHOD_ENTER + Utility.getCurrentMethodName(1) + "(NotificationManagerImpl)", null, Constant.LOGTYPE_INFO); DetachedCriteria mainCriteria = DetachedCriteria.For <Entity_Student>("student"); mainCriteria.CreateAlias("scoreObj", "score"); Conjunction conjunction = Restrictions.Conjunction(); conjunction.Add(Restrictions.Eq("student.myConfigObj.currentBatch", notifyCriteria.batch)); conjunction.Add(Restrictions.Eq("student.myConfigObj.currentDegree", notifyCriteria.degree)); conjunction.Add(Restrictions.Ge("score.X", notifyCriteria.X)); conjunction.Add(Restrictions.Ge("score.cgpa", notifyCriteria.cgpa)); conjunction.Add(Restrictions.Le("score.arrears", notifyCriteria.arrears)); conjunction.Add(Restrictions.In("student.branch", notifyCriteria.branch)); if (notifyCriteria.isDiplomaAllowed) { Disjunction disjunction = Restrictions.Disjunction(); disjunction.Add(Restrictions.Ge("score.XII", notifyCriteria.XII)); disjunction.Add(Restrictions.Ge("score. ", notifyCriteria.XII)); conjunction.Add(disjunction); } else { conjunction.Add(Restrictions.Ge("score.XII", notifyCriteria.XII)); } mainCriteria.Add(conjunction); if (!notifyCriteria.isPlaced) { DetachedCriteria subCriteria = DetachedCriteria.For <Entity_PlacementDetails>("placedObj"); subCriteria.Add(Restrictions.EqProperty("placedObj.studentId", "student.studentId")); subCriteria.SetProjection(Projections.Distinct(Projections.Property("placedObj.studentId"))); mainCriteria.Add(Subqueries.NotExists(subCriteria)); } IList list = persistence.findByCriteria(mainCriteria); if (list != null && list.Count > 0) { IDictionary <string, IList <Entity_Student> > eligibleStudentMap = prepareStudentList(list.Cast <Entity_Student>().ToList()); return(eligibleStudentMap); } else { return(null); } }
public List <StudentPlacedDto> getNonPlacedStudentsBySearchKey(string searchKey) { Utility.logFile(Constant.METHOD_ENTER + Utility.getCurrentMethodName(1) + "(StudentPlacedManagerImpl)", null, Constant.LOGTYPE_INFO); DetachedCriteria mainCriteria = DetachedCriteria.For <Entity_Student>("student"); mainCriteria.Add(Restrictions.Eq("student.myConfigObj.currentBatch", Common.loggedUser.myConfigObj.currentBatch)); mainCriteria.Add(Restrictions.Eq("student.myConfigObj.currentDegree", Common.loggedUser.myConfigObj.currentDegree)); DetachedCriteria subCriteria = DetachedCriteria.For <Entity_PlacementDetails>("placedObj"); subCriteria.Add(Restrictions.EqProperty("placedObj.studentId", "student.studentId")); subCriteria.SetProjection(Projections.Distinct(Projections.Property("placedObj.studentId"))); mainCriteria.Add(Subqueries.NotExists(subCriteria)); Disjunction disjunction = Restrictions.Disjunction(); disjunction.Add(Restrictions.InsensitiveLike("student.collegeId", searchKey, MatchMode.Exact)); mainCriteria.Add(disjunction); ProjectionList projectionsList = Projections.ProjectionList(); projectionsList.Add(Projections.Property("student.collegeId"), "collegeId"); projectionsList.Add(Projections.Property("student.studentName"), "name"); projectionsList.Add(Projections.Property("student.gender"), "gender"); projectionsList.Add(Projections.Property("student.branch"), "branch"); projectionsList.Add(Projections.Property("student.myConfigObj.currentDegree"), "degree"); projectionsList.Add(Projections.Property("student.phone"), "contact"); mainCriteria.SetProjection(projectionsList); mainCriteria.AddOrder(Order.Asc("student.collegeId")); mainCriteria.SetResultTransformer(new AliasToBeanResultTransformer(typeof(StudentPlacedDto))); IList list = persistence.findByCriteria(mainCriteria); if (list != null && list.Count > 0) { return(list.Cast <StudentPlacedDto>().ToList()); } else { return(null); } }
public IEnumerable <CommandEnvelope> Dequeue(int maxCount) { using (var session = _sessionFactory.OpenSession()) { CommandRecord aliasCommandRecord = null; CommandProcessingResultRecord aliasCommandProcessing = null; var processedCommands = QueryOver.Of(() => aliasCommandProcessing) .Where(() => aliasCommandProcessing.Sequence == aliasCommandRecord.Sequence) .Select(x => x.Sequence) .DetachedCriteria; return(session.QueryOver(() => aliasCommandRecord) .Where(Subqueries.NotExists(processedCommands)) .Take(maxCount) .List <CommandRecord>() .Select(x => new CommandEnvelope(x.Sequence, (Command)x.DeserializePayload())) .ToList()); } }
private ICriterion CreateAnyOrAllCriterion(CollectionMethod method, ResolvedMemberExpression resolvedMember, LambdaExpression lambdaExpression) { Require.That(method.MethodType == MethodType.Any || method.MethodType == MethodType.All, "Invalid method type", "method"); // Resolved member's name may contain multiple dots if it's inside a component (i.e. 'root.Component.Collection') int p = resolvedMember.Member.IndexOf('.'); if (p == -1) { throw new ODataException(string.Format("Member '{0}' must have an alias.", resolvedMember.Member)); } var collectionHolderAliasName = resolvedMember.Member.Substring(0, p); var collectionMemberName = resolvedMember.Member.Substring(p + 1); Alias collectionHolderAlias; _context.AliasesByName.TryGetValue(collectionHolderAliasName, out collectionHolderAlias); if (collectionHolderAlias == null) { throw new ODataException(string.Format("Unknown alias '{0}'.", collectionHolderAliasName)); } var subCriteriaAlias = _context.CreateUniqueAliasName(); var detachedCriteria = DetachedCriteria.For(collectionHolderAlias.ReturnedType, subCriteriaAlias); MappedClassMetadata metadata; _context.SessionFactoryContext.MappedClassMetadata.TryGetValue(collectionHolderAlias.ReturnedType, out metadata); if (metadata == null) { throw new ODataException(string.Format("The type '{0}' isn't a NHibernate-mapped class.", collectionHolderAlias.ReturnedType.FullName)); } if (metadata.IdentifierPropertyName == null) { throw new ODataException(string.Format("The type '{0}' doesn't have an identifier property.", collectionHolderAlias.ReturnedType.FullName)); } detachedCriteria.Add(Restrictions.EqProperty( subCriteriaAlias + "." + metadata.IdentifierPropertyName, collectionHolderAliasName + "." + metadata.IdentifierPropertyName )); var lambdaAlias = _context.CreateUniqueAliasName(); System.Type itemType; if (resolvedMember.ReturnedType == null || (itemType = TypeUtil.TryGetCollectionItemType(resolvedMember.ReturnedType)) == null) { throw new ODataException("Cannot get collection item type"); } _context.AddAlias(new Alias(lambdaAlias, string.Empty, itemType)); // The inner joined alias to collection items must be created in any case (whether the lambda expression is specified or not) detachedCriteria.CreateAlias(subCriteriaAlias + "." + collectionMemberName, lambdaAlias, JoinType.InnerJoin); detachedCriteria.SetProjection(Projections.Constant(1)); if (lambdaExpression != null) { if (method.MethodType == MethodType.All) { lambdaExpression = (LambdaExpression)InverseVisitor.Invert(lambdaExpression); } _context.PushLambdaContext(lambdaExpression.ParameterName, itemType, lambdaAlias); try { var lambdaNormalizeVisitor = new AliasingNormalizeVisitor( _context, collectionHolderAlias.ReturnedType, collectionHolderAliasName ); var bodyExpression = lambdaExpression.Body.Visit(lambdaNormalizeVisitor); var criterion = bodyExpression.Visit(new CriterionVisitor(_context)); if (criterion != null) { detachedCriteria.Add(criterion); foreach (var alias in lambdaNormalizeVisitor.Aliases.Values) { detachedCriteria.CreateAlias(alias.AssociationPath, alias.Name, JoinType.LeftOuterJoin); } } } finally { _context.PopLambdaContext(); } } if (method.MethodType == MethodType.Any) { return(Subqueries.Exists(detachedCriteria)); } else { return(Subqueries.NotExists(detachedCriteria)); } }
public void SubqueriesExpressions() { DetachedCriteria dc = DetachedCriteria.For(typeof(Student)) .Add(Expression.Eq("Name", "Gavin King")); ICriterion c = Subqueries.Eq("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.EqAll("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.Exists(dc); NHAssert.IsSerializable(c); c = Subqueries.Ge("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.GeAll("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.GeSome("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.Gt("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.GtAll("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.GtSome("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.In("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.Le("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.LeAll("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.LeSome("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.Lt("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.LtAll("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.LtSome("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.Ne("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.NotExists(dc); NHAssert.IsSerializable(c); c = Subqueries.NotIn("Gavin King", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyEq("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyEqAll("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyGe("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyGeAll("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyGeSome("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyGt("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyGtAll("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyGtSome("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyIn("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyLe("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyLeAll("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyLeSome("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyLt("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyLtAll("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyLtSome("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyNe("Name", dc); NHAssert.IsSerializable(c); c = Subqueries.PropertyNotIn("Name", dc); NHAssert.IsSerializable(c); }
/// <summary> /// Add a NotExists subquery criterion /// </summary> public TReturn WhereNotExists <U>(QueryOver <U> detachedQuery) { root.And(Subqueries.NotExists(detachedQuery.DetachedCriteria)); return(root); }