/*
   Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
   SPDX-License-Identifier: Apache-2.0
*/

package com.aws.rest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.redshiftdata.model.DescribeStatementRequest;
import software.amazon.awssdk.services.redshiftdata.model.DescribeStatementResponse;
import software.amazon.awssdk.services.redshiftdata.model.ExecuteStatementRequest;
import software.amazon.awssdk.services.redshiftdata.model.ExecuteStatementResponse;
import software.amazon.awssdk.services.redshiftdata.model.GetStatementResultRequest;
import software.amazon.awssdk.services.redshiftdata.model.GetStatementResultResponse;
import software.amazon.awssdk.services.redshiftdata.model.RedshiftDataException;
import software.amazon.awssdk.services.redshiftdata.RedshiftDataClient;
import software.amazon.awssdk.services.redshiftdata.model.SqlParameter;
import java.util.List;
import java.util.stream.Collectors;

@SpringBootApplication
public class App {

    // Specify the database name, the database user, and the cluster Id value.
    private static final String database = "dev";
    private static final String dbUser ="awsuser";
    private static final String clusterId = "redshift-cluster-1";

    static RedshiftDataClient getClient() {

        Region region = Region.US_WEST_2;
        return RedshiftDataClient.builder()
            .region(region)
            .credentialsProvider(ProfileCredentialsProvider.create())
            .build();
    }

    static List<WorkItem> getResults(String statementId) {
        try {
            GetStatementResultRequest resultRequest = GetStatementResultRequest.builder()
                .id(statementId)
                .build();

            GetStatementResultResponse response = App.getClient().getStatementResult(resultRequest);
            return response
                .records()
                .stream()
                .map(WorkItem::from)
                .collect(Collectors.toUnmodifiableList());

        } catch (RedshiftDataException e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
        return null;
    }

    // Update the work table.
    static void flipItemArchive(String sqlStatement,  List<SqlParameter> parameters ) {
        try {
            ExecuteStatementRequest statementRequest = ExecuteStatementRequest.builder()
                .clusterIdentifier(clusterId)
                .database(database)
                .dbUser(dbUser)
                .sql(sqlStatement)
                .parameters(parameters)
                .build();

            App.getClient().executeStatement(statementRequest);

        } catch (RedshiftDataException e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
    }

    static void checkStatement(String sqlId ) {
        try {
            DescribeStatementRequest statementRequest = DescribeStatementRequest.builder()
                .id(sqlId)
                .build() ;

            // Wait until the sql statement processing is finished.
            String status;
            while (true) {
                DescribeStatementResponse response = App.getClient().describeStatement(statementRequest);
                status = response.statusAsString();
                System.out.println("..."+status);

                if (status.compareTo("FINISHED") == 0) {
                    break;
                }
                Thread.sleep(500);
            }
            System.out.println("The statement is finished!");

        } catch (RedshiftDataException | InterruptedException e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
    }

    static ExecuteStatementResponse execute(String sqlStatement, List<SqlParameter> parameters) {
        ExecuteStatementRequest sqlRequest = ExecuteStatementRequest.builder()
            .clusterIdentifier(clusterId)
            .database(database)
            .dbUser(dbUser)
            .sql(sqlStatement)
            .parameters(parameters)
            .build();
        return App.getClient().executeStatement(sqlRequest);
    }

   public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

@@ -114,16 +114,18 @@
 %0D%0A*/%0D%0A%0D%0A
+%0D%0A
 package 
@@ -267,4224 +267,59 @@
 n;%0D%0A
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;%0D%0Aimport software.amazon.awssdk.regions.Region;%0D%0Aimport software.amazon.awssdk.services.redshiftdata.model.DescribeStatementRequest;%0D%0Aimport software.amazon.awssdk.services.redshiftdata.model.DescribeStatementResponse;%0D%0Aimport software.amazon.awssdk.services.redshiftdata.model.ExecuteStatementRequest;%0D%0Aimport software.amazon.awssdk.services.redshiftdata.model.ExecuteStatementResponse;%0D%0Aimport software.amazon.awssdk.services.redshiftdata.model.GetStatementResultRequest;%0D%0Aimport software.amazon.awssdk.services.redshiftdata.model.GetStatementResultResponse;%0D%0Aimport software.amazon.awssdk.services.redshiftdata.model.RedshiftDataException;%0D%0Aimport software.amazon.awssdk.services.redshiftdata.RedshiftDataClient;%0D%0Aimport software.amazon.awssdk.services.redshiftdata.model.SqlParameter;%0D%0Aimport java.util.List;%0D%0Aimport java.util.stream.Collectors;%0D%0A%0D%0A@SpringBootApplication%0D%0Apublic class App %7B%0D%0A%0D%0A    // Specify the database name, the database user, and the cluster Id value.%0D%0A    private static final String database = %22dev%22;%0D%0A    private static final String dbUser =%22awsuser%22;%0D%0A    private static final String clusterId = %22redshift-cluster-1%22;%0D%0A%0D%0A    static RedshiftDataClient getClient() %7B%0D%0A%0D%0A        Region region = Region.US_WEST_2;%0D%0A        return RedshiftDataClient.builder()%0D%0A            .region(region)%0D%0A            .credentialsProvider(ProfileCredentialsProvider.create())%0D%0A            .build();%0D%0A    %7D%0D%0A%0D%0A    static List%3CWorkItem%3E getResults(String statementId) %7B%0D%0A        try %7B%0D%0A            GetStatementResultRequest resultRequest = GetStatementResultRequest.builder()%0D%0A                .id(statementId)%0D%0A                .build();%0D%0A%0D%0A            GetStatementResultResponse response = App.getClient().getStatementResult(resultRequest);%0D%0A            return response%0D%0A                .records()%0D%0A                .stream()%0D%0A                .map(WorkItem::from)%0D%0A                .collect(Collectors.toUnmodifiableList());%0D%0A%0D%0A        %7D catch (RedshiftDataException e) %7B%0D%0A            System.err.println(e.getMessage());%0D%0A            System.exit(1);%0D%0A        %7D%0D%0A        return null;%0D%0A    %7D%0D%0A%0D%0A    // Update the work table.%0D%0A    static void flipItemArchive(String sqlStatement,  List%3CSqlParameter%3E parameters ) %7B%0D%0A        try %7B%0D%0A            ExecuteStatementRequest statementRequest = ExecuteStatementRequest.builder()%0D%0A                .clusterIdentifier(clusterId)%0D%0A                .database(database)%0D%0A                .dbUser(dbUser)%0D%0A                .sql(sqlStatement)%0D%0A                .parameters(parameters)%0D%0A                .build();%0D%0A%0D%0A            App.getClient().executeStatement(statementRequest);%0D%0A%0D%0A        %7D catch (RedshiftDataException e) %7B%0D%0A            System.err.println(e.getMessage());%0D%0A            System.exit(1);%0D%0A        %7D%0D%0A    %7D%0D%0A%0D%0A    static void checkStatement(String sqlId ) %7B%0D%0A        try %7B%0D%0A            DescribeStatementRequest statementRequest = DescribeStatementRequest.builder()%0D%0A                .id(sqlId)%0D%0A                .build() ;%0D%0A%0D%0A            // Wait until the sql statement processing is finished.%0D%0A            String status;%0D%0A            while (true) %7B%0D%0A                DescribeStatementResponse response = App.getClient().describeStatement(statementRequest);%0D%0A                status = response.statusAsString();%0D%0A                System.out.println(%22...%22+status);%0D%0A%0D%0A                if (status.compareTo(%22FINISHED%22) == 0) %7B%0D%0A                    break;%0D%0A                %7D%0D%0A                Thread.sleep(500);%0D%0A            %7D%0D%0A            System.out.println(%22The statement is finished!%22);%0D%0A%0D%0A        %7D catch (RedshiftDataException %7C InterruptedException e) %7B%0D%0A            System.err.println(e.getMessage());%0D%0A            System.exit(1);%0D%0A        %7D%0D%0A    %7D%0D%0A%0D%0A    static ExecuteStatementResponse execute(String sqlStatement, List%3CSqlParameter%3E parameters) %7B%0D%0A        ExecuteStatementRequest sqlRequest = ExecuteStatementRequest.builder()%0D%0A            .clusterIdentifier(clusterId)%0D%0A            .database(database)%0D%0A            .dbUser(dbUser)%0D%0A            .sql(sqlStatement)%0D%0A            .parameters(parameters)%0D%0A            .build();%0D%0A        return App.getClient().executeStatement(sqlRequest);%0D%0A    %7D%0D%0A%0D%0A
+%0D%0A@SpringBootApplication%0D%0Apublic class App %7B%0D%0A     
    p

Update App.java