public IList<ProcedureTypeGroup> Find(ProcedureTypeGroupSearchCriteria criteria, Type subClass, SearchResultPage page) { HqlQuery query = new HqlQuery(string.Format("from {0} x", subClass.Name)); query.Conditions.AddRange(HqlCondition.FromSearchCriteria("x", criteria)); query.Sorts.AddRange(HqlSort.FromSearchCriteria("x", criteria)); query.Page = page; return ExecuteHql<ProcedureTypeGroup>(query); }
public IList<WorkQueueItem> GetPendingItems(string type, int maxItems) { var query = new HqlQuery("from WorkQueueItem item"); query.Conditions.Add(new HqlCondition("item.Type = ?", type)); query.Conditions.Add(new HqlCondition("item.Status = ?", WorkQueueStatus.PN)); var now = Platform.Time; query.Conditions.Add(new HqlCondition("item.ScheduledTime < ?", now)); query.Conditions.Add(new HqlCondition("(item.ExpirationTime is null or item.ExpirationTime > ?)", now)); query.Sorts.Add(new HqlSort("item.ScheduledTime", true, 0)); query.Page = new SearchResultPage(0, maxItems); return ExecuteHql<WorkQueueItem>(query); }
public bool AssertUserHasToken(string userName, string token) { UserSearchCriteria whereUser = new UserSearchCriteria(); whereUser.UserName.EqualTo(userName); AuthorityTokenSearchCriteria whereToken = new AuthorityTokenSearchCriteria(); whereToken.Name.EqualTo(token); // want this to be as fast as possible - use joins and only select the count HqlQuery query = new HqlQuery("select count(*) from User u join u.AuthorityGroups g join g.AuthorityTokens t"); query.Conditions.AddRange(HqlCondition.FromSearchCriteria("u", whereUser)); query.Conditions.AddRange(HqlCondition.FromSearchCriteria("t", whereToken)); // expect exactly one integer result return ExecuteHqlUnique<long>(query) > 0; }
public string[] FindTokensByUserName(string userName) { UserSearchCriteria where = new UserSearchCriteria(); where.UserName.EqualTo(userName); // want this to be as fast as possible - use joins and only select the AuthorityToken names HqlQuery query = new HqlQuery("select distinct t.Name from User u join u.AuthorityGroups g join g.AuthorityTokens t"); query.Conditions.AddRange(HqlCondition.FromSearchCriteria("u", where)); // take advantage of query caching if possible query.Cacheable = true; IList<string> tokens = this.ExecuteHql<string>(query); string[] result = new string[tokens.Count]; tokens.CopyTo(result, 0); return result; }
public Guid[] FindDataGroupsByUserName(string userName) { UserSearchCriteria where = new UserSearchCriteria(); where.UserName.EqualTo(userName); AuthorityGroupSearchCriteria groupWhere = new AuthorityGroupSearchCriteria(); groupWhere.DataGroup.EqualTo(true); // want this to be as fast as possible - use joins and only select the AuthorityToken names HqlQuery query = new HqlQuery("select distinct g.OID from User u join u.AuthorityGroups g"); query.Conditions.AddRange(HqlCondition.FromSearchCriteria("u", where)); query.Conditions.AddRange(HqlCondition.FromSearchCriteria("g", groupWhere)); // take advantage of query caching if possible query.Cacheable = true; IList<Guid> oids = ExecuteHql<Guid>(query); var result = new Guid[oids.Count]; oids.CopyTo(result, 0); return result; }
protected int DoQueryCount(HqlQuery query) { return (int)ExecuteHqlUnique<long>(query); }
private static HqlQuery BuildQuery(DomainObject obj, Type entityClass, string[] uniqueConstraintMembers) { // get the id of the object being validated // if the object is unsaved, this id may be null var id = (obj is Entity) ? ((Entity) obj).OID : ((EnumValue) obj).Code; var query = new HqlQuery(string.Format("select count(*) from {0} x", entityClass.Name)); if (id != null) { // this object may have already been saved (i.e. this is an update) and therefore should be // excluded query.Conditions.Add(new HqlCondition("x.id <> ?", new [] { id })); } // add other conditions foreach (var propertyExpression in uniqueConstraintMembers) { var value = EvaluatePropertyExpression(obj, propertyExpression); if (value == null) query.Conditions.Add(new HqlCondition(string.Format("x.{0} is null", propertyExpression), new object[] { })); else query.Conditions.Add(new HqlCondition(string.Format("x.{0} = ?", propertyExpression), new [] { value })); } return query; }
public int GetUserCountForGroup(AuthorityGroup group) { var q = new HqlQuery("select count(elements(g.Users)) from AuthorityGroup g"); q.Conditions.Add(new HqlCondition("g = ?", group)); return (int)ExecuteHqlUnique<long>(q); }