Java Code Examples for org.apache.shardingsphere.transaction.core.TransactionTypeHolder#get()

The following examples show how to use org.apache.shardingsphere.transaction.core.TransactionTypeHolder#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConnectionAdapterTest.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
@Test
public void assertCloseShouldNotClearTransactionType() throws SQLException {
    TransactionTypeHolder.set(TransactionType.XA);
    TransactionType currentTransactionType = TransactionTypeHolder.get();
    try (ShardingSphereConnection actual = getShardingSphereDataSource().getConnection()) {
        actual.createStatement().executeQuery(sql);
    }
    assertThat(TransactionTypeHolder.get(), is(currentTransactionType));
}
 
Example 2
Source File: ShardingTransactionTypeInterceptor.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(final MethodInvocation methodInvocation) throws Throwable {
    ShardingTransactionType shardingTransactionType = getAnnotation(methodInvocation);
    Objects.requireNonNull(shardingTransactionType, "could not found sharding transaction type annotation");
    TransactionType preTransactionType = TransactionTypeHolder.get();
    TransactionTypeHolder.set(shardingTransactionType.value());
    try {
        return methodInvocation.proceed();
    } finally {
        TransactionTypeHolder.clear();
        if (null != preTransactionType) {
            TransactionTypeHolder.set(preTransactionType);
        }
    }
}
 
Example 3
Source File: ShardingTransactionTypeScannerTest.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
@Test
public void assertShardingTransactionType() {
    TransactionType preTransactionType = TransactionTypeHolder.get();
    mockService.executeLocal();
    assertThat(TransactionTypeHolder.get(), is(preTransactionType));
    mockService.executeBase();
    assertThat(TransactionTypeHolder.get(), is(preTransactionType));
    mockService.execute();
    assertThat(TransactionTypeHolder.get(), is(preTransactionType));
}
 
Example 4
Source File: ShardingSphereDataSource.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
@Override
public ShardingSphereConnection getConnection() {
    return new ShardingSphereConnection(getDataSourceMap(), schemaContexts, TransactionTypeHolder.get());
}
 
Example 5
Source File: MockService.java    From shardingsphere with Apache License 2.0 2 votes vote down vote up
/**
 * Execute local.
 *
 * @return transaction type
 */
@ShardingTransactionType(TransactionType.LOCAL)
public TransactionType executeLocal() {
    return TransactionTypeHolder.get();
}
 
Example 6
Source File: MockService.java    From shardingsphere with Apache License 2.0 2 votes vote down vote up
/**
 * Execute BASE.
 *
 * @return transaction type
 */
@ShardingTransactionType(TransactionType.BASE)
public TransactionType executeBase() {
    return TransactionTypeHolder.get();
}
 
Example 7
Source File: MockService.java    From shardingsphere with Apache License 2.0 2 votes vote down vote up
/**
 * Execute.
 *
 * @return transaction type
 */
public TransactionType execute() {
    return TransactionTypeHolder.get();
}