diff --git a/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/InsertAlbum.java b/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/InsertAlbum.java index d6aff0e..c10563c 100644 --- a/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/InsertAlbum.java +++ b/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/InsertAlbum.java @@ -32,22 +32,96 @@ * @param format Maps to {@code $format} in the template. Nullable. * @param recording Maps to {@code $recording} in the template. Nullable. */ -public record InsertAlbum( - String name, - LocalDate released, - AlbumFormat format, - RecordingInfo recording - ) implements Statement { +public final class InsertAlbum implements Statement { + + private final String name; + private final LocalDate released; + private final AlbumFormat format; + private final RecordingInfo recording; + + public InsertAlbum(String name, LocalDate released, AlbumFormat format, RecordingInfo recording) { + this.name = name; + this.released = released; + this.format = format; + this.recording = recording; + } + + public String name() { + return name; + } + + public LocalDate released() { + return released; + } + + public AlbumFormat format() { + return format; + } + + public RecordingInfo recording() { + return recording; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof InsertAlbum)) return false; + InsertAlbum that = (InsertAlbum) o; + return java.util.Objects.equals(name, that.name) && + java.util.Objects.equals(released, that.released) && + java.util.Objects.equals(format, that.format) && + java.util.Objects.equals(recording, that.recording); + } + + @Override + public int hashCode() { + return java.util.Objects.hash(name, released, format, recording); + } + + @Override + public String toString() { + return "InsertAlbum[name=" + name + + ", released=" + released + + ", format=" + format + + ", recording=" + recording + "]"; + } // ------------------------------------------------------------------------- // Result type // ------------------------------------------------------------------------- /** Result of the statement parameterised by {@link Input}. */ - public record Output( - /** Maps to the {@code id} result-set column. */ - long id - ) {} + public static final class Output { + + private final long id; + + Output(long id) { + this.id = id; + } + + /** Maps to the {@code id} result-set column. */ + public long id() { + return id; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Output)) return false; + Output that = (Output) o; + return id == that.id; + } + + @Override + public int hashCode() { + return java.util.Objects.hash(id); + } + + @Override + public String toString() { + return "Output[id=" + id + "]"; + } + } // ------------------------------------------------------------------------- // Statement implementation diff --git a/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/SelectAlbumByFormat.java b/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/SelectAlbumByFormat.java index 132040b..e9678eb 100644 --- a/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/SelectAlbumByFormat.java +++ b/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/SelectAlbumByFormat.java @@ -35,8 +35,36 @@ * * @param format Maps to {@code $format} in the template. Nullable. */ -public record SelectAlbumByFormat(AlbumFormat format) - implements Statement { +public final class SelectAlbumByFormat implements Statement { + + private final AlbumFormat format; + + public SelectAlbumByFormat(AlbumFormat format) { + this.format = format; + } + + public AlbumFormat format() { + return format; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SelectAlbumByFormat)) return false; + SelectAlbumByFormat that = (SelectAlbumByFormat) o; + return java.util.Objects.equals(format, that.format); + } + + @Override + public int hashCode() { + return java.util.Objects.hash(format); + } + + @Override + public String toString() { + return "SelectAlbumByFormat[format=" + format + "]"; + } + // ------------------------------------------------------------------------- // Result type @@ -50,18 +78,60 @@ public static final class Output extends ArrayList { } /** Row of {@link Output}. */ - public record OutputRow( - /** Maps to the {@code id} result-set column. */ - long id, - /** Maps to the {@code name} result-set column. */ - String name, - /** Maps to the {@code released} result-set column. Nullable. */ - LocalDate released, - /** Maps to the {@code format} result-set column. Nullable. */ - AlbumFormat format, - /** Maps to the {@code recording} result-set column. Nullable. */ - RecordingInfo recording - ) {} + public static final class OutputRow { + + private final long id; + private final String name; + private final LocalDate released; + private final AlbumFormat format; + private final RecordingInfo recording; + + OutputRow(long id, String name, LocalDate released, AlbumFormat format, RecordingInfo recording) { + this.id = id; + this.name = name; + this.released = released; + this.format = format; + this.recording = recording; + } + + /** Maps to the {@code id} result-set column. */ + public long id() { return id; } + /** Maps to the {@code name} result-set column. */ + public String name() { return name; } + /** Maps to the {@code released} result-set column. Nullable. */ + public LocalDate released() { return released; } + /** Maps to the {@code format} result-set column. Nullable. */ + public AlbumFormat format() { return format; } + /** Maps to the {@code recording} result-set column. Nullable. */ + public RecordingInfo recording() { return recording; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof OutputRow)) return false; + OutputRow that = (OutputRow) o; + return id == that.id && + java.util.Objects.equals(name, that.name) && + java.util.Objects.equals(released, that.released) && + java.util.Objects.equals(format, that.format) && + java.util.Objects.equals(recording, that.recording); + } + + @Override + public int hashCode() { + return java.util.Objects.hash(id, name, released, format, recording); + } + + @Override + public String toString() { + return "OutputRow[id=" + id + + ", name=" + name + + ", released=" + released + + ", format=" + format + + ", recording=" + recording + "]"; + } + } + // ------------------------------------------------------------------------- // Statement implementation diff --git a/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/SelectGenreByArtist.java b/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/SelectGenreByArtist.java index 441dc48..8516367 100644 --- a/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/SelectGenreByArtist.java +++ b/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/SelectGenreByArtist.java @@ -29,8 +29,36 @@ * * @param artist Maps to {@code $artist} in the template. Nullable. */ -public record SelectGenreByArtist(Integer artist) - implements Statement { +public final class SelectGenreByArtist implements Statement { + + private final Integer artist; + + public SelectGenreByArtist(Integer artist) { + this.artist = artist; + } + + public Integer artist() { + return artist; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SelectGenreByArtist)) return false; + SelectGenreByArtist that = (SelectGenreByArtist) o; + return java.util.Objects.equals(artist, that.artist); + } + + @Override + public int hashCode() { + return java.util.Objects.hash(artist); + } + + @Override + public String toString() { + return "SelectGenreByArtist[artist=" + artist + "]"; + } + // ------------------------------------------------------------------------- // Result type @@ -44,12 +72,40 @@ public static final class Output extends ArrayList { } /** Row of {@link Output}. */ - public record OutputRow( - /** Maps to the {@code id} result-set column. */ - int id, - /** Maps to the {@code name} result-set column. */ - String name - ) {} + public static final class OutputRow { + + private final int id; + private final String name; + + OutputRow(int id, String name) { + this.id = id; + this.name = name; + } + + /** Maps to the {@code id} result-set column. */ + public int id() { return id; } + /** Maps to the {@code name} result-set column. */ + public String name() { return name; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof OutputRow)) return false; + OutputRow that = (OutputRow) o; + return id == that.id && java.util.Objects.equals(name, that.name); + } + + @Override + public int hashCode() { + return java.util.Objects.hash(id, name); + } + + @Override + public String toString() { + return "OutputRow[id=" + id + ", name=" + name + "]"; + } + } + // ------------------------------------------------------------------------- // Statement implementation diff --git a/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/UpdateAlbumRecordingReturning.java b/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/UpdateAlbumRecordingReturning.java index 4c1b0f9..262f09c 100644 --- a/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/UpdateAlbumRecordingReturning.java +++ b/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/UpdateAlbumRecordingReturning.java @@ -34,9 +34,46 @@ * @param recording Maps to {@code $recording} in the template. Nullable. * @param id Maps to {@code $id} in the template. Nullable. */ -public record UpdateAlbumRecordingReturning(RecordingInfo recording, Long id) +public final class UpdateAlbumRecordingReturning implements Statement { + private final RecordingInfo recording; + private final Long id; + + public UpdateAlbumRecordingReturning(RecordingInfo recording, Long id) { + this.recording = recording; + this.id = id; + } + + public RecordingInfo recording() { + return recording; + } + + public Long id() { + return id; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof UpdateAlbumRecordingReturning)) return false; + UpdateAlbumRecordingReturning that = (UpdateAlbumRecordingReturning) o; + return java.util.Objects.equals(recording, that.recording) && + java.util.Objects.equals(id, that.id); + } + + @Override + public int hashCode() { + return java.util.Objects.hash(recording, id); + } + + @Override + public String toString() { + return "UpdateAlbumRecordingReturning[recording=" + recording + + ", id=" + id + "]"; + } + + // ------------------------------------------------------------------------- // Result type // ------------------------------------------------------------------------- @@ -49,18 +86,60 @@ public static final class Output extends ArrayList { } /** Row of {@link Output}. */ - public record OutputRow( - /** Maps to the {@code id} result-set column. */ - long id, - /** Maps to the {@code name} result-set column. */ - String name, - /** Maps to the {@code released} result-set column. Nullable. */ - LocalDate released, - /** Maps to the {@code format} result-set column. Nullable. */ - AlbumFormat format, - /** Maps to the {@code recording} result-set column. Nullable. */ - RecordingInfo recording - ) {} + public static final class OutputRow { + + private final long id; + private final String name; + private final LocalDate released; + private final AlbumFormat format; + private final RecordingInfo recording; + + OutputRow(long id, String name, LocalDate released, AlbumFormat format, RecordingInfo recording) { + this.id = id; + this.name = name; + this.released = released; + this.format = format; + this.recording = recording; + } + + /** Maps to the {@code id} result-set column. */ + public long id() { return id; } + /** Maps to the {@code name} result-set column. */ + public String name() { return name; } + /** Maps to the {@code released} result-set column. Nullable. */ + public LocalDate released() { return released; } + /** Maps to the {@code format} result-set column. Nullable. */ + public AlbumFormat format() { return format; } + /** Maps to the {@code recording} result-set column. Nullable. */ + public RecordingInfo recording() { return recording; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof OutputRow)) return false; + OutputRow that = (OutputRow) o; + return id == that.id && + java.util.Objects.equals(name, that.name) && + java.util.Objects.equals(released, that.released) && + java.util.Objects.equals(format, that.format) && + java.util.Objects.equals(recording, that.recording); + } + + @Override + public int hashCode() { + return java.util.Objects.hash(id, name, released, format, recording); + } + + @Override + public String toString() { + return "OutputRow[id=" + id + + ", name=" + name + + ", released=" + released + + ", format=" + format + + ", recording=" + recording + "]"; + } + } + // ------------------------------------------------------------------------- // Statement implementation diff --git a/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/UpdateAlbumReleased.java b/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/UpdateAlbumReleased.java index b523b5e..f57801f 100644 --- a/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/UpdateAlbumReleased.java +++ b/src/main/java/io/pgenie/example/myspace/musiccatalogue/statements/UpdateAlbumReleased.java @@ -27,8 +27,43 @@ * @param released Maps to {@code $released} in the template. Nullable. * @param id Maps to {@code $id} in the template. Nullable. */ -public record UpdateAlbumReleased(LocalDate released, Long id) - implements Statement { +public final class UpdateAlbumReleased implements Statement { + + private final LocalDate released; + private final Long id; + + public UpdateAlbumReleased(LocalDate released, Long id) { + this.released = released; + this.id = id; + } + + public LocalDate released() { + return released; + } + + public Long id() { + return id; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof UpdateAlbumReleased)) return false; + UpdateAlbumReleased that = (UpdateAlbumReleased) o; + return java.util.Objects.equals(released, that.released) && + java.util.Objects.equals(id, that.id); + } + + @Override + public int hashCode() { + return java.util.Objects.hash(released, id); + } + + @Override + public String toString() { + return "UpdateAlbumReleased[released=" + released + ", id=" + id + "]"; + } + // ------------------------------------------------------------------------- // Statement implementation diff --git a/src/main/java/io/pgenie/example/myspace/musiccatalogue/types/RecordingInfo.java b/src/main/java/io/pgenie/example/myspace/musiccatalogue/types/RecordingInfo.java index 2f1f26a..fc8c4fa 100644 --- a/src/main/java/io/pgenie/example/myspace/musiccatalogue/types/RecordingInfo.java +++ b/src/main/java/io/pgenie/example/myspace/musiccatalogue/types/RecordingInfo.java @@ -6,6 +6,7 @@ import java.time.LocalDate; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * Representation of the {@code recording_info} user-declared PostgreSQL @@ -21,12 +22,64 @@ * @param country Maps to {@code country}. * @param recordedDate Maps to {@code recorded_date}. */ -public record RecordingInfo( - String studioName, - String city, - String country, - LocalDate recordedDate -) { +public final class RecordingInfo { + + private final String studioName; + private final String city; + private final String country; + private final LocalDate recordedDate; + + public RecordingInfo( + String studioName, + String city, + String country, + LocalDate recordedDate) { + this.studioName = studioName; + this.city = city; + this.country = country; + this.recordedDate = recordedDate; + } + + public String studioName() { + return studioName; + } + + public String city() { + return city; + } + + public String country() { + return country; + } + + public LocalDate recordedDate() { + return recordedDate; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof RecordingInfo)) return false; + RecordingInfo that = (RecordingInfo) o; + return Objects.equals(studioName, that.studioName) && + Objects.equals(city, that.city) && + Objects.equals(country, that.country) && + Objects.equals(recordedDate, that.recordedDate); + } + + @Override + public int hashCode() { + return Objects.hash(studioName, city, country, recordedDate); + } + + @Override + public String toString() { + return "RecordingInfo[studioName=" + studioName + + ", city=" + city + + ", country=" + country + + ", recordedDate=" + recordedDate + "]"; + } + /** * Encode this record as a PostgreSQL composite literal string, e.g.