Project

General

Profile

« Previous | Next » 

Revision 1124

Added by Jing Tao over 22 years ago

Delete connection as a class field and make every method to check in and check out connection if it need.

View differences:

src/edu/ucsb/nceas/metacat/DBEntityResolver.java
52 52
 */
53 53
public class DBEntityResolver implements EntityResolver
54 54
{
55
  private Connection conn = null;
55
  //private Connection conn = null;
56 56
  private DefaultHandler handler = null;
57 57
  private String docname = null;
58 58
  private String doctype = null;
......
64 64
   *
65 65
   * @param conn the JDBC connection to which information is written
66 66
   */
67
  public DBEntityResolver(Connection conn)
67
  public DBEntityResolver()
68 68
  {
69
    this.conn = conn;
69
    //this.conn = conn;
70 70
  }
71 71
  /** 
72 72
   * Construct an instance of the DBEntityResolver class
......
75 75
   * @param handler the SAX handler to determine parsing context
76 76
   * @param dtd Reader of new dtd to be uploaded on server's file system
77 77
   */
78
  public DBEntityResolver(Connection conn, DefaultHandler handler, Reader dtd)
78
  public DBEntityResolver(DefaultHandler handler, Reader dtd)
79 79
  {
80
    this.conn = conn;
80
    //this.conn = conn;
81 81
    this.handler = handler;
82 82
    this.dtdtext = dtd;
83 83
  }
......
185 185
                 throws SAXException
186 186
  {
187 187
    String systemid = null;
188
    Statement stmt;
188
    Statement stmt = null;
189
    DBConnection conn = null;
190
    int serialNumber = -1;
189 191
    try {
192
      //check out DBConnection
193
      conn=DBConnectionPool.getDBConnection("AccessControlList.isAccessDoc");
194
      serialNumber=conn.getCheckOutSerialNumber();
195
      
190 196
      stmt = conn.createStatement();
191 197
      stmt.execute("SELECT system_id FROM xml_catalog " + 
192 198
                   "WHERE entry_type = 'DTD' AND public_id = '" +
......
201 207
      throw new SAXException
202 208
      ("DBEntityResolver.getDTDSystemID(): " + e.getMessage());
203 209
    }
210
    finally
211
    {
212
      DBConnectionPool.returnDBConnection(conn, serialNumber);
213
    }//finally
204 214

  
205 215
    // return the selected System ID
206 216
    return systemid;
......
213 223
  private void registerDTD ( String doctype, String systemId )
214 224
                 throws SAXException
215 225
  {
226
    DBConnection conn = null;
227
    int serialNumber = -1;
216 228
    // make a reference in db catalog table with @systemId for @doctype
217 229
    try {
230
      //check out DBConnection
231
      conn=DBConnectionPool.getDBConnection("AccessControlList.isAccessDoc");
232
      serialNumber=conn.getCheckOutSerialNumber();
233
      
218 234
      PreparedStatement pstmt;
219 235
      pstmt = conn.prepareStatement(
220 236
             "INSERT INTO xml_catalog " +
......
230 246
      throw new SAXException
231 247
      ("DBEntityResolver.registerDTD(): " + e.getMessage());
232 248
    }
249
    finally
250
    {
251
      DBConnectionPool.returnDBConnection(conn, serialNumber);
252
    }
233 253
  }
234 254

  
235 255
  /** 

Also available in: Unified diff