KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webdav > connector > WebDAVLocalTransaction


1 /*
2  * $Header: /home/cvs/jakarta-slide/webdavclient/connector/src/java/org/apache/webdav/connector/WebDAVLocalTransaction.java,v 1.2 2004/07/15 12:37:36 ozeigermann Exp $
3  * $Revision: 1.2 $
4  * $Date: 2004/07/15 12:37:36 $
5  *
6  * ====================================================================
7  *
8  * Copyright 2004 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.webdav.connector;
25
26 import java.io.IOException JavaDoc;
27
28 import javax.resource.ResourceException JavaDoc;
29 import org.apache.webdav.lib.WebdavResource;
30
31 /**
32  *
33  * @version $Revision: 1.2 $
34  *
35  */

36 public class WebDAVLocalTransaction implements javax.resource.spi.LocalTransaction JavaDoc, javax.resource.cci.LocalTransaction JavaDoc {
37
38     protected WebdavResource webdavResource;
39     protected String JavaDoc owner;
40     protected int timeout;
41
42     public WebDAVLocalTransaction(WebdavResource webdavResource, String JavaDoc owner, int timeout) {
43         this.webdavResource = webdavResource;
44         this.owner = owner;
45         this.timeout = timeout;
46     }
47
48     public void begin() throws ResourceException JavaDoc {
49         try {
50             webdavResource.startTransaction(owner, timeout);
51         } catch (IOException JavaDoc e) {
52             throw new ResourceException JavaDoc("Could not start transaction", e);
53         }
54     }
55
56     public void commit() throws ResourceException JavaDoc {
57         try {
58             if (!webdavResource.commitTransaction()) {
59                 throw new ResourceException JavaDoc("Could not commit transaction");
60             }
61         } catch (IOException JavaDoc e) {
62             throw new ResourceException JavaDoc("Could not commit transaction", e);
63         }
64     }
65
66     public void rollback() throws ResourceException JavaDoc {
67         try {
68             if (!webdavResource.abortTransaction()) {
69                 throw new ResourceException JavaDoc("Could not roll back transaction");
70             }
71         } catch (IOException JavaDoc e) {
72             throw new ResourceException JavaDoc("Could not roll back transaction", e);
73         }
74     }
75
76 }
77
Popular Tags