Skip to content

DATAJDBC-309 - Add infrastructure for semantic SQL generation #119

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 8 commits into from

Conversation

mp911de
Copy link
Member

@mp911de mp911de commented Feb 18, 2019

We now provide a Statement Builder API to fluently build SQL statements and render these to a SQL string.

This change introduces support for SELECT.

SelectBuilder builder = StatementBuilder.select();

Table employee = SQL.table("employee");
Table department = SQL.table("department");

Column name = employee.column("name").as("emp_name");
Column department_name = employee.column("name").as("department_name");

Select select = builder.select(name, department_name).from(employee).join(department)
		.on(SQL.column("department_id", employee)).equals(SQL.column("id", department))
		.and(SQL.column("tenant", employee)).equals(SQL.column("tenant", department))
		.orderBy(OrderByField.from(name).asc()).build();

String sql = SqlRenderer.render(select);
SELECT employee.name AS emp_name, employee.name AS department_name FROM employee JOIN department ON employee.department_id = department.id AND employee.tenant = department.tenant ORDER BY emp_name ASC

@mp911de mp911de force-pushed the issues/DATAJDBC-309 branch from c323e33 to 8493f98 Compare February 18, 2019 13:10
@mp911de mp911de changed the title Add infrastructure for semantic SQL generation DATAJDBC-309 - Add infrastructure for semantic SQL generation Feb 26, 2019
mp911de and others added 8 commits February 26, 2019 09:39
We now provide a Statement Builder API along with a renderer to build statement object graphs and to render these to SQL.

SelectBuilder builder = StatementBuilder.select();

Table employee = SQL.table("employee");
Table department = SQL.table("department");

Column name = employee.column("name").as("emp_name");
Column department_name = employee.column("name").as("department_name");

Select select = builder.select(name, department_name).from(employee).join(department)
		.on(SQL.column("department_id", employee)).equals(SQL.column("id", department))
		.and(SQL.column("tenant", employee)).equals(SQL.column("tenant", department))
		.orderBy(OrderByField.from(name).asc()).build();

String sql = SqlRenderer.render(select);
We now support LIKE and equal/not equal/less with equals to/greater with equals to conditions.
Column objects can now create conditions for a fluent DSL.

.where(left.isGreater(right) as in

StatementBuilder.select(left).from(table).where(left.isGreater(right)).build().
Introduce naming strategy to customize table and column naming.
Add since tags. Improve Javadoc.
Javadoc, static factory methods, typos. Refactor SQL rendering from a shared stack-based implementation to independent delegating visitors. Introduce DelegatingVisitor and TypedSubtreeVisitor base classes. Introduce SelectList container. Extract nested renderes to top-level types.

Move SQL renderer to renderer package.

Extend In to multi-expression argument. Introduce helper methods in Table to create multiple columns. Introduce factory method on StatementBuilder to create a new builder given a collection of expressions.
@schauder schauder force-pushed the issues/DATAJDBC-309 branch from 8493f98 to 036e046 Compare February 26, 2019 08:44
@schauder
Copy link
Contributor

done.

mp911de added a commit that referenced this pull request Feb 26, 2019
We now provide a Statement Builder API along with a renderer to build statement object graphs and to render these to SQL.

SelectBuilder builder = StatementBuilder.select();

Table employee = SQL.table("employee");
Table department = SQL.table("department");

Column name = employee.column("name").as("emp_name");
Column department_name = employee.column("name").as("department_name");

Select select = builder.select(name, department_name).from(employee).join(department)
		.on(SQL.column("department_id", employee)).equals(SQL.column("id", department))
		.and(SQL.column("tenant", employee)).equals(SQL.column("tenant", department))
		.orderBy(OrderByField.from(name).asc()).build();

String sql = SqlRenderer.render(select);

Original pull request: #119.
mp911de pushed a commit that referenced this pull request Feb 26, 2019
Also added support for conditions.

Original pull request: #119.
mp911de added a commit that referenced this pull request Feb 26, 2019
Javadoc, static factory methods, typos. Refactor SQL rendering from a shared stack-based implementation to independent delegating visitors. Introduce DelegatingVisitor and TypedSubtreeVisitor base classes. Introduce SelectList container. Extract nested renderes to top-level types.

Move SQL renderer to renderer package.

Extend In to multi-expression argument. Introduce helper methods in Table to create multiple columns. Introduce factory method on StatementBuilder to create a new builder given a collection of expressions.

Add support for comparison conditions and LIKE and equal/not equal/less with equals to/greater with equals to conditions.

 Add condition creation methods to Column so Column objects can now create conditions for a fluent DSL as in (.where(left.isGreater(right)).

StatementBuilder.select(left).from(table).where(left.isGreater(right)).build().

Introduce RenderContext and RenderNamingStrategy.

Add since tags. Improve Javadoc.

Original pull request: #119.
@mp911de
Copy link
Member Author

mp911de commented Feb 26, 2019

That's merged now.

@mp911de mp911de closed this Feb 26, 2019
@mp911de mp911de deleted the issues/DATAJDBC-309 branch February 26, 2019 12:35
mp911de pushed a commit that referenced this pull request Feb 26, 2019
Also added support for conditions.

Original pull request: #119.
mp911de added a commit that referenced this pull request Feb 26, 2019
Javadoc, static factory methods, typos. Refactor SQL rendering from a shared stack-based implementation to independent delegating visitors. Introduce DelegatingVisitor and TypedSubtreeVisitor base classes. Introduce SelectList container. Extract nested renderes to top-level types.

Move SQL renderer to renderer package.

Extend In to multi-expression argument. Introduce helper methods in Table to create multiple columns. Introduce factory method on StatementBuilder to create a new builder given a collection of expressions.

Add support for comparison conditions and LIKE and equal/not equal/less with equals to/greater with equals to conditions.

 Add condition creation methods to Column so Column objects can now create conditions for a fluent DSL as in (.where(left.isGreater(right)).

StatementBuilder.select(left).from(table).where(left.isGreater(right)).build().

Introduce RenderContext and RenderNamingStrategy.

Add since tags. Improve Javadoc.

Original pull request: #119.
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