@Test public void testAddJoin() throws JSQLParserException { Select select = (Select)CCJSqlParserUtil.parse("select a from mytable"); final EqualsTo equalsTo = new EqualsTo(); equalsTo.setLeftExpression(new Column("a")); equalsTo.setRightExpression(new Column("b")); Join addJoin = SelectUtils.addJoin(select, new Table("mytable2"), equalsTo); addJoin.setLeft(true); assertEquals("SELECT a FROM mytable LEFT JOIN mytable2 ON a = b", select.toString()); }
public static Join addJoin(Select select, final Table table, final Expression onExpression) { if (select.getSelectBody() instanceof PlainSelect) { PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); List<Join> joins = plainSelect.getJoins(); if (joins == null) { joins = new ArrayList<Join>(); plainSelect.setJoins(joins); } Join join = new Join(); join.setRightItem(table); join.setOnExpression(onExpression); joins.add(join); return join; } throw new UnsupportedOperationException(NOT_SUPPORTED_YET); }
SelectUtils { public static Join addJoin(Select select, final Table table, final Expression onExpression) { if (select.getSelectBody() instanceof PlainSelect) { PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); List<Join> joins = plainSelect.getJoins(); if (joins == null) { joins = new ArrayList<Join>(); plainSelect.setJoins(joins); } Join join = new Join(); join.setRightItem(table); join.setOnExpression(onExpression); joins.add(join); return join; } throw new UnsupportedOperationException(NOT_SUPPORTED_YET); } }
SelectUtils { public static Join addJoin(Select select, final Table table, final Expression onExpression) { if (select.getSelectBody() instanceof PlainSelect) { PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); List<Join> joins = plainSelect.getJoins(); if (joins == null) { joins = new ArrayList<Join>(); plainSelect.setJoins(joins); } Join join = new Join(); join.setRightItem(table); join.setOnExpression(onExpression); joins.add(join); return join; } throw new UnsupportedOperationException(NOT_SUPPORTED_YET); } private  SelectUtils(); }
SelectUtils { public static Join addJoin(Select select, final Table table, final Expression onExpression) { if (select.getSelectBody() instanceof PlainSelect) { PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); List<Join> joins = plainSelect.getJoins(); if (joins == null) { joins = new ArrayList<Join>(); plainSelect.setJoins(joins); } Join join = new Join(); join.setRightItem(table); join.setOnExpression(onExpression); joins.add(join); return join; } throw new UnsupportedOperationException(NOT_SUPPORTED_YET); } private  SelectUtils(); static Select buildSelectFromTableAndExpressions(Table table, Expression ... expr); static Select buildSelectFromTableAndExpressions(Table table, String ... expr); static Select buildSelectFromTableAndSelectItems(Table table, SelectItem ... selectItems); static Select buildSelectFromTable(Table table); static void addExpression(Select select, final Expression expr); static Join addJoin(Select select, final Table table, final Expression onExpression); static void addGroupBy(Select select, final Expression expr); }
SelectUtils { public static Join addJoin(Select select, final Table table, final Expression onExpression) { if (select.getSelectBody() instanceof PlainSelect) { PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); List<Join> joins = plainSelect.getJoins(); if (joins == null) { joins = new ArrayList<Join>(); plainSelect.setJoins(joins); } Join join = new Join(); join.setRightItem(table); join.setOnExpression(onExpression); joins.add(join); return join; } throw new UnsupportedOperationException(NOT_SUPPORTED_YET); } private  SelectUtils(); static Select buildSelectFromTableAndExpressions(Table table, Expression ... expr); static Select buildSelectFromTableAndExpressions(Table table, String ... expr); static Select buildSelectFromTableAndSelectItems(Table table, SelectItem ... selectItems); static Select buildSelectFromTable(Table table); static void addExpression(Select select, final Expression expr); static Join addJoin(Select select, final Table table, final Expression onExpression); static void addGroupBy(Select select, final Expression expr);  }