@Test public void testGetPrimaryKeySet() throws Exception { final MockResultSet resultSet = new MockResultSet(); ArrayMap rowData = new ArrayMap(); rowData.put("COLUMN_NAME", "pk1"); resultSet.addRowData(rowData); rowData = new ArrayMap(); rowData.put("COLUMN_NAME", "pk2"); resultSet.addRowData(rowData); GenMockDatabaseMetaData metaData = new GenMockDatabaseMetaData() { @Override public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { return resultSet; } }; DbTableMetaReaderImpl reader = new DbTableMetaReaderImpl( new MockDataSource(), new StandardGenDialect(), "schemaName", ".*", "", false); Set<String> list = reader.getPrimaryKeySet(metaData, new DbTableMeta()); assertEquals(2, list.size()); assertTrue(list.contains("pk1")); assertTrue(list.contains("pk2")); }
protected Set<String> getPrimaryKeySet(DatabaseMetaData metaData, DbTableMeta tableMeta) { Set<String> result = new HashSet<String>(); try { ResultSet rs = metaData.getPrimaryKeys(tableMeta.getCatalogName(), tableMeta.getSchemaName(), tableMeta.getName()); try { while (rs.next()) { result.add(rs.getString("COLUMN_NAME")); } } finally { ResultSetUtil.close(rs); } return result; } catch (SQLException ex) { throw new SQLRuntimeException(ex); } }
DbTableMetaReaderImpl implements DbTableMetaReader { protected Set<String> getPrimaryKeySet(DatabaseMetaData metaData, DbTableMeta tableMeta) { Set<String> result = new HashSet<String>(); try { ResultSet rs = metaData.getPrimaryKeys(tableMeta.getCatalogName(), tableMeta.getSchemaName(), tableMeta.getName()); try { while (rs.next()) { result.add(rs.getString("COLUMN_NAME")); } } finally { ResultSetUtil.close(rs); } return result; } catch (SQLException ex) { throw new SQLRuntimeException(ex); } } }
DbTableMetaReaderImpl implements DbTableMetaReader { protected Set<String> getPrimaryKeySet(DatabaseMetaData metaData, DbTableMeta tableMeta) { Set<String> result = new HashSet<String>(); try { ResultSet rs = metaData.getPrimaryKeys(tableMeta.getCatalogName(), tableMeta.getSchemaName(), tableMeta.getName()); try { while (rs.next()) { result.add(rs.getString("COLUMN_NAME")); } } finally { ResultSetUtil.close(rs); } return result; } catch (SQLException ex) { throw new SQLRuntimeException(ex); } } DbTableMetaReaderImpl(DataSource dataSource, GenDialect dialect,
            String schemaName, String tableNamePattern,
            String ignoreTableNamePattern, boolean readComment); }
DbTableMetaReaderImpl implements DbTableMetaReader { protected Set<String> getPrimaryKeySet(DatabaseMetaData metaData, DbTableMeta tableMeta) { Set<String> result = new HashSet<String>(); try { ResultSet rs = metaData.getPrimaryKeys(tableMeta.getCatalogName(), tableMeta.getSchemaName(), tableMeta.getName()); try { while (rs.next()) { result.add(rs.getString("COLUMN_NAME")); } } finally { ResultSetUtil.close(rs); } return result; } catch (SQLException ex) { throw new SQLRuntimeException(ex); } } DbTableMetaReaderImpl(DataSource dataSource, GenDialect dialect,
            String schemaName, String tableNamePattern,
            String ignoreTableNamePattern, boolean readComment); List<DbTableMeta> read(); }
DbTableMetaReaderImpl implements DbTableMetaReader { protected Set<String> getPrimaryKeySet(DatabaseMetaData metaData, DbTableMeta tableMeta) { Set<String> result = new HashSet<String>(); try { ResultSet rs = metaData.getPrimaryKeys(tableMeta.getCatalogName(), tableMeta.getSchemaName(), tableMeta.getName()); try { while (rs.next()) { result.add(rs.getString("COLUMN_NAME")); } } finally { ResultSetUtil.close(rs); } return result; } catch (SQLException ex) { throw new SQLRuntimeException(ex); } } DbTableMetaReaderImpl(DataSource dataSource, GenDialect dialect,
            String schemaName, String tableNamePattern,
            String ignoreTableNamePattern, boolean readComment); List<DbTableMeta> read();  }