private static Column findColumn(PrimaryKeyColumn pkc) { requireNonNull(pkc); return pkc.findColumn() .orElseThrow(() -> new SpeedmentException( "Cannot find column for " + pkc )); }
private Stream<Column> columnsFromPks() { return primaryKeyColumns().map(pk -> { try { return pk.findColumn().get(); } catch (final NoSuchElementException ex) { throw new SpeedmentTranslatorException( "Could not find any column belonging to primary key '" + pk.getId() + "'.", ex ); } }); } }
ImmutablePrimaryKeyColumn(ImmutableTable parent, Map<String, Object> pkc) { super(parent, pkc); final PrimaryKeyColumn prototype = new PrimaryKeyColumnImpl(parent, pkc); this.id = prototype.getId(); this.name = prototype.getName(); this.ordinalPosition = prototype.getOrdinalPosition(); this.column = LazyReference.create(); }
/** * Returns {@code true} if the two specified documents represents the same * element in the database. Two documents are considered same if they have * the same name and type and their parents are considered same. * * @param first the first document * @param second the second document * @return {@code true} if same, else {@code false} */ public static boolean isSame(PrimaryKeyColumn first, PrimaryKeyColumn second) { if (first.getId().equals(second.getId())) { final Table firstParent = first.getParentOrThrow(); final Table secondParent = second.getParentOrThrow(); return isSame(firstParent, secondParent); } else { return false; } }
.noneMatch(col -> table.primaryKeyColumns().anyMatch(pkc -> DocumentDbUtil.isSame(pkc.findColumn().get(), col))) && table.columns().map(Column::getId).noneMatch("rowid"::equalsIgnoreCase)) { final Column column = table.mutator().addNewColumn(); final int ordNo = 1 + (int) pkReplacement.indexColumns().count(); final IndexColumn idxCol = mutator.addNewIndexColumn(); idxCol.mutator().setId(pkc.getId()); idxCol.mutator().setName(pkc.getName()); idxCol.mutator().setOrdinalPosition(ordNo); }); pkc.mutator().setId("rowid"); pkc.mutator().setName("rowid"); pkc.mutator().setOrdinalPosition(1); } else { table.columns() .filter(col -> col.getAsString(ORIGINAL_TYPE).filter("INTEGER"::equalsIgnoreCase).isPresent()) .filter(col -> table.primaryKeyColumns().anyMatch(pkc -> DocumentDbUtil.isSame(pkc.findColumn().get(), col))) .forEach(col -> col.mutator().setAutoIncrement(true));
/** * Locate the {@link PrimaryKeyColumn} child with the specified id if it * exists, else return an empty {@code Optional}. * * @param id the {@link HasId#getId()} of the primary key column * @return the child found or an empty {@code Optional} */ default Optional<? extends PrimaryKeyColumn> findPrimaryKeyColumn(String id) { return primaryKeyColumns().filter(child -> child.getId().equals(id)).findAny(); }
private void primaryKeyColumns(Connection conn, Table table, ProgressMeasure progress) { requireNonNulls(conn, table, progress); final SqlSupplier<ResultSet> supplier = () -> conn.getMetaData().getPrimaryKeys(null, null, table.getId()); final TableChildMutator<PrimaryKeyColumn> mutator = (pkc, rs) -> { final String columnName = rs.getString("COLUMN_NAME"); pkc.mutator().setId(columnName); pkc.mutator().setName(columnName); pkc.mutator().setOrdinalPosition(rs.getInt("KEY_SEQ")); }; tableChilds( table, PrimaryKeyColumn.class, table.mutator()::addNewPrimaryKeyColumn, supplier, rsChild -> rsChild.getString("COLUMN_NAME"), mutator ); if (!table.isView() && table.primaryKeyColumns().noneMatch(pk -> true)) { LOGGER.warn(format("Table '%s' does not have any primary key.", table.getId())); } }
.noneMatch(col -> table.primaryKeyColumns().anyMatch(pkc -> DocumentDbUtil.isSame(pkc.findColumn().get(), col))) && table.columns().map(Column::getId).noneMatch("rowid"::equalsIgnoreCase)) { final Column column = table.mutator().addNewColumn(); final int ordNo = 1 + (int) pkReplacement.indexColumns().count(); final IndexColumn idxCol = mutator.addNewIndexColumn(); idxCol.mutator().setId(pkc.getId()); idxCol.mutator().setName(pkc.getName()); idxCol.mutator().setOrdinalPosition(ordNo); }); pkc.mutator().setId("rowid"); pkc.mutator().setName("rowid"); pkc.mutator().setOrdinalPosition(1); } else { table.columns() .filter(col -> col.getAsString(ORIGINAL_TYPE).filter("INTEGER"::equalsIgnoreCase).isPresent()) .filter(col -> table.primaryKeyColumns().anyMatch(pkc -> DocumentDbUtil.isSame(pkc.findColumn().get(), col))) .forEach(col -> col.mutator().setAutoIncrement(true));
protected void primaryKeyColumns(Connection connection, Table table, ProgressMeasure progressListener) { requireNonNulls(connection, table); final Schema schema = table.getParentOrThrow(); final SqlSupplier<ResultSet> supplier = () -> connection.getMetaData().getPrimaryKeys(jdbcCatalogLookupName(schema), jdbcSchemaLookupName(schema), metaDataTableNameForPrimaryKeys(table) ); final AbstractDbmsOperationHandler.TableChildMutator<PrimaryKeyColumn, ResultSet> mutator = (primaryKeyColumn, rs) -> { final String columnName = rs.getString("COLUMN_NAME"); primaryKeyColumn.mutator().setId(columnName); primaryKeyColumn.mutator().setName(columnName); primaryKeyColumn.mutator().setOrdinalPosition(rs.getInt("KEY_SEQ")); }; tableChilds(PrimaryKeyColumn.class, table.mutator()::addNewPrimaryKeyColumn, supplier, mutator, progressListener); if (!table.isView() && table.primaryKeyColumns().noneMatch(pk -> true)) { LOGGER.warn("Table '" + table.getId() + "' does not have any primary key."); } }
private Column findColumn(PrimaryKeyColumn pkc) { return pkc.findColumn() .orElseThrow(() -> new SpeedmentException( "Cannot find column for " + pkc )); }
private void primaryKeyColumns(Connection conn, Table table, ProgressMeasure progress) { requireNonNulls(conn, table, progress); final SqlSupplier<ResultSet> supplier = () -> conn.getMetaData().getPrimaryKeys(null, null, table.getId()); final TableChildMutator<PrimaryKeyColumn> mutator = (pkc, rs) -> { final String columnName = rs.getString("COLUMN_NAME"); pkc.mutator().setId(columnName); pkc.mutator().setName(columnName); pkc.mutator().setOrdinalPosition(rs.getInt("KEY_SEQ")); }; tableChilds( table, PrimaryKeyColumn.class, table.mutator()::addNewPrimaryKeyColumn, supplier, rsChild -> rsChild.getString("COLUMN_NAME"), mutator ); if (!table.isView() && table.primaryKeyColumns().noneMatch(pk -> true)) { LOGGER.warn(format("Table '%s' does not have any primary key.", table.getId())); } }
@Override public Optional<ImmutableColumn> findColumn() { return column.getOrCompute(() -> PrimaryKeyColumn.super.findColumn() .map(ImmutableColumn.class::cast) ); }
protected void primaryKeyColumns(Connection connection, Table table, ProgressMeasure progressListener) { requireNonNulls(connection, table); final Schema schema = table.getParentOrThrow(); final SqlSupplier<ResultSet> supplier = () -> connection.getMetaData().getPrimaryKeys(jdbcCatalogLookupName(schema), jdbcSchemaLookupName(schema), metaDataTableNameForPrimaryKeys(table) ); final AbstractDbmsOperationHandler.TableChildMutator<PrimaryKeyColumn, ResultSet> mutator = (primaryKeyColumn, rs) -> { final String columnName = rs.getString("COLUMN_NAME"); primaryKeyColumn.mutator().setId(columnName); primaryKeyColumn.mutator().setName(columnName); primaryKeyColumn.mutator().setOrdinalPosition(rs.getInt("KEY_SEQ")); }; tableChilds(PrimaryKeyColumn.class, table.mutator()::addNewPrimaryKeyColumn, supplier, mutator, progressListener); if (!table.isView() && table.primaryKeyColumns().noneMatch(pk -> true)) { LOGGER.warn("Table '" + table.getId() + "' does not have any primary key."); } }
private Column findColumn(PrimaryKeyColumn pkc) { return pkc.findColumn() .orElseThrow(() -> new SpeedmentException( "Cannot find column for " + pkc )); }
/** * Returns the full name used in the database for the specified * {@link PrimaryKeyColumn}. This is typically constructed by combining the * table and the column name with a separator, but that might be different * in different implementations. * * @param pkc the primary key column to retrieve the name of * @return the full name */ default String fullNameOf(PrimaryKeyColumn pkc) { return fullNameOf(pkc.findColumn().orElseThrow(() -> new SpeedmentException("Cannot find column for " + pkc))); }
private static Column findColumn(PrimaryKeyColumn pkc) { requireNonNull(pkc); return pkc.findColumn() .orElseThrow(() -> new SpeedmentException( "Cannot find column for " + pkc )); }
private Column findColumn(PrimaryKeyColumn pkc) { return pkc.findColumn() .orElseThrow(() -> new SpeedmentException( "Cannot find column for " + pkc )); }
private Column findColumn(PrimaryKeyColumn pkc) { return pkc.findColumn() .orElseThrow(() -> new SpeedmentException( "Cannot find column for " + pkc )); }
/** * Returns the full name used in the database for the specified * {@link PrimaryKeyColumn}. This is typically constructed by combining the * table and the column name with a separator, but that might be different * in different implementations. * * @param pkc the primary key column to retrieve the name of * @return the full name */ default String fullNameOf(PrimaryKeyColumn pkc) { return fullNameOf(pkc.findColumn().orElseThrow(() -> new SpeedmentException("Cannot find column for " + pkc))); }