Example #1
0
  private void buildTxClause(StringBuilder sb, String txsAlias) {

    sb.append(txsAlias);
    if (!OptionsUtil.isHistorical(getOptions())) {
      sb.append(".tx_current = ");
      sb.append(String.valueOf(TxChange.CURRENT.getValue()));
    }
  }
Example #2
0
  private void writeTxFilter(
      String txsAlias, String artJoinAlias, StringBuilder sb, boolean areDeletedIncluded) {
    // @formatter:off
    /**
     * ******************************************************************* The clause handling the
     * inclusion of deleted items changes based on case note this applies to the 3 tables
     * ARTIFACT_TABLE, ATTRIBUTE_TABLE, RELATION_TABLE case 1: No items allow deleted case 2: One
     * table in query case 3: All tables that are in the query allow deleted case 4: More than one
     * table with differing deletion flags
     */
    // @formatter:on
    boolean hasTable[] = {
      hasAlias(TableEnum.ARTIFACT_TABLE),
      hasAlias(TableEnum.ATTRIBUTE_TABLE),
      hasAlias(TableEnum.RELATION_TABLE)
    };

    /**
     * ******************************************************************** Allow deleted artifacts
     * applies even if the artifact table is not in the query. The other two only make sense when
     * the table is also used
     */
    boolean areDeletedSame = true;
    if (areDeletedIncluded) {
      /**
       * ****************************** there must be at least 2 table in the query for a difference
       */
      int count = 0;
      for (boolean add : hasTable) {
        if (add) {
          count++;
        }
      }
      if (count > 1) {
        boolean allowDeletedAtrifacts = OptionsUtil.areDeletedArtifactsIncluded(getOptions());
        boolean allowDeletedAttributes = OptionsUtil.areDeletedAttributesIncluded(getOptions());
        boolean allowDeletedRelations = OptionsUtil.areDeletedRelationsIncluded(getOptions());
        areDeletedSame =
            !((hasTable[0] && !allowDeletedAtrifacts)
                || (hasTable[1] && !allowDeletedAttributes)
                || (hasTable[2] && !allowDeletedRelations));
      }
    }
    if (OptionsUtil.isHistorical(getOptions())) {
      sb.append(txsAlias);
      sb.append(".transaction_id <= ");
      sb.append(artJoinAlias);
      sb.append(".transaction_id");
      if (!areDeletedIncluded) {
        sb.append(" AND ");
        sb.append(txsAlias);
        sb.append(".mod_type");
        sb.append(" != ");
        sb.append(String.valueOf(ModificationType.DELETED.getValue()));
      } else if (!areDeletedSame) {
        sb.append(" AND ");
        buildDeletedClause(sb, txsAlias);
      }
    } else {
      if (areDeletedIncluded) {
        if (areDeletedSame) {
          sb.append(txsAlias);
          sb.append(".tx_current");
          sb.append(" IN (");
          sb.append(String.valueOf(TxChange.CURRENT.getValue()));
          sb.append(", ");
          sb.append(String.valueOf(TxChange.DELETED.getValue()));
          sb.append(", ");
          sb.append(String.valueOf(TxChange.ARTIFACT_DELETED.getValue()));
          sb.append(")");
        } else {
          buildDeletedClause(sb, txsAlias);
        }
      } else {
        sb.append(txsAlias);
        sb.append(".tx_current = ");
        sb.append(String.valueOf(TxChange.CURRENT.getValue()));
      }
    }
  }