Ejemplo n.º 1
0
 @Test
 public void testGetAttributeColumnsEmpty() {
   GraphStore store = new GraphStore();
   NodeImpl node = new NodeImpl("0", store);
   Iterable<Column> pk = node.getAttributeColumns();
   Assert.assertNotNull(pk);
   Iterator<Column> itr = pk.iterator();
   Assert.assertNotNull(itr);
   int size = 0;
   for (; itr.hasNext(); ) {
     Column c = itr.next();
     Assert.assertTrue(c.isProperty());
     size++;
   }
   Assert.assertTrue(size == getElementPropertiesLength());
 }
Ejemplo n.º 2
0
    private void refreshAttributeFunctions(boolean graphHasChanged) {
      Set<Column> columns = new HashSet<Column>();
      for (Column column : getTable()) {
        if (!column.isProperty()) {
          columns.add(column);
        }
      }

      // Clean
      for (Iterator<Map.Entry<Column, ColumnObserver>> itr = columnObservers.entrySet().iterator();
          itr.hasNext(); ) {
        Map.Entry<Column, ColumnObserver> entry = itr.next();
        if (!columns.contains(entry.getKey()) || forcedColumnsRefresh.contains(entry.getKey())) {
          rankings.remove(getIdCol(entry.getKey()));
          partitions.remove(getIdCol(entry.getKey()));
          for (Transformer t : getTransformers()) {
            attributeFunctions.remove(getId(t, entry.getKey()));
          }
          itr.remove();
          if (!entry.getValue().isDestroyed()) {
            entry.getValue().destroy();
          }
        }
      }

      // Get columns to be refreshed
      Set<Column> toRefreshColumns = new HashSet<Column>(forcedColumnsRefresh);
      for (Column column : columns) {
        if (!columnObservers.containsKey(column)) {
          columnObservers.put(column, column.createColumnObserver());
          toRefreshColumns.add(column);
        } else if (columnObservers.get(column).hasColumnChanged() || graphHasChanged) {
          toRefreshColumns.add(column);
        }
      }
      forcedColumnsRefresh.clear();

      // Refresh ranking and partitions
      for (Column column : toRefreshColumns) {
        RankingImpl ranking = rankings.get(getIdCol(column));
        PartitionImpl partition = partitions.get(getIdCol(column));
        if (ranking == null && partition == null) {
          String id = getIdCol(column);
          if (forcedPartition.contains(id)
              || (!forcedRanking.contains(id) && isPartition(graph, column))) {
            if (column.isIndexed()) {
              partition = new AttributePartitionImpl(column, getIndex(false));
            } else {
              partition = new AttributePartitionImpl(column, graph);
            }
            partitions.put(getIdCol(column), partition);
          }

          if (forcedRanking.contains(id) || isRanking(graph, column)) {
            if (column.isIndexed()) {
              ranking = new AttributeRankingImpl(column, getIndex(localScale));
            } else {
              ranking = new AttributeRankingImpl(column, graph);
            }
            rankings.put(getIdCol(column), ranking);
          }
        }
        if (ranking != null) {
          ranking.refresh();
        }
        if (partition != null) {
          partition.refresh();
        }
      }

      // Ranking functions
      for (Transformer t : getRankingTransformers()) {
        for (Column col : toRefreshColumns) {
          RankingImpl ranking = rankings.get(getIdCol(col));
          if (ranking != null) {
            String id = getId(t, col);
            if (!attributeFunctions.containsKey(id)) {
              attributeFunctions.put(
                  id,
                  new AttributeFunctionImpl(
                      id, graph, col, t, getTransformerUI(t), ranking, defaultInterpolator));
            }
          }
        }
      }

      // Partition functions
      for (Transformer t : getPartitionTransformers()) {
        for (Column col : toRefreshColumns) {
          PartitionImpl partition = partitions.get(getIdCol(col));
          if (partition != null) {
            String id = getId(t, col);
            if (!attributeFunctions.containsKey(id)) {
              attributeFunctions.put(
                  id, new AttributeFunctionImpl(id, graph, col, t, getTransformerUI(t), partition));
            }
          }
        }
      }
    }