public class SQLSession extends BaseSession implements EntrySource
Modifier and Type | Field and Description |
---|---|
protected Set<String> |
emptySet |
protected JDBCLogger |
logger |
protected Map<String,Field> |
schemaFieldMap |
protected SQLStaticFilter[] |
staticFilters |
protected List<String> |
storedFieldNames |
directory, MULTI_TENANT_ID_FORMAT, permissions, POWER_USERS_GROUP, READONLY_ENTRY_FLAG
Constructor and Description |
---|
SQLSession(SQLDirectory directory,
SQLDirectoryDescriptor config) |
Modifier and Type | Method and Description |
---|---|
protected void |
addFilterValues(PreparedStatement ps,
int startIdx) |
protected void |
addFilterValuesForLog(List<Serializable> values) |
protected String |
addFilterWhereClause(String whereClause) |
boolean |
authenticate(String username,
String password)
Checks that the credentials provided by the UserManager match those registered in the directory.
|
protected boolean |
canDeleteMultiTenantEntry(String entryId) |
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.
|
DocumentModel |
createEntry(DocumentModel entry)
Creates an entry in a directory.
|
DocumentModel |
createEntry(Map<String,Object> fieldMap)
Creates an entry in a directory.
|
void |
deleteEntry(DocumentModel docModel)
Deletes a directory entry.
|
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.
|
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) |
protected String |
getCurrentTenantId()
Returns the tenant id of the logged user if any,
null otherwise. |
SQLDirectory |
getDirectory()
To be implemented with a more specific return type.
|
DocumentModelList |
getEntries()
Retrieves all the entries in the directory.
|
DocumentModel |
getEntry(String id)
Retrieves a directory entry using its id.
|
DocumentModel |
getEntry(String id,
boolean fetchReferences)
Retrieves a directory entry using its id.
|
DocumentModel |
getEntryFromSource(String id,
boolean fetchReferences) |
List<String> |
getProjection(Map<String,Serializable> filter,
Set<String> fulltext,
String columnName) |
List<String> |
getProjection(Map<String,Serializable> filter,
String columnName)
Executes a query using filter and return only the column columnName.
|
Connection |
getSqlConnection()
Public getter to allow custom
Reference implementation to access the current connection even if it lives
in a separate java package, typically: com.company.custom.nuxeo.project.MyCustomReference |
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 connections
|
protected boolean |
isMultiTenant()
Returns
true if this directory supports multi tenancy, false otherwise. |
DocumentModelList |
query(Map<String,Serializable> filter)
Executes a simple query.
|
DocumentModelList |
query(Map<String,Serializable> filter,
Set<String> fulltext)
Executes a simple query.
|
DocumentModelList |
query(Map<String,Serializable> filter,
Set<String> fulltext,
Map<String,String> orderBy)
Executes a simple query.
|
DocumentModelList |
query(Map<String,Serializable> filter,
Set<String> fulltext,
Map<String,String> orderBy,
boolean fetchReferences)
Executes a query with the possibility to fetch references
|
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.
|
String |
toString() |
void |
updateEntry(DocumentModel docModel)
Updates a directory entry.
|
checkDeleteConstraints, checkPermission, computeMultiTenantDirectoryId, createEntryModel, createEntryModel, getIdField, getPasswordField, hasPermission, hasPermission, isReadOnly, isReadOnlyEntry, mkObjectMap, mkSerializableMap, setReadOnlyEntry, setReadWriteEntry
protected final Map<String,Field> schemaFieldMap
protected final List<String> storedFieldNames
protected SQLStaticFilter[] staticFilters
protected JDBCLogger logger
public SQLSession(SQLDirectory directory, SQLDirectoryDescriptor config) throws DirectoryException
DirectoryException
public SQLDirectory getDirectory()
BaseSession
getDirectory
in class BaseSession
protected DocumentModel fieldMapToDocumentModel(Map<String,Object> fieldMap)
protected void checkConcurrentUpdate(Throwable e) throws ConcurrentUpdateException
e
- the exceptionConcurrentUpdateException
public DocumentModel createEntry(Map<String,Object> fieldMap)
Session
createEntry
in interface Session
fieldMap
- A map with keys and values that should be stored in a directory
Note: The values in the map should be of type String
public DocumentModel getEntry(String id) throws DirectoryException
Session
TODO what happens when the entry is not found? return null if not found?
getEntry
in interface Session
id
- the entry idDirectoryException
public DocumentModel getEntry(String id, boolean fetchReferences) throws DirectoryException
Session
getEntry
in interface Session
id
- the entry idfetchReferences
- boolean stating if references have to be fetchedDirectoryException
protected String addFilterWhereClause(String whereClause) throws DirectoryException
DirectoryException
protected void addFilterValues(PreparedStatement ps, int startIdx) throws DirectoryException
DirectoryException
protected void addFilterValuesForLog(List<Serializable> values)
public DocumentModel getEntryFromSource(String id, boolean fetchReferences) throws DirectoryException
getEntryFromSource
in interface EntrySource
DirectoryException
public DocumentModelList getEntries()
Session
DocumentModelList#totalsize
on the returned list will return
-2 as a special marker for truncated results.getEntries
in interface Session
public void updateEntry(DocumentModel docModel)
Session
updateEntry
in interface Session
docModel
- The entry to updatepublic void deleteEntry(DocumentModel docModel)
Session
deleteEntry
in interface Session
docModel
- The entry to deletepublic void deleteEntry(String id)
Session
deleteEntry
in interface Session
id
- the id of the entry to deleteprotected boolean canDeleteMultiTenantEntry(String entryId) throws DirectoryException
DirectoryException
public void deleteEntry(String id, Map<String,String> map) throws DirectoryException
Session
This is used for hierarchical vocabularies, where the actual unique key is the couple (parent, id).
deleteEntry
in interface Session
id
- the id of the entry to delete.map
- a map of seconday key values.DirectoryException
- if a communication error occurs.public DocumentModelList query(Map<String,Serializable> filter, Set<String> fulltext, Map<String,String> orderBy)
Session
fieldNames present in the fulltext set are treated as a fulltext match. Does not fetch reference fields.
If the remote server issues a size limit exceeded error while sending partial results up to that limit, the methodDocumentModelList#totalsize
on the returned list will return -2 as a special marker for truncated
results.query
in interface Session
filter
- a filter to apply to entries in directoryfulltext
- a set of field that should be treated as a fulltext searchorderBy
- a LinkedHashMap with the 'order by' criterias.The key of an entry of this map represents the
column name and the value of the same entry represent the column order,which may be 'asc' or 'desc'.public DocumentModelList query(Map<String,Serializable> filter, Set<String> fulltext, Map<String,String> orderBy, boolean fetchReferences)
Session
query
in interface Session
Session.query(Map, Set, Map)
public DocumentModelList query(Map<String,Serializable> filter, Set<String> fulltext, Map<String,String> orderBy, boolean fetchReferences, int limit, int offset) throws DirectoryException
Session
query
in interface Session
query
in class BaseSession
limit
- maximum number of results ignored if less than 1offset
- number of rows skipped before starting, will be 0 if less than 0.DirectoryException
Session.query(Map, Set, Map, boolean)
protected void fillPreparedStatementFields(Map<String,Object> filterMap, List<Column> orderedColumns, PreparedStatement ps) throws DirectoryException
DirectoryException
public DocumentModelList query(Map<String,Serializable> filter)
Session
Does not fetch reference fields.
If the remote server issues a size limit exceeded error while sending partial results up to that limit, the methodDocumentModelList#totalsize
on the returned list will return -2 as a special marker for truncated
results.protected Serializable fieldValueForWrite(Object value, Column column)
public void close() throws DirectoryException
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?
close
in interface AutoCloseable
close
in interface Session
DirectoryException
- if a communication error occurspublic boolean isLive() throws DirectoryException
DirectoryException
public List<String> getProjection(Map<String,Serializable> filter, Set<String> fulltext, String columnName)
getProjection
in interface Session
public List<String> getProjection(Map<String,Serializable> filter, String columnName)
Session
getProjection
in interface Session
filter
- the filter for the querycolumnName
- the column whose content should be returnedpublic boolean authenticate(String username, String password)
Session
authenticate
in interface Session
public boolean isAuthenticating()
Session
isAuthenticating
in interface Session
isAuthenticating
in class BaseSession
public DocumentModelList query(Map<String,Serializable> filter, Set<String> fulltext)
Session
fieldNames present in the fulltext set are treated as a fulltext match. Does not fetch reference fields.
If the remote server issues a size limit exceeded error while sending partial results up to that limit, the methodDocumentModelList#totalsize
on the returned list will return -2 as a special marker for truncated
results.public DocumentModel createEntry(DocumentModel entry)
Session
createEntry
in interface Session
entry
- the document model representing the entry to createpublic boolean hasEntry(String id)
Session
public Connection getSqlConnection()
Reference
implementation to access the current connection even if it lives
in a separate java package, typically: com.company.custom.nuxeo.project.MyCustomReferenceConnection
instanceprotected boolean isMultiTenant()
true
if this directory supports multi tenancy, false
otherwise.protected String getCurrentTenantId()
null
otherwise.Copyright © 2016 Nuxeo SA. All rights reserved.