Unverified Commit ff2c1371 authored by chenqy's avatar chenqy Committed by GitHub
Browse files

Merge pull request #19 from sharding-sphere/dev

update from origin
parents 2e4c47f8 18fcde4c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
 * </p>
 */

package io.shardingsphere.core.constant;
package io.shardingsphere.core.constant.properties;

import com.google.common.base.Joiner;
import com.google.common.base.Strings;
+3 −1
Original line number Diff line number Diff line
@@ -15,8 +15,10 @@
 * </p>
 */

package io.shardingsphere.core.constant;
package io.shardingsphere.core.constant.properties;

import io.shardingsphere.core.constant.ConnectionMode;
import io.shardingsphere.core.constant.transaction.TransactionType;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

+52 −0
Original line number Diff line number Diff line
@@ -15,39 +15,38 @@
 * </p>
 */

package io.shardingsphere.transaction.common.event;
package io.shardingsphere.core.constant.transaction;

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

import java.util.UUID;

/**
 * Abstract Transaction Event.
 * Transaction operation type.
 *
 * @author zhaojun
 */
@RequiredArgsConstructor
@Getter
public abstract class TransactionEvent {
    
    private final String id = UUID.randomUUID().toString();
public enum TransactionOperationType {
    
    private final TCLType tclType;
    
    @Setter
    private Exception exception;
    BEGIN, COMMIT, ROLLBACK;
    
    /**
     * Get exception.
     * Get operation type.
     * 
     * @return exception
     * @param sql SQL
     * @return transaction operation type
     */
    // TODO why not use sharding exception directly?
    public Optional<? extends Exception> getException() {
        return Optional.fromNullable(exception);
    // TODO :hongjun move to TCLParser, need parse comment etc
    public static Optional<TransactionOperationType> getOperationType(final String sql) {
        switch (sql.toUpperCase()) {
            case "BEGIN":
            case "START TRANSACTION":
            case "SET AUTOCOMMIT=0":
                return Optional.of(TransactionOperationType.BEGIN);
            case "COMMIT":
                return Optional.of(TransactionOperationType.COMMIT);
            case "ROLLBACK":
                return Optional.of(TransactionOperationType.ROLLBACK);
            default:
                return Optional.absent();
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
 * </p>
 */

package io.shardingsphere.core.constant;
package io.shardingsphere.core.constant.transaction;

/**
 * Transaction type.
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@

package io.shardingsphere.core.constant;

import io.shardingsphere.core.constant.properties.ShardingPropertiesConstant;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
Loading