@Override public AccountModelDao inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception { return entitySqlDaoWrapperFactory.become(AccountSqlDao.class).getAccountByKey(key, context); } });
@Override public List<AccountModelDao> inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception { return entitySqlDaoWrapperFactory.become(AccountSqlDao.class).getAccountsByParentId(parentAccountId, context); } });
@Override public Integer inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception { return entitySqlDaoWrapperFactory.become(AccountSqlDao.class).getBCD(accountId.toString(), context); } });
@Override public Void inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws EntityPersistenceException, EventBusException { final AccountSqlDao transactional = entitySqlDaoWrapperFactory.become(AccountSqlDao.class); final AccountModelDao currentAccount = transactional.getById(accountId.toString(), context); if (currentAccount == null) { throw new EntityPersistenceException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, accountId); } // Check if an update is really needed. If not, bail early to avoid sending an extra event on the bus if ((currentAccount.getPaymentMethodId() == null && paymentMethodId == null) || (currentAccount.getPaymentMethodId() != null && currentAccount.getPaymentMethodId().equals(paymentMethodId))) { return null; } final String thePaymentMethodId = paymentMethodId != null ? paymentMethodId.toString() : null; final AccountModelDao account = (AccountModelDao) transactional.updatePaymentMethod(accountId.toString(), thePaymentMethodId, context); final AccountChangeInternalEvent changeEvent = new DefaultAccountChangeEvent(accountId, currentAccount, account, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken(), context.getCreatedDate()); try { eventBus.postFromTransaction(changeEvent, entitySqlDaoWrapperFactory.getHandle().getConnection()); } catch (final EventBusException e) { log.warn("Failed to post account change event for accountId='{}'", accountId, e); } return null; } });
@Override public Void inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws EventBusException, AccountApiException { final AccountSqlDao transactional = entitySqlDaoWrapperFactory.become(AccountSqlDao.class); final UUID accountId = specifiedAccount.getId(); final AccountModelDao currentAccount = transactional.getById(accountId.toString(), context); if (currentAccount == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, accountId); } specifiedAccount.validateAccountUpdateInput(currentAccount, treatNullValueAsReset); if (!treatNullValueAsReset) { // Set unspecified (null) fields to their current values specifiedAccount.mergeWithDelegate(currentAccount); } transactional.update(specifiedAccount, context); final AccountChangeInternalEvent changeEvent = new DefaultAccountChangeEvent(accountId, currentAccount, specifiedAccount, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken(), context.getCreatedDate()); try { eventBus.postFromTransaction(changeEvent, entitySqlDaoWrapperFactory.getHandle().getConnection()); } catch (final EventBusException e) { log.warn("Failed to post account change event for accountId='{}'", accountId, e); } return null; } });
@Override public AccountModelDao inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception { return entitySqlDaoWrapperFactory.become(AccountSqlDao.class).luckySearch(searchKey, context); } });
@Override public UUID inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception { return entitySqlDaoWrapperFactory.become(AccountSqlDao.class).getIdFromKey(externalKey, context); } });
@Override public Iterator<AccountModelDao> build(final AccountSqlDao accountSqlDao, final Long offset, final Long limit, final Ordering ordering, final InternalTenantContext context) { return accountSqlDao.search(searchKey, String.format("%%%s%%", searchKey), offset, limit, ordering.toString(), context); } },
@Override public Long getCount(final AccountSqlDao accountSqlDao, final InternalTenantContext context) { return accountSqlDao.getSearchCount(searchKey, String.format("%%%s%%", searchKey), context); }
@Override public Void inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws EntityPersistenceException, EventBusException { final AccountSqlDao transactional = entitySqlDaoWrapperFactory.become(AccountSqlDao.class); final AccountModelDao currentAccount = transactional.getById(accountId.toString(), context); if (currentAccount == null) { throw new EntityPersistenceException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, accountId); } // Check if an update is really needed. If not, bail early to avoid sending an extra event on the bus if ((currentAccount.getPaymentMethodId() == null && paymentMethodId == null) || (currentAccount.getPaymentMethodId() != null && currentAccount.getPaymentMethodId().equals(paymentMethodId))) { return null; } final String thePaymentMethodId = paymentMethodId != null ? paymentMethodId.toString() : null; final AccountModelDao account = (AccountModelDao) transactional.updatePaymentMethod(accountId.toString(), thePaymentMethodId, context); final AccountChangeInternalEvent changeEvent = new DefaultAccountChangeEvent(accountId, currentAccount, account, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken(), context.getCreatedDate()); try { eventBus.postFromTransaction(changeEvent, entitySqlDaoWrapperFactory.getHandle().getConnection()); } catch (final EventBusException e) { log.warn("Failed to post account change event for accountId='{}'", accountId, e); } return null; } });
@Override public Void inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws EventBusException, AccountApiException { final AccountSqlDao transactional = entitySqlDaoWrapperFactory.become(AccountSqlDao.class); final UUID accountId = specifiedAccount.getId(); final AccountModelDao currentAccount = transactional.getById(accountId.toString(), context); if (currentAccount == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, accountId); } specifiedAccount.validateAccountUpdateInput(currentAccount, treatNullValueAsReset); if (!treatNullValueAsReset) { // Set unspecified (null) fields to their current values specifiedAccount.mergeWithDelegate(currentAccount); } transactional.update(specifiedAccount, context); final AccountChangeInternalEvent changeEvent = new DefaultAccountChangeEvent(accountId, currentAccount, specifiedAccount, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken(), context.getCreatedDate()); try { eventBus.postFromTransaction(changeEvent, entitySqlDaoWrapperFactory.getHandle().getConnection()); } catch (final EventBusException e) { log.warn("Failed to post account change event for accountId='{}'", accountId, e); } return null; } });
@Override public AccountModelDao inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception { return entitySqlDaoWrapperFactory.become(AccountSqlDao.class).luckySearch(searchKey, context); } });
@Override public UUID inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception { return entitySqlDaoWrapperFactory.become(AccountSqlDao.class).getIdFromKey(externalKey, context); } });
@Override public Iterator<AccountModelDao> build(final AccountSqlDao accountSqlDao, final Long offset, final Long limit, final Ordering ordering, final InternalTenantContext context) { return accountSqlDao.search(searchKey, String.format("%%%s%%", searchKey), offset, limit, ordering.toString(), context); } },
@Override public Long getCount(final AccountSqlDao accountSqlDao, final InternalTenantContext context) { return accountSqlDao.getSearchCount(searchKey, String.format("%%%s%%", searchKey), context); }
@Override public List<AccountModelDao> inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception { return entitySqlDaoWrapperFactory.become(AccountSqlDao.class).getAccountsByParentId(parentAccountId, context); } });
@Override public AccountModelDao inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception { return entitySqlDaoWrapperFactory.become(AccountSqlDao.class).getAccountByKey(key, context); } });
@Override public Integer inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception { return entitySqlDaoWrapperFactory.become(AccountSqlDao.class).getBCD(accountId.toString(), context); } });