Class EntityFindOptions

java.lang.Object
org.ofbiz.core.entity.EntityFindOptions
All Implemented Interfaces:
Serializable

public class EntityFindOptions extends Object implements Serializable
Advanced options for finding entities. Examples:

     EntityFindOptions options1 = new EntityFindOptions().distinct().limit(10);

     EntityFindOptions options2 = EntityFindOptions.findOptions()
          .scrollInsensitive()
          .updatable()
          .fetchSize(30);
 
Since:
Aug 8, 2002
Version:
1.0
Author:
David E. Jones
See Also:
  • Field Details

    • TYPE_FORWARD_ONLY

      @Deprecated public static final int TYPE_FORWARD_ONLY
      Deprecated.
      use the original constant instead
      Type constant from the java.sql.ResultSet object for convenience.
      See Also:
    • TYPE_SCROLL_INSENSITIVE

      @Deprecated public static final int TYPE_SCROLL_INSENSITIVE
      Deprecated.
      use the original constant instead
      Type constant from the java.sql.ResultSet object for convenience.
      See Also:
    • TYPE_SCROLL_SENSITIVE

      @Deprecated public static final int TYPE_SCROLL_SENSITIVE
      Deprecated.
      use the original constant instead
      Type constant from the java.sql.ResultSet object for convenience.
      See Also:
    • CONCUR_READ_ONLY

      @Deprecated public static final int CONCUR_READ_ONLY
      Deprecated.
      use the original constant instead
      Type constant from the java.sql.ResultSet object for convenience.
      See Also:
    • CONCUR_UPDATABLE

      @Deprecated public static final int CONCUR_UPDATABLE
      Deprecated.
      use the original constant instead
      Type constant from the java.sql.ResultSet object for convenience.
      See Also:
    • specifyTypeAndConcurrency

      protected boolean specifyTypeAndConcurrency
    • resultSetType

      protected int resultSetType
    • resultSetConcurrency

      protected int resultSetConcurrency
    • distinct

      protected boolean distinct
    • maxResults

      protected int maxResults
      maximum results to obtain from DB - negative values mean no limit
    • offset

      protected int offset
    • fetchSize

      protected int fetchSize
  • Constructor Details

    • EntityFindOptions

      public EntityFindOptions()
      Default constructor. Defaults are as follows: specifyTypeAndConcurrency = true resultSetType = TYPE_FORWARD_ONLY resultSetConcurrency = CONCUR_READ_ONLY distinct = false maxResults = -1 (no limit) fetchSize = -1 (use driver's default setting)
    • EntityFindOptions

      @Deprecated public EntityFindOptions(boolean specifyTypeAndConcurrency, int resultSetType, int resultSetConcurrency, boolean distinct, int maxResults)
      Deprecated.
      since 1.0.27 - Please use the chained form as shown in the examples.
      Constructor that allows some options to be provided at construction time.
      Parameters:
      specifyTypeAndConcurrency - if false, then resultSetType and resultSetConcurrency are ignored, and the JDBC driver's defaults are used for these fields, instead
      resultSetType - either TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, or TYPE_SCROLL_SENSITIVE
      resultSetConcurrency - either CONCUR_READ_ONLY, or CONCUR_UPDATABLE
      distinct - if true, then the DISTINCT SQL keyword is used in the query
      maxResults - if specified, then this value is used to limit the number of results retrieved, by using LIMIT on MySQL, ROWNUM on Oracle, and so on
  • Method Details

    • findOptions

      public static EntityFindOptions findOptions()
      Creates a new EntityFindOptions. This is equivalent to the default constructor, but is implemented as a static method so that it can be used more conveniently by other classes that static import it.

      Example: import org.ofbiz.core.entity.EntityFindOptions; import static org.ofbiz.core.entity.EntityFindOptions.findOptions; [...] { EntityFindOptions options = findOptions().distinct().maxEntries(5); [...] }

      Returns:
      the new options
    • getSpecifyTypeAndConcur

      @Deprecated public boolean getSpecifyTypeAndConcur()
      Deprecated.
      use isCustomResultSetTypeAndConcurrency() instead; better named
      Indicates whether the resultSetType and resultSetConcurrency fields will be used to specify how the results will be used; false means that the JDBC driver's default values will be used.
      Returns:
      see above
    • isCustomResultSetTypeAndConcurrency

      public boolean isCustomResultSetTypeAndConcurrency()
      Indicates whether the resultSetType and resultSetConcurrency fields will be used to specify how the results will be used; false means that the JDBC driver's default values will be used.
      Returns:
      see above
    • setSpecifyTypeAndConcur

      @Deprecated public void setSpecifyTypeAndConcur(boolean specifyTypeAndConcurrency)
      Deprecated.
      there's no valid use case for this method; call useDriverDefaultsForTypeAndConcurrency() to revert to the driver's default settings for concurrency and type of result set
      Setting this to true means that the resultSetType and resultSetConcurrency parameters will be used to specify how the results will be used; if false, the JDBC driver's default values will be used.
      Parameters:
      specifyTypeAndConcurrency - see above
    • useDriverDefaultsForTypeAndConcurrency

      public void useDriverDefaultsForTypeAndConcurrency()
      Specifies that the JDBC driver's default values should be used for concurrency and type of result set, in other words any custom settings for those options should be ignored.
    • getResultSetType

      public int getResultSetType()
      Indicates how the ResultSet will be traversed.
      Returns:
      the result set type
      See Also:
    • setResultSetType

      public void setResultSetType(int resultSetType)
      Specifies how the ResultSet will be traversed. Available values: ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, and ResultSet.TYPE_SCROLL_SENSITIVE. If you want it to be fast, use the common default, ResultSet.TYPE_FORWARD_ONLY.
      Parameters:
      resultSetType - the result set type to set
    • getResultSetConcurrency

      public int getResultSetConcurrency()
      Specifies whether or not the ResultSet can be updated. Available values: ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE. Should pretty much always be ResultSet.CONCUR_READ_ONLY with the Entity Engine.
      Returns:
      see above
    • setResultSetConcurrency

      public void setResultSetConcurrency(int resultSetConcurrency)
      Specifies whether or not the ResultSet can be updated. Available values: ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE. Should pretty much always be ResultSet.CONCUR_READ_ONLY with the Entity Engine.
      Parameters:
      resultSetConcurrency - the value to set
    • getDistinct

      public boolean getDistinct()
      Indicates whether the values returned will be filtered to remove duplicate values.
      Returns:
      see above
    • setDistinct

      public void setDistinct(boolean distinct)
      Specifies whether the values returned should be filtered to remove duplicate values.
      Parameters:
      distinct - whether to return only unique values
    • getMaxResults

      public int getMaxResults()
      Specifies the maximum number of results to be returned by the query.
      Returns:
      see above
    • setMaxResults

      public void setMaxResults(int maxResults)
      Specifies the maximum number of results to be returned by the query. Must be positive.
      Parameters:
      maxResults - ignored if zero or less
    • getOffset

      public int getOffset()
      Returns the number of rows to be skipped.
      Returns:
      see above
    • setOffset

      public void setOffset(int offset)
      Specifies the number of rows to be skipped, which is ignored if maxResults is not also set.
      Parameters:
      offset - if negative, this method does nothing
    • getFetchSize

      public int getFetchSize()
      Specifies the value to use for the fetch size on the prepared statement. Please see the comments in setFetchSize(int) for restrictions.
      Returns:
      the fetch size
    • setFetchSize

      public void setFetchSize(int fetchSize)
      Specifies the value to use for the fetch size on the prepared statement. Note that the values that may be used are database-dependent. Use this with caution!

      WARNING: This setting is a hint for the database driver, and the driver is not required to honour it! Several databases put other restrictions on its use as well. Postgres will definitely ignore this setting when the database connection is in auto-commit mode, so you will probably have to use the TransactionUtil if you want this to work.

      WARNING: This value may need to be set to a database-dependent value. For example, the most useful value on MySQL is Integer.MIN_VALUE to get a streaming result set, but this value will be rejected by most other databases.

    • forwardOnly

      public EntityFindOptions forwardOnly()
      Same as using both setSpecifyTypeAndConcur(true) and setResultSetType(TYPE_FORWARD_ONLY). Note that you should also use either readOnly() or updatable() for maximum driver compatibility.
      Returns:
      this, for convenient use as a chained builder
    • scrollSensitive

      public EntityFindOptions scrollSensitive()
      Same as using both setSpecifyTypeAndConcur(true) and setResultSetType(TYPE_SCROLL_SENSITIVE). Note that you should also use either readOnly() or updatable() for maximum driver compatibility.
      Returns:
      this, for convenient use as a chained builder
    • scrollInsensitive

      public EntityFindOptions scrollInsensitive()
      Same as using both setSpecifyTypeAndConcur(true) and setResultSetType(TYPE_SCROLL_INSENSITIVE). Note that you should also use either readOnly() or updatable() for maximum driver compatibility.
      Returns:
      this, for convenient use as a chained builder
    • readOnly

      public EntityFindOptions readOnly()
      Same as using both setSpecifyTypeAndConcur(true) and setResultSetConcurrency(int) setResultSetConcurrency(CONCUR_READ_ONLY)}. Note that you should also use forwardOnly(), scrollSensitive() or scrollInsensitive() for maximum driver compatibility.
      Returns:
      this, for convenient use as a chained builder
    • updatable

      public EntityFindOptions updatable()
      Same as using both setSpecifyTypeAndConcur(true) and setResultSetConcurrency(int) setResultSetConcurrency(CONCUR_UPDATABLE)}. Note that you should also use forwardOnly(), scrollSensitive() or scrollInsensitive() for maximum driver compatibility.
      Returns:
      this, for convenient use as a chained builder
    • distinct

      public EntityFindOptions distinct()
      Returns:
      this, for convenient use as a chained builder
    • maxResults

      public EntityFindOptions maxResults(int maxResults)
      Returns:
      this, for convenient use as a chained builder
    • fetchSize

      public EntityFindOptions fetchSize(int fetchSize)
      Returns:
      this, for convenient use as a chained builder
    • range

      public EntityFindOptions range(int offset, int maxResults)
      Specifies the range of results to find.
      Parameters:
      offset - the offset from which to start
      maxResults - the maximum number of results to find
      Returns:
      this, for convenient use as a chained builder