Index: D:/RHDS/_projects/hibernate/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/JDBCReader.java =================================================================== --- D:/RHDS/_projects/hibernate/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/JDBCReader.java (revision 14416) +++ D:/RHDS/_projects/hibernate/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/JDBCReader.java (working copy) @@ -68,10 +68,17 @@ Set hasIndices = new HashSet(); + // remark: + // all tables in dbs which was collected by readDatabaseTables + // will not be in foundTables, as a result such tables + // will not be fully processed + // processTables has TODO about this + List schemaSelectors = revengStrategy.getSchemaSelections(); List foundTables = new ArrayList(); if(schemaSelectors==null) { - foundTables.addAll( processTables(dbs, new SchemaSelection(catalog, schema), hasIndices, progress) ); + SchemaSelection ss = new SchemaSelection(catalog, schema); + foundTables.addAll( processTables(dbs, ss, hasIndices, progress) ); } else { for (Iterator iter = schemaSelectors.iterator(); iter.hasNext();) { SchemaSelection selection = (SchemaSelection) iter.next(); @@ -102,6 +109,45 @@ } /** + * Just only read information about tables. In contradiction with readDatabaseSchema + * readDatabaseTables does not try to define relations between DB tables, column types, keys, etc. + */ + public List readDatabaseTables(DatabaseCollector dbs, String catalog, String schema, ProgressListener progress) { + try { + ReverseEngineeringRuntimeInfo info = new ReverseEngineeringRuntimeInfo(provider, sec, dbs); + getMetaDataDialect().configure(info); + revengStrategy.configure(info); + + // QUESTION to Max: + // possible TODO: + // processTables does not use SchemaSelection.matchColumn. + // may be it has a sense select only these tables which have columns + // according specified criteria. + + List schemaSelectors = revengStrategy.getSchemaSelections(); + List foundTables = new ArrayList(); + if(schemaSelectors==null) { + SchemaSelection ss = new SchemaSelection(catalog, schema); + foundTables.addAll( processTables(dbs, ss, null, progress) ); + } else { + for (Iterator iter = schemaSelectors.iterator(); iter.hasNext();) { + SchemaSelection selection = (SchemaSelection) iter.next(); + foundTables.addAll( processTables(dbs, selection, null, progress) ); + } + } + return foundTables; + } finally { + getMetaDataDialect().close(); + revengStrategy.close(); + } + } + + public List readDatabaseColumns(DatabaseCollector dbs, String catalog, String schema, ProgressListener progress) { + // TODO: + return null; + } + + /** * Iterates the tables and find all the foreignkeys that refers to something that is available inside the DatabaseCollector. * @param dbs * @param progress @@ -532,7 +578,16 @@ String comment = (String) tableRs.get("REMARKS"); String tableType = (String) tableRs.get("TABLE_TYPE"); - if(dbs.getTable(schemaName, catalogName, tableName)!=null) { + Table table = dbs.getTable(schemaName, catalogName, tableName); + if(null != table) { + // QUESTION to Max: + // possible situation when dbs contains the table, + // but table indices have not been processed. + // TODO: we should handle the situation + //if(tableType.equals("TABLE") && null != hasIndices) { + // hasIndices.add(table); + //} + //processedTables.add( table ); log.debug("Ignoring " + tableName + " since it has already been processed"); continue; } else { @@ -549,9 +604,9 @@ } log.debug("Adding table " + tableName + " of type " + tableType); progress.startSubTask("Found " + tableName); - Table table = dbs.addTable(quote(getSchemaForModel(schemaName)), getCatalogForModel(catalogName), quote(tableName)); + table = dbs.addTable(quote(getSchemaForModel(schemaName)), getCatalogForModel(catalogName), quote(tableName)); table.setComment(comment); - if(tableType.equals("TABLE")) { + if(tableType.equals("TABLE") && null != hasIndices) { hasIndices.add(table); } processedTables.add( table ); @@ -860,6 +915,14 @@ return readDatabaseSchema(dbs, catalog, schema, new NoopProgressListener()); } + public List readDatabaseColumns(DatabaseCollector dbs, String catalog, String schema) { + return readDatabaseColumns(dbs, catalog, schema, new NoopProgressListener()); + } + + public List readDatabaseTables(DatabaseCollector dbs, String catalog, String schema) { + return readDatabaseTables(dbs, catalog, schema, new NoopProgressListener()); + } + /** If catalog is equal to defaultCatalog then we return null so it will be null in the generated code. */ protected String getCatalogForModel(String catalog) { if(catalog==null) return null;