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

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

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

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 Optional<GeneratedKey> getGeneratedKey() {
  if (null != routeResult && routeResult.getSqlStatement() instanceof InsertStatement) {
    return Optional.fromNullable(routeResult.getGeneratedKey());
  }
  return Optional.absent();
}

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(routeUnits));
}

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 setGeneratedKeys(final SQLRouteResult sqlRouteResult, final GeneratedKey generatedKey) {
  generatedKeys.addAll(generatedKey.getGeneratedKeys());
  sqlRouteResult.getGeneratedKey().getGeneratedKeys().clear();
  sqlRouteResult.getGeneratedKey().getGeneratedKeys().addAll(generatedKeys);
}

origin: apache/incubator-shardingsphere

@Override
public ResultSet getResultSet() throws SQLException {
  if (null != currentResultSet) {
    return currentResultSet;
  }
  if (1 == statementExecutor.getStatements().size() && routeResult.getSqlStatement() instanceof DQLStatement) {
    currentResultSet = statementExecutor.getStatements().iterator().next().getResultSet();
    return currentResultSet;
  }
  List<ResultSet> resultSets = new ArrayList<>(statementExecutor.getStatements().size());
  List<QueryResult> queryResults = new ArrayList<>(statementExecutor.getStatements().size());
  for (Statement each : statementExecutor.getStatements()) {
    ResultSet resultSet = each.getResultSet();
    resultSets.add(resultSet);
    queryResults.add(new StreamQueryResult(resultSet));
  }
  if (routeResult.getSqlStatement() instanceof SelectStatement || routeResult.getSqlStatement() instanceof DALStatement) {
    MergeEngine mergeEngine = MergeEngineFactory.newInstance(connection.getShardingContext().getDatabaseType(), 
        connection.getShardingContext().getShardingRule(), routeResult.getSqlStatement(), connection.getShardingContext().getMetaData().getTable(), queryResults);
    currentResultSet = new ShardingResultSet(resultSets, mergeEngine.merge(), this);
  }
  return currentResultSet;
}

origin: apache/incubator-shardingsphere

@Override
public ResultSet getGeneratedKeys() throws SQLException {
  Optional<GeneratedKey> generatedKey = getGeneratedKey();
  if (returnGeneratedKeys && generatedKey.isPresent()) {
    return new GeneratedKeysResultSet(routeResult.getGeneratedKey().getGeneratedKeys().iterator(), generatedKey.get().getColumn().getName(), this);
  }
  if (1 == getRoutedStatements().size()) {
    return getRoutedStatements().iterator().next().getGeneratedKeys();
  }
  return new GeneratedKeysResultSet();
}

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

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

@Override
public ResultSet getResultSet() throws SQLException {
  if (null != currentResultSet) {
    return currentResultSet;
  }
  if (1 == preparedStatementExecutor.getStatements().size() && routeResult.getSqlStatement() instanceof DQLStatement) {
    currentResultSet = preparedStatementExecutor.getStatements().iterator().next().getResultSet();
    return currentResultSet;
  }
  List<ResultSet> resultSets = new ArrayList<>(preparedStatementExecutor.getStatements().size());
  List<QueryResult> queryResults = new ArrayList<>(preparedStatementExecutor.getStatements().size());
  for (Statement each : preparedStatementExecutor.getStatements()) {
    ResultSet resultSet = each.getResultSet();
    resultSets.add(resultSet);
    queryResults.add(new StreamQueryResult(resultSet));
  }
  if (routeResult.getSqlStatement() instanceof SelectStatement || routeResult.getSqlStatement() instanceof DALStatement) {
    MergeEngine mergeEngine = MergeEngineFactory.newInstance(connection.getShardingContext().getDatabaseType(), 
        connection.getShardingContext().getShardingRule(), routeResult.getSqlStatement(), connection.getShardingContext().getMetaData().getTable(), queryResults);
    currentResultSet = new ShardingResultSet(resultSets, mergeEngine.merge(), this);
  }
  return currentResultSet;
}

origin: apache/incubator-shardingsphere

  private Optional<GeneratedKey> getGeneratedKey() {
    if (null != routeResult && routeResult.getSqlStatement() instanceof InsertStatement) {
      return Optional.fromNullable(routeResult.getGeneratedKey());
    }
    return Optional.absent();
  }
}
origin: apache/incubator-shardingsphere

@Override
public ResultSet getGeneratedKeys() throws SQLException {
  Optional<GeneratedKey> generatedKey = getGeneratedKey();
  if (preparedStatementExecutor.isReturnGeneratedKeys() && generatedKey.isPresent()) {
    return new GeneratedKeysResultSet(routeResult.getGeneratedKey().getGeneratedKeys().iterator(), generatedKey.get().getColumn().getName(), this);
  }
  if (1 == preparedStatementExecutor.getStatements().size()) {
    return preparedStatementExecutor.getStatements().iterator().next().getGeneratedKeys();
  }
  return new GeneratedKeysResultSet();
}

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

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

@Override
public boolean isAccumulate() {
  return !connection.getShardingContext().getShardingRule().isAllBroadcastTables(routeResult.getSqlStatement().getTables().getTableNames());
}

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 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 boolean isAccumulate() {
  return !connection.getShardingContext().getShardingRule().isAllBroadcastTables(routeResult.getSqlStatement().getTables().getTableNames());
}

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);
}

org.apache.shardingsphere.core.routingSQLRouteResult

Javadoc

SQL route result.

Most used methods

  • getRouteUnits
  • getSqlStatement
  • <init>
  • getGeneratedKey

Popular in Java

  • Finding current android device location
  • setRequestProperty (URLConnection)
  • getExternalFilesDir (Context)
  • onCreateOptionsMenu (Activity)
  • PrintStream (java.io)
    Fake signature of an existing Java class.
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • BoxLayout (javax.swing)
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • Best plugins for Eclipse
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