Пример #1
0
 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();
 }
Пример #2
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();
  }
Пример #3
0
  @Test
  public void testModifyField() throws Exception {
    sm.register("big", getTempCopyOf(getAnyNonSpatialResource()));
    DataSource d = dsf.getDataSource("big");

    d.open();
    d.getMetadata();
    d.setFieldName(1, "nuevo");
    d.commit();
    d.close();
    d.open();
    assertEquals(d.getMetadata().getFieldName(1), "nuevo");
    d.close();
  }
Пример #4
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();
  }
Пример #5
0
  @Test
  public void testEditionWithFieldRemoved() throws Exception {
    sm.register("ile", getTempCopyOf(super.getAnyNonSpatialResource()));
    DataSource d = dsf.getDataSource("ile", DataSourceFactory.EDITABLE);
    d.open();
    String fieldName = d.getFieldName(1);
    Value testValue = d.getFieldValue(0, 2);
    d.removeField(1);
    assertTrue(equals(testValue, d.getFieldValue(0, 1)));
    new UndoRedoTest().testAlphanumericEditionUndoRedo(d);
    d.commit();
    d.close();

    d.open();
    assertEquals(d.getFieldIndexByName(fieldName), -1);
    d.close();
  }
Пример #6
0
 @Test
 public void testEditionWithFieldAdded() throws Exception {
   sm.register("toto", getTempCopyOf(super.getAnyNonSpatialResource()));
   DataSource d = dsf.getDataSource("toto", DataSourceFactory.EDITABLE);
   d.open();
   d.addField("extra", TypeFactory.createType(Type.STRING));
   int fi = d.getFieldIndexByName("extra");
   new UndoRedoTest().testAlphanumericEditionUndoRedo(d);
   Value newValue = ValueFactory.createValue("hi");
   d.setFieldValue(0, fi, newValue);
   d.undo();
   d.redo();
   d.commit();
   d.close();
   d.open();
   assertTrue(equals(d.getFieldValue(0, d.getFieldIndexByName("extra")), newValue));
   d.close();
 }
Пример #7
0
  @Test
  public void testTypeInAddField() throws Exception {
    String dsName = "toto";
    sm.register(dsName, getTempCopyOf(super.getAnyNonSpatialResource()));
    DataSource d = dsf.getDataSource(dsName);

    d.open();
    int fc = d.getMetadata().getFieldCount();
    Type type = (d.getDriver()).getTypesDefinitions()[0].createType();
    d.addField("new", type);
    assertEquals(d.getMetadata().getFieldType(fc).getTypeCode(), type.getTypeCode());
    d.commit();
    d.close();

    d = dsf.getDataSource(dsName);
    d.open();
    assertEquals(d.getMetadata().getFieldCount(), fc + 1);
    assertEquals(d.getMetadata().getFieldType(fc).getTypeCode(), type.getTypeCode());
    d.close();
  }
Пример #8
0
  @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();
  }