Class JDBCMapper

All Implemented Interfaces:
Mapper, RowMapper

public class JDBCMapper extends JDBCRowMapper implements Mapper
A JDBCMapper maps objects to and from a JDBC database. It is specific to a given database connection, as it computes statements.

The JDBCMapper does the mapping according to the policy defined by a Model, and generates SQL statements recorded in the SQLInfo.

  • Field Details

  • Constructor Details

    • JDBCMapper

      public JDBCMapper(Model model, Session.PathResolver pathResolver, SQLInfo sqlInfo, VCSClusterInvalidator clusterInvalidator, RepositoryImpl repository)
      Creates a new Mapper.
      Parameters:
      model - the model
      pathResolver - the path resolver (used for startswith queries)
      sqlInfo - the sql info
      clusterInvalidator - the cluster invalidator
      repository - the repository
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface Mapper
    • getTableSize

      public int getTableSize(String tableName)
      Specified by:
      getTableSize in interface Mapper
    • getClusterNodeIdType

      public int getClusterNodeIdType()
      Specified by:
      getClusterNodeIdType in interface Mapper
    • createClusterNode

      public void createClusterNode(Serializable nodeId)
      Description copied from interface: Mapper
      Informs the cluster that this node exists.
      Specified by:
      createClusterNode in interface Mapper
    • removeClusterNode

      public void removeClusterNode(Serializable nodeId)
      Description copied from interface: Mapper
      Removes this node from the cluster.
      Specified by:
      removeClusterNode in interface Mapper
    • deleteClusterInvals

      protected void deleteClusterInvals(Serializable nodeId) throws SQLException
      Throws:
      SQLException
    • insertClusterInvalidations

      public void insertClusterInvalidations(Serializable nodeId, VCSInvalidations invalidations)
      Description copied from interface: Mapper
      Inserts the invalidation rows for the other cluster nodes.
      Specified by:
      insertClusterInvalidations in interface Mapper
    • join

      protected static String join(Collection<String> strings, char sep)
    • getClusterInvalidations

      public VCSInvalidations getClusterInvalidations(Serializable nodeId)
      Description copied from interface: Mapper
      Gets the invalidations from other cluster nodes.
      Specified by:
      getClusterInvalidations in interface Mapper
    • getRootId

      public Serializable getRootId(String repositoryId)
      Description copied from interface: Mapper
      Gets the root id for a given repository, if registered.
      Specified by:
      getRootId in interface Mapper
      Parameters:
      repositoryId - the repository id
      Returns:
      the root id, or null if not found
    • setRootId

      public void setRootId(Serializable repositoryId, Serializable id)
      Description copied from interface: Mapper
      Records the newly generated root id for a given repository.
      Specified by:
      setRootId in interface Mapper
      Parameters:
      repositoryId - the repository id, usually 0
      id - the root id
    • findQueryMaker

      protected QueryMaker findQueryMaker(String queryType)
    • prepareUserReadAcls

      protected void prepareUserReadAcls(QueryFilter queryFilter)
    • query

      public PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter, boolean countTotal)
      Description copied from interface: Mapper
      Makes a NXQL query to the database.
      Specified by:
      query in interface Mapper
      Parameters:
      query - the query
      queryType - the query type
      queryFilter - the query filter
      countTotal - if true, count the total size without limit/offset
      Returns:
      the list of matching document ids
    • query

      public PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter, long countUpTo)
      Description copied from interface: Mapper
      Makes a NXQL query to the database.
      Specified by:
      query in interface Mapper
      Parameters:
      query - the query
      queryType - the query type
      queryFilter - the query filter
      countUpTo - if -1, count the total size without offset/limit.
      If 0, don't count the total size.
      If n, count the total number if there are less than n documents otherwise set the size to -1.
      Returns:
      the list of matching document ids
    • queryAndFetch

      public IterableQueryResult queryAndFetch(String query, String queryType, QueryFilter queryFilter, boolean distinctDocuments, Object... params)
      Description copied from interface: Mapper
      Makes a query to the database and returns an iterable (which must be closed when done).
      Specified by:
      queryAndFetch in interface Mapper
      Parameters:
      query - the query
      queryType - the query type
      queryFilter - the query filter
      distinctDocuments - if true then a maximum of one row per document will be returned
      params - optional query-type-dependent parameters
      Returns:
      an iterable, which must be closed when done
    • queryProjection

      public PartialList<Map<String,Serializable>> queryProjection(String query, String queryType, QueryFilter queryFilter, boolean distinctDocuments, long countUpTo, Object... params)
      Description copied from interface: Mapper
      Makes a query to the database.
      Specified by:
      queryProjection in interface Mapper
      Parameters:
      query - the query
      queryType - the query type
      queryFilter - the query filter
      distinctDocuments - if true then a maximum of one row per document will be returned
      countUpTo - if -1, also count the total size without offset/limit.
      If 0, don't count the total size.
      If n, count the total number if there are less than n documents otherwise set the size to -1.
      params - optional query-type-dependent parameters
      Returns:
      a projection
    • computeDistinctDocuments

      protected String computeDistinctDocuments(String query, boolean distinctDocuments)
    • queryProjection

      protected <T> PartialList<T> queryProjection(String query, String queryType, QueryFilter queryFilter, long countUpTo, JDBCMapper.BiFunctionSQLException<SQLInfo.SQLInfoSelect,ResultSet,T> extractor, Object... params)
    • setToPreparedStatement

      public int setToPreparedStatement(PreparedStatement ps, int i, Serializable object) throws SQLException
      Throws:
      SQLException
    • scroll

      public ScrollResult<String> scroll(String query, int batchSize, int keepAliveSeconds)
      Description copied from interface: Mapper
      Executes the given query and returns the first batch of results containing id of documents, next batch must be requested within the keepAliveSeconds delay.
      Specified by:
      scroll in interface Mapper
    • scroll

      public ScrollResult<String> scroll(String query, QueryFilter queryFilter, int batchSize, int keepAliveSeconds)
      Description copied from interface: Mapper
      Executes the given query and returns the first batch of results containing id of documents, next batch must be requested within the keepAliveSeconds delay.
      Specified by:
      scroll in interface Mapper
    • checkForTimedoutScroll

      protected void checkForTimedoutScroll()
    • scrollSearch

      protected ScrollResult<String> scrollSearch(String query, QueryFilter queryFilter, int batchSize, int keepAliveSeconds)
    • registerCursor

      protected void registerCursor(String scrollId, PreparedStatement ps, ResultSet rs, int batchSize, int keepAliveSeconds)
    • unregisterCursor

      protected boolean unregisterCursor(String scrollId)
    • defaultScroll

      protected ScrollResult<String> defaultScroll(String query)
    • scroll

      public ScrollResult<String> scroll(String scrollId)
      Description copied from interface: Mapper
      Get the next batch of results containing id of documents, the scrollId is part of the previous ScrollResult response.
      Specified by:
      scroll in interface Mapper
    • getAncestorsIds

      public Set<Serializable> getAncestorsIds(Collection<Serializable> ids)
      Description copied from interface: Mapper
      Gets the ids for all the ancestors of the given row ids.
      Specified by:
      getAncestorsIds in interface Mapper
      Parameters:
      ids - the ids
      Returns:
      the set of ancestor ids
    • getAncestorsIdsIterative

      protected Set<Serializable> getAncestorsIdsIterative(Collection<Serializable> ids)
      Uses iterative parentid selection.
    • updateReadAcls

      public void updateReadAcls()
      Specified by:
      updateReadAcls in interface Mapper
    • rebuildReadAcls

      public void rebuildReadAcls()
      Specified by:
      rebuildReadAcls in interface Mapper
    • markReferencedBlobs

      public void markReferencedBlobs(BiConsumer<String,String> markerCallback)
      Description copied from interface: Mapper
      Marks the blobs in use by passing them to the provided callback (taking the blob key and the repository name).
      Specified by:
      markReferencedBlobs in interface Mapper