Skip to content

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

Closed
wants to merge 4 commits into from

Conversation

mp911de
Copy link
Member

@mp911de mp911de commented Mar 1, 2019

We now support the building and rendering of Insert, Update, and Delete statements.

We also support literal expressions for character and numeric constants.


Related ticket: DATAJDBC-335.

Copy link
Contributor

@schauder schauder left a 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);
Copy link
Contributor

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.

Copy link
Member Author

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);
Copy link
Contributor

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();

Copy link
Member Author

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>.

Copy link
Contributor

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.

Copy link
Member Author

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 []");
Copy link
Member Author

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]

@mp911de mp911de force-pushed the issue/DATAJDBC-335 branch from 119a83f to e7cf62d Compare March 5, 2019 08:39
mp911de and others added 4 commits March 5, 2019 09:43
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.
@mp911de mp911de force-pushed the issue/DATAJDBC-335 branch from e7cf62d to 33472b7 Compare March 5, 2019 08:43
schauder pushed a commit that referenced this pull request Mar 5, 2019
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.
schauder added a commit that referenced this pull request Mar 5, 2019
Formatting and one additional test.

Original pull request: #121.
schauder added a commit that referenced this pull request Mar 5, 2019
@schauder
Copy link
Contributor

schauder commented Mar 5, 2019

That is merged.

@schauder schauder closed this Mar 5, 2019
@schauder schauder deleted the issue/DATAJDBC-335 branch March 5, 2019 09:31
THD-Thomas-Lang pushed a commit to THD-Thomas-Lang/spring-data-jdbc that referenced this pull request Apr 12, 2019
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.
THD-Thomas-Lang pushed a commit to THD-Thomas-Lang/spring-data-jdbc that referenced this pull request Apr 12, 2019
Formatting and one additional test.

Original pull request: spring-projects#121.
THD-Thomas-Lang pushed a commit to THD-Thomas-Lang/spring-data-jdbc that referenced this pull request Apr 12, 2019
mp911de pushed a commit that referenced this pull request Feb 21, 2022
mp911de pushed a commit that referenced this pull request Feb 21, 2022
mp911de added a commit that referenced this pull request Feb 21, 2022
Reuse inherited configuration from parent pom.
mp911de pushed a commit that referenced this pull request Feb 21, 2022
mp911de pushed a commit that referenced this pull request Feb 21, 2022
mp911de pushed a commit that referenced this pull request Feb 21, 2022
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