Example #1
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();
  }
Example #2
0
  private void testMetadataEditionListenerTest(String dsName, Type type) throws Exception {
    DataSource d = dsf.getDataSource(dsName);

    d.open();
    ListenerCounter elc = new ListenerCounter();
    d.addMetadataEditionListener(elc);
    d.removeField(1);
    d.addField("nuevo", type);
    d.setFieldName(1, "jjjj");
    assertEquals(elc.fieldDeletions, 1);
    assertEquals(elc.fieldInsertions, 1);
    assertEquals(elc.fieldModifications, 1);
    assertEquals(elc.total, 3);
    d.close();
  }
Example #3
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();
 }
Example #4
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();
  }
Example #5
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();
  }