org.apache.shardingsphere.transaction.annotation.ShardingTransactionType Java Examples
The following examples show how to use
org.apache.shardingsphere.transaction.annotation.ShardingTransactionType.
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: SeataATOrderService.java From shardingsphere with Apache License 2.0 | 5 votes |
/** * Execute XA. * * @param count insert record count * @return transaction type */ @Transactional @ShardingTransactionType(TransactionType.BASE) public TransactionType insert(final int count) { return jdbcTemplate.execute("INSERT INTO t_order (user_id, status) VALUES (?, ?)", (PreparedStatementCallback<TransactionType>) preparedStatement -> { doInsert(count, preparedStatement); return TransactionTypeHolder.get(); }); }
Example #2
Source File: ShardingTransactionJDBCAspect.java From opensharding-spi-impl with Apache License 2.0 | 5 votes |
private ShardingTransactionType getAnnotation(final JoinPoint joinPoint) { Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); ShardingTransactionType result = method.getAnnotation(ShardingTransactionType.class); if (null == result) { result = method.getDeclaringClass().getAnnotation(ShardingTransactionType.class); } return result; }
Example #3
Source File: ShardingTransactionProxyAspect.java From opensharding-spi-impl with Apache License 2.0 | 5 votes |
private ShardingTransactionType getAnnotation(final JoinPoint joinPoint) { Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); ShardingTransactionType result = method.getAnnotation(ShardingTransactionType.class); if (null == result) { result = method.getDeclaringClass().getAnnotation(ShardingTransactionType.class); } return result; }
Example #4
Source File: XAOrderService.java From shardingsphere with Apache License 2.0 | 5 votes |
/** * Execute XA. * * @param count insert record count * @return transaction type */ @Transactional @ShardingTransactionType(TransactionType.XA) public TransactionType insert(final int count) { return jdbcTemplate.execute("INSERT INTO t_order (user_id, status) VALUES (?, ?)", (PreparedStatementCallback<TransactionType>) preparedStatement -> { doInsert(count, preparedStatement); return TransactionTypeHolder.get(); }); }
Example #5
Source File: XAOrderService.java From shardingsphere with Apache License 2.0 | 5 votes |
/** * Execute XA with exception. * * @param count insert record count */ @Transactional @ShardingTransactionType(TransactionType.XA) public void insertFailed(final int count) { jdbcTemplate.execute("INSERT INTO t_order (user_id, status) VALUES (?, ?)", (PreparedStatementCallback<TransactionType>) preparedStatement -> { doInsert(count, preparedStatement); throw new SQLException("mock transaction failed"); }); }
Example #6
Source File: XATransactionalService.java From opensharding-spi-impl-example with Apache License 2.0 | 5 votes |
/** * process failure, XA transaction will be rollback. */ @Override @ShardingTransactionType(TransactionType.XA) @Transactional public void processFailure() { springPojoService.processFailure(); }
Example #7
Source File: XATransactionalService.java From opensharding-spi-impl-example with Apache License 2.0 | 5 votes |
/** * process success, XA transaction will be committed. */ @Override @ShardingTransactionType(TransactionType.XA) @Transactional public void processSuccess() { springPojoService.processSuccess(); }
Example #8
Source File: SagaTransactionalService.java From opensharding-spi-impl-example with Apache License 2.0 | 5 votes |
/** * process failure, XA transaction will be rollback. */ @Override @ShardingTransactionType(TransactionType.BASE) @Transactional public void processFailure() { springPojoService.processFailure(); }
Example #9
Source File: SagaTransactionalService.java From opensharding-spi-impl-example with Apache License 2.0 | 5 votes |
/** * process success, XA transaction will be committed. */ @Override @ShardingTransactionType(TransactionType.BASE) @Transactional public void processSuccess() { springPojoService.processSuccess(); }
Example #10
Source File: SeataATOrderService.java From shardingsphere with Apache License 2.0 | 5 votes |
/** * Execute XA with exception. * * @param count insert record count */ @Transactional @ShardingTransactionType(TransactionType.BASE) public void insertFailed(final int count) { jdbcTemplate.execute("INSERT INTO t_order (user_id, status) VALUES (?, ?)", (PreparedStatementCallback<TransactionType>) preparedStatement -> { doInsert(count, preparedStatement); throw new SQLException("mock transaction failed"); }); }
Example #11
Source File: XAOrderService.java From shardingsphere with Apache License 2.0 | 5 votes |
/** * Execute XA. * * @param count insert record count * @return transaction type */ @Transactional @ShardingTransactionType(TransactionType.XA) public TransactionType insert(final int count) { return jdbcTemplate.execute("INSERT INTO t_order (user_id, status) VALUES (?, ?)", (PreparedStatementCallback<TransactionType>) preparedStatement -> { doInsert(count, preparedStatement); return TransactionTypeHolder.get(); }); }
Example #12
Source File: XAOrderService.java From shardingsphere with Apache License 2.0 | 5 votes |
/** * Execute XA with exception. * * @param count insert record count */ @Transactional @ShardingTransactionType(TransactionType.XA) public void insertFailed(final int count) { jdbcTemplate.execute("INSERT INTO t_order (user_id, status) VALUES (?, ?)", (PreparedStatementCallback<TransactionType>) preparedStatement -> { doInsert(count, preparedStatement); throw new SQLException("mock transaction failed"); }); }
Example #13
Source File: ShardingTransactionTypeInterceptor.java From shardingsphere with Apache License 2.0 | 5 votes |
@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 #14
Source File: ShardingTransactionTypeAdvisor.java From shardingsphere with Apache License 2.0 | 5 votes |
ShardingTransactionTypeAdvisor() { Pointcut classPointcut = new ComposablePointcut(AnnotationMatchingPointcut.forClassAnnotation(ShardingTransactionType.class)); Pointcut methodPointcut = new ComposablePointcut(AnnotationMatchingPointcut.forMethodAnnotation(ShardingTransactionType.class)); transactionTypePointcut = new ComposablePointcut(classPointcut).union(methodPointcut); transactionTypeInterceptor = new ShardingTransactionTypeInterceptor(); setOrder(Ordered.LOWEST_PRECEDENCE - 1); }
Example #15
Source File: SagaTransactionalService.java From opensharding-spi-impl-example with Apache License 2.0 | 4 votes |
/** * process failure, XA transaction will be rollback. */ @ShardingTransactionType(TransactionType.BASE) @Transactional public void processFailure() { springPojoService.processFailure(); }
Example #16
Source File: ShardingTransactionTypeInterceptor.java From shardingsphere with Apache License 2.0 | 4 votes |
private ShardingTransactionType getAnnotation(final MethodInvocation invocation) { Objects.requireNonNull(invocation.getThis()); Class<?> targetClass = AopUtils.getTargetClass(invocation.getThis()); ShardingTransactionType result = getMethodAnnotation(invocation, targetClass); return null != result ? result : targetClass.getAnnotation(ShardingTransactionType.class); }
Example #17
Source File: ShardingTransactionalTestService.java From opensharding-spi-impl with Apache License 2.0 | 4 votes |
@ShardingTransactionType(TransactionType.BASE) public void testChangeTransactionTypeToBASE() { }
Example #18
Source File: ShardingTransactionalTestService.java From opensharding-spi-impl with Apache License 2.0 | 4 votes |
@ShardingTransactionType(TransactionType.XA) public void testChangeTransactionTypeToXA() { }
Example #19
Source File: ShardingTransactionalTestService.java From opensharding-spi-impl with Apache License 2.0 | 4 votes |
@ShardingTransactionType public void testChangeTransactionTypeToLOCAL() { }
Example #20
Source File: ShardingTransactionTypeInterceptor.java From shardingsphere with Apache License 2.0 | 4 votes |
private ShardingTransactionType getMethodAnnotation(final MethodInvocation invocation, final Class<?> targetClass) { Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass); final Method userDeclaredMethod = BridgeMethodResolver.findBridgedMethod(specificMethod); return userDeclaredMethod.getAnnotation(ShardingTransactionType.class); }
Example #21
Source File: ShardingTransactionProxyAspect.java From opensharding-spi-impl with Apache License 2.0 | 4 votes |
/** * Set transaction type before transaction begin. * * @param joinPoint join point */ @Before(value = "shardingTransactionalProxyPointCut()") public void setTransactionTypeBeforeTransaction(final JoinPoint joinPoint) { ShardingTransactionType shardingTransactionType = getAnnotation(joinPoint); transactionManagerHandler.switchTransactionType(shardingTransactionType.value()); }
Example #22
Source File: ShardingTransactionalTestService.java From opensharding-spi-impl with Apache License 2.0 | 4 votes |
@ShardingTransactionType(TransactionType.BASE) public void testChangeTransactionTypeToBASE() { assertThat(TransactionTypeHolder.get(), is(TransactionType.BASE)); }
Example #23
Source File: ShardingTransactionalTestService.java From opensharding-spi-impl with Apache License 2.0 | 4 votes |
@ShardingTransactionType(TransactionType.XA) public void testChangeTransactionTypeToXA() { assertThat(TransactionTypeHolder.get(), is(TransactionType.XA)); }
Example #24
Source File: ShardingTransactionalTestService.java From opensharding-spi-impl with Apache License 2.0 | 4 votes |
@ShardingTransactionType public void testChangeTransactionTypeToLOCAL() { assertThat(TransactionTypeHolder.get(), is(TransactionType.LOCAL)); }
Example #25
Source File: ShardingTransactionalTestService.java From opensharding-spi-impl with Apache License 2.0 | 4 votes |
@ShardingTransactionType(TransactionType.BASE) public void testChangeTransactionTypeToBASE() { assertThat(TransactionTypeHolder.get(), is(TransactionType.BASE)); }
Example #26
Source File: SagaTransactionalService.java From opensharding-spi-impl-example with Apache License 2.0 | 4 votes |
/** * process success, XA transaction will be committed. */ @ShardingTransactionType(TransactionType.BASE) @Transactional public void processSuccess() { springPojoService.processSuccess(); }
Example #27
Source File: SagaTransactionalService.java From opensharding-spi-impl-example with Apache License 2.0 | 4 votes |
/** * process success. */ @ShardingTransactionType(TransactionType.BASE) @Transactional public void processSuccess() { jpaCommonService.processSuccess(); }
Example #28
Source File: SagaTransactionalService.java From opensharding-spi-impl-example with Apache License 2.0 | 4 votes |
/** * process failure. */ @ShardingTransactionType(TransactionType.BASE) @Transactional public void processFailure() { jpaCommonService.processFailure(); }
Example #29
Source File: SeataTransactionalService.java From opensharding-spi-impl-example with Apache License 2.0 | 4 votes |
/** * process success. */ @ShardingTransactionType(TransactionType.BASE) @Transactional public void processSuccess() { jpaCommonService.processSuccess(); }
Example #30
Source File: SeataTransactionalService.java From opensharding-spi-impl-example with Apache License 2.0 | 4 votes |
/** * process failure. */ @ShardingTransactionType(TransactionType.BASE) @Transactional public void processFailure() { jpaCommonService.processFailure(); }