Tabnine Logo
SQLRouteResult.getRouteUnits
Code IndexAdd Tabnine to your IDE (free)

How to use
getRouteUnits
method
in
org.apache.shardingsphere.core.routing.SQLRouteResult

Best Java code snippets using org.apache.shardingsphere.core.routing.SQLRouteResult.getRouteUnits (Showing top 16 results out of 315)

origin: apache/incubator-shardingsphere

/**
 * Add batch for route units.
 *
 * @param routeResult route result
 */
public void addBatchForRouteUnits(final SQLRouteResult routeResult) {
  handleOldRouteUnits(createBatchRouteUnits(routeResult.getRouteUnits()));
  handleNewRouteUnits(createBatchRouteUnits(routeResult.getRouteUnits()));
  batchCount++;
}

origin: apache/incubator-shardingsphere

private void route(final MasterSlaveRule masterSlaveRule, final SQLRouteResult sqlRouteResult) {
  Collection<RouteUnit> toBeRemoved = new LinkedList<>();
  Collection<RouteUnit> toBeAdded = new LinkedList<>();
  for (RouteUnit each : sqlRouteResult.getRouteUnits()) {
    if (!masterSlaveRule.getName().equalsIgnoreCase(each.getDataSourceName())) {
      continue;
    }
    toBeRemoved.add(each);
    if (isMasterRoute(sqlRouteResult.getSqlStatement().getType())) {
      MasterVisitedManager.setMasterVisited();
      toBeAdded.add(new RouteUnit(masterSlaveRule.getMasterDataSourceName(), each.getSqlUnit()));
    } else {
      toBeAdded.add(new RouteUnit(masterSlaveRule.getLoadBalanceAlgorithm().getDataSource(
        masterSlaveRule.getName(), masterSlaveRule.getMasterDataSourceName(), new ArrayList<>(masterSlaveRule.getSlaveDataSourceNames())), each.getSqlUnit()));
    }
  }
  sqlRouteResult.getRouteUnits().removeAll(toBeRemoved);
  sqlRouteResult.getRouteUnits().addAll(toBeAdded);
}

origin: apache/incubator-shardingsphere

/**
 * Initialize executor.
 *
 * @param routeResult route result
 * @throws SQLException SQL exception
 */
public void init(final SQLRouteResult routeResult) throws SQLException {
  setSqlStatement(routeResult.getSqlStatement());
  getExecuteGroups().addAll(obtainExecuteGroups(routeResult.getRouteUnits()));
  cacheStatements();
}

origin: apache/incubator-shardingsphere

/**
 * Initialize executor.
 *
 * @param routeResult route result
 * @throws SQLException SQL exception
 */
public void init(final SQLRouteResult routeResult) throws SQLException {
  setSqlStatement(routeResult.getSqlStatement());
  getExecuteGroups().addAll(obtainExecuteGroups(routeResult.getRouteUnits()));
  cacheStatements();
}

origin: apache/incubator-shardingsphere

  @Override
  // TODO insert SQL need parse gen key
  public SQLRouteResult route(final String logicSQL, final List<Object> parameters, final SQLStatement sqlStatement) {
    SQLRouteResult result = new SQLRouteResult(sqlStatement);
    RoutingResult routingResult = new DatabaseHintRoutingEngine(
        shardingRule.getShardingDataSourceNames().getDataSourceNames(), (HintShardingStrategy) shardingRule.getDefaultDatabaseShardingStrategy()).route();
    for (TableUnit each : routingResult.getTableUnits().getTableUnits()) {
      result.getRouteUnits().add(new RouteUnit(each.getDataSourceName(), new SQLUnit(logicSQL, new ArrayList<>(Collections.singleton(parameters)))));
    }
    if (showSQL) {
      SQLLogger.logSQL(logicSQL, sqlStatement, result.getRouteUnits());
    }
    return result;
  }
}
origin: apache/incubator-shardingsphere

private SQLRouteResult doMasterSlaveRoute(final String sql) {
  SQLStatement sqlStatement = new SQLJudgeEngine(sql).judge();
  String rewriteSQL = new MasterSlaveSQLRewriteEngine(((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), sql, sqlStatement, logicSchema.getMetaData()).rewrite();
  SQLRouteResult result = new SQLRouteResult(sqlStatement);
  for (String each : new MasterSlaveRouter(
      ((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), GLOBAL_REGISTRY.getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)).route(rewriteSQL)) {
    result.getRouteUnits().add(new RouteUnit(each, new SQLUnit(rewriteSQL, new ArrayList<>(Collections.singleton(parameters)))));
  }
  return result;
}

origin: apache/incubator-shardingsphere

private SQLRouteResult doMasterSlaveRoute(final String sql) {
  SQLStatement sqlStatement = new SQLJudgeEngine(sql).judge();
  String rewriteSQL = new MasterSlaveSQLRewriteEngine(((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), sql, sqlStatement, logicSchema.getMetaData()).rewrite();
  SQLRouteResult result = new SQLRouteResult(sqlStatement);
  for (String each : new MasterSlaveRouter(
      ((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), GLOBAL_REGISTRY.getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)).route(rewriteSQL)) {
    result.getRouteUnits().add(new RouteUnit(each, new SQLUnit(rewriteSQL, new ArrayList<>(Collections.singleton(parameters)))));
  }
  return result;
}

origin: apache/incubator-shardingsphere

@SuppressWarnings("unchecked")
@Override
public ExecuteResponse execute(final SQLRouteResult routeResult) throws SQLException {
  boolean isReturnGeneratedKeys = routeResult.getSqlStatement() instanceof InsertStatement;
  boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
  Collection<ShardingExecuteGroup<StatementExecuteUnit>> sqlExecuteGroups =
    sqlExecutePrepareTemplate.getExecuteUnitGroups(routeResult.getRouteUnits(), new ProxyJDBCExecutePrepareCallback(isReturnGeneratedKeys));
  SQLExecuteCallback<ExecuteResponseUnit> firstProxySQLExecuteCallback = new FirstProxyJDBCExecuteCallback(isExceptionThrown, isReturnGeneratedKeys);
  SQLExecuteCallback<ExecuteResponseUnit> proxySQLExecuteCallback = new ProxyJDBCExecuteCallback(isExceptionThrown, isReturnGeneratedKeys);
  Collection<ExecuteResponseUnit> executeResponseUnits = sqlExecuteTemplate.executeGroup((Collection) sqlExecuteGroups,
    firstProxySQLExecuteCallback, proxySQLExecuteCallback);
  ExecuteResponseUnit firstExecuteResponseUnit = executeResponseUnits.iterator().next();
  return firstExecuteResponseUnit instanceof ExecuteQueryResponseUnit
    ? getExecuteQueryResponse(((ExecuteQueryResponseUnit) firstExecuteResponseUnit).getPostgreSQLQueryResponsePackets(), executeResponseUnits)
    : new ExecuteUpdateResponse(executeResponseUnits);
}

origin: apache/incubator-shardingsphere

@SuppressWarnings("unchecked")
@Override
public ExecuteResponse execute(final SQLRouteResult routeResult) throws SQLException {
  boolean isReturnGeneratedKeys = routeResult.getSqlStatement() instanceof InsertStatement;
  boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
  Collection<ShardingExecuteGroup<StatementExecuteUnit>> sqlExecuteGroups =
      sqlExecutePrepareTemplate.getExecuteUnitGroups(routeResult.getRouteUnits(), new ProxyJDBCExecutePrepareCallback(isReturnGeneratedKeys));
  SQLExecuteCallback<ExecuteResponseUnit> firstProxySQLExecuteCallback = new FirstProxyJDBCExecuteCallback(isExceptionThrown, isReturnGeneratedKeys);
  SQLExecuteCallback<ExecuteResponseUnit> proxySQLExecuteCallback = new ProxyJDBCExecuteCallback(isExceptionThrown, isReturnGeneratedKeys);
  Collection<ExecuteResponseUnit> executeResponseUnits = sqlExecuteTemplate.executeGroup((Collection) sqlExecuteGroups,
      firstProxySQLExecuteCallback, proxySQLExecuteCallback);
  ExecuteResponseUnit firstExecuteResponseUnit = executeResponseUnits.iterator().next();
  return firstExecuteResponseUnit instanceof ExecuteQueryResponseUnit
      ? getExecuteQueryResponse(((ExecuteQueryResponseUnit) firstExecuteResponseUnit).getQueryResponsePackets(), executeResponseUnits) : new ExecuteUpdateResponse(executeResponseUnits);
}

origin: apache/incubator-shardingsphere

private SQLRouteResult doMasterSlaveRoute(final String sql) {
  SQLStatement sqlStatement = new SQLJudgeEngine(sql).judge();
  String rewriteSQL = new MasterSlaveSQLRewriteEngine(((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), sql, sqlStatement, logicSchema.getMetaData()).rewrite();
  SQLRouteResult result = new SQLRouteResult(sqlStatement);
  for (String each : new MasterSlaveRouter(
      ((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), GLOBAL_REGISTRY.getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)).route(rewriteSQL)) {
    result.getRouteUnits().add(new RouteUnit(each, new SQLUnit(rewriteSQL, Collections.<List<Object>>emptyList())));
  }
  return result;
}

origin: apache/incubator-shardingsphere

private SQLRouteResult doMasterSlaveRoute(final String sql) {
  SQLStatement sqlStatement = new SQLJudgeEngine(sql).judge();
  String rewriteSQL = new MasterSlaveSQLRewriteEngine(((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), sql, sqlStatement, logicSchema.getMetaData()).rewrite();
  SQLRouteResult result = new SQLRouteResult(sqlStatement);
  for (String each : new MasterSlaveRouter(
      ((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), GLOBAL_REGISTRY.getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)).route(rewriteSQL)) {
    result.getRouteUnits().add(new RouteUnit(each, new SQLUnit(rewriteSQL, Collections.<List<Object>>emptyList())));
  }
  return result;
}

origin: apache/incubator-shardingsphere

@Override
public SQLRouteResult route(final String logicSQL, final List<Object> parameters, final SQLStatement sqlStatement) {
  Optional<GeneratedKey> generatedKey = sqlStatement instanceof InsertStatement ? getGenerateKey(parameters, (InsertStatement) sqlStatement) : Optional.<GeneratedKey>absent();
  SQLRouteResult result = new SQLRouteResult(sqlStatement, generatedKey.orNull());
  ShardingConditions shardingConditions = OptimizeEngineFactory.newInstance(shardingRule, sqlStatement, parameters, generatedKey.orNull()).optimize();
  if (generatedKey.isPresent()) {
    setGeneratedKeys(result, generatedKey.get());
  }
  if (sqlStatement instanceof SelectStatement && isNeedMergeShardingValues((SelectStatement) sqlStatement)) {
    checkSubqueryShardingValues(sqlStatement, sqlStatement.getConditions(), shardingConditions);
    mergeShardingValues(shardingConditions);
  }
  RoutingResult routingResult = RoutingEngineFactory.newInstance(shardingRule, shardingMetaData.getDataSource(), sqlStatement, shardingConditions).route();
  boolean isSingleRouting = routingResult.isSingleRouting();
  SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule, logicSQL, databaseType, sqlStatement, shardingConditions, parameters);
  if (sqlStatement instanceof SelectStatement && null != ((SelectStatement) sqlStatement).getLimit()) {
    processLimit(parameters, (SelectStatement) sqlStatement, isSingleRouting);
  }
  SQLBuilder sqlBuilder = rewriteEngine.rewrite(isSingleRouting);
  for (TableUnit each : routingResult.getTableUnits().getTableUnits()) {
    result.getRouteUnits().add(new RouteUnit(each.getDataSourceName(), rewriteEngine.generateSQL(each, sqlBuilder, shardingMetaData.getDataSource())));
  }
  if (showSQL) {
    SQLLogger.logSQL(logicSQL, sqlStatement, result.getRouteUnits());
  }
  return result;
}

origin: apache/incubator-shardingsphere

    logicSchema.getMetaData(), databaseType, GLOBAL_REGISTRY.getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW));
SQLRouteResult routeResult = routingEngine.route(sql);
if (routeResult.getRouteUnits().isEmpty()) {
  return new PostgreSQLCommandResponsePackets(new OKPacket(1));
synchronizedFuture = new SynchronizedFuture(routeResult.getRouteUnits().size());
FutureRegistry.getInstance().put(connectionId, synchronizedFuture);
for (RouteUnit each : routeResult.getRouteUnits()) {
  executeSQL(each.getDataSourceName(), each.getSqlUnit().getSql());
origin: apache/incubator-shardingsphere

    logicSchema.getMetaData(), databaseType, GLOBAL_REGISTRY.getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW));
SQLRouteResult routeResult = routingEngine.route(sql);
if (routeResult.getRouteUnits().isEmpty()) {
  return new CommandResponsePackets(new OKPacket(1));
synchronizedFuture = new SynchronizedFuture(routeResult.getRouteUnits().size());
FutureRegistry.getInstance().put(connectionId, synchronizedFuture);
for (RouteUnit each : routeResult.getRouteUnits()) {
  executeSQL(each.getDataSourceName(), each.getSqlUnit().getSql());
origin: apache/incubator-shardingsphere

private PostgreSQLCommandResponsePackets execute(final SQLRouteResult routeResult) throws SQLException {
  if (routeResult.getRouteUnits().isEmpty()) {
    return new PostgreSQLCommandResponsePackets(new OKPacket(1));
  }
  SQLStatement sqlStatement = routeResult.getSqlStatement();
  if (isUnsupportedXA(sqlStatement.getType())) {
    return new PostgreSQLCommandResponsePackets(new PostgreSQLErrorResponsePacket());
  }
  executeResponse = executeEngine.execute(routeResult);
  if (logicSchema instanceof ShardingSchema) {
    logicSchema.refreshTableMetaData(routeResult.getSqlStatement());
  }
  return merge(sqlStatement);
}

origin: apache/incubator-shardingsphere

private CommandResponsePackets execute(final SQLRouteResult routeResult) throws SQLException {
  if (routeResult.getRouteUnits().isEmpty()) {
    return new CommandResponsePackets(new OKPacket(1));
  }
  SQLStatement sqlStatement = routeResult.getSqlStatement();
  if (isUnsupportedXA(sqlStatement.getType())) {
    return new CommandResponsePackets(new ErrPacket(1,
        ServerErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE, sqlStatement.getTables().isSingleTable() ? sqlStatement.getTables().getSingleTableName() : "unknown_table"));
  }
  executeResponse = executeEngine.execute(routeResult);
  if (logicSchema instanceof ShardingSchema) {
    logicSchema.refreshTableMetaData(routeResult.getSqlStatement());
  }
  return merge(sqlStatement);
}

org.apache.shardingsphere.core.routingSQLRouteResultgetRouteUnits

Popular methods of SQLRouteResult

  • getSqlStatement
  • <init>
  • getGeneratedKey

Popular in Java

  • Start an intent from android
  • getSupportFragmentManager (FragmentActivity)
  • notifyDataSetChanged (ArrayAdapter)
  • onRequestPermissionsResult (Fragment)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now