@Test public void testGetDbUniqueKeyMetaList() throws Exception { final MockResultSet resultSet = new MockResultSet(); ArrayMap rowData = new ArrayMap(); rowData.put("INDEX_NAME", "hoge"); rowData.put("COLUMN_NAME", "aaa"); resultSet.addRowData(rowData); rowData = new ArrayMap(); rowData.put("INDEX_NAME", "hoge"); rowData.put("COLUMN_NAME", "bbb"); resultSet.addRowData(rowData); rowData = new ArrayMap(); rowData.put("INDEX_NAME", "foo"); rowData.put("COLUMN_NAME", "ccc"); resultSet.addRowData(rowData); GenMockDatabaseMetaData metaData = new GenMockDatabaseMetaData() { @Override public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException { return resultSet; } }; DbTableMetaReaderImpl reader = new DbTableMetaReaderImpl( new MockDataSource(), new StandardGenDialect(), null, ".*", "", false); List<DbUniqueKeyMeta> list = reader.getDbUniqueKeyMetaList(metaData, new DbTableMeta()); assertEquals(2, list.size()); DbUniqueKeyMeta ukMeta = list.get(0); assertEquals("hoge", ukMeta.getName()); assertEquals(2, ukMeta.getColumnNameList().size()); assertEquals("aaa", ukMeta.getColumnNameList().get(0)); assertEquals("bbb", ukMeta.getColumnNameList().get(1)); ukMeta = list.get(1); assertEquals("foo", ukMeta.getName()); assertEquals(1, ukMeta.getColumnNameList().size()); assertEquals("ccc", ukMeta.getColumnNameList().get(0)); }
protected List<DbUniqueKeyMeta> getDbUniqueKeyMetaList( DatabaseMetaData metaData, DbTableMeta tableMeta) { if (!dialect.supportsGetIndexInfo(tableMeta.getCatalogName(), tableMeta .getSchemaName(), tableMeta.getName())) { logger.log("WS2JDBCGen0002", new Object[] { tableMeta.getCatalogName(), tableMeta.getSchemaName(), tableMeta.getName() }); return Collections.emptyList(); } @SuppressWarnings("unchecked") Map<String, DbUniqueKeyMeta> map = new ArrayMap(); try { ResultSet rs = metaData .getIndexInfo(tableMeta.getCatalogName(), tableMeta .getSchemaName(), tableMeta.getName(), true, false); try { while (rs.next()) { String name = rs.getString("INDEX_NAME"); if (!map.containsKey(name)) { DbUniqueKeyMeta ukMeta = new DbUniqueKeyMeta(); ukMeta.setName(name); map.put(name, ukMeta); } DbUniqueKeyMeta ukMeta = map.get(name); ukMeta.addColumnName(rs.getString("COLUMN_NAME")); } } finally { ResultSetUtil.close(rs); } DbUniqueKeyMeta[] array = map.values().toArray( new DbUniqueKeyMeta[map.size()]); return Arrays.asList(array); } catch (SQLException ex) { throw new SQLRuntimeException(ex); } }
DbTableMetaReaderImpl implements DbTableMetaReader { protected List<DbUniqueKeyMeta> getDbUniqueKeyMetaList( DatabaseMetaData metaData, DbTableMeta tableMeta) { if (!dialect.supportsGetIndexInfo(tableMeta.getCatalogName(), tableMeta .getSchemaName(), tableMeta.getName())) { logger.log("WS2JDBCGen0002", new Object[] { tableMeta.getCatalogName(), tableMeta.getSchemaName(), tableMeta.getName() }); return Collections.emptyList(); } @SuppressWarnings("unchecked") Map<String, DbUniqueKeyMeta> map = new ArrayMap(); try { ResultSet rs = metaData .getIndexInfo(tableMeta.getCatalogName(), tableMeta .getSchemaName(), tableMeta.getName(), true, false); try { while (rs.next()) { String name = rs.getString("INDEX_NAME"); if (!map.containsKey(name)) { DbUniqueKeyMeta ukMeta = new DbUniqueKeyMeta(); ukMeta.setName(name); map.put(name, ukMeta); } DbUniqueKeyMeta ukMeta = map.get(name); ukMeta.addColumnName(rs.getString("COLUMN_NAME")); } } finally { ResultSetUtil.close(rs); } DbUniqueKeyMeta[] array = map.values().toArray( new DbUniqueKeyMeta[map.size()]); return Arrays.asList(array); } catch (SQLException ex) { throw new SQLRuntimeException(ex); } } }
DbTableMetaReaderImpl implements DbTableMetaReader { protected List<DbUniqueKeyMeta> getDbUniqueKeyMetaList( DatabaseMetaData metaData, DbTableMeta tableMeta) { if (!dialect.supportsGetIndexInfo(tableMeta.getCatalogName(), tableMeta .getSchemaName(), tableMeta.getName())) { logger.log("WS2JDBCGen0002", new Object[] { tableMeta.getCatalogName(), tableMeta.getSchemaName(), tableMeta.getName() }); return Collections.emptyList(); } @SuppressWarnings("unchecked") Map<String, DbUniqueKeyMeta> map = new ArrayMap(); try { ResultSet rs = metaData .getIndexInfo(tableMeta.getCatalogName(), tableMeta .getSchemaName(), tableMeta.getName(), true, false); try { while (rs.next()) { String name = rs.getString("INDEX_NAME"); if (!map.containsKey(name)) { DbUniqueKeyMeta ukMeta = new DbUniqueKeyMeta(); ukMeta.setName(name); map.put(name, ukMeta); } DbUniqueKeyMeta ukMeta = map.get(name); ukMeta.addColumnName(rs.getString("COLUMN_NAME")); } } finally { ResultSetUtil.close(rs); } DbUniqueKeyMeta[] array = map.values().toArray( new DbUniqueKeyMeta[map.size()]); return Arrays.asList(array); } catch (SQLException ex) { throw new SQLRuntimeException(ex); } } DbTableMetaReaderImpl(DataSource dataSource, GenDialect dialect,
            String schemaName, String tableNamePattern,
            String ignoreTableNamePattern, boolean readComment); }
DbTableMetaReaderImpl implements DbTableMetaReader { protected List<DbUniqueKeyMeta> getDbUniqueKeyMetaList( DatabaseMetaData metaData, DbTableMeta tableMeta) { if (!dialect.supportsGetIndexInfo(tableMeta.getCatalogName(), tableMeta .getSchemaName(), tableMeta.getName())) { logger.log("WS2JDBCGen0002", new Object[] { tableMeta.getCatalogName(), tableMeta.getSchemaName(), tableMeta.getName() }); return Collections.emptyList(); } @SuppressWarnings("unchecked") Map<String, DbUniqueKeyMeta> map = new ArrayMap(); try { ResultSet rs = metaData .getIndexInfo(tableMeta.getCatalogName(), tableMeta .getSchemaName(), tableMeta.getName(), true, false); try { while (rs.next()) { String name = rs.getString("INDEX_NAME"); if (!map.containsKey(name)) { DbUniqueKeyMeta ukMeta = new DbUniqueKeyMeta(); ukMeta.setName(name); map.put(name, ukMeta); } DbUniqueKeyMeta ukMeta = map.get(name); ukMeta.addColumnName(rs.getString("COLUMN_NAME")); } } finally { ResultSetUtil.close(rs); } DbUniqueKeyMeta[] array = map.values().toArray( new DbUniqueKeyMeta[map.size()]); return Arrays.asList(array); } 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 List<DbUniqueKeyMeta> getDbUniqueKeyMetaList( DatabaseMetaData metaData, DbTableMeta tableMeta) { if (!dialect.supportsGetIndexInfo(tableMeta.getCatalogName(), tableMeta .getSchemaName(), tableMeta.getName())) { logger.log("WS2JDBCGen0002", new Object[] { tableMeta.getCatalogName(), tableMeta.getSchemaName(), tableMeta.getName() }); return Collections.emptyList(); } @SuppressWarnings("unchecked") Map<String, DbUniqueKeyMeta> map = new ArrayMap(); try { ResultSet rs = metaData .getIndexInfo(tableMeta.getCatalogName(), tableMeta .getSchemaName(), tableMeta.getName(), true, false); try { while (rs.next()) { String name = rs.getString("INDEX_NAME"); if (!map.containsKey(name)) { DbUniqueKeyMeta ukMeta = new DbUniqueKeyMeta(); ukMeta.setName(name); map.put(name, ukMeta); } DbUniqueKeyMeta ukMeta = map.get(name); ukMeta.addColumnName(rs.getString("COLUMN_NAME")); } } finally { ResultSetUtil.close(rs); } DbUniqueKeyMeta[] array = map.values().toArray( new DbUniqueKeyMeta[map.size()]); return Arrays.asList(array); } catch (SQLException ex) { throw new SQLRuntimeException(ex); } } DbTableMetaReaderImpl(DataSource dataSource, GenDialect dialect,
            String schemaName, String tableNamePattern,
            String ignoreTableNamePattern, boolean readComment); List<DbTableMeta> read();  }