public void testRemoveSpecifiedJoinColumn() throws Exception { createTestEntityWithElementCollection(); addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE); JavaResourceField resourceField = resourceType.getFields().iterator().next(); collectionTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); collectionTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); collectionTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); CollectionTableAnnotation2_0 joinTableResource = (CollectionTableAnnotation2_0) resourceField.getAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME); assertEquals(3, joinTableResource.getJoinColumnsSize()); collectionTable.removeSpecifiedJoinColumn(0); assertEquals(2, joinTableResource.getJoinColumnsSize()); assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); collectionTable.removeSpecifiedJoinColumn(0); assertEquals(1, joinTableResource.getJoinColumnsSize()); assertEquals("BAZ", joinTableResource.joinColumnAt(0).getName()); collectionTable.removeSpecifiedJoinColumn(0); assertEquals(0, joinTableResource.getJoinColumnsSize()); }
public void testUpdateJoinColumns() throws Exception { createTestEntityWithElementCollection(); addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE); JavaResourceField resourceField = resourceType.getFields().iterator().next(); CollectionTableAnnotation2_0 joinTableResource = (CollectionTableAnnotation2_0) resourceField.addAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME); joinTableResource.addJoinColumn(0); joinTableResource.addJoinColumn(1); joinTableResource.addJoinColumn(2); joinTableResource.joinColumnAt(0).setName("FOO"); joinTableResource.joinColumnAt(1).setName("BAR"); joinTableResource.joinColumnAt(2).setName("BAZ"); getJpaProject().synchronizeContextModel(); ListIterator<JavaSpecifiedJoinColumn> joinColumns = collectionTable.getSpecifiedJoinColumns().iterator(); assertEquals("FOO", joinColumns.next().getName()); assertEquals("BAR", joinColumns.next().getName()); assertEquals("BAZ", joinColumns.next().getName()); assertFalse(joinColumns.hasNext()); joinTableResource.moveJoinColumn(2, 0); getJpaProject().synchronizeContextModel(); joinColumns = collectionTable.getSpecifiedJoinColumns().iterator(); assertEquals("BAR", joinColumns.next().getName()); assertEquals("BAZ", joinColumns.next().getName()); assertEquals("FOO", joinColumns.next().getName()); assertFalse(joinColumns.hasNext()); joinTableResource.moveJoinColumn(0, 1); getJpaProject().synchronizeContextModel(); joinColumns = collectionTable.getSpecifiedJoinColumns().iterator(); assertEquals("BAZ", joinColumns.next().getName()); assertEquals("BAR", joinColumns.next().getName()); assertEquals("FOO", joinColumns.next().getName()); assertFalse(joinColumns.hasNext()); joinTableResource.removeJoinColumn(1); getJpaProject().synchronizeContextModel(); joinColumns = collectionTable.getSpecifiedJoinColumns().iterator(); assertEquals("BAZ", joinColumns.next().getName()); assertEquals("FOO", joinColumns.next().getName()); assertFalse(joinColumns.hasNext()); joinTableResource.removeJoinColumn(1); getJpaProject().synchronizeContextModel(); joinColumns = collectionTable.getSpecifiedJoinColumns().iterator(); assertEquals("BAZ", joinColumns.next().getName()); assertFalse(joinColumns.hasNext()); joinTableResource.removeJoinColumn(0); getJpaProject().synchronizeContextModel(); assertFalse(collectionTable.getSpecifiedJoinColumns().iterator().hasNext()); }