Class MySqlAccountStore


  • public class MySqlAccountStore
    extends java.lang.Object
    Wrapper class to handle MySql store operations on Account and Container tables
    • Constructor Summary

      Constructors 
      Constructor Description
      MySqlAccountStore​(java.util.List<com.github.ambry.mysql.MySqlUtils.DbEndpoint> dbEndpoints, java.lang.String localDatacenter, com.github.ambry.mysql.MySqlMetrics metrics, com.github.ambry.config.MySqlAccountServiceConfig config)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void closeConnection()
      Helper method to close the active connection, if there is one.
      com.github.ambry.account.Container getContainerById​(int accountId, int containerId)
      Gets container by its Id and parent account Id.
      com.github.ambry.account.Container getContainerByName​(int accountId, java.lang.String containerName)
      Gets container by its name and parent account Id.
      java.util.Collection<com.github.ambry.account.Container> getContainersByAccount​(short accountId)
      Gets all Containers of a given account
      com.github.ambry.mysql.MySqlDataAccessor getMySqlDataAccessor()
      Used for tests.
      java.util.Collection<com.github.ambry.account.Account> getNewAccounts​(long updatedSince)
      Gets all Accounts that have been created or modified since the specified time.
      java.util.Collection<com.github.ambry.account.Container> getNewContainers​(long updatedSince)
      Gets all Containers that have been created or modified since the specified time.
      void updateAccounts​(java.util.List<AccountUtils.AccountUpdateInfo> accountsInfo)
      Adds/Updates accounts and their containers to the database in batches atomically using transaction.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MySqlAccountStore

        public MySqlAccountStore​(java.util.List<com.github.ambry.mysql.MySqlUtils.DbEndpoint> dbEndpoints,
                                 java.lang.String localDatacenter,
                                 com.github.ambry.mysql.MySqlMetrics metrics,
                                 com.github.ambry.config.MySqlAccountServiceConfig config)
                          throws java.sql.SQLException
        Constructor.
        Parameters:
        dbEndpoints - MySql DB end points
        localDatacenter - name of the local data center
        metrics - metrics to track mysql operations
        config - configuration associated with MySqlAccountService
        Throws:
        java.sql.SQLException
    • Method Detail

      • getMySqlDataAccessor

        public com.github.ambry.mysql.MySqlDataAccessor getMySqlDataAccessor()
        Used for tests.
        Returns:
        MySqlDataAccessor
      • updateAccounts

        public void updateAccounts​(java.util.List<AccountUtils.AccountUpdateInfo> accountsInfo)
                            throws java.sql.SQLException
        Adds/Updates accounts and their containers to the database in batches atomically using transaction.
        Parameters:
        accountsInfo - information of updated Accounts
        Throws:
        java.sql.SQLException
      • getNewAccounts

        public java.util.Collection<com.github.ambry.account.Account> getNewAccounts​(long updatedSince)
                                                                              throws java.sql.SQLException
        Gets all Accounts that have been created or modified since the specified time.
        Parameters:
        updatedSince - the last modified time used to filter.
        Returns:
        a collection of Accounts
        Throws:
        java.sql.SQLException
      • getNewContainers

        public java.util.Collection<com.github.ambry.account.Container> getNewContainers​(long updatedSince)
                                                                                  throws java.sql.SQLException
        Gets all Containers that have been created or modified since the specified time.
        Parameters:
        updatedSince - the last modified time used to filter.
        Returns:
        a collection of Containers
        Throws:
        java.sql.SQLException
      • getContainersByAccount

        public java.util.Collection<com.github.ambry.account.Container> getContainersByAccount​(short accountId)
                                                                                        throws java.sql.SQLException
        Gets all Containers of a given account
        Parameters:
        accountId - ID of the account
        Returns:
        a collection of Containers
        Throws:
        java.sql.SQLException
      • getContainerByName

        public com.github.ambry.account.Container getContainerByName​(int accountId,
                                                                     java.lang.String containerName)
                                                              throws java.sql.SQLException
        Gets container by its name and parent account Id.
        Parameters:
        accountId - the id for the parent account.
        containerName - name of the container.
        Returns:
        Container if found in mysql db or null if it doesn't exist.
        Throws:
        java.sql.SQLException
      • getContainerById

        public com.github.ambry.account.Container getContainerById​(int accountId,
                                                                   int containerId)
                                                            throws java.sql.SQLException
        Gets container by its Id and parent account Id.
        Parameters:
        accountId - the id for the parent account.
        containerId - the id of the container.
        Returns:
        Container if found in mysql db or null if it doesn't exist.
        Throws:
        java.sql.SQLException
      • closeConnection

        public void closeConnection()
        Helper method to close the active connection, if there is one.