KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mapper > storage > AbstractPersistentNode


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.mapper.storage;
24
25 import java.sql.*;
26
27 import org.xquark.jdbc.typing.DBMSConstants;
28 import org.xquark.mapper.dbms.AbstractConnection;
29 import org.xquark.mapper.dbms.TableInfo;
30 import org.xquark.mapper.metadata.RepositoryConstants;
31
32 /**
33  * Base implementation for XML structure node storage.
34  *
35  */

36 public abstract class AbstractPersistentNode implements RepositoryConstants, DBMSConstants
37 {
38     private static final String JavaDoc RCSRevision = "$Revision: 1.2 $";
39     private static final String JavaDoc RCSName = "$Name: $";
40
41     /////////////////////////////////////
42
// Storage JDBC variables
43
/////////////////////////////////////
44

45     /** java.sql.Statement object used to fetch the whole data set from the database. */
46     protected TableInfo tableInfo = null;
47     protected Statement stmt = null;
48     protected ResultSet rs = null;
49     
50     protected String JavaDoc insertStmt;
51
52     /** JDBC data used for storing rows in the database with batch style.
53      * IMPORTANT : when storing, and contrary to reading only one batch
54      * is used for all Node objects.
55      */

56     protected PreparedStatement pStmt = null;
57
58     protected long docOID = -1;
59     protected long uoid = -1;
60     protected int rsColumnOffset = 1;
61
62     public AbstractPersistentNode(TableInfo tableInfo)
63     {
64         this.tableInfo = tableInfo;
65     }
66     
67     public void set(long docOID) {this.docOID = docOID;}
68     
69     public long getUOID() { return uoid;}
70     
71     public void close() throws SQLException
72     {
73         reset();
74         // release statement
75
if (pStmt != null)
76             pStmt.close();
77         pStmt = null;
78     }
79     
80     public void reset() throws SQLException
81     {
82         // release statement
83
if (rs != null)
84             rs.close();
85         if (stmt != null)
86             stmt.close();
87         docOID = -1;
88         uoid = -1;
89         rs = null;
90         stmt = null;
91     }
92
93     //
94
// STATIC METHODS
95
//
96

97     /** Delete the links of a given document.
98      * @param connection JDBC connection used for removal.
99      * @param name repository name.
100      * @param first first UOID of the range.
101      * @param last last UOID of the range.
102      * @throws SQLException JDBC error
103      */

104     public static PreparedStatement getDeleteStatement(AbstractConnection connection, TableInfo tableInfo)
105     throws SQLException
106     {
107         return connection.getConnection().prepareStatement("DELETE FROM "
108             + tableInfo.getName() + " WHERE UOID >= ? and UOID <= ?");
109     }
110
111 }
112
Popular Tags