com.atlassian.jira.entity
Class Select

java.lang.Object
  extended by com.atlassian.jira.entity.Select

public class Select
extends Object

Select is the entry point to building up a SelectQuery which can be run in OfBiz Entity Engine.

eg

 SelectQuery<GenericValue> query = Select.columns().from("FilterSubscription")
      .whereEqual("group", (String) null)
      .andEqual("username", username)
      .orderBy("id desc");
 
 

If you are selecting a single column, then you can it can return String objects instead of GenericValues like

 SelectQuery<String> query = Select.distinctString("username").from("FilterSubscription");
 List<String> vals = query.runWith(delegator).asList();
 
 

You can also use an EntityFactory to automatically convert the GenericValues to other entity objects.

 List<ProjectCategory> categories = Select.from(Entity.PROJECT_CATEGORY).runWith(delegator).asList();
 
 

Since:
v5.2

Nested Class Summary
static class Select.ExecutableContext<E>
          Partially constructed query that has enough information supplied to form a complete query.
static class Select.LimitContext<E>
          A fully specified query that is ready to be executed.
static class Select.OrderByContext<E>
          A partially constructed query with completed column, entity, where condition, and ordering information already specified.
static class Select.SelectColumnsContext
          Partially constructed query that has a column list but no entity name, yet.
static class Select.SelectColumnsFromContext<E>
          A partially constructed query that may accept .where and .orderBy clauses.
static class Select.SelectSingleColumnContext<E>
          Partially constructed query that has a column list (with a single target column) but no entity name, yet.
static class Select.WhereClauseAwareContext<E>
          Marker for contexts that can accept a where clause.
static class Select.WhereContext<E>
          A partially constructed query that may accept .where and .orderBy clauses.
 
Constructor Summary
Select()
           
 
Method Summary
static Select.SelectColumnsContext columns(List<String> columns)
          Begins a SELECT query that will only retrieve the specified columns.
static Select.SelectColumnsContext columns(String... columns)
          Begins a SELECT query that will only retrieve the specified columns.
static Select.SelectColumnsFromContext<Long> countFrom(String entityName)
          Builds a "SELECT COUNT(*) FROM ..." query for the given entity.
static Select.SelectColumnsContext distinct(String... columns)
          Begins a SELECT DISTICT query that will only retrieve the specified columns.
static Select.SelectSingleColumnContext<String> distinctString(String columnName)
          Begins a SELECT DISTICT query that will only retrieve the specified String column.
static
<E> Select.SelectColumnsFromContext<E>
from(NamedEntityBuilder<E> entityFactory)
          Begins a SELECT * query for the specified entity factory.
static Select.SelectColumnsFromContext<org.ofbiz.core.entity.GenericValue> from(String entityName)
          Begins a SELECT * query for the specified entity.
static Select.SelectSingleColumnContext<Long> id()
          Begins a SELECT query that will only retrieve the "id" field, which must use Long values.
static Select.SelectSingleColumnContext<String> stringColumn(String columnName)
          Begins a SELECT query that will only retrieve the specified String column.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Select

public Select()
Method Detail

columns

public static Select.SelectColumnsContext columns(List<String> columns)
Begins a SELECT query that will only retrieve the specified columns.

Parameters:
columns - the list of fields to retrieve; must not be null or contain any null values
Returns:
a partially constructed query; use .from(entityName) to continue building it

columns

public static Select.SelectColumnsContext columns(String... columns)
Begins a SELECT query that will only retrieve the specified columns.

Parameters:
columns - the fields to retrieve; must not be null or contain any null values
Returns:
a partially constructed query; use .from(entityName) to continue building it

distinct

public static Select.SelectColumnsContext distinct(String... columns)
Begins a SELECT DISTICT query that will only retrieve the specified columns.

Parameters:
columns - the fields to retrieve; must not be null or contain any null values
Returns:
a partially constructed query; use .from(entityName) to continue building it

id

public static Select.SelectSingleColumnContext<Long> id()
Begins a SELECT query that will only retrieve the "id" field, which must use Long values.

WARNING: Not suitable for use with "id" columns that return a String, such as those used for issue constants.

Returns:
a partially constructed query; use .from(entityName) to continue building it

distinctString

public static Select.SelectSingleColumnContext<String> distinctString(String columnName)
Begins a SELECT DISTICT query that will only retrieve the specified String column.

Parameters:
columnName - the field to query
Returns:
a partially constructed query; use .from(entityName) to continue building it

stringColumn

public static Select.SelectSingleColumnContext<String> stringColumn(String columnName)
Begins a SELECT query that will only retrieve the specified String column.

Parameters:
columnName - the field to query
Returns:
a partially constructed query; use .from(entityName) to continue building it

from

public static <E> Select.SelectColumnsFromContext<E> from(NamedEntityBuilder<E> entityFactory)
Begins a SELECT * query for the specified entity factory.

As the query returns results, EntityBuilder.build(GenericValue) is used on each value to yield its corresponding entity value.

Type Parameters:
E - the entity type that this query will yield, as inferred from its factory
Parameters:
entityFactory - the entity factory to use for coverting GenericValue to the desired return type
Returns:
a partially constructed query; use one of the .where... constraints, an orderBy, or a .runWith method to continue building it

from

public static Select.SelectColumnsFromContext<org.ofbiz.core.entity.GenericValue> from(String entityName)
Begins a SELECT * query for the specified entity.

Parameters:
entityName - the name of the entity to query
Returns:
a partially constructed query; use one of the .where... constraints, an orderBy, or a .runWith method to continue building it

countFrom

public static Select.SelectColumnsFromContext<Long> countFrom(String entityName)
Builds a "SELECT COUNT(*) FROM ..." query for the given entity.

For example:

 long count = Select.countFrom(Entity.Name.COMMENT)
                    .whereEqual("author", userKey)
                    .runWith(ofBizDelegator)
                    .singleValue();
 

This method requires the existence of a "Count" view in the entity model, which has not been defined for all entities. Consider building a normal query with .count() as the finishing action for a more flexible alternative.

Parameters:
entityName - the Entity
Returns:
a query builder for a "SELECT COUNT(*) FROM ..." query


Copyright © 2002-2014 Atlassian. All Rights Reserved.