Project

General

Profile

« Previous | Next » 

Revision 457

Added by bojilova over 23 years ago

changes related to decrease the time of INSERT of document.
With these changes I inserted 200KB file for 3 minutes, 50KB for 50sec.
This is mainly simplifing the DBSAXNode class and
using batching feature of Oracle JDBC driver.

View differences:

DBSAXNode.java
17 17
import java.io.IOException;
18 18
import java.util.Hashtable;
19 19
import java.util.Enumeration;
20
import oracle.jdbc.driver.*;
20 21

  
21 22
/** 
22 23
 * A Class that represents an XML node and its contents and
......
32 33
   *
33 34
   * @param conn the JDBC Connection to which all information is written
34 35
   */
35
  public DBSAXNode (Connection conn) {
36
  public DBSAXNode (Connection conn, String docid) {
36 37
    super();
37 38
    this.conn = conn;
38 39
    this.parentNode = null;
39
    writeChildNodeToDB("DOCUMENT", null, null);
40
    writeChildNodeToDB("DOCUMENT", null, null, docid);
40 41
  }
41 42

  
42 43
  /** 
......
47 48
   * @param parentNode the parent node for this node being created
48 49
   */
49 50
  public DBSAXNode (Connection conn, String tagname, DBSAXNode parentNode, 
50
                    DocumentImpl currentDocument) {
51
                    long rootnodeid, String docid, String doctype) {
51 52

  
52 53
    super(tagname);
53 54
    setParentID(parentNode.getNodeID());
54
    setRootNodeID(currentDocument.getRootNodeID());
55
    setDocID(currentDocument.getDocID());
55
    setRootNodeID(rootnodeid);
56
    setDocID(docid);
56 57
    setNodeIndex(parentNode.incChildNum());
57 58
    this.conn = conn;
58 59
    this.parentNode = parentNode;
59
    writeChildNodeToDB("ELEMENT", getTagName(), null);
60
    updateNodeIndex(currentDocument.getDocID(), currentDocument.getDoctype());
60
    writeChildNodeToDB("ELEMENT", getTagName(), null, docid);
61
    updateNodeIndex(docid, doctype);
61 62
  }
62 63
    
63 64
  /** creates SQL code and inserts new node into DB connection */
64 65
  public void writeChildNodeToDB(String nodetype, String nodename,
65
                                 String data) {
66
                                 String data, String docid) {
66 67
    try {
67 68
      PreparedStatement pstmt;
68 69
      if (nodetype == "DOCUMENT") {
69 70
        pstmt = conn.prepareStatement(
70 71
            "INSERT INTO xml_nodes " +
71
            "(nodeid, nodetype, nodename, rootnodeid) " +
72
            "VALUES (?, ?, ?, ?)");
72
            "(nodeid, nodetype, nodename, docid, rootnodeid) " +
73
            "VALUES (?, ?, ?, ?, ?)");
73 74
        MetaCatUtil.debugMessage("INSERTING DOCNAME: " + nodename);
74 75
      } else {
75 76
        pstmt = conn.prepareStatement(
76 77
            "INSERT INTO xml_nodes " +
77
            "(nodeid, nodetype, nodename, " +
78
            "rootnodeid, parentnodeid, docid, nodedata, nodeindex) " +
78
            "(nodeid, nodetype, nodename, docid, " +
79
            "rootnodeid, parentnodeid, nodedata, nodeindex) " +
79 80
            "VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
80 81
      }
81 82

  
......
84 85
      pstmt.setLong(1, nid);
85 86
      pstmt.setString(2, nodetype);
86 87
      pstmt.setString(3, nodename);
88
      pstmt.setString(4, docid);
87 89
      if (nodetype == "DOCUMENT") {
88
        pstmt.setLong(4, nid);
90
        pstmt.setLong(5, nid);
89 91
      } else {
90 92
        if (nodetype == "ELEMENT") {
91
          pstmt.setLong(4, getRootNodeID());
92
          pstmt.setLong(5, getParentID());
93
          pstmt.setString(6, getDocID());
93
          pstmt.setLong(5, getRootNodeID());
94
          pstmt.setLong(6, getParentID());
94 95
          pstmt.setString(7, data);
95 96
          pstmt.setInt(8, getNodeIndex());
96 97
        } else {
97
          pstmt.setLong(4, getRootNodeID());
98
          pstmt.setLong(5, getNodeID());
99
          pstmt.setString(6, getDocID());
98
          pstmt.setLong(5, getRootNodeID());
99
          pstmt.setLong(6, getNodeID());
100 100
          if ( nodetype == "TEXT" && getTagName().equals("meta_file_id") ) {
101 101
            pstmt.setString(7, getDocID());
102 102
          } else {
......
208 208
  }
209 209

  
210 210
  /** Add a new attribute to this node, or set its value */
211
  public void setAttribute(String attName, String attValue) {
211
  public void setAttribute(String attName, String attValue, String docid) {
212 212
    if (attName != null) {
213 213
      // Enter the attribute in the hash table
214 214
      super.setAttribute(attName, attValue);
215 215

  
216 216
      // And enter the attribute in the database
217
      writeChildNodeToDB("ATTRIBUTE", attName, attValue);
217
      writeChildNodeToDB("ATTRIBUTE", attName, attValue, docid);
218 218
    } else {
219 219
      System.err.println("Attribute name must not be null!");
220 220
    }
......
231 231
    boolean atRootDocumentNode = false;
232 232
    DBSAXNode nodePointer = this;
233 233
    StringBuffer currentPath = new StringBuffer();
234
    int counter = 0;
234 235

  
235 236
    // Create a Hashtable of all of the paths to reach this node
236 237
    // including absolute paths and relative paths
......
238 239
      if (atStartingNode) {
239 240
        currentPath.insert(0, nodePointer.getTagName());
240 241
        pathlist.put(currentPath.toString(), new Long(getNodeID()));
242
        counter++;
241 243
        atStartingNode = false;
242 244
      } else {
243 245
        currentPath.insert(0, "/");
244 246
        currentPath.insert(0, nodePointer.getTagName());
245 247
        pathlist.put(currentPath.toString(), new Long(getNodeID()));
248
        counter++;
246 249
      }
247 250

  
248 251
      // advance to the next parent node
......
253 256
      if (nodePointer.getNodeType().equals("DOCUMENT")) {
254 257
        currentPath.insert(0, "/");
255 258
        pathlist.put(currentPath.toString(), new Long(getNodeID()));
259
        counter++;
256 260
        atRootDocumentNode = true;
257 261
      } 
258 262
    }
......
263 267
              "INSERT INTO xml_index (nodeid, path, docid, doctype, " + 
264 268
               "parentnodeid) " + 
265 269
              "VALUES (?, ?, ?, ?, ?)");
270
      ((OraclePreparedStatement)pstmt).setExecuteBatch(counter);
266 271
  
267 272
      pstmt.setString(3, docid);
268 273
      pstmt.setString(4, doctype);
......
275 280
        Long nodeid = (Long)pathlist.get(path);
276 281
        pstmt.setLong(1, nodeid.longValue());
277 282
        pstmt.setString(2, path);
278
        pstmt.execute();
283
        pstmt.executeUpdate();
279 284
  
280 285
        //System.out.println(nodeid + " ==> " + path);
281 286
      }

Also available in: Unified diff