001package io.ebean.meta;
002
003import java.sql.Connection;
004import java.util.ArrayList;
005import java.util.List;
006import java.util.Set;
007
008/**
009 * Request used to capture query plans.
010 */
011public class QueryPlanRequest {
012
013  private List<MetaQueryPlan> plans = new ArrayList<>();
014
015  private Connection connection;
016
017  private boolean store;
018
019  private long since;
020
021  private Set<Class<?>> includedBeanTypes;
022
023  private Set<String> includedLabels;
024
025  public List<MetaQueryPlan> getPlans() {
026    return plans;
027  }
028
029  /**
030   * Return the connection to use to capture the query plans.
031   */
032  public Connection getConnection() {
033    return connection;
034  }
035
036  /**
037   * Set the connection to use to capture the query plans.
038   */
039  public void setConnection(Connection connection) {
040    this.connection = connection;
041  }
042
043  /**
044   * Return true if the captured query plan is stored.
045   */
046  public boolean isStore() {
047    return store;
048  }
049
050  /**
051   * Set to true to store the captured query plan.
052   */
053  public void setStore(boolean store) {
054    this.store = store;
055  }
056
057  /**
058   * Return the epoch time after which the query plan was capture (to be included).
059   */
060  public long getSince() {
061    return since;
062  }
063
064  /**
065   * Set the epoch time after which the query plan was captured.
066   * <p>
067   * This is used to only capture plans that have changed since a given time (like the time of last capture).
068   * </p>
069   *
070   * @param since The time after which the query plan was captured to be included
071   */
072  public void setSince(long since) {
073    this.since = since;
074  }
075
076  /**
077   * Process consume the query plan.
078   */
079  public void process(MetaQueryPlan plan) {
080    plans.add(plan);
081  }
082
083  /**
084   * Return true if the bean type should be included in the query plan capture.
085   */
086  public boolean includeType(Class<?> beanType) {
087    return includedBeanTypes == null || includedBeanTypes.isEmpty() || includedBeanTypes.contains(beanType);
088  }
089
090  /**
091   * Return true if the label should be included in the query plan capture.
092   */
093  public boolean includeLabel(String label) {
094    return includedLabels == null || includedLabels.isEmpty() || includedLabels.contains(label);
095  }
096
097}