Project

General

Profile

« Previous | Next » 

Revision 683

Added by berkley over 23 years ago

fixed some problems with database connections getting a time out error. Also updated some catch statements

View differences:

RelationHandler.java
43 43
    //this.conn = conn;
44 44
    try
45 45
    {
46
      this.conn = util.openDBConnection();
46
      conn = MetacatReplication.getDBConnection("RelationHandler." +
47
                                                "relationHandler");
47 48
    }
48 49
    catch(Exception e)
49 50
    {
50
      System.out.println("error opening connection in " + 
51
                         "relationHandler.relationHandler: " + e.getMessage());
51
      System.out.println("unable to get db connection in relationhandler." + 
52
                         "relationhandler: " + e.getMessage());
52 53
    }
53
    
54 54
    this.xmldoc = xmldoc;
55 55
    if(xmldoc.getDoctype().equals(util.getOption("packagedoctype")))
56 56
    { //make sure this doctype is a package document then run the thread
......
62 62
  
63 63
  /**
64 64
   * The thread handler
65
   */
65
   */ 
66 66
  public void run()
67 67
  {
68
    Connection dbconn = null;
68 69
    String docid = xmldoc.getDocID();
69

  
70 70
    // deletes all of the relations with a docid of @docid.
71 71
    deleteRelations(docid);
72 72
    //pseudo-code algorithm
......
77 77
    //    add a new row to xml_relation that represents this new relation
78 78
    try
79 79
    {
80
      PreparedStatement pstmt = conn.prepareStatement(
80
      dbconn = MetacatReplication.getDBConnection("RelationHandler." +
81
                                                  "run");
82
      PreparedStatement pstmt = dbconn.prepareStatement(
81 83
                                QuerySpecification.printPackageSQL(docid));
82 84
      pstmt.execute();
83 85
      
......
103 105
          paramDocid = subject;
104 106
        }
105 107
        
106
        DocumentImpl subDoc = new DocumentImpl(conn, paramDocid);
108
        DocumentImpl subDoc = new DocumentImpl(dbconn, paramDocid);
107 109
        subjectDoctype = subDoc.getDoctype();
108 110
        String relationship = rs.getString(2);
109 111
        String object = rs.getString(3);
110 112
      
111 113
        //compare r to each relation in xml_relation
112 114
        
113
        pstmt = conn.prepareStatement("select subject, subdoctype, " +
115
        pstmt = dbconn.prepareStatement("select subject, subdoctype, " +
114 116
                                      "relationship, object, objdoctype " +
115 117
                                      "from xml_relation");
116 118
        pstmt.execute();
......
139 141
            insertTransRelation.append(subject).append("', '");
140 142
            insertTransRelation.append(subjectDoctype).append("')");
141 143
            //System.out.println("sql1: " + insertTransRelation.toString());
142
            pstmt = conn.prepareStatement(insertTransRelation.toString());
144
            pstmt = dbconn.prepareStatement(insertTransRelation.toString());
143 145
            pstmt.execute(); 
144 146
            
145 147
            insertTransRelation = new StringBuffer();
......
155 157
            insertTransRelation.append(currentSub).append("', '");
156 158
            insertTransRelation.append(currentSubDoctype).append("')");
157 159
            //System.out.println("sql2: " + insertTransRelation.toString());
158
            pstmt = conn.prepareStatement(insertTransRelation.toString());
160
            pstmt = dbconn.prepareStatement(insertTransRelation.toString());
159 161
            pstmt.execute();
160 162
          }
161 163
          
......
177 179
            subDocid = (String)subMurlParams.get("docid");
178 180
            if(subMurl.getProtocol().equals("metacat"))
179 181
            {
180
              subDoc = new DocumentImpl(conn, subDocid);
182
              subDoc = new DocumentImpl(dbconn, subDocid);
181 183
              subDoctype = subDoc.getDoctype();
182 184
            }
183 185
          }
......
200 202
            objDocid = (String)objMurlParams.get("docid");
201 203
            if(objMurl.getProtocol().equals("metacat"))
202 204
            {
203
              DocumentImpl objDoc = new DocumentImpl(conn, objDocid);
205
              DocumentImpl objDoc = new DocumentImpl(dbconn, objDocid);
204 206
              objDoctype = objDoc.getDoctype();
205 207
            }
206 208
          }
......
228 230
        insertStmt.append(object).append("', '");
229 231
        insertStmt.append(objDoctype).append("')");
230 232
        
231
        pstmt = conn.prepareStatement(insertStmt.toString());
233
        pstmt = dbconn.prepareStatement(insertStmt.toString());
232 234
        pstmt.execute(); 
233 235
        
234 236
        hasmorerows = rs.next();
235 237
      }
236 238
      
237
      conn.commit();
239
      dbconn.commit();
238 240
      pstmt.close();
239
      conn.close();
241
      dbconn.close();
240 242
      btThread = null;
241 243

  
242 244
    } 
243 245
    catch(Exception e) 
244 246
    { 
247
      System.out.println("Error in relationHandler.run: " + e.getMessage());
248
      util.debugMessage("Error in relationHandler.run: " + e.getMessage());
249
      e.printStackTrace(System.out);
250
      btThread = null;
245 251
      try 
246 252
      { 
247 253
        conn.rollback();
248 254
      } 
249 255
      catch (SQLException sqle) {}
250
      System.out.println("Error in relationHandler.run: " + e.getMessage());
251
      util.debugMessage("Error in relationHandler.run: " + e.getMessage());
252
      e.printStackTrace(System.out);
253
      btThread = null;
254 256
    }
255 257
  }
256 258
  
......
260 262
   */
261 263
  public void deleteRelations(String docid)
262 264
  {
265
    Connection dbconn = null;
263 266
    try
264 267
    {
265
      PreparedStatement pstmt = conn.prepareStatement("delete from " +
268
      dbconn = MetacatReplication.getDBConnection("RelationHandler."+
269
                                                  "deleteRelations");
270
    }
271
    catch(Exception ee)
272
    {
273
      System.out.println("error in relationHandler.deleteRelations: " +
274
                          ee.getMessage());
275
    }
276
    
277
    try
278
    {
279
      PreparedStatement pstmt = dbconn.prepareStatement("delete from " +
266 280
                             "xml_relation where docid like '" + docid + "'");
267 281
      pstmt.execute();
268 282
      pstmt.close();
283
      dbconn.close();
269 284
    }
270 285
    catch(Exception e)
271 286
    {
287
      System.out.println("error in RelationHandler.deleteRelations(): " + 
288
                          e.getMessage());
289
      e.printStackTrace(System.out);
272 290
      try 
273 291
      { 
274
        conn.rollback();
292
        dbconn.rollback();
293
        dbconn.close();
275 294
      } 
276 295
      catch (SQLException sqle) {}
277
      System.out.println("error in RelationHandler.deleteRelations(): " + 
278
                          e.getMessage());
279
      e.printStackTrace(System.out);
280 296
    }
281 297
    
282 298
  }

Also available in: Unified diff