AbstractSQLExecutionEvent.java 1.5 KB
Newer Older
T
terrymanu 已提交
1
/*
T
terrymanu 已提交
2
 * Copyright 2016-2018 shardingsphere.io.
T
terrymanu 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </p>
 */

18
package io.shardingsphere.core.executor.event;
19 20

import com.google.common.base.Optional;
21
import io.shardingsphere.core.routing.SQLUnit;
22 23 24 25 26 27 28 29 30 31
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.sql.SQLException;
import java.util.List;

/**
 * SQL execution event.
 * 
 * @author gaohongtao
32
 * @author maxiaoguang
33 34 35 36 37 38 39
 */
@RequiredArgsConstructor
@Getter
public abstract class AbstractSQLExecutionEvent extends AbstractExecutionEvent {
    
    private final String dataSource;
    
40
    private final SQLUnit sqlUnit;
41 42 43
    
    private final List<Object> parameters;
    
44 45 46 47 48
    /**
     * Get exception.
     *
     * @return exception
     */
49 50 51 52 53 54 55 56
    public Optional<SQLException> getException() {
        Optional<? extends Exception> ex = super.getException();
        if (ex.isPresent()) {
            return Optional.of((SQLException) ex.get());
        }
        return Optional.absent();
    }
}