Beispiel #1
0
  /**
   * Get all the CollectionObjectIDs that that use this Taxon as the Current determination and put
   * them into the RecordSet.
   *
   * @param taxon the Taxon
   * @param recordSet the RecordSet to be filled.
   */
  protected void fillRecordSet(final Taxon taxon, final RecordSet recordSet) {
    // The old way using Hibernate relationships was too slow,
    // so instead I am using straight SQL it is a lot faster.
    String sql =
        "SELECT DISTINCT co.CollectionObjectID FROM taxon as tx INNER JOIN determination as dt ON tx.TaxonID = "
            + (taxon.getIsAccepted() ? "dt.PreferredTaxonID " : "dt.TaxonID ")
            + "INNER JOIN collectionobject as co ON dt.CollectionObjectID = co.CollectionObjectID "
            + "WHERE tx.TaxonID = "
            + taxon.getId()
            + " AND co.CollectionMemberID = COLMEMID";

    Vector<Integer> list = new Vector<Integer>();

    fillListWithIds(sql, list);

    for (Integer id : list) {
      recordSet.addItem(id);
    }
  }
  /* (non-Javadoc)
   * @see edu.ku.brc.af.core.expresssearch.QueryAdjusterForDomain#getSpecialColumns(edu.ku.brc.dbsupport.DBTableInfo, boolean, boolean, java.lang.String)
   */
  @Override
  public String getSpecialColumns(
      final DBTableInfo tableInfo,
      final boolean isHQL,
      final boolean isLeftJoin,
      final String tblAlias) {
    if (tableInfo != null) {
      String prefix = tblAlias == null ? "" : tblAlias + ".";
      String criterion = null;
      String fld = null;
      boolean adjustFldToSQL = true;

      if (tableInfo.getFieldByName("collectionMemberId") != null) {
        fld = isHQL ? "collectionMemberId" : "CollectionMemberId";
        criterion = COLMEMID;

      } else if (tableInfo.getTableId() == Agent.getClassTableId()
          || tableInfo.getTableId() == Accession.getClassTableId()
          || tableInfo.getTableId() == RepositoryAgreement.getClassTableId()
          || tableInfo.getTableId() == ExchangeIn.getClassTableId()
          || tableInfo.getTableId() == ExchangeOut.getClassTableId()) {
        if (prefix.equals("")) {
          prefix = isHQL ? "dv." : "";
        } else {
          prefix = isHQL ? ("dv" + prefix) : prefix;
        }
        fld = isHQL ? "divisionId" : "DivisionID";
        criterion = DIVID;

      } else if (tableInfo.getRelationshipByName("discipline") != null) {
        DBRelationshipInfo ri = tableInfo.getRelationshipByName("discipline");
        if (ri.getType() != DBRelationshipInfo.RelationshipType.OneToOne) {
          if (prefix.equals("")) {
            // rods - 9/29/08 - This was messing up the Geography Count (SQL) but is needed for HQL
            prefix = isHQL ? "dsp." : "";
          } else {
            prefix = isHQL ? ("dsp" + prefix) : prefix;
          }
          fld = isHQL ? "disciplineId" : "DisciplineID";
          criterion = DSPLNID;
        }

        //            } else if (tableInfo.getTableId() == DeterminationStatus.getClassTableId())
        //            {
        //                fld = isHQL ? "disciplineId" : "DisciplineID";
        //                criterion = DSPLNID;
        //
      } else if (tableInfo.getTableId() == Geography.getClassTableId()) {
        fld = isHQL ? "definition" : "GeographyTreeDefID";
        criterion = GEOTREEDEFID;

      } else if (tableInfo.getTableId() == GeologicTimePeriod.getClassTableId()) {
        fld = isHQL ? "definition" : "GeologicTimePeriodTreeDefID";
        criterion = GTPTREEDEFID;

      } else if (tableInfo.getTableId() == LithoStrat.getClassTableId()) {
        fld = isHQL ? "definition" : "LithoStratTreeDefID";
        criterion = LITHOTREEDEFID;

      } else if (tableInfo.getTableId() == Storage.getClassTableId()) {
        fld = isHQL ? "definition" : "StorageTreeDefID";
        criterion = STORTREEDEFID;

      } else if (tableInfo.getTableId() == PrepType.getClassTableId()) {
        fld = isHQL ? "collection" : "CollectionID";
        criterion = COLLID;

      } else if (tableInfo.getTableId() == Taxon.getClassTableId()) {
        fld = isHQL ? "definition" : "TaxonTreeDefID";
        criterion = TAXTREEDEFID;

      } else if (tableInfo.getTableId() == Locality.getClassTableId()) {
        fld = isHQL ? "discipline" : "DisciplineID";
        criterion = DSPLNID;

      } else if (tableInfo.getTableId() == Locality.getClassTableId()) {
        fld = isHQL ? "discipline" : "DisciplineID";
        criterion = DSPLNID;

      } else if (tableInfo.getTableId() == Locality.getClassTableId()) {
        fld = isHQL ? "discipline" : "DisciplineID";
        criterion = DSPLNID;
      } /*else if (tableInfo.getTableId() == Agent.getClassTableId())
        {
            if (StringUtils.isEmpty(prefix))
            {
                prefix = "ag.";
            }
            criterion = DIVID;
            if (isHQL)
            {
                fld = criterion + " = " + prefix + "division.id";
                adjustFldToSQL = false;
            }
            else
            {
                //this probably won't actually work without additional
                //changes to the from clause for the query
                fld = criterion + " = " + prefix + "D";
                prefix = "";
                //throw new RuntimeException("Fix me I am probably broken!");
            }
        }*/

      if (criterion != null && fld != null) {
        String sql;
        if (adjustFldToSQL) {
          sql = "(" + prefix + fld + " = " + criterion + ")";
        } else {
          sql = fld;
        }
        if (isLeftJoin) {
          if (isHQL) {
            if (tblAlias != null) {
              sql = "(" + sql + " or " + tblAlias + " is null)";
            } else {
              log.error("can't adjust hql for left join without a tblAlias.");
            }
          } else {
            sql = "(" + sql + " or " + prefix + fld + " is null)";
          }
        }
        return adjustSQL(sql);
      }
    }
    return null;
  }