Revision 4450
Added by ben leinfelder over 15 years ago
AccessControlForSingleFile.java | ||
---|---|---|
185 | 185 |
|
186 | 186 |
} |
187 | 187 |
|
188 |
/** |
|
189 |
* |
|
190 |
* @return true if the Access Control for this file already exists in the DB |
|
191 |
* @throws SQLException |
|
192 |
*/ |
|
193 |
public boolean accessControlExists() throws SQLException |
|
194 |
{ |
|
195 |
boolean exists = false; |
|
196 |
PreparedStatement pstmt = null; |
|
197 |
DBConnection conn = null; |
|
198 |
int serialNumber = -1; |
|
199 |
try |
|
200 |
{ |
|
201 |
//check out DBConnection |
|
202 |
conn=DBConnectionPool.getDBConnection |
|
203 |
("AccessControlForSingleFiel.accessControlExists"); |
|
204 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
205 |
pstmt = conn.prepareStatement( |
|
206 |
"SELECT * FROM xml_access " + |
|
207 |
"WHERE docid = ? " + |
|
208 |
"AND principal_name = ? " + |
|
209 |
"AND permission = ? " + |
|
210 |
"AND perm_type = ? " + |
|
211 |
"AND perm_order =? "); |
|
212 |
|
|
213 |
// Bind the values to the query |
|
214 |
pstmt.setString(1, docId); |
|
215 |
pstmt.setString(2, principal); |
|
216 |
pstmt.setInt(3, permission); |
|
217 |
pstmt.setString(4, permType); |
|
218 |
pstmt.setString(5, permOrder); |
|
219 |
|
|
220 |
pstmt.execute(); |
|
221 |
ResultSet rs = pstmt.getResultSet(); |
|
222 |
exists = rs.next(); |
|
223 |
|
|
224 |
}//try |
|
225 |
catch (SQLException e) |
|
226 |
{ |
|
227 |
logMetacat.error("Error in AccessControlForSingleFile.accessControlExists: " |
|
228 |
+ e.getMessage()); |
|
229 |
throw e; |
|
230 |
} |
|
231 |
finally |
|
232 |
{ |
|
233 |
try |
|
234 |
{ |
|
235 |
pstmt.close(); |
|
236 |
} |
|
237 |
finally |
|
238 |
{ |
|
239 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
240 |
} |
|
241 |
} |
|
242 |
|
|
243 |
return exists; |
|
244 |
|
|
245 |
} |
|
246 |
|
|
188 | 247 |
public String getAccessString() { |
189 | 248 |
StringBuffer sb = new StringBuffer(); |
190 | 249 |
sb.append("<access>"); |
Also available in: Unified diff
check for existing access control rows before inserting (we do not need duplicate rows specifying the same access control)