core-java
core-java copied to clipboard
Strongly-typed columns in query/subscription client API
At the moment when composing a query or subscribing to some updates an end-user refers to the fields by their string representation. E.g.
client.asGuest()
.subscribe(ProjectDetails.class)
.where(eq("project_name", value))
.post()
A potential typo in "project_name"
would be invisible at the first glance.
Also, there is a difference in language. As the Java definitions use the camel-cased representation when Proto fields are snake-cased.
What would be nice to do is to introduce the generated enumerations, such as FieldName
and ColumnName
for events and entities respectively. Each listing the available Protobuf fields and making the code snippet above to transform into something like this:
client.asGuest()
.subscribe(ProjectDetails.class)
.where(eq(ProjectDetails.Columns.projectName, value))
.post()
Or, for the event subscriptions:
client.asGuest()
.subscribe(PizzaDelivered.class)
.where(eq(PizzaDelivered.Fields.overdue, value))
.post()
This effectively will make eq
methods not accepting String
s but strong-typed objects, depending on the type of the target object.
@alexander-yevsyukov FYI, that's what we have discussed vocally.