Revision 23
Added by Matt Jones almost 25 years ago
src/edu/ucsb/nceas/metacat/ElementNode.java | ||
---|---|---|
13 | 13 |
|
14 | 14 |
import java.sql.*; |
15 | 15 |
import java.io.IOException; |
16 |
import java.util.Hashtable;
|
|
16 |
import java.util.Vector;
|
|
17 | 17 |
import java.util.Enumeration; |
18 | 18 |
|
19 | 19 |
public class ReaderElement extends BasicElement { |
20 | 20 |
|
21 |
private Connection conn; |
|
21 |
private Connection conn; |
|
22 |
private Vector children; |
|
22 | 23 |
|
23 | 24 |
public ReaderElement (Connection conn, long nodeid) { |
24 | 25 |
|
25 | 26 |
this.conn = conn; |
27 |
|
|
26 | 28 |
//Lookup data for self |
27 |
String tagname = "foo"; |
|
28 |
long parent_id = 999; |
|
29 |
super(tagname, parent_id); |
|
29 |
getElementInfo(nodeid); |
|
30 | 30 |
|
31 | 31 |
//Lookup list of child nodes |
32 | 32 |
//foreach childnode (childid,childtype) |
... | ... | |
39 | 39 |
//} |
40 | 40 |
|
41 | 41 |
} |
42 |
|
|
43 |
private void getElementInfo(long nodeid) { |
|
44 |
long element_id=0; |
|
45 |
long parentnodeid=0; |
|
46 |
String nodetype=null; |
|
47 |
String nodename=null; |
|
48 |
String nodedata=null; |
|
49 |
|
|
50 |
PreparedStatement pstmt; |
|
51 |
try { |
|
52 |
pstmt = |
|
53 |
conn.prepareStatement("SELECT nodeid,parentnodeid,nodetype, " + |
|
54 |
"nodename,nodedata FROM xml_nodes WHERE nodeid = ?"); |
|
55 |
// Bind the values to the query |
|
56 |
pstmt.setLong(1, nodeid); |
|
57 |
|
|
58 |
pstmt.execute(); |
|
59 |
try { |
|
60 |
ResultSet rs = pstmt.getResultSet(); |
|
61 |
try { |
|
62 |
boolean tableHasRows = rs.next(); |
|
63 |
if (tableHasRows) { |
|
64 |
try { |
|
65 |
element_id = rs.getLong(1); |
|
66 |
parentnodeid = rs.getLong(2); |
|
67 |
nodetype = rs.getString(3); |
|
68 |
nodename = rs.getString(4); |
|
69 |
nodedata = rs.getString(5); |
|
70 |
} catch (SQLException e) { |
|
71 |
System.out.println("Error with getInt: " + e.getMessage()); |
|
72 |
} |
|
73 |
} |
|
74 |
} catch (SQLException e) { |
|
75 |
System.out.println("Error with next: " + e.getMessage()); |
|
76 |
} |
|
77 |
} catch (SQLException e) { |
|
78 |
System.out.println("Error with getrset: " + e.getMessage()); |
|
79 |
} |
|
80 |
pstmt.close(); |
|
81 |
} catch (SQLException e) { |
|
82 |
System.out.println("Error getting id: " + e.getMessage()); |
|
83 |
} |
|
84 |
|
|
85 |
if (nodetype.equals("ELEMENT")) { |
|
86 |
setElementID(element_id); |
|
87 |
setParentID(parentnodeid); |
|
88 |
setTagName(nodename); |
|
89 |
content.append(nodedata); |
|
90 |
} |
|
91 |
} |
|
42 | 92 |
} |
src/edu/ucsb/nceas/metacat/BasicNode.java | ||
---|---|---|
22 | 22 |
protected long parent_id; |
23 | 23 |
protected Hashtable attributes; |
24 | 24 |
|
25 |
public BasicElement () { |
|
26 |
content = new StringBuffer(); |
|
27 |
attributes = new Hashtable(); |
|
28 |
} |
|
29 |
|
|
25 | 30 |
public BasicElement (String tagname, long parent_id) { |
31 |
this(); |
|
26 | 32 |
this.tagname = tagname; |
27 | 33 |
this.parent_id = parent_id; |
28 |
content = new StringBuffer(); |
|
29 |
attributes = new Hashtable(); |
|
30 | 34 |
} |
31 | 35 |
|
32 | 36 |
public BasicElement (long element_id, String tagname, long parent_id) { |
... | ... | |
46 | 50 |
} |
47 | 51 |
|
48 | 52 |
/** Get the id of this element */ |
49 |
public long getElementID() { return element_id; } |
|
53 |
public long getElementID() |
|
54 |
{ |
|
55 |
return element_id; |
|
56 |
} |
|
50 | 57 |
|
58 |
/** Set the id of this element */ |
|
59 |
public void setElementID(long element_id) |
|
60 |
{ |
|
61 |
this.element_id = element_id; |
|
62 |
} |
|
63 |
|
|
64 |
/** Get the parent id of this element */ |
|
65 |
public long getParentID() |
|
66 |
{ |
|
67 |
return parent_id; |
|
68 |
} |
|
69 |
|
|
70 |
/** Set the parent id of this element */ |
|
71 |
public void setParentID(long parent_id) |
|
72 |
{ |
|
73 |
this.parent_id = parent_id; |
|
74 |
} |
|
75 |
|
|
51 | 76 |
/** Get the name of this element */ |
52 |
public String getTagName() { return tagname; } |
|
77 |
public String getTagName() |
|
78 |
{ |
|
79 |
return tagname; |
|
80 |
} |
|
53 | 81 |
|
82 |
/** Set the tagname of this element */ |
|
83 |
public void setTagName(String tagname) |
|
84 |
{ |
|
85 |
this.tagname = tagname; |
|
86 |
} |
|
87 |
|
|
54 | 88 |
/** Get the attributes as a string */ |
55 | 89 |
public String getAttributes() { |
56 | 90 |
StringBuffer buf = new StringBuffer(); |
src/edu/ucsb/nceas/metacat/DBReader.java | ||
---|---|---|
31 | 31 |
} else { |
32 | 32 |
try { |
33 | 33 |
|
34 |
String nodeid = args[0]; |
|
34 |
String nodeidstr = args[0]; |
|
35 |
long nodeid = (new Long(nodeidstr).longValue()); |
|
35 | 36 |
String user = args[1]; |
36 | 37 |
String password = args[2]; |
37 | 38 |
String dbstring = null; |
... | ... | |
77 | 78 |
return conn; |
78 | 79 |
} |
79 | 80 |
|
80 |
public String readDocument(String nodeid) {
|
|
81 |
public String readDocument(long nodeid) {
|
|
81 | 82 |
StringBuffer doc = new StringBuffer(); |
82 | 83 |
|
83 | 84 |
System.out.println("\nGetting document with nodeid: " + nodeid + "\n"); |
84 |
BasicElement element = readNodeFromDB(nodeid); |
|
85 |
//BasicElement element = readNodeFromDB(nodeid); |
|
86 |
ReaderElement element = new ReaderElement(conn, nodeid); |
|
85 | 87 |
doc.append(element); |
86 | 88 |
|
87 | 89 |
return (doc.toString()); |
88 | 90 |
} |
89 | 91 |
|
90 | 92 |
/** look up the assigned element id from DB connection */ |
91 |
private BasicElement readNodeFromDB(String nodeid) {
|
|
93 |
private BasicElement readNodeFromDB(long nodeid) {
|
|
92 | 94 |
long element_id=0; |
93 | 95 |
long nodeparentid=0; |
94 | 96 |
String nodetype=null; |
... | ... | |
98 | 100 |
PreparedStatement pstmt; |
99 | 101 |
try { |
100 | 102 |
pstmt = |
101 |
conn.prepareStatement("SELECT nodeid,nodeparentid,nodetype, |
|
102 |
nodename,nodedata FROM xml_nodes WHERE nodeid = ?"); |
|
103 |
conn.prepareStatement("SELECT nodeid,nodeparentid,nodetype, " +
|
|
104 |
"nodename,nodedata FROM xml_nodes WHERE nodeid = ?");
|
|
103 | 105 |
// Bind the values to the query |
104 |
pstmt.setString(1, nodeid);
|
|
106 |
pstmt.setLong(1, nodeid);
|
|
105 | 107 |
|
106 | 108 |
pstmt.execute(); |
107 | 109 |
try { |
... | ... | |
130 | 132 |
System.out.println("Error getting id: " + e.getMessage()); |
131 | 133 |
} |
132 | 134 |
|
135 |
BasicElement element = null; |
|
133 | 136 |
if (nodetype.equals("ELEMENT")) { |
134 |
BasicElement element = |
|
135 |
new BasicElement(element_id,nodename,nodeparentid); |
|
137 |
element = new BasicElement(element_id,nodename,nodeparentid); |
|
136 | 138 |
element.appendContent(nodedata); |
137 | 139 |
} |
138 | 140 |
|
... | ... | |
143 | 145 |
"nodename,nodedata FROM xml_nodes " + |
144 | 146 |
"WHERE nodeparentid = ?"); |
145 | 147 |
// Bind the values to the query |
146 |
pstmt.setString(1, nodeid);
|
|
148 |
pstmt.setLong(1, nodeid);
|
|
147 | 149 |
|
148 | 150 |
pstmt.execute(); |
149 | 151 |
try { |
src/edu/ucsb/nceas/metacat/BasicElement.java | ||
---|---|---|
22 | 22 |
protected long parent_id; |
23 | 23 |
protected Hashtable attributes; |
24 | 24 |
|
25 |
public BasicElement () { |
|
26 |
content = new StringBuffer(); |
|
27 |
attributes = new Hashtable(); |
|
28 |
} |
|
29 |
|
|
25 | 30 |
public BasicElement (String tagname, long parent_id) { |
31 |
this(); |
|
26 | 32 |
this.tagname = tagname; |
27 | 33 |
this.parent_id = parent_id; |
28 |
content = new StringBuffer(); |
|
29 |
attributes = new Hashtable(); |
|
30 | 34 |
} |
31 | 35 |
|
32 | 36 |
public BasicElement (long element_id, String tagname, long parent_id) { |
... | ... | |
46 | 50 |
} |
47 | 51 |
|
48 | 52 |
/** Get the id of this element */ |
49 |
public long getElementID() { return element_id; } |
|
53 |
public long getElementID() |
|
54 |
{ |
|
55 |
return element_id; |
|
56 |
} |
|
50 | 57 |
|
58 |
/** Set the id of this element */ |
|
59 |
public void setElementID(long element_id) |
|
60 |
{ |
|
61 |
this.element_id = element_id; |
|
62 |
} |
|
63 |
|
|
64 |
/** Get the parent id of this element */ |
|
65 |
public long getParentID() |
|
66 |
{ |
|
67 |
return parent_id; |
|
68 |
} |
|
69 |
|
|
70 |
/** Set the parent id of this element */ |
|
71 |
public void setParentID(long parent_id) |
|
72 |
{ |
|
73 |
this.parent_id = parent_id; |
|
74 |
} |
|
75 |
|
|
51 | 76 |
/** Get the name of this element */ |
52 |
public String getTagName() { return tagname; } |
|
77 |
public String getTagName() |
|
78 |
{ |
|
79 |
return tagname; |
|
80 |
} |
|
53 | 81 |
|
82 |
/** Set the tagname of this element */ |
|
83 |
public void setTagName(String tagname) |
|
84 |
{ |
|
85 |
this.tagname = tagname; |
|
86 |
} |
|
87 |
|
|
54 | 88 |
/** Get the attributes as a string */ |
55 | 89 |
public String getAttributes() { |
56 | 90 |
StringBuffer buf = new StringBuffer(); |
src/edu/ucsb/nceas/metacat/ReaderElement.java | ||
---|---|---|
13 | 13 |
|
14 | 14 |
import java.sql.*; |
15 | 15 |
import java.io.IOException; |
16 |
import java.util.Hashtable;
|
|
16 |
import java.util.Vector;
|
|
17 | 17 |
import java.util.Enumeration; |
18 | 18 |
|
19 | 19 |
public class ReaderElement extends BasicElement { |
20 | 20 |
|
21 |
private Connection conn; |
|
21 |
private Connection conn; |
|
22 |
private Vector children; |
|
22 | 23 |
|
23 | 24 |
public ReaderElement (Connection conn, long nodeid) { |
24 | 25 |
|
25 | 26 |
this.conn = conn; |
27 |
|
|
26 | 28 |
//Lookup data for self |
27 |
String tagname = "foo"; |
|
28 |
long parent_id = 999; |
|
29 |
super(tagname, parent_id); |
|
29 |
getElementInfo(nodeid); |
|
30 | 30 |
|
31 | 31 |
//Lookup list of child nodes |
32 | 32 |
//foreach childnode (childid,childtype) |
... | ... | |
39 | 39 |
//} |
40 | 40 |
|
41 | 41 |
} |
42 |
|
|
43 |
private void getElementInfo(long nodeid) { |
|
44 |
long element_id=0; |
|
45 |
long parentnodeid=0; |
|
46 |
String nodetype=null; |
|
47 |
String nodename=null; |
|
48 |
String nodedata=null; |
|
49 |
|
|
50 |
PreparedStatement pstmt; |
|
51 |
try { |
|
52 |
pstmt = |
|
53 |
conn.prepareStatement("SELECT nodeid,parentnodeid,nodetype, " + |
|
54 |
"nodename,nodedata FROM xml_nodes WHERE nodeid = ?"); |
|
55 |
// Bind the values to the query |
|
56 |
pstmt.setLong(1, nodeid); |
|
57 |
|
|
58 |
pstmt.execute(); |
|
59 |
try { |
|
60 |
ResultSet rs = pstmt.getResultSet(); |
|
61 |
try { |
|
62 |
boolean tableHasRows = rs.next(); |
|
63 |
if (tableHasRows) { |
|
64 |
try { |
|
65 |
element_id = rs.getLong(1); |
|
66 |
parentnodeid = rs.getLong(2); |
|
67 |
nodetype = rs.getString(3); |
|
68 |
nodename = rs.getString(4); |
|
69 |
nodedata = rs.getString(5); |
|
70 |
} catch (SQLException e) { |
|
71 |
System.out.println("Error with getInt: " + e.getMessage()); |
|
72 |
} |
|
73 |
} |
|
74 |
} catch (SQLException e) { |
|
75 |
System.out.println("Error with next: " + e.getMessage()); |
|
76 |
} |
|
77 |
} catch (SQLException e) { |
|
78 |
System.out.println("Error with getrset: " + e.getMessage()); |
|
79 |
} |
|
80 |
pstmt.close(); |
|
81 |
} catch (SQLException e) { |
|
82 |
System.out.println("Error getting id: " + e.getMessage()); |
|
83 |
} |
|
84 |
|
|
85 |
if (nodetype.equals("ELEMENT")) { |
|
86 |
setElementID(element_id); |
|
87 |
setParentID(parentnodeid); |
|
88 |
setTagName(nodename); |
|
89 |
content.append(nodedata); |
|
90 |
} |
|
91 |
} |
|
42 | 92 |
} |
DBReader.java | ||
---|---|---|
31 | 31 |
} else { |
32 | 32 |
try { |
33 | 33 |
|
34 |
String nodeid = args[0]; |
|
34 |
String nodeidstr = args[0]; |
|
35 |
long nodeid = (new Long(nodeidstr).longValue()); |
|
35 | 36 |
String user = args[1]; |
36 | 37 |
String password = args[2]; |
37 | 38 |
String dbstring = null; |
... | ... | |
77 | 78 |
return conn; |
78 | 79 |
} |
79 | 80 |
|
80 |
public String readDocument(String nodeid) {
|
|
81 |
public String readDocument(long nodeid) {
|
|
81 | 82 |
StringBuffer doc = new StringBuffer(); |
82 | 83 |
|
83 | 84 |
System.out.println("\nGetting document with nodeid: " + nodeid + "\n"); |
84 |
BasicElement element = readNodeFromDB(nodeid); |
|
85 |
//BasicElement element = readNodeFromDB(nodeid); |
|
86 |
ReaderElement element = new ReaderElement(conn, nodeid); |
|
85 | 87 |
doc.append(element); |
86 | 88 |
|
87 | 89 |
return (doc.toString()); |
88 | 90 |
} |
89 | 91 |
|
90 | 92 |
/** look up the assigned element id from DB connection */ |
91 |
private BasicElement readNodeFromDB(String nodeid) {
|
|
93 |
private BasicElement readNodeFromDB(long nodeid) {
|
|
92 | 94 |
long element_id=0; |
93 | 95 |
long nodeparentid=0; |
94 | 96 |
String nodetype=null; |
... | ... | |
98 | 100 |
PreparedStatement pstmt; |
99 | 101 |
try { |
100 | 102 |
pstmt = |
101 |
conn.prepareStatement("SELECT nodeid,nodeparentid,nodetype, |
|
102 |
nodename,nodedata FROM xml_nodes WHERE nodeid = ?"); |
|
103 |
conn.prepareStatement("SELECT nodeid,nodeparentid,nodetype, " +
|
|
104 |
"nodename,nodedata FROM xml_nodes WHERE nodeid = ?");
|
|
103 | 105 |
// Bind the values to the query |
104 |
pstmt.setString(1, nodeid);
|
|
106 |
pstmt.setLong(1, nodeid);
|
|
105 | 107 |
|
106 | 108 |
pstmt.execute(); |
107 | 109 |
try { |
... | ... | |
130 | 132 |
System.out.println("Error getting id: " + e.getMessage()); |
131 | 133 |
} |
132 | 134 |
|
135 |
BasicElement element = null; |
|
133 | 136 |
if (nodetype.equals("ELEMENT")) { |
134 |
BasicElement element = |
|
135 |
new BasicElement(element_id,nodename,nodeparentid); |
|
137 |
element = new BasicElement(element_id,nodename,nodeparentid); |
|
136 | 138 |
element.appendContent(nodedata); |
137 | 139 |
} |
138 | 140 |
|
... | ... | |
143 | 145 |
"nodename,nodedata FROM xml_nodes " + |
144 | 146 |
"WHERE nodeparentid = ?"); |
145 | 147 |
// Bind the values to the query |
146 |
pstmt.setString(1, nodeid);
|
|
148 |
pstmt.setLong(1, nodeid);
|
|
147 | 149 |
|
148 | 150 |
pstmt.execute(); |
149 | 151 |
try { |
BasicElement.java | ||
---|---|---|
22 | 22 |
protected long parent_id; |
23 | 23 |
protected Hashtable attributes; |
24 | 24 |
|
25 |
public BasicElement () { |
|
26 |
content = new StringBuffer(); |
|
27 |
attributes = new Hashtable(); |
|
28 |
} |
|
29 |
|
|
25 | 30 |
public BasicElement (String tagname, long parent_id) { |
31 |
this(); |
|
26 | 32 |
this.tagname = tagname; |
27 | 33 |
this.parent_id = parent_id; |
28 |
content = new StringBuffer(); |
|
29 |
attributes = new Hashtable(); |
|
30 | 34 |
} |
31 | 35 |
|
32 | 36 |
public BasicElement (long element_id, String tagname, long parent_id) { |
... | ... | |
46 | 50 |
} |
47 | 51 |
|
48 | 52 |
/** Get the id of this element */ |
49 |
public long getElementID() { return element_id; } |
|
53 |
public long getElementID() |
|
54 |
{ |
|
55 |
return element_id; |
|
56 |
} |
|
50 | 57 |
|
58 |
/** Set the id of this element */ |
|
59 |
public void setElementID(long element_id) |
|
60 |
{ |
|
61 |
this.element_id = element_id; |
|
62 |
} |
|
63 |
|
|
64 |
/** Get the parent id of this element */ |
|
65 |
public long getParentID() |
|
66 |
{ |
|
67 |
return parent_id; |
|
68 |
} |
|
69 |
|
|
70 |
/** Set the parent id of this element */ |
|
71 |
public void setParentID(long parent_id) |
|
72 |
{ |
|
73 |
this.parent_id = parent_id; |
|
74 |
} |
|
75 |
|
|
51 | 76 |
/** Get the name of this element */ |
52 |
public String getTagName() { return tagname; } |
|
77 |
public String getTagName() |
|
78 |
{ |
|
79 |
return tagname; |
|
80 |
} |
|
53 | 81 |
|
82 |
/** Set the tagname of this element */ |
|
83 |
public void setTagName(String tagname) |
|
84 |
{ |
|
85 |
this.tagname = tagname; |
|
86 |
} |
|
87 |
|
|
54 | 88 |
/** Get the attributes as a string */ |
55 | 89 |
public String getAttributes() { |
56 | 90 |
StringBuffer buf = new StringBuffer(); |
ReaderElement.java | ||
---|---|---|
13 | 13 |
|
14 | 14 |
import java.sql.*; |
15 | 15 |
import java.io.IOException; |
16 |
import java.util.Hashtable;
|
|
16 |
import java.util.Vector;
|
|
17 | 17 |
import java.util.Enumeration; |
18 | 18 |
|
19 | 19 |
public class ReaderElement extends BasicElement { |
20 | 20 |
|
21 |
private Connection conn; |
|
21 |
private Connection conn; |
|
22 |
private Vector children; |
|
22 | 23 |
|
23 | 24 |
public ReaderElement (Connection conn, long nodeid) { |
24 | 25 |
|
25 | 26 |
this.conn = conn; |
27 |
|
|
26 | 28 |
//Lookup data for self |
27 |
String tagname = "foo"; |
|
28 |
long parent_id = 999; |
|
29 |
super(tagname, parent_id); |
|
29 |
getElementInfo(nodeid); |
|
30 | 30 |
|
31 | 31 |
//Lookup list of child nodes |
32 | 32 |
//foreach childnode (childid,childtype) |
... | ... | |
39 | 39 |
//} |
40 | 40 |
|
41 | 41 |
} |
42 |
|
|
43 |
private void getElementInfo(long nodeid) { |
|
44 |
long element_id=0; |
|
45 |
long parentnodeid=0; |
|
46 |
String nodetype=null; |
|
47 |
String nodename=null; |
|
48 |
String nodedata=null; |
|
49 |
|
|
50 |
PreparedStatement pstmt; |
|
51 |
try { |
|
52 |
pstmt = |
|
53 |
conn.prepareStatement("SELECT nodeid,parentnodeid,nodetype, " + |
|
54 |
"nodename,nodedata FROM xml_nodes WHERE nodeid = ?"); |
|
55 |
// Bind the values to the query |
|
56 |
pstmt.setLong(1, nodeid); |
|
57 |
|
|
58 |
pstmt.execute(); |
|
59 |
try { |
|
60 |
ResultSet rs = pstmt.getResultSet(); |
|
61 |
try { |
|
62 |
boolean tableHasRows = rs.next(); |
|
63 |
if (tableHasRows) { |
|
64 |
try { |
|
65 |
element_id = rs.getLong(1); |
|
66 |
parentnodeid = rs.getLong(2); |
|
67 |
nodetype = rs.getString(3); |
|
68 |
nodename = rs.getString(4); |
|
69 |
nodedata = rs.getString(5); |
|
70 |
} catch (SQLException e) { |
|
71 |
System.out.println("Error with getInt: " + e.getMessage()); |
|
72 |
} |
|
73 |
} |
|
74 |
} catch (SQLException e) { |
|
75 |
System.out.println("Error with next: " + e.getMessage()); |
|
76 |
} |
|
77 |
} catch (SQLException e) { |
|
78 |
System.out.println("Error with getrset: " + e.getMessage()); |
|
79 |
} |
|
80 |
pstmt.close(); |
|
81 |
} catch (SQLException e) { |
|
82 |
System.out.println("Error getting id: " + e.getMessage()); |
|
83 |
} |
|
84 |
|
|
85 |
if (nodetype.equals("ELEMENT")) { |
|
86 |
setElementID(element_id); |
|
87 |
setParentID(parentnodeid); |
|
88 |
setTagName(nodename); |
|
89 |
content.append(nodedata); |
|
90 |
} |
|
91 |
} |
|
42 | 92 |
} |
Makefile | ||
---|---|---|
24 | 24 |
reader: |
25 | 25 |
javac -classpath "$(CPATH)" \ |
26 | 26 |
DBReader.java \ |
27 |
BasicElement.java |
|
27 |
BasicElement.java \ |
|
28 |
ReaderElement.java |
|
28 | 29 |
|
29 | 30 |
test: |
30 | 31 |
java -cp $(CPATH) DBSAXWriter test.xml $(USER) $(PW) |
Also available in: Unified diff
adding recursive build for ReaderElement