Discussion: Fluent builder api
See original GitHub issueIs it desirable that the model also supports the builder pattern?
If we change setters and add* methods returning “this” building sql will be very easy … i.e.
@Test
public void testParseAndBuild() throws JSQLParserException {
String sql = "SELECT * FROM tab1 t1 "
+ "JOIN tab2 t2 ON t1.ref = t2.id WHERE t1.col1 = ? OR t1.col2 = ?";
Statement stmt = CCJSqlParserUtil.parse(sql);
StringBuilder buffer = new StringBuilder();
stmt.accept(new StatementDeParser(buffer));
assertEquals(sql, buffer.toString());
Table t1 = new Table("tab1").setAlias(new Alias("t1", false));
Table t2 = new Table("tab2").setAlias(new Alias("t2", false));
Select select = new Select().setSelectBody(
new PlainSelect().setFromItem(t1)
.setSelectItems(Arrays.asList(new AllColumns()))
.setJoins(
Arrays.asList(new Join().setRightItem(t2).setOnExpression(
new EqualsTo(new Column(t1, "ref"), new Column(t2, "id")))))
.setWhere(new OrExpression(new EqualsTo(new Column(t1, "col1"), new JdbcParameter()),
new EqualsTo(new Column(t1, "col2"), new JdbcParameter()))));
buffer = new StringBuilder();
select.accept(new StatementDeParser(buffer));
assertEquals(sql, buffer.toString());
}
I did a fork starting the change to get a picture of it.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:30 (30 by maintainers)
Top Results From Across the Web
Fluent Builder Pattern with a real-world example - Medium
In this blog, we will try and understand what classical builder pattern is, how it is used with the help of a real-world...
Read more >Fluent API: Practice and Theory - | SIGPLAN Blog
In this post we discuss fluent APIs, which are produced by a funky and popular design technique. We learn what fluent API is,...
Read more >Simple Implementation of Fluent Builder - Safe Alternative To ...
So, what to do in cases when object must be built completely and there are no safe defaults for fields (i.e. Builder pattern...
Read more >camunda-docs-manual/fluent-builder-api.md at master - GitHub
To create simple BPMN processes we provide a fluent builder API. With this API you can easily create basic processes in a few...
Read more >Best Practices for Designing a Fluent API
The first step in designing a fluent API is to decide which of those activities may be performed together and, as a result,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Since the corresponding pull request was merged, I close this issue.
@gitmotte thx for reminding me. I got into another issue.