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 }
public int createEntity1RowAndChildren( ConnectionContext cc, Table entity1Table, EntityHierarchyTable entity1HierarchyTable, Object parentId, String namePrefix, int createChildrenCount, int maxDepth, int atDepth) throws SQLException, NamingException { int result = 0; if (atDepth > maxDepth) return result; for (int i = 0; i < createChildrenCount; i++) { final Row entity1Row = entity1Table.createRow(); final ColumnValues entity1ColumnValues = entity1Row.getColumnValues(); final String entityName = namePrefix + i; entity1ColumnValues.getByName("name").setValue(entityName); entity1Table.insert(cc, entity1Row); // we've inserted an entity record so keep track result++; final Object entity1IdValue = entity1ColumnValues.getByName("entity_1_id").getValue(); if (parentId != null) { final Row hierChildRow = entity1HierarchyTable.createRow(); final ColumnValues entity1HierColumnValues = hierChildRow.getColumnValues(); entity1HierColumnValues .getByName("hier_type_id") .setValue(EntityHierarchyTable.RELTYPEID_OBJ_HIERARCHY_PARENT); entity1HierColumnValues.getByName("primary_id").setValue(parentId); entity1HierColumnValues.getByName("related_id").setValue(entity1IdValue); entity1HierarchyTable.insert(cc, hierChildRow); } result = result + createEntity1RowAndChildren( cc, entity1Table, entity1HierarchyTable, entity1IdValue, entityName + ".", createChildrenCount, maxDepth, atDepth + 1); } return result; }