package com.qiaoba.common.database.handlers.schema;

import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * OracleSchemaHandler
 *
 * @author ailanyin
 * @version 1.0
 * @since 2023/6/20 9:25
 */
@Component
public class OracleSchemaHandler implements SchemaHandler {

    private static final String ORACLE_CHANGE_SCHEMA_SQL = "alter session set current_schema = {};";

    @Override
    public void setSchema(Connection conn) {
        Statement statement = null;
        try {
            statement = conn.createStatement();
            statement.execute(StrUtil.format(ORACLE_CHANGE_SCHEMA_SQL, "ROOT"));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            IoUtil.close(statement);
        }
    }
}
