@Test public void testGetDbTableMetaList() throws Exception { final MockResultSet resultSet = new MockResultSet(); ArrayMap rowData = new ArrayMap(); rowData.put("TABLE_CAT", "catalog1"); rowData.put("TABLE_SCHEM", "schemaName1"); rowData.put("TABLE_NAME", "table1"); rowData.put("REMARKS", "comment1"); resultSet.addRowData(rowData); rowData = new ArrayMap(); rowData.put("TABLE_CAT", "catalog2"); rowData.put("TABLE_SCHEM", "schemaName2"); rowData.put("TABLE_NAME", "table2"); rowData.put("REMARKS", "comment2"); resultSet.addRowData(rowData); rowData = new ArrayMap(); rowData.put("TABLE_CAT", "catalog3"); rowData.put("TABLE_SCHEM", "schemaName3"); rowData.put("TABLE_NAME", "table3"); rowData.put("REMARKS", "comment3"); resultSet.addRowData(rowData); GenMockDatabaseMetaData metaData = new GenMockDatabaseMetaData() { @Override public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException { return resultSet; } }; DbTableMetaReaderImpl reader = new DbTableMetaReaderImpl( new MockDataSource(), new StandardGenDialect(), "schemaName", ".*", "TABLE3", true); List<DbTableMeta> list = reader.getDbTableMetaList(metaData, "schemaName"); assertEquals(2, list.size()); assertEquals("catalog1", list.get(0).getCatalogName()); assertEquals("schemaName1", list.get(0).getSchemaName()); assertEquals("table1", list.get(0).getName()); assertEquals("comment1", list.get(0).getComment()); assertEquals("catalog2", list.get(1).getCatalogName()); assertEquals("schemaName2", list.get(1).getSchemaName()); assertEquals("table2", list.get(1).getName()); assertEquals("comment2", list.get(1).getComment()); }
protected List<DbTableMeta> getDbTableMetaList(DatabaseMetaData metaData, String schemaName) { List<DbTableMeta> result = new ArrayList<DbTableMeta>(); try { ResultSet rs = metaData.getTables(null, schemaName, null, new String[] { "TABLE" }); try { while (rs.next()) { DbTableMeta dbTableMeta = new DbTableMeta(); dbTableMeta.setCatalogName(rs.getString("TABLE_CAT")); dbTableMeta.setSchemaName(rs.getString("TABLE_SCHEM")); dbTableMeta.setName(rs.getString("TABLE_NAME")); if (readComment) { dbTableMeta.setComment(rs.getString("REMARKS")); } if (isTargetTable(dbTableMeta)) { result.add(dbTableMeta); } } return result; } finally { ResultSetUtil.close(rs); } } catch (SQLException e) { throw new SQLRuntimeException(e); } }
DbTableMetaReaderImpl implements DbTableMetaReader { protected List<DbTableMeta> getDbTableMetaList(DatabaseMetaData metaData, String schemaName) { List<DbTableMeta> result = new ArrayList<DbTableMeta>(); try { ResultSet rs = metaData.getTables(null, schemaName, null, new String[] { "TABLE" }); try { while (rs.next()) { DbTableMeta dbTableMeta = new DbTableMeta(); dbTableMeta.setCatalogName(rs.getString("TABLE_CAT")); dbTableMeta.setSchemaName(rs.getString("TABLE_SCHEM")); dbTableMeta.setName(rs.getString("TABLE_NAME")); if (readComment) { dbTableMeta.setComment(rs.getString("REMARKS")); } if (isTargetTable(dbTableMeta)) { result.add(dbTableMeta); } } return result; } finally { ResultSetUtil.close(rs); } } catch (SQLException e) { throw new SQLRuntimeException(e); } } }
DbTableMetaReaderImpl implements DbTableMetaReader { protected List<DbTableMeta> getDbTableMetaList(DatabaseMetaData metaData, String schemaName) { List<DbTableMeta> result = new ArrayList<DbTableMeta>(); try { ResultSet rs = metaData.getTables(null, schemaName, null, new String[] { "TABLE" }); try { while (rs.next()) { DbTableMeta dbTableMeta = new DbTableMeta(); dbTableMeta.setCatalogName(rs.getString("TABLE_CAT")); dbTableMeta.setSchemaName(rs.getString("TABLE_SCHEM")); dbTableMeta.setName(rs.getString("TABLE_NAME")); if (readComment) { dbTableMeta.setComment(rs.getString("REMARKS")); } if (isTargetTable(dbTableMeta)) { result.add(dbTableMeta); } } return result; } finally { ResultSetUtil.close(rs); } } catch (SQLException e) { throw new SQLRuntimeException(e); } } DbTableMetaReaderImpl(DataSource dataSource, GenDialect dialect,
            String schemaName, String tableNamePattern,
            String ignoreTableNamePattern, boolean readComment); }
DbTableMetaReaderImpl implements DbTableMetaReader { protected List<DbTableMeta> getDbTableMetaList(DatabaseMetaData metaData, String schemaName) { List<DbTableMeta> result = new ArrayList<DbTableMeta>(); try { ResultSet rs = metaData.getTables(null, schemaName, null, new String[] { "TABLE" }); try { while (rs.next()) { DbTableMeta dbTableMeta = new DbTableMeta(); dbTableMeta.setCatalogName(rs.getString("TABLE_CAT")); dbTableMeta.setSchemaName(rs.getString("TABLE_SCHEM")); dbTableMeta.setName(rs.getString("TABLE_NAME")); if (readComment) { dbTableMeta.setComment(rs.getString("REMARKS")); } if (isTargetTable(dbTableMeta)) { result.add(dbTableMeta); } } return result; } finally { ResultSetUtil.close(rs); } } catch (SQLException e) { throw new SQLRuntimeException(e); } } DbTableMetaReaderImpl(DataSource dataSource, GenDialect dialect,
            String schemaName, String tableNamePattern,
            String ignoreTableNamePattern, boolean readComment); List<DbTableMeta> read(); }
DbTableMetaReaderImpl implements DbTableMetaReader { protected List<DbTableMeta> getDbTableMetaList(DatabaseMetaData metaData, String schemaName) { List<DbTableMeta> result = new ArrayList<DbTableMeta>(); try { ResultSet rs = metaData.getTables(null, schemaName, null, new String[] { "TABLE" }); try { while (rs.next()) { DbTableMeta dbTableMeta = new DbTableMeta(); dbTableMeta.setCatalogName(rs.getString("TABLE_CAT")); dbTableMeta.setSchemaName(rs.getString("TABLE_SCHEM")); dbTableMeta.setName(rs.getString("TABLE_NAME")); if (readComment) { dbTableMeta.setComment(rs.getString("REMARKS")); } if (isTargetTable(dbTableMeta)) { result.add(dbTableMeta); } } return result; } finally { ResultSetUtil.close(rs); } } catch (SQLException e) { throw new SQLRuntimeException(e); } } DbTableMetaReaderImpl(DataSource dataSource, GenDialect dialect,
            String schemaName, String tableNamePattern,
            String ignoreTableNamePattern, boolean readComment); List<DbTableMeta> read();  }