@Test public void test_OneToMany() throws Exception { EntityDesc entityDesc = new EntityDesc(); entityDesc.setCatalogName("AAA"); entityDesc.setSchemaName("BBB"); entityDesc.setTableName("CCC"); entityDesc.setName("Ccc"); EntityDesc entityDesc2 = new EntityDesc(); entityDesc2.setCatalogName("DDD"); entityDesc2.setSchemaName("EEE"); entityDesc2.setTableName("FFF"); entityDesc2.setName("Fff"); EntitySetDesc entitySetDesc = new EntitySetDesc(); entitySetDesc.addEntityDesc(entityDesc); entitySetDesc.addEntityDesc(entityDesc2); DbTableMeta tableMeta = new DbTableMeta(); tableMeta.setCatalogName("DDD"); tableMeta.setSchemaName("EEE"); tableMeta.setName("FFF"); DbForeignKeyMeta fkMeta = new DbForeignKeyMeta(); fkMeta.setPrimaryKeyCatalogName("AAA"); fkMeta.setPrimaryKeySchemaName("BBB"); fkMeta.setPrimaryKeyTableName("CCC"); fkMeta.addPrimaryKeyColumnName("GGG_ID"); fkMeta.addPrimaryKeyColumnName("HHH_ID"); fkMeta.addForeignKeyColumnName("GGG"); fkMeta.addForeignKeyColumnName("HHH"); AssociationResolver resolver = new AssociationResolver(entitySetDesc, new PluralFormDictinary(), new PersistenceConventionImpl()); resolver.resolve(tableMeta, fkMeta); assertEquals(1, entityDesc.getAssociationDescList().size()); AssociationDesc assoDesc = entityDesc.getAssociationDescList().get(0); assertSame(entityDesc2, assoDesc.getReferencedEntityDesc()); assertEquals(AssociationType.ONE_TO_MANY, assoDesc.getAssociationType()); assertEquals("fffList", assoDesc.getName()); assertEquals("ccc", assoDesc.getMappedBy()); assertTrue(assoDesc.getColumnNameList().isEmpty()); assertNull(assoDesc.getReferencedCatalogName()); assertNull(assoDesc.getReferencedSchemaName()); assertNull(assoDesc.getReferencedTableName()); assertTrue(assoDesc.getReferencedColumnNameList().isEmpty()); assertEquals(1, entityDesc2.getAssociationDescList().size()); assoDesc = entityDesc2.getAssociationDescList().get(0); assertSame(entityDesc, assoDesc.getReferencedEntityDesc()); assertEquals(AssociationType.MANY_TO_ONE, assoDesc.getAssociationType()); assertEquals("ccc", assoDesc.getName()); assertNull(assoDesc.getMappedBy()); assertEquals(Arrays.asList("GGG", "HHH"), assoDesc.getColumnNameList()); assertEquals("AAA", assoDesc.getReferencedCatalogName()); assertEquals("BBB", assoDesc.getReferencedSchemaName()); assertEquals("CCC", assoDesc.getReferencedTableName()); assertEquals(Arrays.asList("GGG_ID", "HHH_ID"), assoDesc .getReferencedColumnNameList()); }
public void resolve(DbTableMeta tableMeta, DbForeignKeyMeta fkMeta) { EntityDesc ownerEntityDesc = entitySetDesc.getEntityDesc(tableMeta .getFullTableName()); if (ownerEntityDesc == null) { return; } EntityDesc inverseEntityDesc = entitySetDesc.getEntityDesc(fkMeta .getPrimaryKeyFullTableName()); if (inverseEntityDesc == null) { return; } AssociationDesc ownerAssociationDesc = doOwnerAssociationDesc(fkMeta, ownerEntityDesc, inverseEntityDesc); doInverseAssociationDesc(fkMeta, ownerEntityDesc, inverseEntityDesc, ownerAssociationDesc.getName()); }
AssociationResolver { public void resolve(DbTableMeta tableMeta, DbForeignKeyMeta fkMeta) { EntityDesc ownerEntityDesc = entitySetDesc.getEntityDesc(tableMeta .getFullTableName()); if (ownerEntityDesc == null) { return; } EntityDesc inverseEntityDesc = entitySetDesc.getEntityDesc(fkMeta .getPrimaryKeyFullTableName()); if (inverseEntityDesc == null) { return; } AssociationDesc ownerAssociationDesc = doOwnerAssociationDesc(fkMeta, ownerEntityDesc, inverseEntityDesc); doInverseAssociationDesc(fkMeta, ownerEntityDesc, inverseEntityDesc, ownerAssociationDesc.getName()); } }
AssociationResolver { public void resolve(DbTableMeta tableMeta, DbForeignKeyMeta fkMeta) { EntityDesc ownerEntityDesc = entitySetDesc.getEntityDesc(tableMeta .getFullTableName()); if (ownerEntityDesc == null) { return; } EntityDesc inverseEntityDesc = entitySetDesc.getEntityDesc(fkMeta .getPrimaryKeyFullTableName()); if (inverseEntityDesc == null) { return; } AssociationDesc ownerAssociationDesc = doOwnerAssociationDesc(fkMeta, ownerEntityDesc, inverseEntityDesc); doInverseAssociationDesc(fkMeta, ownerEntityDesc, inverseEntityDesc, ownerAssociationDesc.getName()); } AssociationResolver(EntitySetDesc entitySetDesc,
            PluralFormDictinary pluralFormDictinary,
            PersistenceConvention persistenceConvention); }
AssociationResolver { public void resolve(DbTableMeta tableMeta, DbForeignKeyMeta fkMeta) { EntityDesc ownerEntityDesc = entitySetDesc.getEntityDesc(tableMeta .getFullTableName()); if (ownerEntityDesc == null) { return; } EntityDesc inverseEntityDesc = entitySetDesc.getEntityDesc(fkMeta .getPrimaryKeyFullTableName()); if (inverseEntityDesc == null) { return; } AssociationDesc ownerAssociationDesc = doOwnerAssociationDesc(fkMeta, ownerEntityDesc, inverseEntityDesc); doInverseAssociationDesc(fkMeta, ownerEntityDesc, inverseEntityDesc, ownerAssociationDesc.getName()); } AssociationResolver(EntitySetDesc entitySetDesc,
            PluralFormDictinary pluralFormDictinary,
            PersistenceConvention persistenceConvention); void resolve(DbTableMeta tableMeta, DbForeignKeyMeta fkMeta); }
AssociationResolver { public void resolve(DbTableMeta tableMeta, DbForeignKeyMeta fkMeta) { EntityDesc ownerEntityDesc = entitySetDesc.getEntityDesc(tableMeta .getFullTableName()); if (ownerEntityDesc == null) { return; } EntityDesc inverseEntityDesc = entitySetDesc.getEntityDesc(fkMeta .getPrimaryKeyFullTableName()); if (inverseEntityDesc == null) { return; } AssociationDesc ownerAssociationDesc = doOwnerAssociationDesc(fkMeta, ownerEntityDesc, inverseEntityDesc); doInverseAssociationDesc(fkMeta, ownerEntityDesc, inverseEntityDesc, ownerAssociationDesc.getName()); } AssociationResolver(EntitySetDesc entitySetDesc,
            PluralFormDictinary pluralFormDictinary,
            PersistenceConvention persistenceConvention); void resolve(DbTableMeta tableMeta, DbForeignKeyMeta fkMeta);  }