}
    public Collection query(Query query, String viewlogprivileges, String capriviledges) throws IllegalQueryException{        debug(">query()");        Connection con = null;        PreparedStatement ps = null;        ResultSet rs = null;        ArrayList returnval = new ArrayList();        if(capriviledges == null || capriviledges.equals(""))          throw new IllegalQueryException();                                 // Check if query is legal.        if(!query.isLegalQuery())          throw new IllegalQueryException();        try{           // Construct SQL query.            con = getConnection();            if(viewlogprivileges.equals(""))              ps = con.prepareStatement("select " + LOGENTRYDATA_COL + " from LogEntryData where ( " + query.getQueryString() +                                          ") and (" + capriviledges + ")");            else              ps = con.prepareStatement("select " + LOGENTRYDATA_COL + " from LogEntryData where (" + query.getQueryString() + ") and ("                                          + viewlogprivileges + ") and (" + capriviledges + ")");            //ps.setFetchDirection(ResultSet.FETCH_REVERSE);            ps.setFetchSize(MAXIMUM_QUERY_ROWCOUNT +1 );            // Execute query.            rs = ps.executeQuery();            // Assemble result.            while(rs.next() && returnval.size() <= MAXIMUM_QUERY_ROWCOUNT){              LogEntry data = new LogEntry(rs.getInt(1), rs.getString(2), rs.getInt(3), rs.getInt(4),  new java.util.Date(rs.getLong(5)), rs.getString(6), rs.getString(7)                                               , rs.getInt(8), rs.getString(9));              returnval.add(data);            }            debug("<query()");            return returnval;        }catch(Exception e){          throw new EJBException(e);        }finally{           try{             if(rs != null) rs.close();             if(ps != null) ps.close();             if(con!= null) con.close();           }catch(SQLException se){               error("Fel vid upprensning: ", se);           }        }    } // query