use of com.dangdang.ddframe.rdb.transaction.soft.api.SoftTransactionManager in project sharding-jdbc by dangdangdotcom.
the class Main method updateFailure.
private static void updateFailure(final DataSource dataSource) throws SQLException {
String sql1 = "UPDATE t_order SET status='UPDATE_1' WHERE user_id=10 AND order_id=1000";
String sql2 = "UPDATE t_order SET not_existed_column=1 WHERE user_id=1 AND order_id=?";
String sql3 = "UPDATE t_order SET status='UPDATE_2' WHERE user_id=10 AND order_id=1000";
SoftTransactionManager transactionManager = new SoftTransactionManager(getSoftTransactionConfiguration(dataSource));
transactionManager.init();
BEDSoftTransaction transaction = (BEDSoftTransaction) transactionManager.getTransaction(SoftTransactionType.BestEffortsDelivery);
Connection conn = null;
try {
conn = dataSource.getConnection();
transaction.begin(conn);
PreparedStatement preparedStatement1 = conn.prepareStatement(sql1);
PreparedStatement preparedStatement2 = conn.prepareStatement(sql2);
preparedStatement2.setObject(1, 1000);
PreparedStatement preparedStatement3 = conn.prepareStatement(sql3);
preparedStatement1.executeUpdate();
preparedStatement2.executeUpdate();
preparedStatement3.executeUpdate();
} finally {
transaction.end();
if (conn != null) {
conn.close();
}
}
}
use of com.dangdang.ddframe.rdb.transaction.soft.api.SoftTransactionManager in project sharding-jdbc by dangdangdotcom.
the class AbstractSoftTransactionMockTest method setUp.
@Before
public void setUp() throws Exception {
SoftTransactionConfiguration softTransactionConfiguration = mock(SoftTransactionConfiguration.class);
when(softTransactionConfiguration.getTransactionLogDataSource()).thenReturn(mock(DataSource.class));
when(softTransactionConfiguration.getBestEffortsDeliveryJobConfiguration()).thenReturn(Optional.<NestedBestEffortsDeliveryJobConfiguration>absent());
softTransactionConfiguration.setBestEffortsDeliveryJobConfiguration(Optional.<NestedBestEffortsDeliveryJobConfiguration>absent());
softTransactionManager = new SoftTransactionManager(softTransactionConfiguration);
}
use of com.dangdang.ddframe.rdb.transaction.soft.api.SoftTransactionManager in project sharding-jdbc by dangdangdotcom.
the class SoftTransactionTest method bedSoftTransactionTest.
@Test
public void bedSoftTransactionTest() throws SQLException {
SoftTransactionManager transactionManagerFactory = new SoftTransactionManager(getSoftTransactionConfiguration(getShardingDataSource()));
transactionManagerFactory.init();
BEDSoftTransaction transactionManager = (BEDSoftTransaction) transactionManagerFactory.getTransaction(SoftTransactionType.BestEffortsDelivery);
transactionManager.begin(getShardingDataSource().getConnection());
insert();
assertThat(select(), is(1));
transactionManager.end();
}
Aggregations