com.alibaba.druid.stat.TableStat.Relationship Java Examples
The following examples show how to use
com.alibaba.druid.stat.TableStat.Relationship.
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: ServerSchemaStatVisitor.java From dble with GNU General Public License v2.0 | 6 votes |
/** * Equal or not equal to relationship transfer * E.g. ntest.id = mtest.id and xtest.id = ntest.id * we try to add a derivative relationship "xtest.id = mtest.id" * so when there has limit in mtest.id the xtest.id can also get the limit * P.S.:Only order insensitive operator can be optimize,like = or <=> * */ private void relationMerge(Set<Relationship> relationships) { HashSet<Relationship> loopReSet = new HashSet<>(); loopReSet.addAll(relationships); for (Relationship re : loopReSet) { for (Relationship inv : loopReSet) { if (inv.getOperator().equals(re.getOperator()) && (inv.getOperator().equals("=") || inv.getOperator().equals("<=>"))) { List<Column> tempSet = new ArrayList<>(); addAndCheckDuplicate(tempSet, re.getLeft()); addAndCheckDuplicate(tempSet, re.getRight()); addAndCheckDuplicate(tempSet, inv.getLeft()); addAndCheckDuplicate(tempSet, inv.getRight()); if (tempSet.size() == 2) { Relationship rs1 = new Relationship(tempSet.get(0), tempSet.get(1), inv.getOperator()); Relationship rs2 = new Relationship(tempSet.get(1), tempSet.get(0), inv.getOperator()); if (!relationships.contains(rs1) && !relationships.contains(rs2)) { relationships.add(rs1); } } } } } }
Example #2
Source File: DruidMycatRouteStrategy.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
/** * 子查询中存在关联查询的情况下,检查关联字段是否是分片字段 * @param rulemap * @param * @return */ private boolean checkRuleField(Map<String,RuleConfig> rulemap,MycatSchemaStatVisitor visitor){ if(!MycatServer.getInstance().getConfig().getSystem().isSubqueryRelationshipCheck()){ return true; } Set<Relationship> ships = visitor.getRelationships(); Iterator<Relationship> iter = ships.iterator(); while(iter.hasNext()){ Relationship ship = iter.next(); String lefttable = ship.getLeft().getTable().toUpperCase(); String righttable = ship.getRight().getTable().toUpperCase(); // 如果是同一个表中的关联条件,不做处理 if(lefttable.equals(righttable)){ return true; } RuleConfig leftconfig = rulemap.get(lefttable); RuleConfig rightconfig = rulemap.get(righttable); if(null!=leftconfig&&null!=rightconfig &&leftconfig.equals(rightconfig) &&leftconfig.getColumn().equals(ship.getLeft().getName().toUpperCase()) &&rightconfig.getColumn().equals(ship.getRight().getName().toUpperCase())){ return true; } } return false; }
Example #3
Source File: ServerSchemaStatVisitor.java From dble with GNU General Public License v2.0 | 5 votes |
/** * turn all the condition in or into conditionList * exp (conditionA OR conditionB) into conditionList{conditionA,conditionB} * so the conditionA,conditionB can be group with outer conditions * */ private void resetConditionsFromWhereUnit(WhereUnit whereUnit) { if (!whereUnit.isFinishedExtend()) { List<List<Condition>> retList = new ArrayList<>(); List<Condition> outSideCondition = new ArrayList<>(); outSideCondition.addAll(conditions); List<Relationship> outSideRelationship = new ArrayList<>(); outSideRelationship.addAll(relationships); this.conditions.clear(); this.relationships.clear(); for (SQLExpr sqlExpr : whereUnit.getSplitedExprList()) { sqlExpr.accept(this); List<Condition> conds = new ArrayList<>(); conds.addAll(getConditions()); conds.addAll(outSideCondition); Set<Relationship> relations = new HashSet<>(); relations.addAll(getRelationships()); relations.addAll(outSideRelationship); ConditionUtil.extendConditionsFromRelations(conds, relations); retList.add(conds); this.conditions.clear(); this.relationships.clear(); } whereUnit.setOrConditionList(retList); for (WhereUnit subWhere : whereUnit.getSubWhereUnit()) { resetConditionsFromWhereUnit(subWhere); } whereUnit.setFinishedExtend(true); } }
Example #4
Source File: WhereUnit.java From dble with GNU General Public License v2.0 | 4 votes |
public Set<Relationship> getOutRelationships() { return outRelationships; }
Example #5
Source File: WhereUnit.java From dble with GNU General Public License v2.0 | 4 votes |
public void addOutRelationships(Set<Relationship> relationships) { this.outRelationships.addAll(relationships); }