net.sf.jsqlparser.statement.select.Join Java Examples
The following examples show how to use
net.sf.jsqlparser.statement.select.Join.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CTEToNestedQueryConverter.java From quetzal with Eclipse Public License 2.0 | 6 votes |
protected int getNumberNonPlaceHolderFromItem(PlainSelect plainSelect) { int ret = 0; if (useExplicitJoinSyntax) { for (Join join: plainSelect.getJoins()) { if (join.getRightItem()!=null) { if ( (join.getRightItem() instanceof Table)) { String tableName = ((Table) join.getRightItem()).getFullyQualifiedName(); if (!placeHolderTables.contains(tableName)) { ret++; } } else { ret++; } } } } return ret; }
Example #2
Source File: SqlBuilder.java From das with Apache License 2.0 | 4 votes |
private static String plainSelectToStringAppendWithNoLock(PlainSelect plain) { StringBuilder sql = new StringBuilder("SELECT "); if (plain.getDistinct() != null) sql.append(plain.getDistinct()).append(" "); if (plain.getTop() != null) sql.append(plain.getTop()).append(" "); sql.append(PlainSelect.getStringList(plain.getSelectItems())); if (plain.getFromItem() != null) { sql.append(" FROM ").append(plain.getFromItem()).append(" WITH (NOLOCK) "); if (plain.getJoins() != null) { Iterator<Join> it = plain.getJoins().iterator(); while (it.hasNext()) { Join join = it.next(); if (join.isSimple()) { sql.append(", ").append(join).append(" WITH (NOLOCK) "); } else { String temp = join.toString().replace(join.getRightItem().toString(), join.getRightItem().toString() + " WITH (NOLOCK) "); sql.append(" ").append(temp); } } } if (plain.getWhere() != null) sql.append(" WHERE ").append(plain.getWhere()); if (plain.getOracleHierarchical() != null) sql.append(plain.getOracleHierarchical().toString()); sql.append(PlainSelect.getFormatedList(plain.getGroupByColumnReferences(), "GROUP BY")); if (plain.getHaving() != null) sql.append(" HAVING ").append(plain.getHaving()); sql.append(PlainSelect.orderByToString(plain.isOracleSiblings(), plain.getOrderByElements())); if (plain.getLimit() != null) sql.append(plain.getLimit()); } return sql.toString(); }
Example #3
Source File: SelectVisitorImpl.java From DataPermissionHelper with Apache License 2.0 | 4 votes |
@Override public void visit(PlainSelect plainSelect) { // 访问 select if (plainSelect.getSelectItems() != null) { for (SelectItem item : plainSelect.getSelectItems()) { item.accept(new SelectItemVisitorImpl()); } } // 访问from FromItem fromItem = plainSelect.getFromItem(); FromItemVisitorImpl fromItemVisitorImpl = new FromItemVisitorImpl(); fromItem.accept(fromItemVisitorImpl); if (fromItemVisitorImpl.getSubSelect() != null) { plainSelect.setFromItem(fromItemVisitorImpl.getSubSelect()); if (!DPHelper.getChangeTable()) { DPHelper.setChangeTable(true); } } // 访问where if (plainSelect.getWhere() != null) { plainSelect.getWhere().accept(new ExpressionVisitorImpl()); } // 访问join if (plainSelect.getJoins() != null) { for (Join join : plainSelect.getJoins()) { FromItemVisitorImpl fromItemVisitorImplTemp = new FromItemVisitorImpl(); join.getRightItem().accept(fromItemVisitorImplTemp); if (fromItemVisitorImplTemp.getSubSelect() != null) { join.setRightItem(fromItemVisitorImplTemp.getSubSelect()); if (!DPHelper.getChangeTable()) { DPHelper.setChangeTable(true); } } } } // 访问 order by if (plainSelect.getOrderByElements() != null) { for (OrderByElement orderByElement : plainSelect .getOrderByElements()) { orderByElement.getExpression().accept( new ExpressionVisitorImpl()); } } // 访问group by having if (plainSelect.getHaving() != null) { plainSelect.getHaving().accept(new ExpressionVisitorImpl()); } }
Example #4
Source File: JoinProcessor.java From sql-to-mongo-db-query-converter with Apache License 2.0 | 4 votes |
public static List<Document> toPipelineSteps(QueryConverter queryConverter, FromHolder tholder, List<Join> ljoins, Expression whereExpression) throws ParseException, net.sf.jsqlparser.parser.ParseException { List<Document> ldoc = new LinkedList<Document>(); MutableBoolean haveOrExpression = new MutableBoolean(); for(Join j : ljoins) { if(j.isInner() || j.isLeft()) { if(j.getRightItem() instanceof Table || j.getRightItem() instanceof SubSelect) { ExpressionHolder whereExpHolder; String joinTableAlias = j.getRightItem().getAlias().getName(); String joinTableName = tholder.getSQLHolder(j.getRightItem()).getBaseTableName(); whereExpHolder = new ExpressionHolder(null); if(whereExpression != null) { haveOrExpression.setValue(false); whereExpression.accept(new WhereVisitorMatchAndLookupPipelineMatchBuilder(joinTableAlias, whereExpHolder, haveOrExpression)); if(!haveOrExpression.booleanValue() && whereExpHolder.getExpression() != null) { whereExpHolder.getExpression().accept(new ExpVisitorEraseAliasTableBaseBuilder(joinTableAlias)); } else { whereExpHolder.setExpression(null); } } List<Document> subqueryDocs = new LinkedList<>(); if(j.getRightItem() instanceof SubSelect) { subqueryDocs = queryConverter.fromSQLCommandInfoHolderToAggregateSteps((SQLCommandInfoHolder)tholder.getSQLHolder(j.getRightItem())); } ldoc.add(generateLookupStep(tholder,joinTableName,joinTableAlias,j.getOnExpression(),whereExpHolder.getExpression(),subqueryDocs)); ldoc.add(generateUnwindStep(tholder,joinTableAlias,j.isLeft())); } else { throw new ParseException("From join not supported"); } } else { throw new ParseException("Only inner join and left supported"); } } if(haveOrExpression.booleanValue()) {//if there is some "or" we use this step for support this logic and no other match steps ldoc.add(generateMatchAfterJoin(tholder,whereExpression)); } return ldoc; }
Example #5
Source File: SqlBuilder.java From dal with Apache License 2.0 | 4 votes |
private static String plainSelectToStringAppendWithNoLock(PlainSelect plain) { StringBuilder sql = new StringBuilder("SELECT "); if (plain.getDistinct() != null) sql.append(plain.getDistinct()).append(" "); if (plain.getTop() != null) sql.append(plain.getTop()).append(" "); sql.append(PlainSelect.getStringList(plain.getSelectItems())); if (plain.getFromItem() != null) { sql.append(" FROM ").append(plain.getFromItem()).append(" WITH (NOLOCK) "); if (plain.getJoins() != null) { Iterator<Join> it = plain.getJoins().iterator(); while (it.hasNext()) { Join join = it.next(); if (join.isSimple()) { sql.append(", ").append(join).append(" WITH (NOLOCK) "); } else { String temp = join.toString().replace(join.getRightItem().toString(), join.getRightItem().toString() + " WITH (NOLOCK) "); sql.append(" ").append(temp); } } } if (plain.getWhere() != null) sql.append(" WHERE ").append(plain.getWhere()); if (plain.getOracleHierarchical() != null) sql.append(plain.getOracleHierarchical().toString()); sql.append(PlainSelect.getFormatedList(plain.getGroupByColumnReferences(), "GROUP BY")); if (plain.getHaving() != null) sql.append(" HAVING ").append(plain.getHaving()); sql.append(PlainSelect.orderByToString(plain.isOracleSiblings(), plain.getOrderByElements())); if (plain.getLimit() != null) sql.append(plain.getLimit()); } return sql.toString(); }