KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jdbc > support > lob > JtaLobCreatorSynchronization


1 /*
2  * Copyright 2002-2006 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
17 package org.springframework.jdbc.support.lob;
18
19 import javax.transaction.Synchronization JavaDoc;
20
21 import org.springframework.util.Assert;
22
23 /**
24  * Callback for resource cleanup at the end of a JTA transaction.
25  * Invokes <code>LobCreator.close()</code> to clean up temporary LOBs
26  * that might have been created.
27  *
28  * @author Juergen Hoeller
29  * @since 2.0
30  * @see org.springframework.jdbc.support.lob.LobCreator#close()
31  * @see javax.transaction.Transaction#registerSynchronization
32  */

33 public class JtaLobCreatorSynchronization implements Synchronization JavaDoc {
34
35     private final LobCreator lobCreator;
36
37     private boolean beforeCompletionCalled = false;
38
39
40     /**
41      * Create a JtaLobCreatorSynchronization for the given LobCreator.
42      * @param lobCreator the LobCreator to close after transaction completion
43      */

44     public JtaLobCreatorSynchronization(LobCreator lobCreator) {
45         Assert.notNull(lobCreator, "LobCreator must not be null");
46         this.lobCreator = lobCreator;
47     }
48
49     public void beforeCompletion() {
50         // Close the LobCreator early if possible, to avoid issues with strict JTA
51
// implementations that issue warnings when doing JDBC operations after
52
// transaction completion.
53
this.beforeCompletionCalled = true;
54         this.lobCreator.close();
55     }
56
57     public void afterCompletion(int status) {
58         if (!this.beforeCompletionCalled) {
59             // beforeCompletion not called before (probably because of JTA rollback).
60
// Close the LobCreator here.
61
this.lobCreator.close();
62         }
63     }
64
65 }
66
Popular Tags