public TableModel extractTableModel ( final Table table ) { Objects . requireNonNull ( table ) ; final TableModel model = new TableModel ( ) ; model . setClassName ( this . classPrefix + this . nameProvider . getClassNameForTable ( table ) ) ; model . setName ( this . nameProvider . getClassNameForTable ( table ) ) ; model . setSqlFullName ( table . getFullName ( ) ) ; model . setSqlName ( table . getName ( ) ) ; model . setPackageName ( this . targetPackage ) ; model . setColumns ( table . getColumns ( ) . stream ( ) //.filter(c -> !c.isPartOfForeignKey()) // no longer filter due to #12 . map ( this . columnExtractor :: extractColumnModel ) . collect ( Collectors . toList ( ) ) ) ; Set < Set < String > > seenForeignKeyColumnNameTuples = new HashSet <> ( ) ; // TODO unit test removing duplicates model . setForeignKeys ( table . getImportedForeignKeys ( ) . stream ( ) // only get data about "outgoing" foreign keys . filter ( foreignKeyColumnReferences -> { Set < String > foreignKeyColumnNames = foreignKeyColumnReferences . getColumnReferences ( ) . stream ( ) . map ( foreignKeyColumnReference -> foreignKeyColumnReference . getForeignKeyColumn ( ) . getFullName ( ) ) . collect ( Collectors . toSet ( ) ) ; return seenForeignKeyColumnNameTuples . add ( foreignKeyColumnNames ) ; } ) . map ( this . foreignKeyExtractor :: extractForeignKeyModel ) . collect ( Collectors . toList ( ) ) ) ; Set < Set < String > > seenForeignKeyColumnNameTuples2 = new HashSet <> ( ) ; // TODO unit test removing duplicates model . setIncomingForeignKeys ( table . getExportedForeignKeys ( ) . stream ( ) . filter ( foreignKeyColumnReferences -> { Set < String > foreignKeyColumnNames = foreignKeyColumnReferences . getColumnReferences ( ) . stream ( ) . map ( foreignKeyColumnReference -> foreignKeyColumnReference . getForeignKeyColumn ( ) . getFullName ( ) ) . collect ( Collectors . toSet ( ) ) ; return seenForeignKeyColumnNameTuples2 . add ( foreignKeyColumnNames ) ; } ) . map ( this . foreignKeyExtractor :: extractIncomingForeignKeyModel ) . collect ( Collectors . toList ( ) ) ) ; model . setHasColumnsAndForeignKeys ( ! model . getNonForeignKeyColumns ( ) . isEmpty ( ) && ! model . getForeignKeys ( ) . isEmpty ( ) ) ; return model ; }
Extracts the table model from a single table . Every table this table references via foreign keys must be fully loaded otherwise an exception will be thrown .