Package com.github.ambry.account.mysql
Class MySqlAccountStore
- java.lang.Object
-
- com.github.ambry.account.mysql.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 allContainer
s of a given accountcom.github.ambry.mysql.MySqlDataAccessor
getMySqlDataAccessor()
Used for tests.java.util.Collection<com.github.ambry.account.Account>
getNewAccounts(long updatedSince)
Gets allAccount
s that have been created or modified since the specified time.java.util.Collection<com.github.ambry.account.Container>
getNewContainers(long updatedSince)
Gets allContainer
s 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.
-
-
-
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 pointslocalDatacenter
- name of the local data centermetrics
- metrics to track mysql operationsconfig
- configuration associated withMySqlAccountService
- 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 allAccount
s that have been created or modified since the specified time.- Parameters:
updatedSince
- the last modified time used to filter.- Returns:
- a collection of
Account
s - Throws:
java.sql.SQLException
-
getNewContainers
public java.util.Collection<com.github.ambry.account.Container> getNewContainers(long updatedSince) throws java.sql.SQLException
Gets allContainer
s that have been created or modified since the specified time.- Parameters:
updatedSince
- the last modified time used to filter.- Returns:
- a collection of
Container
s - Throws:
java.sql.SQLException
-
getContainersByAccount
public java.util.Collection<com.github.ambry.account.Container> getContainersByAccount(short accountId) throws java.sql.SQLException
Gets allContainer
s of a given account- Parameters:
accountId
- ID of the account- Returns:
- a collection of
Container
s - 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 ornull
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 ornull
if it doesn't exist.- Throws:
java.sql.SQLException
-
closeConnection
public void closeConnection()
Helper method to close the active connection, if there is one.
-
-