Skip to content

Commit

Permalink
fix apache#69
Browse files Browse the repository at this point in the history
  • Loading branch information
haocao committed May 11, 2016
1 parent 01b9e1c commit 7d9546f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public final class StatementExecutorTest {

private static final String SELECT_FROM_DUAL = "SELECT * FROM dual";

private static final String DELETE_FROM_DUAL = "DELETE FROM dual";
private static final String DELETE_FROM_DUAL = "DELETE FROM dual";

private ExecutorEngine executorEngine;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public AbstractSoftTransaction getTransaction(final SoftTransactionType type) {
*/
public static Optional<SoftTransactionConfiguration> getCurrentTransactionConfiguration() {
Object transactionConfig = ExecutorDataMap.getDataMap().get(TRANSACTION_CONFIG);
return (transactionConfig == null)
return (null == transactionConfig)
? Optional.<SoftTransactionConfiguration>absent()
: Optional.of((SoftTransactionConfiguration) transactionConfig);
}
Expand All @@ -128,7 +128,7 @@ public static Optional<SoftTransactionConfiguration> getCurrentTransactionConfig
*/
public static Optional<AbstractSoftTransaction> getCurrentTransaction() {
Object transaction = ExecutorDataMap.getDataMap().get(TRANSACTION);
return (transaction == null)
return (null == transaction)
? Optional.<AbstractSoftTransaction>absent()
: Optional.of((AbstractSoftTransaction) transaction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource;
import com.dangdang.ddframe.rdb.transaction.soft.constants.TransactionLogDataSourceType;
import com.dangdang.ddframe.rdb.transaction.soft.datasource.TransactionLogDataSource;
import com.dangdang.ddframe.rdb.transaction.soft.datasource.impl.MemoryTransactionLogDataSource;
import com.dangdang.ddframe.rdb.transaction.soft.datasource.impl.RdbTransactionLogDataSource;
import com.google.common.base.Optional;
import lombok.AccessLevel;
import lombok.Getter;
Expand All @@ -29,6 +32,8 @@
import java.sql.Connection;
import java.sql.SQLException;

import static com.dangdang.ddframe.rdb.transaction.soft.constants.TransactionLogDataSourceType.RDB;

/**
* 柔性事务配置对象.
*
Expand All @@ -53,7 +58,7 @@ public class SoftTransactionConfiguration {
/**
* 事务日志存储类型.
*/
private TransactionLogDataSourceType storageType = TransactionLogDataSourceType.RDB;
private TransactionLogDataSourceType storageType = RDB;

/**
* 存储事务日志的数据源.
Expand All @@ -77,4 +82,24 @@ public Connection getTargetConnection(final String dataSourceName) throws SQLExc
}
return ((ShardingDataSource) targetDataSource).getConnection().getConnection(dataSourceName);
}

/**
* 构建事务日志事务源.
*
* @return 存储事务日志的数据源
*/
public TransactionLogDataSource buildTransactionLogDataSource() {
TransactionLogDataSource result;
switch (storageType) {
case MEMORY:
result = new MemoryTransactionLogDataSource();
break;
case RDB:
result = new RdbTransactionLogDataSource(transactionLogDataSource);
break;
default:
throw new UnsupportedOperationException();
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
import com.dangdang.ddframe.job.api.JobScheduler;
import com.dangdang.ddframe.rdb.transaction.soft.api.config.AbstractBestEffortsDeliveryJobConfiguration;
import com.dangdang.ddframe.rdb.transaction.soft.api.config.SoftTransactionConfiguration;
import com.dangdang.ddframe.rdb.transaction.soft.datasource.impl.RdbTransactionLogDataSource;
import com.dangdang.ddframe.rdb.transaction.soft.storage.TransactionLogStorageFactory;
import com.dangdang.ddframe.reg.base.CoordinatorRegistryCenter;
import com.dangdang.ddframe.reg.zookeeper.ZookeeperConfiguration;
import com.dangdang.ddframe.reg.zookeeper.ZookeeperRegistryCenter;

import lombok.RequiredArgsConstructor;

/**
Expand All @@ -49,7 +47,7 @@ public final void init() {
regCenter.init();
JobScheduler jobScheduler = new JobScheduler(regCenter, createBedJobConfiguration(bedJobConfig));
jobScheduler.setField("transactionConfig", transactionConfig);
jobScheduler.setField("transactionLogStorage", TransactionLogStorageFactory.createTransactionLogStorage(new RdbTransactionLogDataSource(transactionConfig.getTransactionLogDataSource())));
jobScheduler.setField("transactionLogStorage", TransactionLogStorageFactory.createTransactionLogStorage(transactionConfig.buildTransactionLogDataSource()));
jobScheduler.init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import com.dangdang.ddframe.rdb.transaction.soft.api.SoftTransactionManager;
import com.dangdang.ddframe.rdb.transaction.soft.api.config.SoftTransactionConfiguration;
import com.dangdang.ddframe.rdb.transaction.soft.bed.BEDSoftTransaction;
import com.dangdang.ddframe.rdb.transaction.soft.constants.SoftTransactionType;
import com.dangdang.ddframe.rdb.transaction.soft.datasource.impl.RdbTransactionLogDataSource;
import com.dangdang.ddframe.rdb.transaction.soft.storage.TransactionLog;
import com.dangdang.ddframe.rdb.transaction.soft.storage.TransactionLogStorage;
import com.dangdang.ddframe.rdb.transaction.soft.storage.TransactionLogStorageFactory;
Expand All @@ -36,6 +34,11 @@
import java.sql.ResultSet;
import java.sql.SQLException;

import static com.dangdang.ddframe.rdb.sharding.executor.event.EventExecutionType.BEFORE_EXECUTE;
import static com.dangdang.ddframe.rdb.sharding.executor.event.EventExecutionType.EXECUTE_FAILURE;
import static com.dangdang.ddframe.rdb.sharding.executor.event.EventExecutionType.EXECUTE_SUCCESS;
import static com.dangdang.ddframe.rdb.transaction.soft.constants.SoftTransactionType.BestEffortsDelivery;

/**
* 最大努力送达型事务监听器.
*
Expand All @@ -51,7 +54,7 @@ public void listen(final DMLExecutionEvent event) {
return;
}
SoftTransactionConfiguration transactionConfig = SoftTransactionManager.getCurrentTransactionConfiguration().get();
TransactionLogStorage transactionLogStorage = TransactionLogStorageFactory.createTransactionLogStorage(new RdbTransactionLogDataSource(transactionConfig.getTransactionLogDataSource()));
TransactionLogStorage transactionLogStorage = TransactionLogStorageFactory.createTransactionLogStorage(transactionConfig.buildTransactionLogDataSource());
BEDSoftTransaction bedSoftTransaction = (BEDSoftTransaction) SoftTransactionManager.getCurrentTransaction().get();
switch (event.getEventExecutionType()) {
case BEFORE_EXECUTE:
Expand Down Expand Up @@ -97,7 +100,7 @@ public void listen(final DMLExecutionEvent event) {

private boolean isProcessContinuously() {
return SoftTransactionManager.getCurrentTransaction().isPresent()
&& SoftTransactionType.BestEffortsDelivery == SoftTransactionManager.getCurrentTransaction().get().getTransactionType();
&& BestEffortsDelivery == SoftTransactionManager.getCurrentTransaction().get().getTransactionType();
}

private boolean isValidConnection(final Connection conn) {
Expand Down

0 comments on commit 7d9546f

Please sign in to comment.