Skip to content

Commit

Permalink
Remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
mfvanek committed Dec 9, 2024
1 parent fd91998 commit 825f13c
Showing 1 changed file with 1 addition and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@
import io.github.mfvanek.pg.model.column.Column;
import io.github.mfvanek.pg.model.column.ColumnWithSerialType;
import io.github.mfvanek.pg.model.column.SerialType;
import io.github.mfvanek.pg.model.context.PgContext;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Locale;
import javax.annotation.Nonnull;

public class ColumnWithSerialTypeExtractor implements ResultSetExtractor<ColumnWithSerialType> {

private static final String PUBLIC_SCHEMA_PREFIX = PgContext.DEFAULT_SCHEMA_NAME + '.';

private final ResultSetExtractor<Column> columnExtractor;

private ColumnWithSerialTypeExtractor() {
Expand All @@ -40,20 +36,7 @@ public ColumnWithSerialType extractData(@Nonnull final ResultSet resultSet) thro
final Column column = columnExtractor.extractData(resultSet);
final String columnType = resultSet.getString("column_type");
final String sequenceName = resultSet.getString("sequence_name");
return ColumnWithSerialType.of(column, SerialType.valueFrom(columnType), normalizeSequenceName(sequenceName));
}

// Issue here is that pg_catalog.pg_sequence.seqrelid::regclass returns sequence name without 'public' schema prefix
// but function 'pg_get_serial_sequence' does.
//
// See https://www.postgresql.org/docs/current/catalog-pg-sequence.html
// See https://www.postgresql.org/docs/current/functions-info.html
@Nonnull
private static String normalizeSequenceName(@Nonnull final String sequenceName) {
if (sequenceName.toLowerCase(Locale.ROOT).startsWith(PUBLIC_SCHEMA_PREFIX)) {
return sequenceName.substring(PUBLIC_SCHEMA_PREFIX.length());
}
return sequenceName;
return ColumnWithSerialType.of(column, SerialType.valueFrom(columnType), sequenceName);
}

/**
Expand Down

0 comments on commit 825f13c

Please sign in to comment.