Class DatabaseAccess

java.lang.Object
org.languagetool.server.DatabaseAccess
Direct Known Subclasses:
DatabaseAccessOpenSource

abstract class DatabaseAccess extends Object
Encapsulate database access. Will do nothing if database access is not configured.
Since:
4.2
  • Field Details

    • instance

      private static DatabaseAccess instance
    • sqlSessionFactory

      protected org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory
  • Constructor Details

    • DatabaseAccess

      protected DatabaseAccess(HTTPServerConfig config)
      Implementations required to provide a constructor with the same signature
  • Method Details

    • init

      static void init(HTTPServerConfig config)
    • reset

      static void reset()
    • getInstance

      static DatabaseAccess getInstance()
    • isReady

      static boolean isReady()
      Since:
      5.7 Test if instance is configured and can be used
    • invalidateCaches

      abstract void invalidateCaches()
      For tests, to avoid waiting for the invalidation period.
    • addWord

      abstract boolean addWord(String word, Long userId, String groupName)
    • deleteWord

      abstract boolean deleteWord(String word, Long userId, String groupName)
    • deleteWordBatch

      abstract boolean deleteWordBatch(List<String> words, Long userId, String groupName)
      remove words in sql batch mode, no auto commit for better performance with large lists also suppresses uniqueness checks
    • addWordBatch

      abstract void addWordBatch(List<String> words, Long userId, String groupName)
      add words in sql batch mode, no auto commit for better performance with large lists also suppresses uniqueness checks
    • getUserInfoWithPassword

      abstract UserInfoEntry getUserInfoWithPassword(String username, String password)
    • getExtendedUserInfo

      abstract ExtendedUserInfo getExtendedUserInfo(String user)
      Get more general information on a user Expects access to already be authorized
      Parameters:
      user - email address of user
      Returns:
      POJO with user information
    • getExtendedUserInfo

      abstract ExtendedUserInfo getExtendedUserInfo(long userId)
      Get more general information on a user. Expects access to already be authorized.
      Parameters:
      userId - user id
      Returns:
      POJO with more user information
    • getUserInfoWithApiKey

      abstract UserInfoEntry getUserInfoWithApiKey(String username, String apiKey)
    • getUserInfoWithAddonToken

      abstract UserInfoEntry getUserInfoWithAddonToken(String username, String apiKey)
    • invalidateUserInfoCache

      abstract void invalidateUserInfoCache(String user)
    • getUserRequestCount

      abstract Long getUserRequestCount(Long userId)
    • getOrCreateServerId

      abstract Long getOrCreateServerId()
    • getOrCreateClientId

      abstract Long getOrCreateClientId(String client)
    • getDictGroups

      abstract List<DictGroupEntry> getDictGroups(Long userId)
      get all dictionary groups belonging to a user
    • getOrCreateDictGroup

      abstract Long getOrCreateDictGroup(Long userId, String groupName)
      get or create a group with this name if it doesn't exist
      Returns:
      id of the created/existing group
    • createAndFillTestTables

      public void createAndFillTestTables()
      For unit tests only!
    • createAndFillTestTables

      public void createAndFillTestTables(boolean mysql)
      For unit tests only!
    • createAndFillTestTables

      public abstract void createAndFillTestTables(boolean mysql, List<String> skipStatements)
      For unit tests only!
    • shutdownCompact

      public void shutdownCompact()
      For unit tests only!
    • deleteTestTables

      abstract void deleteTestTables()
      For unit tests only!
    • executeStatement

      ResultSet executeStatement(org.apache.ibatis.jdbc.SQL sql) throws SQLException
      For unit tests only!
      Throws:
      SQLException
    • execute

      void execute(org.apache.ibatis.jdbc.SQL sql) throws SQLException
      For unit tests only!
      Throws:
      SQLException
    • getWords

      public abstract List<String> getWords(UserLimits limits, List<String> groups, int offset, int limit)
      Parameters:
      limits - user account and settings for e.g. caching
      groups - names of dictionaries to be fetched, or null for default dictionary
      offset - use offset with limit for an ordered list of words in the dictionary, or RowBounds.NO_ROW_OFFSET
      limit - use limit with offset for an ordered list of words in the dictionary, or use RowBounds.NO_ROW_LIMIT
      Returns:
      a list of words from the user's dictionary (complete, or from the given range)
    • getRules

      public abstract List<Rule> getRules(UserLimits limits, Language lang, @Nullable List<String> groups)
      Parameters:
      limits - user account and settings for e.g. caching
      lang - language of rules to fetch; fetches global rules and language-specific rules for that language
      groups - names of groups of rules to be fetched, or null for default set of rules
      Returns:
      a list of user rules (complete, or from the given range)