Package org.opencms.db.generic
Class CmsUserQueryBuilder
- java.lang.Object
-
- org.opencms.db.generic.CmsUserQueryBuilder
-
public class CmsUserQueryBuilder extends java.lang.Object
Default implementation of the user query builder.- Since:
- 8.0.0
-
-
Constructor Summary
Constructors Constructor Description CmsUserQueryBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addAllowedOuCondition(CmsSelectQuery select, CmsSelectQuery.TableAlias users, java.util.List<CmsOrganizationalUnit> allowedOus)
Adds OU conditions to an SQL query.protected void
addEmailCondition(CmsSelectQuery select, CmsSelectQuery.TableAlias users, java.lang.String email)
Adds an equality test for the email address.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 java.lang.String
colDateCreated()
Column name accessor.protected java.lang.String
colEmail()
Column name accessor.protected java.lang.String
colFirstName()
Column name accessor.protected java.lang.String
colFlags()
Column name accessor.protected java.lang.String
colGroupUserGroupId()
Column name accessor.protected java.lang.String
colGroupUserUserId()
Column name accessor.protected java.lang.String
colId()
Column name accessor.protected java.lang.String
colLastLogin()
Column name accessor.protected java.lang.String
colLastName()
Column name accessor.protected java.lang.String
colName()
Column name accessor.protected java.lang.String
colOu()
Column name accessor.protected java.lang.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<java.lang.String,java.util.List<java.lang.Object>>
createUserQuery(CmsUserSearchParameters searchParams, boolean countOnly)
Creates a query for searching users.protected java.lang.String
generateConcat(java.lang.String... expressions)
Generates an SQL expression for concatenating several other SQL expressions.protected java.lang.String
generateTrim(java.lang.String expression)
Generates an SQL expression for trimming whitespace from the beginning and end of a string.protected java.lang.String
getGroupUserSubqueryColumns()
Returns the columns that should be returned by user subqueries.protected java.lang.String
getSortExpression(CmsSelectQuery.TableAlias users, CmsUserSearchParameters searchParams)
Returns the expression used for sorting the results.protected java.lang.String
getUserActivatedExpression(CmsSelectQuery.TableAlias users)
Returns an expression for checking whether a user is activated.protected java.lang.String
getUserFlagExpression(CmsSelectQuery.TableAlias users, int flags)
Returns a bitwise AND expression with a fixed second operand.protected java.lang.String
getUserFullNameExpression(CmsSelectQuery.TableAlias users)
Returns the SQL expression for generating the user's full name in the format 'firstname lastname (loginname)'.protected CmsPair<java.lang.String,java.util.List<java.lang.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 java.lang.String
tabGroups()
Table name accessor.protected java.lang.String
tabGroupUsers()
Table name accessor.protected java.lang.String
tabUsers()
Table name accessor.protected boolean
useWindowFunctionsForPaging()
Returns true if window functions should be used for paging.protected java.lang.String
wrapLower(java.lang.String expr, boolean caseInsensitive)
Wraps an SQL expression in a "LOWER" call conditionally.
-
-
-
Constructor Detail
-
CmsUserQueryBuilder
public CmsUserQueryBuilder()
-
-
Method Detail
-
createUserQuery
public CmsPair<java.lang.String,java.util.List<java.lang.Object>> createUserQuery(CmsUserSearchParameters searchParams, boolean countOnly)
Creates a query for searching users.- Parameters:
searchParams
- the user search criteriacountOnly
- 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, java.util.List<CmsOrganizationalUnit> allowedOus)
Adds OU conditions to an SQL query.- Parameters:
select
- the queryusers
- the user table aliasallowedOus
- the allowed ous
-
addEmailCondition
protected void addEmailCondition(CmsSelectQuery select, CmsSelectQuery.TableAlias users, java.lang.String email)
Adds an equality test for the email address. If the email address is null, no test is added.- Parameters:
select
- the select statement to add the test tousers
- the user table aliasemail
- the email address to compare the column to
-
addFlagCondition
protected void addFlagCondition(CmsSelectQuery select, CmsSelectQuery.TableAlias users, int flags, boolean allowCore)
Adds flag checking conditions to an SQL query.- Parameters:
select
- the queryusers
- the user table aliasflags
- the flagsallowCore
- 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 queryusers
- the user table aliassearchParams
- 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 queryusers
- the user table aliasorgUnit
- the organizational unitrecursive
- 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 queryusers
- the user table aliassearchParams
- 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 queryusers
- the user table aliassearchParams
- 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 queryorgUnit
- the organizational unitusers
- the user table alias
-
colDateCreated
protected java.lang.String colDateCreated()
Column name accessor.- Returns:
- the name of the column
-
colEmail
protected java.lang.String colEmail()
Column name accessor.- Returns:
- the name of the column
-
colFirstName
protected java.lang.String colFirstName()
Column name accessor.- Returns:
- the name of the column
-
colFlags
protected java.lang.String colFlags()
Column name accessor.- Returns:
- the name of the column
-
colGroupUserGroupId
protected java.lang.String colGroupUserGroupId()
Column name accessor.- Returns:
- the name of the column
-
colGroupUserUserId
protected java.lang.String colGroupUserUserId()
Column name accessor.- Returns:
- the name of the column
-
colId
protected java.lang.String colId()
Column name accessor.- Returns:
- the name of the column
-
colLastLogin
protected java.lang.String colLastLogin()
Column name accessor.- Returns:
- the name of the column
-
colLastName
protected java.lang.String colLastName()
Column name accessor.- Returns:
- the name of the column
-
colName
protected java.lang.String colName()
Column name accessor.- Returns:
- the name of the column
-
colOu
protected java.lang.String colOu()
Column name accessor.- Returns:
- the name of the column
-
colPassword
protected java.lang.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 aliasflags
- the flags to check- Returns:
- the resulting SQL expression
-
generateConcat
protected java.lang.String generateConcat(java.lang.String... expressions)
Generates an SQL expression for concatenating several other SQL expressions.- Parameters:
expressions
- the expressions to concatenate- Returns:
- the concat expression
-
generateTrim
protected java.lang.String generateTrim(java.lang.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 java.lang.String getGroupUserSubqueryColumns()
Returns the columns that should be returned by user subqueries.- Returns:
- the columns that should be returned by user subqueries
-
getSortExpression
protected java.lang.String getSortExpression(CmsSelectQuery.TableAlias users, CmsUserSearchParameters searchParams)
Returns the expression used for sorting the results.- Parameters:
users
- the user table aliassearchParams
- the search parameters- Returns:
- the sorting expressiong
-
getUserActivatedExpression
protected java.lang.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 java.lang.String getUserFlagExpression(CmsSelectQuery.TableAlias users, int flags)
Returns a bitwise AND expression with a fixed second operand.- Parameters:
users
- the user table aliasflags
- the user flags- Returns:
- the resulting SQL expression
-
getUserFullNameExpression
protected java.lang.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<java.lang.String,java.util.List<java.lang.Object>> makePaged(CmsSelectQuery select, CmsUserSearchParameters params)
Creates a query which uses paging from another query.- Parameters:
select
- the base queryparams
- 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 java.lang.String tabGroups()
Table name accessor.- Returns:
- the name of a table
-
tabGroupUsers
protected java.lang.String tabGroupUsers()
Table name accessor.- Returns:
- the name of a table
-
tabUsers
protected java.lang.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 java.lang.String wrapLower(java.lang.String expr, boolean caseInsensitive)
Wraps an SQL expression in a "LOWER" call conditionally.- Parameters:
expr
- the expression to wrapcaseInsensitive
- if false, no wrapping should occur- Returns:
- the resulting expression
-
-