public void run()

in openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ReverseMappingTool.java [664:787]


    public void run() {
        // map base classes first
        Schema[] schemas = getSchemaGroup().getSchemas();
        Table[] tables;
        for (Schema schema2 : schemas) {
            tables = schema2.getTables();
            for (Table table : tables)
                if (isBaseTable(table))
                    mapBaseClass(table);
        }

        // map vertical subclasses
        Set subs = null;
        for (Schema schema1 : schemas) {
            tables = schema1.getTables();
            for (Table table : tables) {
                if (!_tables.containsKey(table)
                        && getSecondaryType(table, false) == TABLE_SUBCLASS) {
                    if (subs == null)
                        subs = new HashSet();
                    subs.add(table);
                }
            }
        }
        if (subs != null)
            mapSubclasses(subs);

        // map fields in the primary tables of the classes
        ClassMapping cls;
        for (Object o1 : _tables.values()) {
            cls = (ClassMapping) o1;
            mapColumns(cls, cls.getTable(), null, false);
        }

        // map association tables, join tables, and secondary tables
        for (Schema element : schemas) {
            tables = element.getTables();
            for (Table table : tables)
                if (!_tables.containsKey(table))
                    mapTable(table, getSecondaryType(table, false));
        }

        // map discriminators and versions, make sure identity type is correct,
        // set simple field column java types, and ref schema components so
        // we can tell what is unmapped
        FieldMapping[] fields;
        for (Object item : _tables.values()) {
            cls = (ClassMapping) item;
            cls.refSchemaComponents();
            if (cls.getDiscriminator().getStrategy() == null)
                getStrategyInstaller().installStrategy
                        (cls.getDiscriminator());
            cls.getDiscriminator().refSchemaComponents();
            if (cls.getVersion().getStrategy() == null)
                getStrategyInstaller().installStrategy(cls.getVersion());
            cls.getVersion().refSchemaComponents();

            // double-check identity type; if it was set for builtin identity
            // it might have to switch to std application identity if pk field
            // not compatible
            if (cls.getPCSuperclass() == null
                    && cls.getIdentityType() == ClassMetaData.ID_APPLICATION) {
                if (cls.getPrimaryKeyFields().length == 0)
                    throw new MetaDataException(_loc.get("no-pk-fields", cls));
                if (cls.getObjectIdType() == null
                        || (cls.isOpenJPAIdentity() && !isBuiltinIdentity(cls)))
                    setObjectIdType(cls);
            }
            else if (cls.getIdentityType() == ClassMetaData.ID_DATASTORE)
                cls.getPrimaryKeyColumns()[0].setJavaType(JavaTypes.LONG);

            // set java types for simple fields;
            fields = cls.getDeclaredFieldMappings();
            for (FieldMapping field : fields) {
                field.refSchemaComponents();
                setColumnJavaType(field);
                setColumnJavaType(field.getElementMapping());
            }
        }

        // set the java types of foreign key columns; we couldn't do this
        // earlier because we rely on the linked-to columns to do it
        for (Object value : _tables.values()) {
            cls = (ClassMapping) value;
            setForeignKeyJavaType(cls.getJoinForeignKey());

            fields = cls.getDeclaredFieldMappings();
            for (FieldMapping field : fields) {
                setForeignKeyJavaType(field.getJoinForeignKey());
                setForeignKeyJavaType(field.getForeignKey());
                setForeignKeyJavaType(field.getElementMapping().
                        getForeignKey());
            }
        }

        // allow customizer to map unmapped tables, and warn about anything
        // that ends up unmapped
        Column[] cols;
        Collection unmappedCols = new ArrayList(5);
        for (Schema schema : schemas) {
            tables = schema.getTables();
            for (Table table : tables) {
                unmappedCols.clear();
                cols = table.getColumns();
                for (Column col : cols)
                    if (col.getRefCount() == 0)
                        unmappedCols.add(col);

                if (unmappedCols.size() == cols.length) {
                    if (_custom == null || !_custom.unmappedTable(table))
                        _log.info(_loc.get("unmap-table", table));
                }
                else if (unmappedCols.size() > 0)
                    _log.info(_loc.get("unmap-cols", table, unmappedCols));
            }
        }
        if (_custom != null)
            _custom.close();

        // resolve mappings
        for (Object o : _tables.values()) {
            ((ClassMapping) o).resolve(MODE_META | MODE_MAPPING);
        }
    }