Skip to content

Commit 8836f38

Browse files
committed
end-of-line normalization
1 parent 8238816 commit 8836f38

File tree

7 files changed

+339
-339
lines changed

7 files changed

+339
-339
lines changed
Lines changed: 106 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,106 @@
1-
/*
2-
* Copyright 2010-2013 the original author or authors.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
package org.mybatis.spring.asyncsynchronization;
17-
18-
import java.lang.reflect.InvocationHandler;
19-
import java.lang.reflect.InvocationTargetException;
20-
import java.lang.reflect.Method;
21-
import java.lang.reflect.Proxy;
22-
import java.util.HashSet;
23-
import java.util.Set;
24-
25-
import org.springframework.transaction.support.TransactionSynchronization;
26-
27-
/**
28-
* For use as ByteMan helper
29-
*
30-
* @author Alex Rykov
31-
*
32-
*/
33-
public class AsyncAfterCompletionHelper {
34-
/**
35-
*
36-
* Invocation handler that performs afterCompletion on a separate thread
37-
* See Github issue #18
38-
*
39-
* @author Alex Rykov
40-
*
41-
*/
42-
static class AsynchAfterCompletionInvocationHandler implements
43-
InvocationHandler {
44-
45-
private Object target;
46-
47-
AsynchAfterCompletionInvocationHandler(Object target) {
48-
this.target = target;
49-
}
50-
51-
public Object invoke(final Object proxy, final Method method,
52-
final Object[] args) throws Throwable {
53-
if ("afterCompletion".equals(method.getName())) {
54-
final Set<Object> retValSet = new HashSet<Object>();
55-
final Set<Throwable> exceptionSet = new HashSet<Throwable>();
56-
Thread thread = new Thread() {
57-
@Override
58-
public void run() {
59-
try {
60-
retValSet.add(method.invoke(target, args));
61-
} catch (InvocationTargetException ite) {
62-
exceptionSet.add(ite.getCause());
63-
64-
} catch (IllegalArgumentException e) {
65-
exceptionSet.add(e);
66-
67-
} catch (IllegalAccessException e) {
68-
exceptionSet.add(e);
69-
}
70-
}
71-
};
72-
thread.start();
73-
thread.join();
74-
if (exceptionSet.isEmpty()) {
75-
return retValSet.iterator().next();
76-
} else {
77-
throw exceptionSet.iterator().next();
78-
}
79-
} else {
80-
return method.invoke(target, args);
81-
}
82-
}
83-
84-
}
85-
86-
/**
87-
* Creates proxy that performs afterCompletion call on a separate thread
88-
*
89-
* @param synchronization
90-
* @return
91-
*/
92-
public TransactionSynchronization createSynchronizationWithAsyncAfterComplete(
93-
TransactionSynchronization synchronization) {
94-
if (Proxy.isProxyClass(synchronization.getClass())
95-
&& Proxy.getInvocationHandler(synchronization) instanceof AsynchAfterCompletionInvocationHandler) {
96-
// avoiding double wrapping just in case
97-
return synchronization;
98-
}
99-
Class<?>[] interfaces = { TransactionSynchronization.class };
100-
return (TransactionSynchronization) Proxy.newProxyInstance(synchronization
101-
.getClass().getClassLoader(), interfaces,
102-
new AsynchAfterCompletionInvocationHandler(synchronization));
103-
104-
}
105-
106-
}
1+
/*
2+
* Copyright 2010-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.spring.asyncsynchronization;
17+
18+
import java.lang.reflect.InvocationHandler;
19+
import java.lang.reflect.InvocationTargetException;
20+
import java.lang.reflect.Method;
21+
import java.lang.reflect.Proxy;
22+
import java.util.HashSet;
23+
import java.util.Set;
24+
25+
import org.springframework.transaction.support.TransactionSynchronization;
26+
27+
/**
28+
* For use as ByteMan helper
29+
*
30+
* @author Alex Rykov
31+
*
32+
*/
33+
public class AsyncAfterCompletionHelper {
34+
/**
35+
*
36+
* Invocation handler that performs afterCompletion on a separate thread
37+
* See Github issue #18
38+
*
39+
* @author Alex Rykov
40+
*
41+
*/
42+
static class AsynchAfterCompletionInvocationHandler implements
43+
InvocationHandler {
44+
45+
private Object target;
46+
47+
AsynchAfterCompletionInvocationHandler(Object target) {
48+
this.target = target;
49+
}
50+
51+
public Object invoke(final Object proxy, final Method method,
52+
final Object[] args) throws Throwable {
53+
if ("afterCompletion".equals(method.getName())) {
54+
final Set<Object> retValSet = new HashSet<Object>();
55+
final Set<Throwable> exceptionSet = new HashSet<Throwable>();
56+
Thread thread = new Thread() {
57+
@Override
58+
public void run() {
59+
try {
60+
retValSet.add(method.invoke(target, args));
61+
} catch (InvocationTargetException ite) {
62+
exceptionSet.add(ite.getCause());
63+
64+
} catch (IllegalArgumentException e) {
65+
exceptionSet.add(e);
66+
67+
} catch (IllegalAccessException e) {
68+
exceptionSet.add(e);
69+
}
70+
}
71+
};
72+
thread.start();
73+
thread.join();
74+
if (exceptionSet.isEmpty()) {
75+
return retValSet.iterator().next();
76+
} else {
77+
throw exceptionSet.iterator().next();
78+
}
79+
} else {
80+
return method.invoke(target, args);
81+
}
82+
}
83+
84+
}
85+
86+
/**
87+
* Creates proxy that performs afterCompletion call on a separate thread
88+
*
89+
* @param synchronization
90+
* @return
91+
*/
92+
public TransactionSynchronization createSynchronizationWithAsyncAfterComplete(
93+
TransactionSynchronization synchronization) {
94+
if (Proxy.isProxyClass(synchronization.getClass())
95+
&& Proxy.getInvocationHandler(synchronization) instanceof AsynchAfterCompletionInvocationHandler) {
96+
// avoiding double wrapping just in case
97+
return synchronization;
98+
}
99+
Class<?>[] interfaces = { TransactionSynchronization.class };
100+
return (TransactionSynchronization) Proxy.newProxyInstance(synchronization
101+
.getClass().getClassLoader(), interfaces,
102+
new AsynchAfterCompletionInvocationHandler(synchronization));
103+
104+
}
105+
106+
}
Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
/*
2-
* Copyright 2010-2013 the original author or authors.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
package org.mybatis.spring.asyncsynchronization;
17-
18-
import org.jboss.byteman.contrib.bmunit.BMRule;
19-
import org.jboss.byteman.contrib.bmunit.BMUnitRunner;
20-
import org.junit.runner.RunWith;
21-
import org.mybatis.spring.SqlSessionTemplateTest;
22-
23-
/**
24-
*
25-
* The same test as original but afterCompletion is being called on a separate thread
26-
*
27-
* @author Alex Rykov
28-
*
29-
*/
30-
@RunWith(BMUnitRunner.class)
31-
@BMRule(name = "proxy synchronizations", targetClass = "TransactionSynchronizationManager", targetMethod = "registerSynchronization(TransactionSynchronization)", helper = "org.mybatis.spring.asyncsynchronization.AsyncAfterCompletionHelper", action = "$1=createSynchronizationWithAsyncAfterComplete($1)")
32-
public class SqlSessionTemplateAsyncAfterCompletionTest extends SqlSessionTemplateTest {
33-
34-
}
1+
/*
2+
* Copyright 2010-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.spring.asyncsynchronization;
17+
18+
import org.jboss.byteman.contrib.bmunit.BMRule;
19+
import org.jboss.byteman.contrib.bmunit.BMUnitRunner;
20+
import org.junit.runner.RunWith;
21+
import org.mybatis.spring.SqlSessionTemplateTest;
22+
23+
/**
24+
*
25+
* The same test as original but afterCompletion is being called on a separate thread
26+
*
27+
* @author Alex Rykov
28+
*
29+
*/
30+
@RunWith(BMUnitRunner.class)
31+
@BMRule(name = "proxy synchronizations", targetClass = "TransactionSynchronizationManager", targetMethod = "registerSynchronization(TransactionSynchronization)", helper = "org.mybatis.spring.asyncsynchronization.AsyncAfterCompletionHelper", action = "$1=createSynchronizationWithAsyncAfterComplete($1)")
32+
public class SqlSessionTemplateAsyncAfterCompletionTest extends SqlSessionTemplateTest {
33+
34+
}
Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
/*
2-
* Copyright 2010-2013 the original author or authors.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
package org.mybatis.spring.submitted.xa;
17-
18-
public class User {
19-
20-
private Integer id;
21-
private String name;
22-
23-
public User() {
24-
}
25-
26-
public User(Integer id, String name) {
27-
this.id = id;
28-
this.name = name;
29-
}
30-
31-
public String getName() {
32-
return name;
33-
}
34-
35-
public void setName(String name) {
36-
this.name = name;
37-
}
38-
39-
public Integer getId() {
40-
return this.id;
41-
}
42-
43-
public void setId(Integer id) {
44-
this.id = id;
45-
}
46-
}
1+
/*
2+
* Copyright 2010-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.spring.submitted.xa;
17+
18+
public class User {
19+
20+
private Integer id;
21+
private String name;
22+
23+
public User() {
24+
}
25+
26+
public User(Integer id, String name) {
27+
this.id = id;
28+
this.name = name;
29+
}
30+
31+
public String getName() {
32+
return name;
33+
}
34+
35+
public void setName(String name) {
36+
this.name = name;
37+
}
38+
39+
public Integer getId() {
40+
return this.id;
41+
}
42+
43+
public void setId(Integer id) {
44+
this.id = id;
45+
}
46+
}

0 commit comments

Comments
 (0)