org.opencms.db.generic
Class CmsUserQueryBuilder

java.lang.Object
  extended by org.opencms.db.generic.CmsUserQueryBuilder
Direct Known Subclasses:
CmsJpaUserQueryBuilder

public class CmsUserQueryBuilder
extends Object

Default implementation of the user query builder.

Since:
8.0.0

Constructor Summary
CmsUserQueryBuilder()
           
 
Method Summary
protected  void addAllowedOuCondition(CmsSelectQuery select, CmsSelectQuery.TableAlias users, List<CmsOrganizationalUnit> allowedOus)
          Adds OU conditions to an SQL query.
protected  void addFlagCondition(CmsSelectQuery select, CmsSelectQuery.TableAlias users, int flags, boolean allowCore)
          Adds flag checking conditions to an SQL query.
protected  void addGroupCondition(CmsSelectQuery select, CmsSelectQuery.TableAlias users, CmsUserSearchParameters searchParams)
          Adds group conditions to an SQL query.
protected  void addOrgUnitCondition(CmsSelectQuery select, CmsSelectQuery.TableAlias users, CmsOrganizationalUnit orgUnit, boolean recursive)
          Adds a check for an OU to an SQL query.
protected  void addSearchFilterCondition(CmsSelectQuery select, CmsSelectQuery.TableAlias users, CmsUserSearchParameters searchParams)
          Adds a search condition to a query.
protected  void addSorting(CmsSelectQuery select, CmsSelectQuery.TableAlias users, CmsUserSearchParameters searchParams)
          Adds a sort order to an SQL query.
protected  void addWebuserCondition(CmsSelectQuery select, CmsOrganizationalUnit orgUnit, CmsSelectQuery.TableAlias users)
          Adds a check for the web user condition to an SQL query.
protected  String colDateCreated()
          Column name accessor.
protected  String colEmail()
          Column name accessor.
protected  String colFirstName()
          Column name accessor.
protected  String colFlags()
          Column name accessor.
protected  String colGroupUserGroupId()
          Column name accessor.
protected  String colGroupUserUserId()
          Column name accessor.
protected  String colId()
          Column name accessor.
protected  String colLastLogin()
          Column name accessor.
protected  String colLastName()
          Column name accessor.
protected  String colName()
          Column name accessor.
protected  String colOu()
          Column name accessor.
protected  String colPassword()
          Column name accessor.
protected  I_CmsQueryFragment createCoreCondition(CmsSelectQuery.TableAlias users)
          Creates a core user check condition.
protected  I_CmsQueryFragment createFlagCondition(CmsSelectQuery.TableAlias users, int flags)
          Creates an SQL flag check condition.
 CmsPair<String,List<Object>> createUserQuery(CmsUserSearchParameters searchParams, boolean countOnly)
          Creates a query for searching users.
protected  String generateConcat(String... expressions)
          Generates an SQL expression for concatenating several other SQL expressions.
protected  String generateTrim(String expression)
          Generates an SQL expression for trimming whitespace from the beginning and end of a string.
protected  String getGroupUserSubqueryColumns()
          Returns the columns that should be returned by user subqueries.
protected  String getSortExpression(CmsSelectQuery.TableAlias users, CmsUserSearchParameters searchParams)
          Returns the expression used for sorting the results.
protected  String getUserActivatedExpression(CmsSelectQuery.TableAlias users)
          Returns an expression for checking whether a user is activated.
protected  String getUserFlagExpression(CmsSelectQuery.TableAlias users, int flags)
          Returns a bitwise AND expression with a fixed second operand.
protected  String getUserFullNameExpression(CmsSelectQuery.TableAlias users)
          Returns the SQL expression for generating the user's full name in the format 'firstname lastname (loginname)'.
protected  CmsPair<String,List<Object>> makePaged(CmsSelectQuery select, CmsUserSearchParameters params)
          Creates a query which uses paging from another query.
protected  boolean shouldNameSubqueries()
          Should return true if subqueries in a FROM clause should be named.
protected  String tabGroups()
          Table name accessor.
protected  String tabGroupUsers()
          Table name accessor.
protected  String tabUsers()
          Table name accessor.
protected  boolean useWindowFunctionsForPaging()
          Returns true if window functions should be used for paging.
protected  String wrapLower(String expr, boolean caseInsensitive)
          Wraps an SQL expression in a "LOWER" call conditionally.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsUserQueryBuilder

public CmsUserQueryBuilder()
Method Detail

createUserQuery

public CmsPair<String,List<Object>> createUserQuery(CmsUserSearchParameters searchParams,
                                                    boolean countOnly)
Creates a query for searching users.

Parameters:
searchParams - the user search criteria
countOnly - if true, the query will only count the total number of results instead of returning them
Returns:
a pair consisting of the query string and its parameters

addAllowedOuCondition

protected void addAllowedOuCondition(CmsSelectQuery select,
                                     CmsSelectQuery.TableAlias users,
                                     List<CmsOrganizationalUnit> allowedOus)
Adds OU conditions to an SQL query.

Parameters:
select - the query
users - the user table alias
allowedOus - the allowed ous

addFlagCondition

protected void addFlagCondition(CmsSelectQuery select,
                                CmsSelectQuery.TableAlias users,
                                int flags,
                                boolean allowCore)
Adds flag checking conditions to an SQL query.

Parameters:
select - the query
users - the user table alias
flags - the flags
allowCore - set to true if core users should not be filtered out

addGroupCondition

protected void addGroupCondition(CmsSelectQuery select,
                                 CmsSelectQuery.TableAlias users,
                                 CmsUserSearchParameters searchParams)
Adds group conditions to an SQL query.

Parameters:
select - the query
users - the user table alias
searchParams - the search parameters

addOrgUnitCondition

protected void addOrgUnitCondition(CmsSelectQuery select,
                                   CmsSelectQuery.TableAlias users,
                                   CmsOrganizationalUnit orgUnit,
                                   boolean recursive)
Adds a check for an OU to an SQL query.

Parameters:
select - the query
users - the user table alias
orgUnit - the organizational unit
recursive - if true, checks for sub-OUs too

addSearchFilterCondition

protected void addSearchFilterCondition(CmsSelectQuery select,
                                        CmsSelectQuery.TableAlias users,
                                        CmsUserSearchParameters searchParams)
Adds a search condition to a query.

Parameters:
select - the query
users - the user table alias
searchParams - the search criteria

addSorting

protected void addSorting(CmsSelectQuery select,
                          CmsSelectQuery.TableAlias users,
                          CmsUserSearchParameters searchParams)
Adds a sort order to an SQL query.

Parameters:
select - the query
users - the user table alias
searchParams - the user search criteria

addWebuserCondition

protected void addWebuserCondition(CmsSelectQuery select,
                                   CmsOrganizationalUnit orgUnit,
                                   CmsSelectQuery.TableAlias users)
Adds a check for the web user condition to an SQL query.

Parameters:
select - the query
orgUnit - the organizational unit
users - the user table alias

colDateCreated

protected String colDateCreated()
Column name accessor.

Returns:
the name of the column

colEmail

protected String colEmail()
Column name accessor.

Returns:
the name of the column

colFirstName

protected String colFirstName()
Column name accessor.

Returns:
the name of the column

colFlags

protected String colFlags()
Column name accessor.

Returns:
the name of the column

colGroupUserGroupId

protected String colGroupUserGroupId()
Column name accessor.

Returns:
the name of the column

colGroupUserUserId

protected String colGroupUserUserId()
Column name accessor.

Returns:
the name of the column

colId

protected String colId()
Column name accessor.

Returns:
the name of the column

colLastLogin

protected String colLastLogin()
Column name accessor.

Returns:
the name of the column

colLastName

protected String colLastName()
Column name accessor.

Returns:
the name of the column

colName

protected String colName()
Column name accessor.

Returns:
the name of the column

colOu

protected String colOu()
Column name accessor.

Returns:
the name of the column

colPassword

protected String colPassword()
Column name accessor.

Returns:
the name of the column

createCoreCondition

protected I_CmsQueryFragment createCoreCondition(CmsSelectQuery.TableAlias users)
Creates a core user check condition.

Parameters:
users - the user table alias
Returns:
the resulting SQL expression

createFlagCondition

protected I_CmsQueryFragment createFlagCondition(CmsSelectQuery.TableAlias users,
                                                 int flags)
Creates an SQL flag check condition.

Parameters:
users - the user table alias
flags - the flags to check
Returns:
the resulting SQL expression

generateConcat

protected String generateConcat(String... expressions)
Generates an SQL expression for concatenating several other SQL expressions.

Parameters:
expressions - the expressions to concatenate
Returns:
the concat expression

generateTrim

protected String generateTrim(String expression)
Generates an SQL expression for trimming whitespace from the beginning and end of a string.

Parameters:
expression - the expression to wrap
Returns:
the expression for trimming the given expression

getGroupUserSubqueryColumns

protected String getGroupUserSubqueryColumns()
Returns the columns that should be returned by user subqueries.

Returns:
the columns that should be returned by user subqueries

getSortExpression

protected String getSortExpression(CmsSelectQuery.TableAlias users,
                                   CmsUserSearchParameters searchParams)
Returns the expression used for sorting the results.

Parameters:
users - the user table alias
searchParams - the search parameters
Returns:
the sorting expressiong

getUserActivatedExpression

protected String getUserActivatedExpression(CmsSelectQuery.TableAlias users)
Returns an expression for checking whether a user is activated.

Parameters:
users - the user table alias
Returns:
the expression for checking whether the user is activated

getUserFlagExpression

protected String getUserFlagExpression(CmsSelectQuery.TableAlias users,
                                       int flags)
Returns a bitwise AND expression with a fixed second operand.

Parameters:
users - the user table alias
flags - the user flags
Returns:
the resulting SQL expression

getUserFullNameExpression

protected String getUserFullNameExpression(CmsSelectQuery.TableAlias users)
Returns the SQL expression for generating the user's full name in the format 'firstname lastname (loginname)'.

Parameters:
users - the user table alias
Returns:
the expression for generating the user's full name

makePaged

protected CmsPair<String,List<Object>> makePaged(CmsSelectQuery select,
                                                 CmsUserSearchParameters params)
Creates a query which uses paging from another query.

Parameters:
select - the base query
params - the query parameters
Returns:
the paged version of the query

shouldNameSubqueries

protected boolean shouldNameSubqueries()
Should return true if subqueries in a FROM clause should be named.

Returns:
true if subqueries in a FROM clause should be named

tabGroups

protected String tabGroups()
Table name accessor.

Returns:
the name of a table

tabGroupUsers

protected String tabGroupUsers()
Table name accessor.

Returns:
the name of a table

tabUsers

protected String tabUsers()
Table name accessor.

Returns:
the name of a table

useWindowFunctionsForPaging

protected boolean useWindowFunctionsForPaging()
Returns true if window functions should be used for paging.

Returns:
true if window functions should be used for paging

wrapLower

protected String wrapLower(String expr,
                           boolean caseInsensitive)
Wraps an SQL expression in a "LOWER" call conditionally.

Parameters:
expr - the expression to wrap
caseInsensitive - if false, no wrapping should occur
Returns:
the resulting expression