Project

General

Profile

« Previous | Next » 

Revision 148

Added by bojilova over 24 years ago

to use single transaction

View differences:

src/edu/ucsb/nceas/metacat/DBSAXDocument.java
33 33
     * @param conn the JDBC Connection to which all information is written
34 34
     * @param rootnodeid - sequence id of the root node in the document
35 35
     * @param docname - the name of DTD, i.e. the name immediately following 
36
     *        the DOCTYPE keyword - should be the root element name.
36
     *        the DOCTYPE keyword ( should be the root element name ) or
37
     *        the root element name if no DOCTYPE declaration provided
37 38
     *        (Oracle's and IBM parsers are not aware if it is not the 
38 39
     *        root element name)
39 40
     * @param doctype - Public ID of the DTD, i.e. the name immediately 
40
     *                  following the PUBLIC keyword in DOCTYPE declaration.
41
     *                  following the PUBLIC keyword in DOCTYPE declaration or
42
     *                  the docname if no Public ID provided or
43
     *                  null if no DOCTYPE declaration provided
41 44
     *
42 45
     */
43 46
    public DBSAXDocument (Connection conn, long rootnodeid, String docname, 
......
53 56
    /** creates SQL code and inserts new document into DB connection */
54 57
    private void writeDocumentToDB() {
55 58
        try {
56
          conn.setAutoCommit(false);
57 59
          PreparedStatement pstmt;
58 60
          pstmt = conn.prepareStatement(
59 61
                "INSERT INTO xml_documents " +
......
80 82
          }
81 83
          stmt.close();
82 84

  
83
          conn.commit();
84
          conn.setAutoCommit(true);
85 85
        } catch (SQLException e) {
86 86
          System.out.println(e.getMessage());
87 87
        }
src/edu/ucsb/nceas/metacat/DBEntityResolver.java
169 169
                     (new URL(systemId)).openConnection();
170 170
            urlConn.connect();
171 171
        } catch (java.io.IOException e) {
172
            System.out.println("IOException: " + e.getMessage());
172
            System.out.println(e.getMessage());
173 173
            return;
174 174
        }    
175 175
        try {
176
          conn.setAutoCommit(false);
177 176
          PreparedStatement pstmt;
178 177
          pstmt = conn.prepareStatement(
179 178
                "INSERT INTO xml_catalog " +
......
187 186
          // Do the insertion
188 187
          pstmt.execute();
189 188
          pstmt.close();
190
          conn.commit();
191
          conn.setAutoCommit(true);
192 189
        } catch (SQLException e) {
193 190
          System.out.println(e.getMessage());
194 191
        }
......
198 195
    * Look at db XML Catalog to get System ID (if any) for that Public ID 
199 196
    * and doctype. Return empty string if there are not 
200 197
    */
198
/*
201 199
   private String getEntitySystemID (Connection conn, String doctype, 
202 200
                                     String publicId)
203 201
   {
......
237 235
        // return the selected System ID number
238 236
        return system_id;
239 237
   }
240

  
238
*/
241 239
   /** 
242 240
    * Register Public ID in db XML Catalog 
243 241
    */
242
/*    
244 243
   private void registerEntityPublicID (Connection conn, String doctype, 
245 244
                                        String publicId, String systemId)
246 245
   {
247 246
        try {
248
          conn.setAutoCommit(false);
249 247
          PreparedStatement pstmt;
250 248
          pstmt = conn.prepareStatement(
251 249
                "INSERT INTO xml_catalog (catalog_id, entry_type, " +
......
258 256
          // Do the insertion
259 257
          pstmt.execute();
260 258
          pstmt.close();
261
          conn.commit();
262
          conn.setAutoCommit(true);
263 259
        } catch (SQLException e) {
264 260
          System.out.println(e.getMessage());
265 261
        }
266 262
   }
263
*/   
267 264
}
src/edu/ucsb/nceas/metacat/DBDTDHandler.java
120 120
                                        String publicId, String systemId)
121 121
   {
122 122
        try {
123
          conn.setAutoCommit(false);
124 123
          PreparedStatement pstmt;
125 124
          pstmt = conn.prepareStatement(
126 125
                "INSERT INTO xml_catalog (entity_id, entity_name, " +
......
133 132
          // Do the insertion
134 133
          pstmt.execute();
135 134
          pstmt.close();
136
          conn.commit();
137
          conn.setAutoCommit(true);
138 135
        } catch (SQLException e) {
139 136
          System.out.println(e.getMessage());
140 137
        }
src/edu/ucsb/nceas/metacat/DBWriter.java
99 99

  
100 100
    try {
101 101
        SAXParser parser = initializeParser(conn);
102
        conn.setAutoCommit(false);
102 103
        parser.parse(xml);
104
        conn.commit();
105
        conn.setAutoCommit(true);
103 106
      } catch (SAXParseException e) {
104 107
        System.err.println(e.getMessage());
105 108
      } catch (SAXException e) {
......
118 121
     FileReader xmlfile = new FileReader(new File(filename).toString());
119 122
     try {
120 123
       SAXParser parser = initializeParser(conn);
124
       conn.setAutoCommit(false);
121 125
       parser.parse(xmlfile);
126
       conn.commit();
127
       conn.setAutoCommit(true);
122 128
     } catch (SAXParseException e) {
123 129
       System.err.println(e.getMessage());
124 130
     } catch (SAXException e) {
125 131
       System.err.println(e.getMessage());
126 132
     } catch (Exception e) {
127
       System.err.println(e.toString());
133
       System.err.println("from DBWriter:" + e.toString());
128 134
     }
129 135
  }
130 136
  

Also available in: Unified diff