Ejemplo n.º 1
0
  public void testBasicRow() throws NamingException, SQLException {
    BasicTable table = (BasicTable) populatedSchema.getTables().getByName("Test_Three");
    DatabaseConnValueContext dbvc = new BasicDatabaseConnValueContext();
    dbvc.setConnectionProvider(TestUtils.getConnProvider(this.getClass().getPackage().getName()));
    dbvc.setDefaultDataSource(this.getClass().getPackage().getName());
    ConnectionContext cc = dbvc.getConnection(this.getClass().getPackage().getName(), true);

    Row initialRow = table.createRow();
    QueryDefnSelect query =
        table.getAccessorByColumnEquality(table.getColumns().getByName("column_a"));
    QueryResultSet qrs = query.execute(dbvc, new Object[] {"abc"}, false);
    ResultSet rs = qrs.getResultSet();
    if (rs.next()) initialRow.getColumnValues().populateValues(rs, 1);

    assertNotNull(initialRow.toString());

    qrs.close(true);
  }
Ejemplo n.º 2
0
  public void testBasicTable() throws NamingException, SQLException {
    BasicTable table = (BasicTable) populatedSchema.getTables().getByName("Test_Three");
    BasicTable table2 = (BasicTable) populatedSchema.getTables().getByName("Enum_set_Lookup");

    // Test getTableTypes Method
    assertEquals("Default", table.getTableTypes().get(0));

    // For this particular table there is no ParentColumn.  Need to create a scenario where this is
    // not null and assert
    assertNull(table.getParentColumn());

    table.setXmlNodeName("Test-Three");
    assertEquals("Test-Three", table.getXmlNodeName());

    assertEquals(
        "This is a sample table that is used in the SchemaTableTest Unit Test.  Do not discard.",
        table.getDescription());

    assertNotNull(table.getForeignKeyColumns().getByName("record_status_id"));
    assertNotNull(table.getForeignKeyColumns().getByName("enumIdRef"));

    try {
      table.createColumn(Byte.class);
      fail();
    } catch (RuntimeException e) {
      // This is good
    } catch (NoSuchMethodException e) {
      fail();
    } catch (InstantiationException e) {
      fail();
    } catch (IllegalAccessException e) {
      fail();
    } catch (InvocationTargetException e) {
      fail();
    }

    assertTrue(table.isParentTable());
    assertTrue(!table2.isParentTable());

    DatabaseConnValueContext dbvc = new BasicDatabaseConnValueContext();
    dbvc.setConnectionProvider(TestUtils.getConnProvider(this.getClass().getPackage().getName()));
    dbvc.setDefaultDataSource(this.getClass().getPackage().getName());
    ConnectionContext cc = dbvc.getConnection(this.getClass().getPackage().getName(), true);

    Row initialRow = table.createRow();
    QueryDefnSelect query =
        table.getAccessorByColumnEquality(table.getColumns().getByName("column_a"));
    QueryResultSet qrs = query.execute(dbvc, new Object[] {"abc"}, false);
    ResultSet rs = qrs.getResultSet();
    if (rs.next()) initialRow.getColumnValues().populateValues(rs, 1);

    qrs.close(true);

    Row row = table.createRow();
    row = table.getRowByPrimaryKeys(cc, initialRow.getPrimaryKeyValues(), row);

    assertEquals(initialRow, row);

    assertTrue(!table.dataChangedInStorage(cc, row));
    row.getColumnValues().getByName("column_a").setTextValue("cba");
    assertTrue(table.dataChangedInStorage(cc, row));

    table.refreshData(cc, row);
    assertEquals(initialRow, row);

    Rows rows = table.createRows();
    assertNotNull(rows);

    ColumnsCollection columns = new ColumnsCollection();
    columns.add(table.getColumns().getByName("column_a"));
    columns.add(table.getColumns().getByName("column_b"));
    table.getAccessorByColumnsEquality(columns);

    // TODO: Need to do some assertion on the columns accessor
    // QueryResultSet qrs3 = query.execute(dbvc, new Object[]{"abc","a"}, false);
    // ResultSet rs3 = qrs3.getResultSet();
    // if (rs3.next())
    //    initialRow.getColumnValues().populateValues(rs,1);

    try {
      assertNotNull(table.createAccessor());
    } catch (QueryDefinitionException e) {
      fail();
    }

    // getRowByPrimaryKeys
    // getRowByPrimaryKeys
    cc.commitAndClose();
  }