Project

General

Profile

« Previous | Next » 

Revision 136

Added by Matt Jones over 24 years ago

rearranged API for incrementing the node index within the parent node

View differences:

src/edu/ucsb/nceas/metacat/DBSAXHandler.java
62 62
      System.out.println("start Document");
63 63
    }
64 64
    // Create the document node represantation as root
65
    //DBSAXElement documentNode = new DBSAXElement(conn, docname, 0, 0);
66 65
    DBSAXElement documentNode = new DBSAXElement(conn, docname);
67 66
    // Add the element to the stack, so that any text data can be 
68 67
    // added as it is encountered
......
116 115
      String nsName;
117 116
      String expName;
118 117
      DBSAXElement parentElement = null;
119
      DBSAXElement currentElement;
118
      DBSAXElement currentElement = null;
120 119

  
121 120
      qName = name.getQualifiedName();
122 121
      localName = name.getLocalName();
src/edu/ucsb/nceas/metacat/ElementNode.java
154 154
                  "replace(nodedata,'&','&')" +
155 155
                  ",'<','&lt;') " +
156 156
                  ",'>','&gt;') " +
157
                  "FROM xml_nodes WHERE parentnodeid = ?");
157
                  "FROM xml_nodes WHERE parentnodeid = ? " +
158
                  "ORDER BY nodeindex");
158 159

  
159
                  // ORDER BY nodeindex
160

  
161 160
        // Bind the values to the query
162 161
        pstmt.setLong(1, nodeid);
163 162

  
src/edu/ucsb/nceas/metacat/DBSAXNode.java
24 24
  private Connection		conn;
25 25

  
26 26
  /** 
27
   * Construct a new element instance
27
   * Construct a new node instance for DOCUMENT nodes
28 28
   *
29 29
   * @param conn the JDBC Connection to which all information is written
30
   * @param tagname the name of the element
31
   * @param parent_id the parent id number for this element
30
   * @param tagname the name of the node
32 31
   */
32
  public DBSAXElement (Connection conn, String tagname) {
33
    super(tagname);
34
    this.conn = conn;
35
    writeChildNodeToDB("DOCUMENT", tagname, null);
36
    setNodeID(getAssignedNodeID());
37
  }
38

  
39
  /** 
40
   * Construct a new node instance for ELEMENT nodes
41
   *
42
   * @param conn the JDBC Connection to which all information is written
43
   * @param tagname the name of the node
44
   * @param parentNode the parent node for this node being created
45
   */
33 46
  public DBSAXElement (Connection conn, String tagname, 
34
                       long parent_id, int nodeIndex) {
47
                       DBSAXElement parentNode) {
35 48

  
36
    super(tagname, parent_id, nodeIndex);
37

  
49
    super(tagname);
50
    setParentID(parentNode.getNodeID());
51
    setNodeIndex(parentNode.incChildNum());
38 52
    this.conn = conn;
39
    if (getParentID() != 0) {
40
      writeChildNodeToDB("ELEMENT", getTagName(), null, getNodeIndex());
41
    } else {
42
      writeChildNodeToDB("DOCUMENT", getTagName(), null, 0);
43
    }
44

  
53
    writeChildNodeToDB("ELEMENT", getTagName(), null);
45 54
    setNodeID(getAssignedNodeID());
46 55
  }
47 56
    
48 57
  /** creates SQL code and inserts new node into DB connection */
49 58
  public void writeChildNodeToDB(String nodetype, String nodename,
50
                                  String data, int nodeIndex) {
59
                                 String data) {
51 60
    try {
52 61
      PreparedStatement pstmt;
53 62
      if (nodetype == "DOCUMENT") {
......
69 78
      if (nodetype != "DOCUMENT") {
70 79
        if (nodetype == "ELEMENT") {
71 80
          pstmt.setLong(3, getParentID());
81
          pstmt.setString(4, data);
82
          pstmt.setInt(5, getNodeIndex());
72 83
        } else {
73 84
          pstmt.setLong(3, getNodeID());
85
          pstmt.setString(4, data);
86
          pstmt.setInt(5, incChildNum());
74 87
        }
75
        pstmt.setString(4, data);
76
        pstmt.setInt(5, nodeIndex);
77 88
      }
78 89
      // Do the insertion
79 90
      pstmt.execute();
......
81 92
    } catch (SQLException e) {
82 93
      System.err.println("Error inserting node: (" + nodetype + ", " +
83 94
                                                     nodename + ", " + 
84
                                                     data + ", " + 
85
                                                     nodeIndex + ")" );
86

  
95
                                                     data + ")" );
87 96
      System.err.println(e.getMessage());
88 97
    }
89 98
  }
......
137 146
      // Enter the attribute in the hash table
138 147
      super.setAttribute(attName, attValue);
139 148

  
140
      writeChildNodeToDB("ATTRIBUTE", attName, attValue, 0);
141 149
      // And enter the attribute in the database
150
      writeChildNodeToDB("ATTRIBUTE", attName, attValue);
142 151
    } else {
143 152
      System.err.println("Attribute name must not be null!");
144 153
    }

Also available in: Unified diff