Revision 1217
Added by Jing Tao almost 22 years ago
RelationHandler.java | ||
---|---|---|
27 | 27 |
public class RelationHandler //implements Runnable |
28 | 28 |
{ |
29 | 29 |
private Thread btThread = null; |
30 |
private Connection conn = null;
|
|
30 |
private DBConnection connection = null;
|
|
31 | 31 |
private String docid = null; |
32 | 32 |
MetaCatUtil util = new MetaCatUtil(); |
33 | 33 |
|
... | ... | |
37 | 37 |
* relations. |
38 | 38 |
* @param docid the ID of the XML document to index. |
39 | 39 |
*/ |
40 |
public RelationHandler(String docid, Connection conn) |
|
40 |
public RelationHandler(String docid, DBConnection conn)
|
|
41 | 41 |
throws McdbException, SQLException, AccessionNumberException |
42 | 42 |
{ |
43 |
this.conn = conn; |
|
43 |
this.connection = conn;
|
|
44 | 44 |
this.docid = docid; |
45 | 45 |
putRelations(); |
46 | 46 |
} |
... | ... | |
69 | 69 |
*/ |
70 | 70 |
|
71 | 71 |
//DocumentImpl xmldoc = new DocumentImpl(conn,docid,false); |
72 |
packagetype = (new DocumentImpl(conn,docid,false)).getDoctype();
|
|
72 |
packagetype = (new DocumentImpl(docid,false)).getDoctype(); |
|
73 | 73 |
|
74 | 74 |
// first delete the relations for this package document if any |
75 | 75 |
deleteRelations(docid); |
76 | 76 |
|
77 | 77 |
// to put the new relations get them out of xml_nodes |
78 |
pstmt = conn.prepareStatement(QuerySpecification.printPackageSQL(docid)); |
|
78 |
pstmt = connection.prepareStatement |
|
79 |
(QuerySpecification.printPackageSQL(docid)); |
|
80 |
//increase usage cont |
|
81 |
connection.increaseUsageCount(1); |
|
79 | 82 |
pstmt.execute(); |
80 | 83 |
ResultSet rs = pstmt.getResultSet(); |
81 | 84 |
boolean hasmorerows = rs.next(); |
82 | 85 |
if (hasmorerows) { |
83 |
tstmt = conn.prepareStatement("INSERT INTO xml_relation (" + |
|
86 |
tstmt = connection.prepareStatement("INSERT INTO xml_relation (" +
|
|
84 | 87 |
"docid,packagetype,subject,subdoctype," + |
85 | 88 |
"relationship, object, objdoctype) " + |
86 | 89 |
"VALUES (?, ?, ?, ?, ?, ?, ?)"); |
90 |
//increase usage count |
|
91 |
connection.increaseUsageCount(1); |
|
87 | 92 |
} |
88 | 93 |
while(hasmorerows) { |
89 | 94 |
subject = rs.getString(1); |
... | ... | |
115 | 120 |
tstmt.close(); |
116 | 121 |
} |
117 | 122 |
pstmt.close(); |
118 |
conn.commit(); |
|
123 |
connection.commit();
|
|
119 | 124 |
} |
120 | 125 |
|
121 | 126 |
/** |
... | ... | |
125 | 130 |
public void deleteRelations(String docid) throws SQLException |
126 | 131 |
{ |
127 | 132 |
try { |
128 |
PreparedStatement pstmt = conn.prepareStatement( |
|
133 |
PreparedStatement pstmt = connection.prepareStatement(
|
|
129 | 134 |
"DELETE FROM xml_relation " + |
130 | 135 |
"WHERE docid = '" + docid + "'"); |
136 |
//increase usage count |
|
137 |
connection.increaseUsageCount(1); |
|
131 | 138 |
pstmt.execute(); |
132 | 139 |
pstmt.close(); |
133 | 140 |
} catch(SQLException e) { |
... | ... | |
147 | 154 |
public String getAccessFileID(String docid) throws SQLException |
148 | 155 |
{ |
149 | 156 |
String aclid = null; |
157 |
PreparedStatement pstmt = null; |
|
158 |
DBConnection dbConn = null; |
|
159 |
int serialNumber = -1; |
|
150 | 160 |
|
151 | 161 |
StringBuffer sql = new StringBuffer(); |
152 | 162 |
sql.append("SELECT docid FROM xml_documents WHERE docid in (SELECT subject "); |
... | ... | |
176 | 186 |
pstmt.setString(1, docid); |
177 | 187 |
pstmt.setString(2, MetaCatUtil.getOption("accessdoctype")); |
178 | 188 |
*/ |
179 |
PreparedStatement pstmt = conn.prepareStatement(sql.toString()); |
|
180 |
pstmt.execute(); |
|
181 |
ResultSet rs = pstmt.getResultSet(); |
|
182 |
boolean hasRow = rs.next(); |
|
183 |
if (hasRow) { |
|
184 |
aclid = rs.getString(1); |
|
185 |
} |
|
186 |
pstmt.close(); |
|
189 |
try |
|
190 |
{ |
|
191 |
dbConn=DBConnectionPool. |
|
192 |
getDBConnection("RelationHandler.getAccessFileID"); |
|
193 |
serialNumber=dbConn.getCheckOutSerialNumber(); |
|
194 |
pstmt = dbConn.prepareStatement(sql.toString()); |
|
195 |
pstmt.execute(); |
|
196 |
ResultSet rs = pstmt.getResultSet(); |
|
197 |
boolean hasRow = rs.next(); |
|
198 |
if (hasRow) { |
|
199 |
aclid = rs.getString(1); |
|
200 |
} |
|
201 |
pstmt.close(); |
|
202 |
}//try |
|
203 |
finally |
|
204 |
{ |
|
205 |
try |
|
206 |
{ |
|
207 |
pstmt.close(); |
|
208 |
}//try |
|
209 |
finally |
|
210 |
{ |
|
211 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
|
212 |
}//finally |
|
213 |
}//finally |
|
214 |
|
|
187 | 215 |
|
188 | 216 |
return aclid; |
189 | 217 |
} |
Also available in: Unified diff
Merge DBConnection branch to head.