Project

General

Profile

« Previous | Next » 

Revision 1803

Added by Jing Tao over 21 years ago

Add a new constructor to hanlde DTD node.

View differences:

src/edu/ucsb/nceas/metacat/DBSAXNode.java
83 83
    //No writing XML Index from here. New Thread used instead.
84 84
    //updateNodeIndex(docid, doctype);
85 85
  }
86
  
87
  /** 
88
   * Construct a new node instance for DTD nodes
89
   * This Node will write docname, publicId and systemId into db. Only
90
   * handle systemid  existed.(external dtd)
91
   *
92
   * @param conn the JDBC Connection to which all information is written
93
   * @param tagname the name of the node
94
   * @param parentNode the parent node for this node being created
95
   */
96
  public DBSAXNode (DBConnection conn, String docName, String publicId, 
97
                    String systemId, DBSAXNode parentNode, long rootnodeid, 
98
                    String docid) throws SAXException 
99
  {
100

  
101
    super();
102
    this.connection = conn;
103
    this.parentNode = parentNode;
104
    setParentID(parentNode.getNodeID());
105
    setRootNodeID(rootnodeid);
106
    setDocID(docid);
107
    // insert dtd node only for external dtd definiation
108
    if (systemId != null)
109
    {
110
      //write docname to DB
111
      if (docName != null)
112
      {
113
        setNodeIndex(parentNode.incChildNum());
114
        writeDTDNodeToDB(DocumentImpl.DOCNAME, docName, docid);
115
      }
116
      //write publicId to DB
117
      if (publicId != null)
118
      {
119
        setNodeIndex(parentNode.incChildNum());
120
        writeDTDNodeToDB(DocumentImpl.PUBLICID, publicId, docid);
121
      }
122
      //write systemId to DB
123
      setNodeIndex(parentNode.incChildNum());
124
      writeDTDNodeToDB(DocumentImpl.SYSTEMID, systemId, docid);
125
    }
126
  }
86 127
    
87 128
  /** creates SQL code and inserts new node into DB connection */
88 129
  public long writeChildNodeToDB(String nodetype, String nodename,
......
227 268
      }
228 269
  }
229 270

  
271
 /** creates SQL code and inserts new node into DB connection */
272
  public long writeDTDNodeToDB(String nodename, String data, String docid) 
273
                                 throws SAXException 
274
  {
275
    long nid = -1;
276
    try 
277
    {
278
 
279
      PreparedStatement pstmt;
280
      MetaCatUtil.debugMessage("Insert dtd into db: "+nodename +" "+data, 45);
281
      pstmt = connection.prepareStatement(
282
            "INSERT INTO xml_nodes " +
283
            "(nodetype, nodename, docid, " +
284
            "rootnodeid, parentnodeid, nodedata, nodeindex) " +
285
            "VALUES (?, ?, ?, ?, ?, ?, ?)");
286
       // Increase DBConnection usage count
287
      connection.increaseUsageCount(1);
288
      
289
      // Bind the values to the query
290
      pstmt.setString(1, DocumentImpl.DTD);
291
      pstmt.setString(2, nodename);
292
      pstmt.setString(3, docid);
293
      pstmt.setLong(4, getRootNodeID());
294
      pstmt.setLong(5, getParentID());
295
      pstmt.setString(6, data);
296
      pstmt.setInt(7, getNodeIndex());
297
    
298
      // Do the insertion
299
      pstmt.execute();
300
      pstmt.close();
301

  
302
      // get the generated unique id afterward
303
      nid = dbAdapter.getUniqueID(connection.getConnections(), "xml_nodes");
304
      //should incease connection usage!!!!!!
305
     
306
    } catch (SQLException e) {
307
      System.out.println("Error in DBSaxNode.writeDTDNodeToDB");
308
      System.err.println("Error inserting node: (" + DocumentImpl.DTD + ", " +
309
                                                     nodename + ", " + 
310
                                                     data + ")" );
311
      System.err.println(e.getMessage());
312
      e.printStackTrace(System.err);
313
      throw new SAXException(e.getMessage());
314
    }
315
    return nid;
316
  }
317
 
318
  
230 319
  /** get next node id from DB connection */
231 320
  private long generateNodeID() throws SAXException {
232 321
      long nid=0;

Also available in: Unified diff