예제 #1
0
 @Override
 public String getTxBranchFilter(String txsAlias) {
   boolean allowDeletedAtrifacts = OptionsUtil.areDeletedArtifactsIncluded(getOptions());
   boolean allowDeletedAttributes = OptionsUtil.areDeletedAttributesIncluded(getOptions());
   boolean allowDeletedRelations = OptionsUtil.areDeletedRelationsIncluded(getOptions());
   boolean areDeletedIncluded =
       allowDeletedAtrifacts || allowDeletedAttributes || allowDeletedRelations;
   return getTxBranchFilter(txsAlias, areDeletedIncluded);
 }
예제 #2
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()));
    }
  }
예제 #3
0
 private void buildDeletedClause(StringBuilder sb, String txsAlias) {
   /**
    * *************************************************************** It is assumed this is called
    * only if at least one type of deleted is allowed and they differ. These checks are not made
    */
   int count = 0;
   if (hasAlias(TableEnum.ARTIFACT_TABLE)) {
     List<String> artTables = getAliases(TableEnum.ARTIFACT_TABLE);
     if (OptionsUtil.areDeletedArtifactsIncluded(getOptions())) {
       sb.append("(");
       buildTableGamma(sb, artTables, txsAlias);
       sb.append(" AND ");
       buildTxClause(sb, txsAlias);
       sb.append(")");
       count++;
     }
   }
   if (hasAlias(TableEnum.ATTRIBUTE_TABLE)) {
     List<String> attrTables = getAliases(TableEnum.ATTRIBUTE_TABLE);
     if (OptionsUtil.areDeletedAttributesIncluded(getOptions())) {
       if (count > 1) {
         sb.append(" AND ");
       }
       sb.append("(");
       buildTableGamma(sb, attrTables, txsAlias);
       sb.append(" AND ");
       buildTxClause(sb, txsAlias);
       sb.append(")");
       count++;
     }
   }
   if (hasAlias(TableEnum.RELATION_TABLE)) {
     List<String> relationTables = getAliases(TableEnum.RELATION_TABLE);
     if (OptionsUtil.areDeletedAttributesIncluded(getOptions())) {
       if (count > 1) {
         sb.append(" AND ");
       }
       sb.append("(");
       buildTableGamma(sb, relationTables, txsAlias);
       sb.append(" AND ");
       buildTxClause(sb, txsAlias);
       sb.append(")");
       count++;
     }
   }
 }
예제 #4
0
  @Override
  public void writeSelect(Iterable<SqlHandler<?>> handlers) throws OseeCoreException {
    String txAlias = getLastAlias(TableEnum.TXS_TABLE);
    String artJoinAlias = getLastAlias(TableEnum.ARTIFACT_JOIN_TABLE);

    write("SELECT%s ", getSqlHint());
    write(
        "%s.gamma_id, %s.mod_type, %s.branch_id, %s.transaction_id",
        txAlias, txAlias, txAlias, txAlias);
    if (OptionsUtil.isHistorical(getOptions())) {
      write(", %s.transaction_id as stripe_transaction_id", txAlias);
    }
    write(",\n %s.art_id", artJoinAlias);
    for (SqlHandler<?> handler : handlers) {
      setHandlerLevel(handler);
      write(", ");
      handler.addSelect(this);
    }
  }
예제 #5
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()));
      }
    }
  }