Skip to content

Conversation

@p14n
Copy link
Owner

@p14n p14n commented Oct 25, 2025

Summary by Sourcery

Return database-generated idn in publish calls, propagate it through the EventBus, provide an Event.withIdn helper, and update project versions to 1.3.3.

New Features:

  • Return the generated idn from Publisher.publish and propagate it to the Vert.x EventBus
  • Add withIdn method to Event to create a copy with the generated idn

Build:

  • Bump module versions from 1.3.3-SNAPSHOT to 1.3.3 across core, grpc, debezium, and vertx
  • Update javax.annotation-api dependency to release version 1.3.3

Tests:

  • Adjust VertxConsumerExample to omit manual idn assignment and handle null idn

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 25, 2025

Reviewer's Guide

This PR updates the publish workflow to return the generated database identifier (idn), propagates it through the EventBus, extends the Event model to support idn, aligns build configurations to a release version, and adjusts test examples accordingly.

Sequence diagram for publishing an event with generated idn propagation

sequenceDiagram
  participant "EventBusMessageBroker"
  participant "Publisher"
  participant "Database"
  participant "EventBus"

  "EventBusMessageBroker"->>"Publisher": publish(event, dataSource, topic)
  "Publisher"->>"Database": INSERT INTO postevent.<topic> ... RETURNING idn
  "Database"-->>"Publisher": idn
  "Publisher"-->>"EventBusMessageBroker": idn
  "EventBusMessageBroker"->>"EventBus": publish("events.<topic>", event.withIdn(idn))
Loading

Entity relationship diagram for event publishing and idn generation

erDiagram
  EVENT {
    id VARCHAR
    source VARCHAR
    type VARCHAR
    datacontenttype VARCHAR
    dataschema VARCHAR
    subject VARCHAR
    data BLOB
    time TIMESTAMP
    idn BIGINT
    topic VARCHAR
    traceparent VARCHAR
  }

  EVENT ||..|| "postevent.<topic>" : contains
  "postevent.<topic>" {
    idn BIGINT PK
  }

  EVENT }|..|{ "postevent.<topic>" : published_to
Loading

Updated class diagram for Event and Publisher

classDiagram
  class Event {
    +String id
    +String source
    +String type
    +String datacontenttype
    +String dataschema
    +String subject
    +Object data
    +Instant time
    +Long idn
    +String topic
    +String traceparent
    +static Event create(...)
    +Event withIdn(Long idn)
  }

  class Publisher {
    +static Long publish(Event event, Connection connection, String topic)
    +static Long publish(Event event, DataSource ds, String topic)
  }

  Event <.. Publisher: uses
Loading

File-Level Changes

Change Details Files
Publisher.publish now returns the generated idn
  • Changed publish signatures to return Long
  • Added RETURNING idn clause to SQL insert
  • Retrieved generated keys and returned idn
  • Updated DataSource overload to return the publish result
core/src/main/java/com/p14n/postevent/Publisher.java
EventBusMessageBroker includes the generated idn in published events
  • Captured idn from Publisher.publish
  • Used event.withIdn(idn) when publishing on EventBus for async path
  • Applied same idn propagation in transactional publish path
vertx/src/main/java/com/p14n/postevent/vertx/adapter/EventBusMessageBroker.java
Event data model gains a withIdn helper for immutability
  • Added withIdn(Long) method to create a new Event instance with the idn
core/src/main/java/com/p14n/postevent/data/Event.java
Build configurations bumped from SNAPSHOT to release 1.3.3
  • Updated version property in core, grpc, debezium, and vertx modules
  • Upgraded javax.annotation-api dependency to 1.3.3
grpc/build.gradle
core/build.gradle
debezium/build.gradle
vertx/build.gradle
VertxConsumerExample test updated for null idn
  • Removed hardcoded idn values (1L, 2L) and passed null for idn in example messages
vertx/src/test/java/com/p14n/postevent/vertx/example/VertxConsumerExample.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Instead of returning null when no generated key is found, consider throwing an exception or returning an Optional so missing IDs aren’t silently dropped.
  • Use stmt.getLong(1) (or getLong("idn")) rather than getObject and casting to Long to avoid potential ClassCastExceptions with certain JDBC drivers.
  • Since your SQL includes a RETURNING clause, the Statement.RETURN_GENERATED_KEYS flag may be redundant—consider simplifying to a normal prepareStatement(sql) and rely solely on RETURNING behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Instead of returning null when no generated key is found, consider throwing an exception or returning an Optional<Long> so missing IDs aren’t silently dropped.
- Use stmt.getLong(1) (or getLong("idn")) rather than getObject and casting to Long to avoid potential ClassCastExceptions with certain JDBC drivers.
- Since your SQL includes a RETURNING clause, the Statement.RETURN_GENERATED_KEYS flag may be redundant—consider simplifying to a normal prepareStatement(sql) and rely solely on RETURNING behavior.

## Individual Comments

### Comment 1
<location> `core/src/main/java/com/p14n/postevent/Publisher.java:71` </location>
<code_context>
      */
-    public static void publish(Event event, Connection connection, String topic) throws SQLException {
+    public static Long publish(Event event, Connection connection, String topic) throws SQLException {
         if (topic == null || topic.trim().isEmpty()) {
             throw new IllegalArgumentException("Topic name cannot be null or empty");
         }
</code_context>

<issue_to_address>
**suggestion:** Topic validation logic is inconsistent between overloads.

Unify topic validation logic across both overloads to ensure consistent behavior.

Suggested implementation:

```java
    public static Long publish(Event event, Connection connection, String topic) throws SQLException {
        validateTopic(topic);

        String sql = String.format("INSERT INTO postevent.%s (%s) VALUES (%s) RETURNING idn",
                topic, SQL.CORE_COLS, SQL.CORE_PH);

        try (PreparedStatement stmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
            setEventOnStatement(stmt, event);

```

```java
    private static void validateTopic(String topic) {
        if (topic == null || topic.trim().isEmpty()) {
            throw new IllegalArgumentException("Topic name cannot be null or empty");
        }
        if (!topic.matches("^[a-z_]+$")) {
            throw new IllegalArgumentException("Topic name must contain only lowercase letters and underscores");
        }
    }

```

You must also update any other overloads of `publish` in this file to use `validateTopic(topic);` instead of their own topic validation logic.
</issue_to_address>

### Comment 2
<location> `vertx/src/test/java/com/p14n/postevent/vertx/example/VertxConsumerExample.java:46` </location>
<code_context>
                     "text",
                     null,
                     "test",
-                    "hello".getBytes(), Instant.now(),1L ,"order",null));
+                    "hello".getBytes(), Instant.now(),null ,"order",null));

             client.subscribe("order", message -> {
</code_context>

<issue_to_address>
**suggestion (testing):** No test added to verify that the generated idn is returned and propagated.

Please update the test to assert that the idn is generated, returned by publish, and included in the event received by the consumer.

Suggested implementation:

```java
                    "text",
                    null,
                    "test",
                    "hello".getBytes(), Instant.now(),null ,"order",null));

            // Capture the returned idn from publish
            String publishedIdn = client.publish(
                "text",
                null,
                "test",
                "hello".getBytes(), Instant.now(),null ,"order",null
            );

            // Assert that the idn is generated
            assertNotNull(publishedIdn, "Published idn should not be null");

            // Use an AtomicReference to capture the received idn in the consumer
            AtomicReference<String> receivedIdn = new AtomicReference<>();

            client.subscribe("order", message -> {
                System.out.println("Got message");
                // Extract idn from the received message/event
                String eventIdn = message.getIdn(); // Adjust this if your message object uses a different getter
                receivedIdn.set(eventIdn);
                // Assert that the received idn matches the published idn
                assertEquals(publishedIdn, eventIdn, "Received idn should match published idn");

```

```java
                    "text",
                    null,
                    "test",
                    "hello".getBytes(), Instant.now(),null ,"order",null));

            latch.await(10, TimeUnit.SECONDS);

            // Final assertion after latch to ensure propagation
            assertEquals(publishedIdn, receivedIdn.get(), "idn should be propagated to consumer");

```

- Ensure that `client.publish` returns the idn. If it does not, update its implementation accordingly.
- Ensure that the `message` object in the consumer has a `getIdn()` method or equivalent to extract the idn.
- Make sure `assertNotNull` and `assertEquals` are statically imported from your test framework (e.g., JUnit).
- Add `AtomicReference<String> receivedIdn = new AtomicReference<>();` at the appropriate scope if not already present.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

*/
public static void publish(Event event, Connection connection, String topic) throws SQLException {
public static Long publish(Event event, Connection connection, String topic) throws SQLException {
if (topic == null || topic.trim().isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Topic validation logic is inconsistent between overloads.

Unify topic validation logic across both overloads to ensure consistent behavior.

Suggested implementation:

    public static Long publish(Event event, Connection connection, String topic) throws SQLException {
        validateTopic(topic);

        String sql = String.format("INSERT INTO postevent.%s (%s) VALUES (%s) RETURNING idn",
                topic, SQL.CORE_COLS, SQL.CORE_PH);

        try (PreparedStatement stmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
            setEventOnStatement(stmt, event);
    private static void validateTopic(String topic) {
        if (topic == null || topic.trim().isEmpty()) {
            throw new IllegalArgumentException("Topic name cannot be null or empty");
        }
        if (!topic.matches("^[a-z_]+$")) {
            throw new IllegalArgumentException("Topic name must contain only lowercase letters and underscores");
        }
    }

You must also update any other overloads of publish in this file to use validateTopic(topic); instead of their own topic validation logic.

"text",
null,
"test",
"hello".getBytes(), Instant.now(),1L ,"order",null));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): No test added to verify that the generated idn is returned and propagated.

Please update the test to assert that the idn is generated, returned by publish, and included in the event received by the consumer.

Suggested implementation:

                    "text",
                    null,
                    "test",
                    "hello".getBytes(), Instant.now(),null ,"order",null));

            // Capture the returned idn from publish
            String publishedIdn = client.publish(
                "text",
                null,
                "test",
                "hello".getBytes(), Instant.now(),null ,"order",null
            );

            // Assert that the idn is generated
            assertNotNull(publishedIdn, "Published idn should not be null");

            // Use an AtomicReference to capture the received idn in the consumer
            AtomicReference<String> receivedIdn = new AtomicReference<>();

            client.subscribe("order", message -> {
                System.out.println("Got message");
                // Extract idn from the received message/event
                String eventIdn = message.getIdn(); // Adjust this if your message object uses a different getter
                receivedIdn.set(eventIdn);
                // Assert that the received idn matches the published idn
                assertEquals(publishedIdn, eventIdn, "Received idn should match published idn");
                    "text",
                    null,
                    "test",
                    "hello".getBytes(), Instant.now(),null ,"order",null));

            latch.await(10, TimeUnit.SECONDS);

            // Final assertion after latch to ensure propagation
            assertEquals(publishedIdn, receivedIdn.get(), "idn should be propagated to consumer");
  • Ensure that client.publish returns the idn. If it does not, update its implementation accordingly.
  • Ensure that the message object in the consumer has a getIdn() method or equivalent to extract the idn.
  • Make sure assertNotNull and assertEquals are statically imported from your test framework (e.g., JUnit).
  • Add AtomicReference<String> receivedIdn = new AtomicReference<>(); at the appropriate scope if not already present.

@p14n p14n merged commit 145a212 into main Oct 25, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants