Ignore:
Timestamp:
03/25/09 14:48:56 (12 years ago)
Author:
gkronber
Message:

Introduced paging for queries to fix problems with large WCF messages. #257 (CEDMA console doesn't handle communication- and timeout exceptions correctly)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Core/Results.cs

    r1287 r1417  
    3737namespace HeuristicLab.CEDMA.Core {
    3838  public class Results : ItemBase {
     39    private const int PAGE_SIZE = 1000;
    3940    private string[] categoricalVariables = null;
    4041    public string[] CategoricalVariables {
     
    8485
    8586    private IEnumerable<ResultsEntry> SelectRows() {
     87      int page = 0;
     88      int resultsReturned = 0;
     89      bool newEntry = false;
    8690      if (store == null) yield break;
    8791      entries = new List<ResultsEntry>();
    88       var results = store.Query("<" + dataSetEntity + "> <" + Ontology.PredicateHasModel + "> ?Model ." + Environment.NewLine +
    89         "?Model ?Attribute ?Value .")
    90         .GroupBy(x => (Entity)x.Get("Model"));
    91       foreach (var modelBindings in results) {
    92         ResultsEntry entry = new ResultsEntry(modelBindings.Key.Uri);
    93         foreach (var binding in modelBindings) {
    94           if (binding.Get("Value") is Literal) {
    95             string name = ((Entity)binding.Get("Attribute")).Uri.Replace(Ontology.CedmaNameSpace, "");
    96             if (entry.Get(name) == null) {
    97               object value = ((Literal)binding.Get("Value")).Value;
    98               entry.Set(name, value);
     92      do {
     93        var allBindings = store.Query("<" + dataSetEntity + "> <" + Ontology.PredicateHasModel + "> ?Model ." + Environment.NewLine +
     94          "?Model ?Attribute ?Value .", page, PAGE_SIZE);
     95        var allModelBindings = allBindings.GroupBy(x => (Entity)x.Get("Model"));
     96        resultsReturned = allBindings.Count;
     97
     98        foreach (var modelBindings in allModelBindings) {
     99          ResultsEntry entry = entries.FirstOrDefault(x => x.Uri == modelBindings.Key.Uri);
     100          newEntry = false;
     101          if (entry == null) {
     102            entry = new ResultsEntry();
     103            entry.Uri = modelBindings.Key.Uri;
     104            entries.Add(entry);
     105            newEntry = true;
     106          }
     107          foreach (var binding in modelBindings) {
     108            if (binding.Get("Value") is Literal) {
     109              string name = ((Entity)binding.Get("Attribute")).Uri.Replace(Ontology.CedmaNameSpace, "");
     110              if (entry.Get(name) == null) {
     111                object value = ((Literal)binding.Get("Value")).Value;
     112                entry.Set(name, value);
     113              }
    99114            }
    100115          }
     116          if (newEntry) yield return entry;
    101117        }
    102         entries.Add(entry);
    103         yield return entry;
    104       }
     118        page++;
     119      } while (resultsReturned == PAGE_SIZE);
    105120
    106121      FireChanged();
     
    114129    private void LoadModelAttributes() {
    115130      this.ordinalVariables =
    116         store.Query("?ModelAttribute <" + Ontology.PredicateInstanceOf + "> <" + Ontology.TypeOrdinalAttribute + "> .")
     131        store.Query("?ModelAttribute <" + Ontology.PredicateInstanceOf + "> <" + Ontology.TypeOrdinalAttribute + "> .", 0, 100)
    117132        .Select(s => ((Entity)s.Get("ModelAttribute")).Uri.Replace(Ontology.CedmaNameSpace, ""))
    118133        .ToArray();
    119134      this.categoricalVariables =
    120         store.Query("?ModelAttribute <" + Ontology.PredicateInstanceOf + "> <" + Ontology.TypeCategoricalAttribute + "> .")
     135        store.Query("?ModelAttribute <" + Ontology.PredicateInstanceOf + "> <" + Ontology.TypeCategoricalAttribute + "> .", 0, 100)
    121136        .Select(s => ((Entity)s.Get("ModelAttribute")).Uri.Replace(Ontology.CedmaNameSpace, ""))
    122137        .ToArray();
Note: See TracChangeset for help on using the changeset viewer.