-
Notifications
You must be signed in to change notification settings - Fork 359
DATAJDBC-335 - Add DSL and renderer for Insert, Update, and Delete. #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added two commits.
The first is just minor polishing, but the second demonstrates a loop hole that applies to the Validators and should get fixed.
Also to minor comments.
Feel free to merge without further review when the added test is green.
@Override | ||
public String toString() { | ||
|
||
StringBuilder builder = new StringBuilder(32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming there is a good reason for the chosen initial capacity we should spend a comment to explain it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably there's no need for premature optimization. I'll check the other places as well.
* @return {@code this} builder. | ||
* @see Assignment | ||
*/ | ||
UpdateAssignAnd and(Assignment assignment); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find a series of set
calls more intuitive than and
.
How about offering set
as an alias to and
?
We even could go for a vararg:
Update update = StatementBuilder.update(table)
.set(
foo.set(SQL.bindMarker()),
bar.set(SQL.bindMarker())
).build();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and(…)
and or(…)
syntax aligns with the where and join syntax. We can accept varargs here, probably, also a Collection<? extends Assignment>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference to joins and where syntax I see is that in SQL there is no AND
between assignments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
assertThatThrownBy(() -> { | ||
Select.builder().select(bah).from(foo).where(Conditions.in(bar, subselect)).build(); | ||
}).isInstanceOf(IllegalStateException.class) | ||
.hasMessageContaining("Required table [bah] by a SELECT column not imported by FROM [foo] or JOIN []"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be rather: Required table [floo]
119a83f
to
e7cf62d
Compare
We now provide Statement builders for Insert, Update, and Delete statements. Table myTable = SQL.table("mytable"); Insert insert = StatementBuilder.insert().into(myTable).values(SQL.bindMarker()).build(); Update update = StatementBuilder.update(table).set(myTable.column("foo").set(SQL.bindMarker())).build(); Delete delete = StatementBuilder.delete().from(table).where(myTable.column("foo").isEqualTo(SQL.literal("bar"))).build();
Formatting and one additional test.
e7cf62d
to
33472b7
Compare
We now provide Statement builders for Insert, Update, and Delete statements. Table myTable = SQL.table("mytable"); Insert insert = StatementBuilder.insert().into(myTable).values(SQL.bindMarker()).build(); Update update = StatementBuilder.update(table).set(myTable.column("foo").set(SQL.bindMarker())).build(); Delete delete = StatementBuilder.delete().from(table).where(myTable.column("foo").isEqualTo(SQL.literal("bar"))).build(); Original pull request: #121.
Formatting and one additional test. Original pull request: #121.
That is merged. |
We now provide Statement builders for Insert, Update, and Delete statements. Table myTable = SQL.table("mytable"); Insert insert = StatementBuilder.insert().into(myTable).values(SQL.bindMarker()).build(); Update update = StatementBuilder.update(table).set(myTable.column("foo").set(SQL.bindMarker())).build(); Delete delete = StatementBuilder.delete().from(table).where(myTable.column("foo").isEqualTo(SQL.literal("bar"))).build(); Original pull request: spring-projects#121.
Formatting and one additional test. Original pull request: spring-projects#121.
Original pull request: spring-projects#121.
Reuse inherited configuration from parent pom.
We now support the building and rendering of
Insert
,Update
, andDelete
statements.We also support literal expressions for character and numeric constants.
Related ticket: DATAJDBC-335.