/// <summary> /// Query the registration system for records /// </summary> public VersionedDomainIdentifier[] QueryRecord(IComponent queryParameters) { if (m_disposed) { throw new ObjectDisposedException("DatabasePersistenceService"); } // TODO: Store consent policy override if applicable List <VersionedDomainIdentifier> retVal = new List <VersionedDomainIdentifier>(30); ISystemConfigurationService configService = this.Context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService; // Get the subject of the query var queryFilter = (queryParameters as HealthServiceRecordContainer).FindComponent(HealthServiceRecordSiteRoleType.FilterOf) as QueryParameters; // Query Filter if (queryFilter == null || queryFilter.MatchingAlgorithm == MatchAlgorithm.Unspecified) { queryFilter = new QueryParameters() { MatchStrength = DatabasePersistenceService.ValidationSettings.DefaultMatchStrength, MatchingAlgorithm = DatabasePersistenceService.ValidationSettings.DefaultMatchAlgorithms } } ; // Subject of the query QueryEvent queryEvent = queryParameters as QueryEvent; // Connect to the database IDbConnection conn = m_configuration.ReadonlyConnectionManager.GetConnection(); try { using (IDbCommand cmd = conn.CreateCommand()) { var subject = queryEvent.FindComponent(HealthServiceRecordSiteRoleType.SubjectOf); string queryFilterString = String.Format("{0}", DbUtil.BuildQueryFilter(subject, this.Context, queryFilter.MatchingAlgorithm == MatchAlgorithm.Exact)); cmd.CommandType = CommandType.Text; cmd.CommandText = queryFilterString; #if DEBUG Trace.TraceInformation(cmd.CommandText); #endif try { using (IDataReader rdr = cmd.ExecuteReader()) { // Read all results while (rdr.Read()) { // Id var id = new VersionedResultIdentifier() { Domain = GetQueryPersister(subject.GetType()).ComponentTypeOid, Identifier = Convert.ToString(rdr[0]), Version = Convert.ToString(rdr[1]) }; // Add the ID retVal.Add(id); if (retVal.Count % 30 == 29) { retVal.Capacity += 30; } } } } catch { Trace.TraceInformation("Query in error: {0}", queryFilterString); throw; } } } catch (Exception e) { throw new DataException("Query error : " + e.Message, e); } finally { m_configuration.ConnectionManager.ReleaseConnection(conn); } //retVal.Sort((a, b) => b.Identifier.CompareTo(a.Identifier)); #if DEBUG Trace.TraceInformation("{0} records returned by function", retVal.Count); #endif return(retVal.ToArray()); }