@@ -0,0 +1,2536 @@
+/*%0A  Copyright (C) 2003 EBI, GRL%0A %0A  This library is free software; you can redistribute it and/or%0A  modify it under the terms of the GNU Lesser General Public%0A  License as published by the Free Software Foundation; either%0A  version 2.1 of the License, or (at your option) any later version.%0A %0A  This library is distributed in the hope that it will be useful,%0A  but WITHOUT ANY WARRANTY; without even the implied warranty of%0A  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A  Lesser General Public License for more details.%0A %0A  You should have received a copy of the GNU Lesser General Public%0A  License along with this library; if not, write to the Free Software%0A  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA%0A */%0A%0Apackage org.ensembl.healthcheck.testcase;%0A%0Aimport java.sql.*;%0A%0Aimport org.ensembl.healthcheck.*;%0A%0Aimport org.ensembl.healthcheck.util.*;%0A%0A/**%0A * An EnsEMBL Healthcheck test case that looks for broken foreign-key relationships.%0A */%0A%0Apublic class ComparaForeignKeyTestCaseHomologyId extends EnsTestCase %7B%0A  %0A  /**%0A   * Create an OrphanTestCase that applies to a specific set of databases.%0A   */%0A  public ComparaForeignKeyTestCaseHomologyId() %7B%0A      databaseRegexp = %22%5Eensembl_compara_.*%22;%0A      addToGroup(%22compara_db_constraints%22);%0A      setDescription(%22Check for broken foreign-key relationships in ensembl_compara databases.%22);%0A  %7D%0A  %0A  public TestResult run() %7B%0A    %0A    boolean result = true;%0A    %0A    DatabaseConnectionIterator it = getDatabaseConnectionIterator();%0A    int orphans = 0;%0A    %0A    while (it.hasNext()) %7B%0A      %0A      Connection con = (Connection)it.next();%0A      // 1 test to check gene_relationship_id used as foreign key%0A      %0A      if( getRowCount( con, %22select count(*) from homology%22 ) %3E 0 ) %7B%0A        orphans = countOrphans(con, %22homology_member%22, %22homology_id%22, %22homology%22, %22homology_id%22, false );%0A        if( orphans == 0 ) %7B%0A%09    ReportManager.correct(this, con, %22homology_member %3C-%3E homology relationships PASSED%22);%0A%09%7D else if( orphans %3E 0 ) %7B%0A%09    ReportManager.problem(this, con, %22homology_member has unlinked entries in homology FAILED%22);%0A        %7D else %7B%0A%09    ReportManager.problem(this, con, %22homology_member %3C-%3E homology TEST NOT COMPLETED, look at the StackTrace if any%22);%0A        %7D%0A      %7D else %7B%0A%09  ReportManager.correct(this, con, %22NO ENTRIES in homology table, so nothing to test IGNORED%22);%0A      %7D%0A%0A      result &= (orphans == 0);%0A%0A    %7D%0A    %0A    return new TestResult(getShortTestName(), result);%0A    %0A  %7D%0A  %0A%7D // OrphanTestCase%0A

Check homology_id when used as ForeignKey