private void loadIndexes(Table table, DatabaseMetaData metaData) throws MetaModelException { Schema schema = table.getSchema(); // Ticket #170: IndexInfo is nice-to-have, not need-to-have, so // we will do a nice failover on SQLExceptions try (ResultSet rs = metaData.getIndexInfo(getCatalogName(schema), getJdbcSchemaName(schema), table.getName(), false, true)) { while (rs.next()) { String columnName = rs.getString(9); if (columnName != null) { MutableColumn column = (MutableColumn) table.getColumnByName(columnName); if (column != null) { column.setIndexed(true); } else { logger.error("Indexed column \"{}\" could not be found in table: {}", columnName, table); } } } } catch (SQLException e) { throw JdbcUtils.wrapException(e, "retrieve index information for " + table.getName(), JdbcActionType.METADATA); } }
public MutableColumn(String name, ColumnType type, Table table, int columnNumber, Integer columnSize, String nativeType, Boolean nullable, String remarks, boolean indexed, String quote) { this(name, type, table, columnNumber, nullable); setColumnSize(columnSize); setNativeType(nativeType); setRemarks(remarks); setIndexed(indexed); setQuote(quote); }
public MutableColumn(String name, ColumnType type, Table table, int columnNumber, Integer columnSize, String nativeType, Boolean nullable, String remarks, boolean indexed, String quote) { this(name, type, table, columnNumber, nullable); setColumnSize(columnSize); setNativeType(nativeType); setRemarks(remarks); setIndexed(indexed); setQuote(quote); }
private void loadIndexes(Table table, DatabaseMetaData metaData) throws MetaModelException { Schema schema = table.getSchema(); // Ticket #170: IndexInfo is nice-to-have, not need-to-have, so // we will do a nice failover on SQLExceptions try (ResultSet rs = metaData.getIndexInfo(getCatalogName(schema), getJdbcSchemaName(schema), table.getName(), false, true)) { while (rs.next()) { String columnName = rs.getString(9); if (columnName != null) { MutableColumn column = (MutableColumn) table.getColumnByName(columnName); if (column != null) { column.setIndexed(true); } else { logger.error("Indexed column \"{}\" could not be found in table: {}", columnName, table); } } } } catch (SQLException e) { throw JdbcUtils.wrapException(e, "retrieve index information for " + table.getName(), JdbcActionType.METADATA); } }
private MutableColumn getIdColumn(MutableTable table) { MutableColumn column = null; for (Column col : table.getColumns()) { if (NATIVE_TYPE_PRIMARY_KEY.equals(col.getNativeType())) { column = (MutableColumn) col; break; } } if (column == null) { String tableName = table.getName(); logger.info("Creating id column for table: " + tableName); column = new MutableColumn(tableName + "_metamodel_surrogate_id", ColumnType.INTEGER, table, table .getColumnCount(), false); column.setNativeType(NATIVE_TYPE_PRIMARY_KEY); column.setIndexed(true); table.addColumn(column); } return column; }
MutableColumn newPrimaryColumn = new MutableColumn(foreignColumn.getName(), foreignColumn.getType(), primaryTable, primaryTable.getColumnCount(), foreignColumn.isNullable()); newPrimaryColumn.setIndexed(foreignColumn.isIndexed()); newPrimaryColumn.setNativeType(foreignColumn.getNativeType()); primaryTable.addColumn(newPrimaryColumn);
column.setIndexed(true); column.setNativeType(attributeType);