* @param directoryId : the identifier of the directory
* @return Directory
*/
public IDirectory getDirectoryById(Integer directoryId, boolean recursive) {
DirectoryImpl directory = null;
String query = "SELECT * FROM directory where directoryid=" + directoryId;
try {
startOperation();
if (stmt != null) {
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
directory = new DirectoryImpl();
directory.setId(rs.getInt("directoryid"));
directory.setName(rs.getString("name"));
directory.setPositionInDirectory(rs.getInt("positionInDirectory"));
directory.setTimestamp(rs.getTimestamp("timestamp"));
Integer dir = rs.getInt("directory");
if (dir != null && !rs.wasNull()) {
IDirectory parent = getDirectoryById(dir, recursive);
directory.setDirectory(parent);
}
}
rs.close();
stmt.clearBatch();
}
}
catch (SQLException e) {
CommonsJDBC.catchException(e);
}
finally {
doCloseConn();
}
if (recursive && directory != null && directory.getDirectory() != null) {
directory.setDirectory(getDirectoryById(directory.getDirectory().getId(), recursive));
}
return directory;
}