Package org.nuxeo.ecm.directory.sql
Class SQLSession
- java.lang.Object
-
- org.nuxeo.ecm.directory.BaseSession
-
- org.nuxeo.ecm.directory.sql.SQLSession
-
- All Implemented Interfaces:
AutoCloseable
,EntrySource
,Session
public class SQLSession extends BaseSession
This class represents a session against an SQLDirectory.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.nuxeo.ecm.directory.BaseSession
BaseSession.FieldDetector
-
-
Field Summary
Fields Modifier and Type Field Description protected Dialect
dialect
protected JDBCLogger
logger
protected SQLStaticFilter[]
staticFilters
-
Fields inherited from class org.nuxeo.ecm.directory.BaseSession
autoincrementId, computeMultiTenantId, directory, directoryName, MULTI_TENANT_ID_FORMAT, passwordHashAlgorithm, permissions, POWER_USERS_GROUP, readAllColumns, READONLY_ENTRY_FLAG, referenceClass, schemaName, substringMatchType, TENANT_ID_FIELD
-
-
Constructor Summary
Constructors Constructor Description SQLSession(SQLDirectory directory, SQLDirectoryDescriptor config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addFilterValues(PreparedStatement ps, int startIdx)
protected void
addFilterValuesForLog(List<Serializable> values)
protected String
addFilterWhereClause(String whereClause)
protected void
addFilterWhereClause(StringBuilder clause, List<SQLQueryBuilder.ColumnAndValue> params)
boolean
authenticate(String username, String password)
Checks that the credentials provided by the UserManager match those registered in the directory.protected void
checkConcurrentUpdate(Throwable e)
Checks the SQL error we got and determine if a concurrent update happened.void
close()
Closes the session and all open result sets obtained from this session.protected DocumentModel
createEntryWithoutReferences(Map<String,Object> fieldMap)
To be implemented for specific creation.void
deleteEntry(String id)
Deletes a directory entry by id.void
deleteEntry(String id, Map<String,String> map)
Deletes a directory entry by id and secondary ids.void
deleteEntryWithoutReferences(String id)
To be implemented for specific deletion.protected DocumentModel
fieldMapToDocumentModel(Map<String,Object> fieldMap)
protected Serializable
fieldValueForWrite(Object value, Column column)
protected void
fillPreparedStatementFields(Map<String,Object> filterMap, List<Column> orderedColumns, PreparedStatement ps)
SQLDirectory
getDirectory()
To be implemented with a more specific return type.DocumentModel
getEntryFromSource(String id, boolean fetchReferences)
protected Column
getIdColumn()
protected String
getPassword(String id)
Internal method to read the hashed password for authentication.protected List<Column>
getReadColumns()
protected String
getReadColumnsSQL()
boolean
hasEntry(String id)
Returns true if session has an entry with given id.boolean
isAuthenticating()
Tells whether the directory implementation can be used as an authenticating backend for the UserManager (based on login / password check).boolean
isLive()
Enable connection status checking on SQL directory connectionsprotected PreparedStatement
prepareStatementWithAutoKeys(String sql)
Create aPreparedStatement
returning the id key if it is auto-incremented and dialect has identity generated key (Dialect.hasIdentityGeneratedKey()
).DocumentModelList
query(Map<String,Serializable> filter, Set<String> fulltext, Map<String,String> orderBy, boolean fetchReferences, int limit, int offset)
Executes a query with the possibility to fetch a subset of the results.DocumentModelList
query(QueryBuilder queryBuilder, boolean fetchReferences)
Executes a query with the possibility to fetch a subset of the results.List<String>
queryIds(QueryBuilder queryBuilder)
Executes a query with the possibility to fetch a subset of the results.protected void
setIdFieldInMap(ResultSet rs, Column column, String idFieldName, Map<String,Object> fieldMap)
String
toString()
protected List<String>
updateEntryWithoutReferences(DocumentModel docModel)
To be implemented for specific update.-
Methods inherited from class org.nuxeo.ecm.directory.BaseSession
addTenantId, applyQueryLimits, applyQueryLimits, canDeleteMultiTenantEntry, checkDeleteConstraints, checkPermission, computeMultiTenantDirectoryId, createEntry, createEntry, createEntryModel, createEntryModel, createEntryModel, createEntryModel, createEntryModel, deleteEntry, getCurrentTenantId, getEntries, getEntry, getEntry, getIdField, getPasswordField, getProjection, getProjection, hasPermission, hasPermission, isMultiTenant, isReadOnly, isReadOnlyEntry, query, query, query, query, setReadAllColumns, setReadOnlyEntry, setReadWriteEntry, toStringList, updateEntry
-
-
-
-
Field Detail
-
staticFilters
protected SQLStaticFilter[] staticFilters
-
dialect
protected final Dialect dialect
-
logger
protected JDBCLogger logger
-
-
Constructor Detail
-
SQLSession
public SQLSession(SQLDirectory directory, SQLDirectoryDescriptor config)
-
-
Method Detail
-
getDirectory
public SQLDirectory getDirectory()
Description copied from class:BaseSession
To be implemented with a more specific return type.- Specified by:
getDirectory
in classBaseSession
-
getEntryFromSource
public DocumentModel getEntryFromSource(String id, boolean fetchReferences)
- Specified by:
getEntryFromSource
in interfaceEntrySource
- Overrides:
getEntryFromSource
in classBaseSession
-
getReadColumnsSQL
protected String getReadColumnsSQL()
-
getIdColumn
protected Column getIdColumn()
-
fieldMapToDocumentModel
protected DocumentModel fieldMapToDocumentModel(Map<String,Object> fieldMap)
-
checkConcurrentUpdate
protected void checkConcurrentUpdate(Throwable e) throws ConcurrentUpdateException
Checks the SQL error we got and determine if a concurrent update happened. Throws if that's the case.- Parameters:
e
- the exception- Throws:
ConcurrentUpdateException
- Since:
- 7.10-HF04, 8.2
-
addFilterWhereClause
protected void addFilterWhereClause(StringBuilder clause, List<SQLQueryBuilder.ColumnAndValue> params)
-
addFilterValues
protected void addFilterValues(PreparedStatement ps, int startIdx)
-
addFilterValuesForLog
protected void addFilterValuesForLog(List<Serializable> values)
-
getPassword
protected String getPassword(String id)
Internal method to read the hashed password for authentication.- Since:
- 9.1
-
deleteEntry
public void deleteEntry(String id)
Description copied from interface:Session
Deletes a directory entry by id.- Specified by:
deleteEntry
in interfaceSession
- Overrides:
deleteEntry
in classBaseSession
- Parameters:
id
- the id of the entry to delete
-
deleteEntry
public void deleteEntry(String id, Map<String,String> map)
Description copied from interface:Session
Deletes a directory entry by id and secondary ids.This is used for hierarchical vocabularies, where the actual unique key is the couple (parent, id).
- Specified by:
deleteEntry
in interfaceSession
- Overrides:
deleteEntry
in classBaseSession
- Parameters:
id
- the id of the entry to delete.map
- a map of secondary key values.
-
query
public DocumentModelList query(Map<String,Serializable> filter, Set<String> fulltext, Map<String,String> orderBy, boolean fetchReferences, int limit, int offset)
Description copied from interface:Session
Executes a query with the possibility to fetch a subset of the results. org.nuxeo.ecm.directory.BaseSession provides a default implementation fetching all results to return the subset. Not recommended.limit
- maximum number of results ignored if less than 1offset
- number of rows skipped before starting, will be 0 if less than 0.- See Also:
Session.query(Map, Set, Map, boolean)
-
query
public DocumentModelList query(QueryBuilder queryBuilder, boolean fetchReferences)
Description copied from interface:Session
Executes a query with the possibility to fetch a subset of the results.- Parameters:
queryBuilder
- the query to use, including limit, offset, ordering and countTotalfetchReferences
- boolean stating if references have to be fetched- Returns:
- the list of documents, where the total size may be present if countTotal was true
-
queryIds
public List<String> queryIds(QueryBuilder queryBuilder)
Description copied from interface:Session
Executes a query with the possibility to fetch a subset of the results. Returns the matching ids.- Parameters:
queryBuilder
- the query to use, including limit, offset and ordering- Returns:
- the list of document ids
-
createEntryWithoutReferences
protected DocumentModel createEntryWithoutReferences(Map<String,Object> fieldMap)
Description copied from class:BaseSession
To be implemented for specific creation.- Specified by:
createEntryWithoutReferences
in classBaseSession
-
setIdFieldInMap
protected void setIdFieldInMap(ResultSet rs, Column column, String idFieldName, Map<String,Object> fieldMap) throws SQLException
- Throws:
SQLException
-
prepareStatementWithAutoKeys
protected PreparedStatement prepareStatementWithAutoKeys(String sql) throws SQLException
Create aPreparedStatement
returning the id key if it is auto-incremented and dialect has identity generated key (Dialect.hasIdentityGeneratedKey()
).- Throws:
SQLException
- Since:
- 10.1
-
updateEntryWithoutReferences
protected List<String> updateEntryWithoutReferences(DocumentModel docModel)
Description copied from class:BaseSession
To be implemented for specific update.- Specified by:
updateEntryWithoutReferences
in classBaseSession
-
deleteEntryWithoutReferences
public void deleteEntryWithoutReferences(String id)
Description copied from class:BaseSession
To be implemented for specific deletion.- Specified by:
deleteEntryWithoutReferences
in classBaseSession
-
fillPreparedStatementFields
protected void fillPreparedStatementFields(Map<String,Object> filterMap, List<Column> orderedColumns, PreparedStatement ps)
-
fieldValueForWrite
protected Serializable fieldValueForWrite(Object value, Column column)
-
close
public void close()
Description copied from interface:Session
Closes the session and all open result sets obtained from this session.Releases this Connection object's resources immediately instead of waiting for them to be automatically released.
TODO: should this operation auto-commit pending changes?
-
isLive
public boolean isLive()
Enable connection status checking on SQL directory connections- Since:
- 5.7.2
-
authenticate
public boolean authenticate(String username, String password)
Description copied from interface:Session
Checks that the credentials provided by the UserManager match those registered in the directory. If username is not in the directory, this should return false instead of throrwing an exception.- Returns:
- true is the credentials match those stored in the directory
-
isAuthenticating
public boolean isAuthenticating()
Description copied from interface:Session
Tells whether the directory implementation can be used as an authenticating backend for the UserManager (based on login / password check).- Specified by:
isAuthenticating
in interfaceSession
- Overrides:
isAuthenticating
in classBaseSession
- Returns:
- true is the directory is authentication aware
-
hasEntry
public boolean hasEntry(String id)
Description copied from interface:Session
Returns true if session has an entry with given id.
-
-