Esempio n. 1
0
 private void insertInIndex(Value[] values, int rowIndex) throws DriverException {
   if (indexEditionManager != null) {
     try {
       for (DataSourceIndex index : indexEditionManager.getDataSourceIndexes()) {
         Metadata metadata = getMetadata();
         String[] idxFields = index.getFieldNames();
         if (idxFields.length == 1) {
           for (int i = 0; i < metadata.getFieldCount(); i++) {
             if (metadata.getFieldName(i).equals(idxFields[0])) {
               index.insertRow(values[i], rowIndex);
             }
           }
         } else {
           Value[] toInsert = new Value[idxFields.length];
           for (int i = 0; i < metadata.getFieldCount(); i++) {
             for (int j = 0; j < idxFields.length; j++) {
               if (metadata.getFieldName(i).equals(idxFields[j])) {
                 toInsert[j] = values[i];
               }
             }
             index.insertRow(ValueFactory.createValue(values), rowIndex);
           }
         }
       }
     } catch (IndexException e) {
       throw new DriverException("Cannot update index", e);
     }
   }
 }
Esempio n. 2
0
 private void deleteInIndex(int rowIndex) throws DriverException {
   if (indexEditionManager != null) {
     try {
       for (DataSourceIndex index : indexEditionManager.getDataSourceIndexes()) {
         Metadata metadata = getMetadata();
         String[] idxFields = index.getFieldNames();
         if (idxFields.length == 1) {
           for (int i = 0; i < metadata.getFieldCount(); i++) {
             if (metadata.getFieldName(i).equals(idxFields[0])) {
               Value v = getFieldValue(rowIndex, i);
               index.deleteRow(v, rowIndex);
             }
           }
         } else {
           Value[] toInsert = new Value[idxFields.length];
           for (int i = 0; i < metadata.getFieldCount(); i++) {
             for (int j = 0; j < idxFields.length; j++) {
               if (metadata.getFieldName(i).equals(idxFields[j])) {
                 toInsert[j] = getFieldValue(rowIndex, i);
               }
             }
             index.deleteRow(ValueFactory.createValue(toInsert), rowIndex);
           }
         }
       }
     } catch (IndexException e) {
       throw new DriverException(e);
     }
   }
 }
Esempio n. 3
0
  private void testAddField(String dsName, Type type) throws Exception {
    DataSource d = dsf.getDataSource(dsName, DataSourceFactory.EDITABLE);

    d.open();
    Metadata m = d.getMetadata();
    int fc = m.getFieldCount();
    String name = "toto";
    int i = 0;
    while (m.getFieldIndex(name + "_" + i) != -1) {
      i++;
    }
    //                System.out.println(fc + " fields");
    //                System.out.println("adding " + name + "_" + i);
    d.addField(name + "_" + i, type);
    d.commit();
    d.close();
    d.open();
    assertEquals(fc + 1, d.getMetadata().getFieldCount());
    //                System.out.println(d.getMetadata().getFieldCount() + " fields");
    //                for (int j = 0; j < d.getFieldCount(); j++) {
    //                        System.out.println(j + " field " + d.getFieldName(j));
    //                }
    //                System.out.println(d.getFieldName(fc));
    assertEquals(d.getFieldName(fc), name + "_" + i);
    assertEquals(d.getFieldType(fc).getTypeCode(), Type.STRING);

    assertNull(d.getFieldType(fc).getConstraintValue(Constraint.PK));
    assertNull(d.getFieldType(fc).getConstraintValue(Constraint.READONLY));
    d.close();
  }
Esempio n. 4
0
  @Override
  public Number[] getScope(int dimension) throws DriverException {
    if (cachedScope == null) {
      boolean open = isOpen();
      if (!open) {
        open();
      }
      for (int i = 0; i < getRowCount(); i++) {
        Metadata m = getMetadata();
        for (int j = 0; j < m.getFieldCount(); j++) {
          int typeCode = m.getFieldType(j).getTypeCode();
          Envelope r = null;
          if ((typeCode & Type.GEOMETRY) != 0) {
            Value v = getFieldValue(i, j);
            if ((v != null) && (!v.isNull())) {
              r = v.getAsGeometry().getEnvelopeInternal();
            }
          } else if (typeCode == Type.RASTER) {
            Value v = getFieldValue(i, j);
            if ((v != null) && (!v.isNull())) {
              r = v.getAsRaster().getMetadata().getEnvelope();
            }
          } else if (typeCode == Type.STREAM) {
            Value v = getFieldValue(i, j);
            if ((v != null) && (!v.isNull())) {
              r = v.getAsStream().getEnvelope();
            }
          }
          if (r != null) {
            if (cachedScope == null) {
              cachedScope = new Envelope(r);
            } else {
              cachedScope.expandToInclude(r);
            }
          }
        }
      }
      if (!open) {
        close();
      }
    }

    if (cachedScope == null) {
      return new Number[] {0, 0};
    } else {
      if (dimension == DataSet.X) {
        return new Number[] {cachedScope.getMinX(), cachedScope.getMaxX()};
      } else if (dimension == DataSet.Y) {
        return new Number[] {cachedScope.getMinY(), cachedScope.getMaxY()};
      } else {
        throw new UnsupportedOperationException("Not yet implemented");
      }
    }
  }
Esempio n. 5
0
  @Test
  public void testDeleteField() throws Exception {
    sm.register(
        "big", getTempCopyOf(new File(TestResourceHandler.TESTRESOURCES, "landcover2000.shp")));
    DataSource d = dsf.getDataSource("big");

    d.open();
    Metadata m = d.getMetadata();
    int fc = m.getFieldCount();
    d.removeField(1);
    d.commit();
    d.close();
    d.open();
    assertEquals(fc - 1, m.getFieldCount());
    d.close();
  }
Esempio n. 6
0
  private synchronized List<Field> getFields() throws DriverException {
    if (null == fields) {
      ArrayList<Field> fieldArray = new ArrayList<Field>();
      Metadata metadata = getDataSource().getMetadata();
      if (metadata == null) {
        throw new DriverException(
            "Error initializing metadata; cannot get the metadata of" + " the inner source.");
      }
      final int fc = metadata.getFieldCount();

      for (int i = 0; i < fc; i++) {
        fieldArray.add(new Field(i, metadata.getFieldName(i), getDataSource().getFieldType(i)));
      }
      fields = fieldArray;
    }
    return fields;
  }
Esempio n. 7
0
  private void initializeEdition() throws DriverException {
    if (!initialized) {
      long rowCount = getDataSource().getRowCount();

      // build alpha indexes on unique fields
      Metadata m = getMetadata();
      for (int i = 0; i < m.getFieldCount(); i++) {
        Type type = m.getFieldType(i);
        if (type.getBooleanConstraint(Constraint.UNIQUE)
            || type.getBooleanConstraint(Constraint.PK)) {
          IndexManager indexManager = getDataSourceFactory().getIndexManager();
          try {
            if (!indexManager.isIndexed(getName(), m.getFieldName(i))) {
              indexManager.buildIndex(getName(), m.getFieldName(i), new NullProgressMonitor());
            }
          } catch (NoSuchTableException e) {
            throw new DriverException("table not found: " + getName(), e);
          } catch (IndexException e) {
            throw new DriverException("Cannot create index on unique fields", e);
          }
        }
      }

      // initialize directions
      rowsAddresses = new ArrayList<PhysicalRowAddress>();
      for (int i = 0; i < rowCount; i++) {
        PhysicalRowAddress dir = new OriginalRowAddress(getDataSource(), i);
        rowsAddresses.add(dir);
        editionActions.add(new NoEditionInfo(getPK(i), i));
      }

      Number[] xScope = getDataSource().getScope(DataSet.X);
      Number[] yScope = getDataSource().getScope(DataSet.Y);
      if ((xScope != null) && (yScope != null)) {
        cachedScope =
            new Envelope(
                new Coordinate(xScope[0].doubleValue(), yScope[0].doubleValue()),
                new Coordinate(xScope[1].doubleValue(), yScope[1].doubleValue()));
      } else {
        cachedScope = null;
      }

      initialized = true;
    }
  }
Esempio n. 8
0
 /**
  * Adds the symbol panel attached to the given {@link Symbolizer} and returns the panel.
  *
  * @param symb Symbolizer
  * @return The newly generated symbol panel
  */
 private ILegendPanel addSymbolPanel(Symbolizer symb) {
   // Get the legend corresponding to this symbolizer.
   Legend legend = LegendFactory.getLegend(symb);
   if (legend instanceof AbstractRecodedLegend) {
     DataSource dataSource = layer.getDataSource();
     AbstractRecodedLegend leg = (AbstractRecodedLegend) legend;
     try {
       Metadata metadata = dataSource.getMetadata();
       String f = leg.getLookupFieldName();
       int in = metadata.getFieldIndex(f);
       leg.setComparator(AbstractRecodedLegend.getComparator(metadata.getFieldType(in)));
     } catch (DriverException e) {
       LOGGER.warn("Can't retrieve an accurate Comparator for this classification");
     }
   }
   // Initialize a panel for this legend.
   ILegendPanel panel = ILegendPanelFactory.getILegendPanel(this, legend);
   // Give it a new id.
   panel.setId(createNewID());
   // Add the symbol panel to the container after putting it in a
   // new JScrollPane.
   dialogContainer.add(panel.getId(), getJScrollPane(panel));
   return panel;
 }