/*
 * Copyright 2016-2018 shardingsphere.io.
 * <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>
 */

package io.shardingsphere.proxy.backend.jdbc.transaction;

import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TCLType;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

/**
 * Abstract transaction engine.
 *
 * @author zhaojun
 */
@RequiredArgsConstructor
public abstract class TransactionEngine {
    
    @Getter
    @Setter
    private boolean isNeedProcessByBackendHandler = true;
    
    @Getter
    private final String sql;
    
    protected Optional<TCLType> parseSQL() {
        switch (sql.toUpperCase()) {
            case "BEGIN": case "START TRANSACTION": case "SET AUTOCOMMIT=0":
                return Optional.of(TCLType.BEGIN);
            case "COMMIT":
                return Optional.of(TCLType.COMMIT);
            case "ROLLBACK":
                return Optional.of(TCLType.ROLLBACK);
            default:
                return Optional.absent();
        }
    }
    
    /**
     * Execute transaction with binding tm.
     *
     * @return TransactionEngine
     * @throws Exception Exception
     */
    public abstract TransactionEngine execute() throws Exception;
}

@@ -931,16 +931,32 @@
 tructor%0A
+@Getter%0A@Setter%0A
 public a
@@ -1002,27 +1002,38 @@
     
-@Getter%0A    @Setter
+private final String sql;%0A    
 %0A   
@@ -1100,50 +1100,33 @@
     
-@Getter%0A    private final String sql;%0A    
+// TODO move to TCLParser
 %0A   
@@ -1226,24 +1226,37 @@
 se %22BEGIN%22: 
+%0A            
 case %22START 
@@ -1268,16 +1268,101 @@
 ACTION%22:
+%0A                // TODO SET AUTOCOMMIT=0 is not transaction begin flag? %0A           
  case %22S
@@ -1725,17 +1725,34 @@
 inding t
-m
+ransaction manager
 .%0A     *

add todo for TransactionEngine