Package org.cyclos.impl.sql
Interface NativeQueryHandler
-
- All Superinterfaces:
CustomBean
public interface NativeQueryHandler extends CustomBean
Single place which contains the native queries
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceNativeQueryHandler.DatabaseInfoInformation about the underlying database engine and JDBC driver
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description longarchiveAccountBalances()Archives account balances according toApplication.getArchivingDate(), returning the number of balances closedlongcloseAccountBalances()Closes the account balances, returning the number of balances closedlongcopyLargeObject(long sourceOid)Makes a copy of the large object with the specified oid and returns the oid of the copy.Map<Role,Integer>countConnectedUsers(CountConnectedUsersParams params)Counts the connected users.List<Pair<String,Long>>countUsersByUrl()Groups all non removed nor purged members and brokers (not admins) by each root URL defined in the configurations.voiddeleteLargeObject(long oid)Deletes the large object with the specified oid.List<InconsistentBalance>fixInconsistentAccountBalances(List<Long> accountIds)Fixes the balances for the given accounts.List<BalanceEntryVO>getAccountBalanceHistory(Long accountId, List<Date> timepoints)Returns the account balance on each of the given timepoints, plus the current status as the last resultMap<Account,NativeAccountStatus>getAccountStatuses(Collection<Account> accounts, Date date)Returns the native account statuses of the given accounts at a given dateNativeQueryHandler.DatabaseInfogetDatabaseInfo()Returns information about the underlying databaseDbLockHandlergetDbLockHandler()Returns the handler for the db_lock.com.querydsl.jpa.JPQLTemplatesgetJpaQueryTemplates()Returns the templates used for jpa queriesLonggetNextTransactionNumber()Returns the number used to generate the next transaction numberLonggetObjectId(long id)Returns the oid associated to the specified stored file id.DategetRunningVacuumStart()Returns the date when the vacuum started if there is a running vacuum.SearchHandlergetSearchHandler()Returns a handler to search on the databaseDatabaseVacuumInformationgetVacuumInfo()Returns information about the last vacuum/analyze executionslonginsertArchiveAccountFees()Inserts theBackgroundTaskExecutions for each account fee log older thanCyclosProperties.getArchiveAccountFeesDays()longinsertArchiveBulkActions()Inserts theBackgroundTaskExecutions for each bulk action older thanCyclosProperties.getArchiveBulkActionsDays()longinsertBackgroundTaskExecution(BaseBackgroundTaskScheduling<?> scheduling)Insert or updates a background task execution for the given type and context.longinsertEntityNotificationProcessingBackgroundTasks(NotificationProcessingEntityType<?> type, int batchSize)Inserts n executions of a notification processing task for a given entity type returning the number of affected entities associated to the type.longinsertIdRangeBackgroundTasks(Class<?> bgTaskClass, long maxId, long batchSize, String payload, Long forkJoinId)Inserts n executions for the given background task class.longinsertIpAddressLocalization(IpGeolocation ip)Insert or updates an IP address locatization result.longinsertReindexBackgroundTasks(Class<? extends SimpleEntity> entityClass, String indexName, int batchSize)Inserts n executions of the background task for indexing, returning the number of inserted tasksvoidinsertTransferInitialStatus(TransferType transferType, TransferStatus status)Inserts the relation for current status and a log for each transfer of the given typelonginsertUserAccountFeeLogs(AccountFeeLog log)Inserts into the users_account_fee_logs table, for each users that should be charged (has a product that enables the given fee)voidinsertUserIncomingMessages(SendMessageDTO sendMessage, MessageOwner messageOwner, User sendingUser, OutgoingMessage outgoing)Inserts incoming messages for users for a given outgoing messagelonginsertUsersForBulkAction(Long bulkActionId, UserQuery query)Inserts a record ofBulkActionUserfor each returned user of the given querybooleanisConnectionError(SQLException sqlException)Indicates whether the given SQL exception refers to a database connection errorList<Long>nextAccountIdsToClose(int maxCount, Date limit)Returns up to the maximum count of account ids to close balance.InputStreamopenLargeObject(long oid)Opens the large object associated to the specified oid.
NOTE: After read, the input stream must be closed (the large object will be closed in turn).Pair<Set<String>,Set<Long>>purgeRemovedBuiltinLanguages()Removes all languages that were pointing toBuiltinLanguages that no longer exist, returning both the language templates that no longer exist and the ids of languages that were removedlongrebuildClosedAccountBalances(List<Long> ids)Rebuilds the closed account balances.default voidretryIfConnectionError(Exception e)Throws aRetryExceptionif the given exception was caused by a connection errorList<Long>scriptIdsMatchingContent(Long networkId, String content)Return the ids of custom scripts which match the given content, in the given network, plus global modevoidsetObjectId(long storedFileId, long oid)Sets the oid to the specified stored file id.voidstoreLoginDate(BasicUser user, Date date)Inserts or updates the login log of the given userbooleansupportsBlobsInReadOnlyTransactions()Returns whether the underlying database supports accessing BLOBs from pure read-only transactionsbooleantryLock(LockKey key)Attempt to acquire an exclusive lock with a given key.booleantryLock(JdbcTemplate jdbc, LockKey key)Attempt to acquire an exclusive lock with a given key using the givenJdbcTemplate.List<AccountStatusUpdateResult>updateAccountStatuses(Collection<AccountStatusUpdateParams> updates)Updates a set of account statuses.Map<UserAccountType,IUserAccount>userAccounts(User user, Collection<UserAccountType> accountTypes, boolean withNumberOnly, Integer limit)Returns either all accounts (when accountType is null / empty) or filtered by type, both physical and pending user accounts, for a specific user.voidvacuum()Performs a vacuum and then an analyze for the database.longwriteLargeObject(InputStream in)Creates a new large object reading the content from the stream and returns its oid.
NOTE: The input stream parameter won't be closed it is responsibility of the client code.
-
-
-
Method Detail
-
archiveAccountBalances
long archiveAccountBalances()
Archives account balances according toApplication.getArchivingDate(), returning the number of balances closed
-
closeAccountBalances
long closeAccountBalances()
Closes the account balances, returning the number of balances closed
-
copyLargeObject
long copyLargeObject(long sourceOid) throws IOExceptionMakes a copy of the large object with the specified oid and returns the oid of the copy.- Throws:
IOException
-
countConnectedUsers
Map<Role,Integer> countConnectedUsers(CountConnectedUsersParams params)
Counts the connected users. Only accept basic roles, as perRole.isBasic(). If roles is empty or null, returns for all basic roles. Guarantees that the returned map contains an entry for each requested role.
-
countUsersByUrl
List<Pair<String,Long>> countUsersByUrl()
Groups all non removed nor purged members and brokers (not admins) by each root URL defined in the configurations.- Returns:
-
deleteLargeObject
void deleteLargeObject(long oid)
Deletes the large object with the specified oid.
-
fixInconsistentAccountBalances
List<InconsistentBalance> fixInconsistentAccountBalances(List<Long> accountIds)
Fixes the balances for the given accounts. Returns details about the inconsistent balances.
-
getAccountBalanceHistory
List<BalanceEntryVO> getAccountBalanceHistory(Long accountId, List<Date> timepoints)
Returns the account balance on each of the given timepoints, plus the current status as the last result
-
getAccountStatuses
Map<Account,NativeAccountStatus> getAccountStatuses(Collection<Account> accounts, Date date)
Returns the native account statuses of the given accounts at a given date
-
getDatabaseInfo
NativeQueryHandler.DatabaseInfo getDatabaseInfo()
Returns information about the underlying database
-
getDbLockHandler
DbLockHandler getDbLockHandler()
Returns the handler for the db_lock. Don't confuse this withtryLock(LockKey), which has a key. This one is for the database itself, so 2 instances don't use the same database.
-
getJpaQueryTemplates
com.querydsl.jpa.JPQLTemplates getJpaQueryTemplates()
Returns the templates used for jpa queries
-
getNextTransactionNumber
Long getNextTransactionNumber()
Returns the number used to generate the next transaction number
-
getObjectId
Long getObjectId(long id)
Returns the oid associated to the specified stored file id. Returns null if the stored file doesn't have any associated content.
-
getRunningVacuumStart
Date getRunningVacuumStart()
Returns the date when the vacuum started if there is a running vacuum. Otherwise it returns null.
-
getSearchHandler
SearchHandler getSearchHandler()
Returns a handler to search on the database
-
getVacuumInfo
DatabaseVacuumInformation getVacuumInfo()
Returns information about the last vacuum/analyze executions
-
insertArchiveAccountFees
long insertArchiveAccountFees()
Inserts theBackgroundTaskExecutions for each account fee log older thanCyclosProperties.getArchiveAccountFeesDays()
-
insertArchiveBulkActions
long insertArchiveBulkActions()
Inserts theBackgroundTaskExecutions for each bulk action older thanCyclosProperties.getArchiveBulkActionsDays()
-
insertBackgroundTaskExecution
long insertBackgroundTaskExecution(BaseBackgroundTaskScheduling<?> scheduling)
Insert or updates a background task execution for the given type and context. Returns the id of the created / updated background task execution.
-
insertEntityNotificationProcessingBackgroundTasks
long insertEntityNotificationProcessingBackgroundTasks(NotificationProcessingEntityType<?> type, int batchSize)
Inserts n executions of a notification processing task for a given entity type returning the number of affected entities associated to the type.
-
insertIdRangeBackgroundTasks
long insertIdRangeBackgroundTasks(Class<?> bgTaskClass, long maxId, long batchSize, String payload, Long forkJoinId)
Inserts n executions for the given background task class. Optionally, a payload and a forkJoinId can be given. The maxId is divided by the batchSize to calculate the number of tasks to be inserted. In case of a payload is given then it's added to the background task's context. Returns the number of inserted tasks.
-
insertIpAddressLocalization
long insertIpAddressLocalization(IpGeolocation ip)
Insert or updates an IP address locatization result. Returns the id of the created / updated ip address localization.
-
insertReindexBackgroundTasks
long insertReindexBackgroundTasks(Class<? extends SimpleEntity> entityClass, String indexName, int batchSize)
Inserts n executions of the background task for indexing, returning the number of inserted tasks
-
insertTransferInitialStatus
void insertTransferInitialStatus(TransferType transferType, TransferStatus status)
Inserts the relation for current status and a log for each transfer of the given type
-
insertUserAccountFeeLogs
long insertUserAccountFeeLogs(AccountFeeLog log)
Inserts into the users_account_fee_logs table, for each users that should be charged (has a product that enables the given fee)
-
insertUserIncomingMessages
void insertUserIncomingMessages(SendMessageDTO sendMessage, MessageOwner messageOwner, User sendingUser, OutgoingMessage outgoing)
Inserts incoming messages for users for a given outgoing message
-
insertUsersForBulkAction
long insertUsersForBulkAction(Long bulkActionId, UserQuery query)
Inserts a record ofBulkActionUserfor each returned user of the given query
-
isConnectionError
boolean isConnectionError(SQLException sqlException)
Indicates whether the given SQL exception refers to a database connection error
-
nextAccountIdsToClose
List<Long> nextAccountIdsToClose(int maxCount, Date limit)
Returns up to the maximum count of account ids to close balance. Accounts that are returned:- Accounts that have never been closed yet
- Accounts whose last closing was before the given limit and the current account balance's date is newer than the last closing
-
openLargeObject
InputStream openLargeObject(long oid)
Opens the large object associated to the specified oid.
NOTE: After read, the input stream must be closed (the large object will be closed in turn).
-
purgeRemovedBuiltinLanguages
Pair<Set<String>,Set<Long>> purgeRemovedBuiltinLanguages()
Removes all languages that were pointing toBuiltinLanguages that no longer exist, returning both the language templates that no longer exist and the ids of languages that were removed
-
rebuildClosedAccountBalances
long rebuildClosedAccountBalances(List<Long> ids)
Rebuilds the closed account balances. When no ids are passed, rebuilds for all accounts.
-
retryIfConnectionError
default void retryIfConnectionError(Exception e) throws RetryException
Throws aRetryExceptionif the given exception was caused by a connection error- Throws:
RetryException
-
scriptIdsMatchingContent
List<Long> scriptIdsMatchingContent(Long networkId, String content)
Return the ids of custom scripts which match the given content, in the given network, plus global mode
-
setObjectId
void setObjectId(long storedFileId, long oid)Sets the oid to the specified stored file id.
-
storeLoginDate
void storeLoginDate(BasicUser user, Date date)
Inserts or updates the login log of the given user
-
supportsBlobsInReadOnlyTransactions
boolean supportsBlobsInReadOnlyTransactions()
Returns whether the underlying database supports accessing BLOBs from pure read-only transactions
-
tryLock
boolean tryLock(JdbcTemplate jdbc, LockKey key)
Attempt to acquire an exclusive lock with a given key using the givenJdbcTemplate.
-
tryLock
boolean tryLock(LockKey key)
Attempt to acquire an exclusive lock with a given key. The lock will be bound to the current transaction, and will be automatically unlocked when the transaction ends.
-
updateAccountStatuses
List<AccountStatusUpdateResult> updateAccountStatuses(Collection<AccountStatusUpdateParams> updates)
Updates a set of account statuses. Must be called only after acquiring the lock on the affected accounts.
-
userAccounts
Map<UserAccountType,IUserAccount> userAccounts(User user, Collection<UserAccountType> accountTypes, boolean withNumberOnly, Integer limit)
Returns either all accounts (when accountType is null / empty) or filtered by type, both physical and pending user accounts, for a specific user. May also only return accounts with numbers, and optionally limits the number of results. IMPORTANT: the entities contained in the resulting map are not attached to the persisted context, be aware if you need to modify some of them.
-
vacuum
void vacuum()
Performs a vacuum and then an analyze for the database.
-
writeLargeObject
long writeLargeObject(InputStream in) throws IOException
Creates a new large object reading the content from the stream and returns its oid.
NOTE: The input stream parameter won't be closed it is responsibility of the client code.- Throws:
IOException
-
-