private void failedCommit(DataSource ds, IndexQuery query)
     throws DriverException, NonEditableDataSourceException {
   ds.deleteRow(2);
   ds.setFieldValue(0, 1, ValueFactory.createValue("nouveau"));
   Value[] row = ds.getRow(0);
   row[1] = ValueFactory.createValue("aaaaa");
   ds.insertFilledRow(row);
   Value[][] table = super.getDataSourceContents(ds);
   Iterator<Integer> it = ds.queryIndex(query);
   try {
     ReadDriver.failOnWrite = true;
     ds.commit();
     ds.close();
   } catch (DriverException e) {
     assertTrue(equals(table, super.getDataSourceContents(ds)));
     if (it != null) {
       assertTrue(ds.queryIndex(query) != null);
     } else {
       assertTrue(ds.queryIndex(query) == null);
     }
     ReadDriver.failOnWrite = false;
     ds.commit();
     ds.close();
   }
   ds.open();
   assertTrue(equals(table, super.getDataSourceContents(ds)));
   ds.close();
 }
 @Test
 public void testFieldDeletionEditionWhileEdition() throws Exception {
   sm.register("toto", super.getAnyNonSpatialResource());
   DataSource d = dsf.getDataSource("toto");
   d.open();
   Value[][] content = super.getDataSourceContents(d);
   d.deleteRow(0);
   d.setFieldValue(0, 2, d.getFieldValue(1, 2));
   d.removeField(1);
   assertTrue(equals(d.getFieldValue(0, 1), content[2][2]));
   d.setFieldValue(0, 0, d.getFieldValue(1, 0));
   assertTrue(equals(d.getFieldValue(0, 0), content[2][0]));
   d.close();
 }
 public boolean execute(PlugInContext context) throws Exception {
   IEditor editor = getPlugInContext().getActiveEditor();
   MapContext map = (MapContext) editor.getElement().getObject();
   ILayer activeLayer = map.getActiveLayer();
   int[] sel = activeLayer.getSelection().clone();
   Arrays.sort(sel);
   DataSource dataSource = activeLayer.getDataSource();
   try {
     dataSource.setDispatchingMode(DataSource.STORE);
     for (int i = sel.length - 1; i >= 0; i--) {
       dataSource.deleteRow(sel[i]);
     }
     dataSource.setDispatchingMode(DataSource.DISPATCH);
   } catch (DriverException e) {
     ErrorMessages.error(ErrorMessages.CannotDeleteSelectedRow, e);
   }
   return true;
 }
  @Test
  public void testFieldInsertionEditionWhileEdition() throws Exception {
    sm.register("toto", getTempCopyOf(super.getAnyNonSpatialResource()));
    DataSource d = dsf.getDataSource("toto");
    d.open();
    String nouveau = "nouveau";
    Value newValue = ValueFactory.createValue(nouveau);
    Value testValue = d.getFieldValue(2, 1);
    int lastField = d.getMetadata().getFieldCount();
    d.deleteRow(0);
    d.setFieldValue(0, 1, d.getFieldValue(1, 1));
    d.addField(nouveau, TypeFactory.createType(Type.STRING));
    d.setFieldValue(0, lastField, newValue);
    assertTrue(equals(d.getFieldValue(0, lastField), newValue));
    d.commit();
    d.close();

    d.open();
    assertEquals(d.getMetadata().getFieldName(lastField).toLowerCase(), nouveau);
    assertTrue(equals(d.getFieldValue(0, lastField), newValue));
    assertTrue(equals(d.getFieldValue(0, 1), testValue));
    d.close();
  }