Java Code Examples for net.sf.jsqlparser.statement.delete.Delete#getTables()

The following examples show how to use net.sf.jsqlparser.statement.delete.Delete#getTables() . 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: CloudSpannerPreparedStatement.java    From spanner-jdbc with MIT License 5 votes vote down vote up
private DeleteWorker createDeleteWorker(Delete delete) throws SQLException {
  if (delete.getTable() == null
      || (delete.getTables() != null && !delete.getTables().isEmpty())) {
    throw new CloudSpannerSQLException("DELETE statement must contain only one table",
        Code.INVALID_ARGUMENT);
  }
  return new DeleteWorker(getConnection(), delete, getParameterStore(),
      getConnection().isAllowExtendedMode());
}
 
Example 2
Source File: TxcSqlExecuteInterceptor.java    From tx-lcn with Apache License 2.0 5 votes vote down vote up
@Override
public void preDelete(Delete delete) throws SQLException {
    // 获取线程传递参数
    Connection connection = (Connection) DTXLocalContext.cur().getResource();

    // 获取Sql Table
    if (delete.getTables().size() == 0) {
        delete.setTables(Collections.singletonList(delete.getTable()));
    }

    // Delete Sql 数据
    List<String> tables = new ArrayList<>(delete.getTables().size());
    List<String> primaryKeys = new ArrayList<>(3);
    List<String> columns = new ArrayList<>();

    for (Table table : delete.getTables()) {
        TableStruct tableStruct = globalContext.tableStruct(table.getName(),
                () -> tableStructAnalyser.analyse(connection, table.getName()));
        tableStruct.getColumns().forEach((k, v) -> columns.add(tableStruct.getTableName() + SqlUtils.DOT + k));
        tableStruct.getPrimaryKeys().forEach(primaryKey -> primaryKeys.add(tableStruct.getTableName() + SqlUtils.DOT + primaryKey));
        tables.add(tableStruct.getTableName());
    }

    // 前置准备
    try {
        DeleteImageParams deleteImageParams = new DeleteImageParams();
        deleteImageParams.setColumns(columns);
        deleteImageParams.setPrimaryKeys(primaryKeys);
        deleteImageParams.setTables(tables);
        deleteImageParams.setSqlWhere(delete.getWhere().toString());
        txcService.resolveDeleteImage(deleteImageParams);
    } catch (TxcLogicException e) {
        throw new SQLException(e.getMessage());
    }
}