Hhuawei-committermessage
a56017af创建于 2022年9月22日历史提交
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

package com.huawei.demo;

import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.http.HttpConfig;
import com.huaweicloud.sdk.ugo.v1.UgoClient;
import com.huaweicloud.sdk.ugo.v1.model.RunSqlConversionRequest;
import com.huaweicloud.sdk.ugo.v1.model.RunSqlConversionResponse;
import com.huaweicloud.sdk.ugo.v1.model.SqlConvertReq;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 数据库和应用迁移 UGO的示例代码:SQL语句转换
 *
 * @since 2022-08-20
 */
public class SqlConversionDemo {

    private static final Logger logger = LoggerFactory.getLogger(SqlConversionDemo.class);

    public static void main(String[] args) {

        UgoClient ugoClient = getUgoClient();

        // Start to convert SQL statement
        RunSqlConversionRequest sqlConversionRequest = new RunSqlConversionRequest();
        SqlConvertReq sqlConversionBody = new SqlConvertReq();
        sqlConversionBody.setSourceDbType(SqlConvertReq.SourceDbTypeEnum.ORACLE);
        sqlConversionBody.setTargetDbType(SqlConvertReq.TargetDbTypeEnum.RDS_FOR_MYSQL);
        sqlConversionBody.setTargetDbVersion(SqlConvertReq.TargetDbVersionEnum._5_7);
        sqlConversionBody.setSqlStatement("select * from dual;");
        sqlConversionRequest.setBody(sqlConversionBody);
        RunSqlConversionResponse runSqlConversionResponse = ugoClient.runSqlConversion(sqlConversionRequest);
        logger.info(runSqlConversionResponse.toString());
    }

    private static UgoClient getUgoClient() {
        String ak = "<YOUR AK>";
        String sk = "<YOUR SK>";
        String endpoint = "<YOUR ENDPOINT>";
        String projectId = "<YOUR PROJECTID>";

        // Http Configuration for client
        HttpConfig config = HttpConfig.getDefaultHttpConfig();
        config.withIgnoreSSLVerification(true);

        // Create the authentication
        BasicCredentials auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk)
                .withProjectId(projectId);

        // Create UgoClient instance
        return UgoClient.newBuilder()
                .withHttpConfig(config)
                .withCredential(auth)
                .withEndpoint(endpoint)
                .build();
    }
}