示例#1
0
  public void testRowDeleteTypes() throws SQLException, NamingException {
    DatabaseConnValueContext dbvc = new BasicDatabaseConnValueContext();
    dbvc.setConnectionProvider(TestUtils.getConnProvider(this.getClass().getPackage().getName()));
    dbvc.setDefaultDataSource(this.getClass().getPackage().getName());

    final Table testTable = populatedSchema.getTables().getByName("Test_Retire");
    assertEquals(
        RowDeleteType.LOGICAL_CASCADE_CHILDREN, testTable.getRowDeleteType().getValueIndex());

    final Row testTableRow = testTable.createRow();
    final ColumnValues testTableRowValues = testTableRow.getColumnValues();
    testTableRowValues.getByName("text").setTextValue("Test 001");

    ConnectionContext cc = dbvc.getConnection(this.getClass().getPackage().getName(), true);
    testTable.insert(cc, testTableRow);

    cc.commitAndClose();

    cc = dbvc.getConnection(this.getClass().getPackage().getName(), true);
    testTable.delete(cc, testTableRow);
    cc.commitAndClose();

    cc = dbvc.getConnection(this.getClass().getPackage().getName(), true);
    assertEquals(
        1, testTable.getCount(cc)); // make sure the record is there (it's status should be updated)
    cc.commitAndClose();

    // TODO: add child cascade tests
  }
示例#2
0
  public void testHierarchyTables() throws SQLException, NamingException {
    Table entity1Table = populatedSchema.getTables().getByName("Entity_1");
    Table entity2Table = populatedSchema.getTables().getByName("Entity_2");
    EntityHierarchyTable entity1HierarchyTable =
        (EntityHierarchyTable) populatedSchema.getTables().getByName("Entity_1_Hierarchy");
    RelationshipMapTable entity12RelationshipTable =
        (RelationshipMapTable) populatedSchema.getTables().getByName("Entity_1_2_Relationship");

    assertNotNull(entity1Table);
    assertNotNull(entity2Table);
    assertNotNull(entity1HierarchyTable);
    assertNotNull(entity12RelationshipTable);

    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);

    final int entity1RowsCreateCount = 3;
    final int created =
        createEntity1RowAndChildren(
            cc,
            entity1Table,
            entity1HierarchyTable,
            null,
            "Entity 1.",
            entity1RowsCreateCount,
            2,
            0);

    cc.commitAndClose();

    cc = dbvc.getConnection(this.getClass().getPackage().getName(), true);

    /*
            assertNotNull(entity1HierarchyTable.getHierarchyRow(cc, EntityHierarchyTable.RELTYPEID_OBJ_HIERARCHY_PARENT, entity1IdValue, entity2IdValue));
            assertNotNull(entity12RelationshipTable.getRelationshipRow(cc, RelationshipMapTable.RELTYPEID_OBJ_HIERARCHY_CHILD, entity1IdValue, entity2IdValue));
    */

    cc.close();
  }
示例#3
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();
  }