Project

General

Profile

« Previous | Next » 

Revision 1416

Added by Jing Tao almost 22 years ago

Every call to write into xml_nodes will return current node id.

View differences:

src/edu/ucsb/nceas/metacat/DBSAXNode.java
85 85
  }
86 86
    
87 87
  /** creates SQL code and inserts new node into DB connection */
88
  public void writeChildNodeToDB(String nodetype, String nodename,
88
  public long writeChildNodeToDB(String nodetype, String nodename,
89 89
                                 String data, String docid) 
90
                                 throws SAXException {
91
    try {
92
      /*if(conn == null)
93
      {
94
        try
95
        {
96
          MetaCatUtil util = new MetaCatUtil();
97
          conn = util.getConnection();
98
        }
99
        catch(Exception e)
100
        {
101
          MetaCatUtil.debug("Error while getting db connection in " +
102
                            "DBSAXNode: " + e.getMessage());
103
        }
104
      }*/
105
        
90
                                 throws SAXException 
91
  {
92
    long nid = -1;
93
    try 
94
    {
95
 
106 96
      PreparedStatement pstmt;
107 97
      if (nodetype == "DOCUMENT") {
108 98
        pstmt = connection.prepareStatement(
......
155 145
      pstmt.close();
156 146

  
157 147
      // get the generated unique id afterward
158
      long nid = dbAdapter.
159
                         getUniqueID(connection.getConnections(), "xml_nodes");
148
      nid = dbAdapter.getUniqueID(connection.getConnections(), "xml_nodes");
160 149
      //should incease connection usage!!!!!!
161 150
     
162 151
      
......
184 173
      e.printStackTrace(System.err);
185 174
      throw new SAXException(e.getMessage());
186 175
    }
176
    return nid;
187 177
  }
188 178

  
189 179
  /** 
......
270 260
  }
271 261

  
272 262
  /** Add a new attribute to this node, or set its value */
273
  public void setAttribute(String attName, String attValue, String docid)
274
              throws SAXException {
275
    if (attName != null) {
263
  public long setAttribute(String attName, String attValue, String docid)
264
              throws SAXException 
265
  {
266
    long nodeId = -1;
267
    if (attName != null) 
268
    {
276 269
      // Enter the attribute in the hash table
277 270
      super.setAttribute(attName, attValue);
278 271

  
279 272
      // And enter the attribute in the database
280
      writeChildNodeToDB("ATTRIBUTE", attName, attValue, docid);
281
    } else {
273
      nodeId = writeChildNodeToDB("ATTRIBUTE", attName, attValue, docid);
274
    } 
275
    else 
276
    {
282 277
      System.err.println("Attribute name must not be null!");
283 278
      throw new SAXException("Attribute name must not be null!");
284 279
    }
280
    return nodeId;
285 281
  }
286 282

  
287 283
  /** Add a namespace to this node */
288
  public void setNamespace(String prefix, String uri, String docid)
289
              throws SAXException {
290
    if (prefix != null) {
284
  public long setNamespace(String prefix, String uri, String docid)
285
              throws SAXException 
286
  {
287
    long nodeId = -1;
288
    if (prefix != null) 
289
    {
291 290
      // Enter the namespace in a hash table
292 291
      super.setNamespace(prefix, uri);
293 292
      // And enter the namespace in the database
294
      writeChildNodeToDB("NAMESPACE", prefix, uri, docid);
295
    } else {
293
      nodeId = writeChildNodeToDB("NAMESPACE", prefix, uri, docid);
294
    } 
295
    else 
296
    {
296 297
      System.err.println("Namespace prefix must not be null!");
297 298
      throw new SAXException("Namespace prefix must not be null!");
298 299
    }
300
    return nodeId;
299 301
  }
300 302

  
301 303
 

Also available in: Unified diff