question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discussion: Fluent builder api

See original GitHub issue

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

See https://github.com/gitmotte/JSqlParser

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:30 (30 by maintainers)

github_iconTop GitHub Comments

2reactions
wumpzcommented, Aug 25, 2020

Since the corresponding pull request was merged, I close this issue.

0reactions
wumpzcommented, Jul 15, 2020

@gitmotte thx for reminding me. I got into another issue.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found