killbill-aplcache
Changes
entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/AuditedEntitlementDao.java 12(+3 -9)
entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/BundleSqlDao.sql.stg 56(+9 -47)
entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/EntitlementEventSqlDao.sql.stg 117(+36 -81)
entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/SubscriptionSqlDao.sql.stg 111(+25 -86)
util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDaoWrapperInvocationHandler.java 3(+2 -1)
Details
diff --git a/account/src/main/java/com/ning/billing/account/api/DefaultAccountEmail.java b/account/src/main/java/com/ning/billing/account/api/DefaultAccountEmail.java
index 4053a32..e6bdb24 100644
--- a/account/src/main/java/com/ning/billing/account/api/DefaultAccountEmail.java
+++ b/account/src/main/java/com/ning/billing/account/api/DefaultAccountEmail.java
@@ -21,7 +21,7 @@ import java.util.UUID;
import com.ning.billing.util.entity.Entity;
import com.ning.billing.util.entity.EntityBase;
-public class DefaultAccountEmail extends EntityBase implements AccountEmail, Entity {
+public class DefaultAccountEmail extends EntityBase implements AccountEmail {
private final UUID accountId;
private final String email;
diff --git a/account/src/main/java/com/ning/billing/account/dao/AuditedAccountDao.java b/account/src/main/java/com/ning/billing/account/dao/AuditedAccountDao.java
index 5cbf61e..e967067 100644
--- a/account/src/main/java/com/ning/billing/account/dao/AuditedAccountDao.java
+++ b/account/src/main/java/com/ning/billing/account/dao/AuditedAccountDao.java
@@ -114,7 +114,6 @@ public class AuditedAccountDao implements AccountDao {
final Long recordId = accountSqlDao.getRecordId(account.getId().toString(), context);
// We need to re-hydrate the context with the account record id
final InternalCallContext rehydratedContext = internalCallContextFactory.createInternalCallContext(recordId, context);
-
final AccountCreationInternalEvent creationEvent = new DefaultAccountCreationEvent(account,
rehydratedContext.getUserToken(),
context.getAccountRecordId(),
diff --git a/account/src/main/java/com/ning/billing/account/dao/AuditedAccountEmailDao.java b/account/src/main/java/com/ning/billing/account/dao/AuditedAccountEmailDao.java
index d807f76..fd19c96 100644
--- a/account/src/main/java/com/ning/billing/account/dao/AuditedAccountEmailDao.java
+++ b/account/src/main/java/com/ning/billing/account/dao/AuditedAccountEmailDao.java
@@ -32,6 +32,7 @@ import com.ning.billing.account.api.AccountEmail;
import com.ning.billing.account.api.DefaultAccountEmail;
import com.ning.billing.util.callcontext.InternalCallContext;
import com.ning.billing.util.callcontext.InternalTenantContext;
+import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.dao.AuditedCollectionDaoBase;
import com.ning.billing.util.dao.TableName;
import com.ning.billing.util.entity.EntityPersistenceException;
@@ -45,7 +46,8 @@ public class AuditedAccountEmailDao extends AuditedCollectionDaoBase<AccountEmai
private final AccountEmailSqlDao accountEmailSqlDao;
@Inject
- public AuditedAccountEmailDao(final IDBI dbi) {
+ public AuditedAccountEmailDao(final IDBI dbi, final Clock clock) {
+ super(clock);
this.accountEmailSqlDao = dbi.onDemand(AccountEmailSqlDao.class);
}
diff --git a/account/src/main/resources/com/ning/billing/account/dao/AccountEmailSqlDao.sql.stg b/account/src/main/resources/com/ning/billing/account/dao/AccountEmailSqlDao.sql.stg
index 6ded4ea..fc11f5c 100644
--- a/account/src/main/resources/com/ning/billing/account/dao/AccountEmailSqlDao.sql.stg
+++ b/account/src/main/resources/com/ning/billing/account/dao/AccountEmailSqlDao.sql.stg
@@ -1,24 +1,26 @@
-group account_emails;
+group account_emails: EntitySqlDao;
-CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
-AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"
-fields(prefix) ::= <<
- <prefix>id,
- <prefix>account_id,
- <prefix>email,
- <prefix>created_by,
- <prefix>created_date,
- <prefix>updated_by,
- <prefix>updated_date,
- <prefix>account_record_id,
- <prefix>tenant_record_id
+tableFields(prefix) ::= <<
+ account_id
+, email
+, created_by
+, created_date
+, updated_by
+, updated_date
>>
-insertFromTransaction() ::= <<
- INSERT INTO account_emails(<fields()>)
- VALUES (:id, :accountId, :email, :userName, :createdDate, :userName, :updatedDate, :accountRecordId, :tenantRecordId);
->>
+
+tableValues() ::= <<
+ :accountId
+, :email
+, :createdBy
+, :createdDate
+, :updatedBy
+, :updatedDate
+ >>
+
+ historyTableName() ::= "account_email_history"
updateFromTransaction() ::= <<
UPDATE account_emails
@@ -31,63 +33,8 @@ deleteFromTransaction() ::= <<
WHERE id = :id <AND_CHECK_TENANT()>;
>>
-addHistoryFromTransaction() ::= <<
- INSERT INTO account_email_history(record_id, id, account_id, email, change_type, updated_by, date, account_record_id, tenant_record_id)
- VALUES (:recordId, :id, :accountId, :email, :changeType, :userName, :updatedDate, :accountRecordId, :tenantRecordId);
->>
-
-load() ::= <<
- SELECT <fields()> FROM account_emails WHERE account_id = :objectId <AND_CHECK_TENANT()>;
->>
-
-getRecordIds() ::= <<
- SELECT record_id, id
- FROM account_emails
- WHERE account_id = :objectId <AND_CHECK_TENANT()>;
->>
-
-getMaxHistoryRecordId() ::= <<
- SELECT MAX(history_record_id)
- FROM account_email_history
- WHERE <CHECK_TENANT()>;
->>
-
-getHistoryRecordIds() ::= <<
- SELECT history_record_id, record_id
- FROM account_email_history
- WHERE history_record_id > :maxHistoryRecordId <AND_CHECK_TENANT()>;
->>
-
-getById() ::= <<
- SELECT <fields()> FROM account_emails WHERE id = :id <AND_CHECK_TENANT()>;
->>
-
-get() ::= <<
- SELECT <fields()> FROM account_emails WHERE <CHECK_TENANT()>;
->>
getByAccountId() ::= <<
SELECT <fields()> FROM account_emails WHERE account_id = :accountId <AND_CHECK_TENANT()>;
>>
-auditFields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<auditFields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
-
-test() ::= <<
- SELECT 1 FROM account_emails where <CHECK_TENANT()>;
->>
diff --git a/account/src/main/resources/com/ning/billing/account/dao/AccountSqlDao.sql.stg b/account/src/main/resources/com/ning/billing/account/dao/AccountSqlDao.sql.stg
index f366a47..a3d6075 100644
--- a/account/src/main/resources/com/ning/billing/account/dao/AccountSqlDao.sql.stg
+++ b/account/src/main/resources/com/ning/billing/account/dao/AccountSqlDao.sql.stg
@@ -1,46 +1,62 @@
-group AccountDaoSql;
-
-CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
-AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"
-
-accountFields(prefix) ::= <<
- <prefix>id,
- <prefix>external_key,
- <prefix>email,
- <prefix>name,
- <prefix>first_name_length,
- <prefix>currency,
- <prefix>billing_cycle_day_local,
- <prefix>billing_cycle_day_utc,
- <prefix>payment_method_id,
- <prefix>time_zone,
- <prefix>locale,
- <prefix>address1,
- <prefix>address2,
- <prefix>company_name,
- <prefix>city,
- <prefix>state_or_province,
- <prefix>country,
- <prefix>postal_code,
- <prefix>phone,
- <prefix>migrated,
- <prefix>is_notified_for_invoices,
- <prefix>created_by,
- <prefix>created_date,
- <prefix>updated_by,
- <prefix>updated_date,
- <prefix>tenant_record_id
->>
-
-create() ::= <<
- INSERT INTO accounts
- (<accountFields()>)
- VALUES
- (:id, :externalKey, :email, :name, :firstNameLength, :currency, :billingCycleDayLocal,
- :billingCycleDayUTC, :paymentMethodId, :timeZone, :locale,
- :address1, :address2, :companyName, :city, :stateOrProvince, :country, :postalCode, :phone,
- :migrated, :isNotifiedForInvoices, :userName, :createdDate, :userName, :updatedDate, :tenantRecordId);
->>
+group AccountDaoSql: EntitySqlDao;
+
+
+tableFields(prefix) ::= <<
+ <prefix>external_key
+, <prefix>email
+, <prefix>name
+, <prefix>first_name_length
+, <prefix>currency
+, <prefix>billing_cycle_day_local
+, <prefix>billing_cycle_day_utc
+, <prefix>payment_method_id
+, <prefix>time_zone
+, <prefix>locale
+, <prefix>address1
+, <prefix>address2
+, <prefix>company_name
+, <prefix>city
+, <prefix>state_or_province
+, <prefix>country
+, <prefix>postal_code
+, <prefix>phone
+, <prefix>migrated
+, <prefix>is_notified_for_invoices
+, <prefix>created_by
+, <prefix>created_date
+, <prefix>updated_by
+, <prefix>updated_date
+>>
+
+tableValues() ::= <<
+ :externalKey
+, :email
+, :name
+, :firstNameLength
+, :currency
+, :billingCycleDayLocal
+, :billingCycleDayUTC
+, :paymentMethodId
+, :timeZone
+, :locale
+, :address1
+, :address2
+, :companyName
+, :city
+, :stateOrProvince
+, :country
+, :postalCode
+, :phone
+, :migrated
+, :isNotifiedForInvoices
+, :createdBy
+, :createdDate
+, :updatedBy
+ >>
+
+historyTableName() ::= "account_history"
+
+accountRecordIdField(prefix) ::= ""
update() ::= <<
UPDATE accounts
@@ -63,61 +79,6 @@ updatePaymentMethod() ::= <<
>>
-historyFields() ::= <<
- record_id,
- id,
- external_key,
- email,
- name,
- first_name_length,
- currency,
- billing_cycle_day_local,
- billing_cycle_day_utc,
- payment_method_id,
- time_zone,
- locale,
- address1,
- address2,
- company_name,
- city,
- state_or_province,
- country,
- postal_code,
- phone,
- migrated,
- is_notified_for_invoices,
- change_type,
- updated_by,
- date,
- tenant_record_id
->>
-
-getRecordId() ::= <<
- SELECT record_id
- FROM accounts
- WHERE id = :id <AND_CHECK_TENANT()>;
->>
-
-getByRecordId() ::= <<
- SELECT <accountFields()>
- FROM accounts
- WHERE record_id = :recordId <AND_CHECK_TENANT()>;
->>
-
-getHistoryRecordId() ::= <<
- SELECT MAX(history_record_id)
- FROM account_history
- WHERE record_id = :recordId <AND_CHECK_TENANT()>;
->>
-
-addHistoryFromTransaction() ::= <<
- INSERT INTO account_history(<historyFields()>)
- VALUES
- (:recordId, :id, :externalKey, :email, :name, :firstNameLength, :currency,
- :billingCycleDayLocal, :billingCycleDayUTC, :paymentMethodId, :timeZone, :locale,
- :address1, :address2, :companyName, :city, :stateOrProvince,
- :country, :postalCode, :phone, :migrated, :isNotifiedForInvoices, :changeType, :userName, :createdDate, :tenantRecordId);
->>
getAccountByKey() ::= <<
select <accountFields()>
@@ -125,17 +86,6 @@ getAccountByKey() ::= <<
where external_key = :externalKey <AND_CHECK_TENANT()>;
>>
-getById() ::= <<
- SELECT <accountFields()>
- FROM accounts
- WHERE id = :id <AND_CHECK_TENANT()>;
->>
-
-get() ::= <<
- SELECT <accountFields()>
- FROM accounts
- WHERE <CHECK_TENANT()>;
->>
getIdFromKey() ::= <<
SELECT id
@@ -143,25 +93,3 @@ getIdFromKey() ::= <<
WHERE external_key = :externalKey <AND_CHECK_TENANT()>;
>>
-auditFields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<auditFields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
-
-test() ::= <<
- SELECT 1 FROM accounts WHERE <CHECK_TENANT()>;
->>
-;
diff --git a/account/src/test/java/com/ning/billing/account/dao/AccountDaoTestBase.java b/account/src/test/java/com/ning/billing/account/dao/AccountDaoTestBase.java
index ef2486c..c486939 100644
--- a/account/src/test/java/com/ning/billing/account/dao/AccountDaoTestBase.java
+++ b/account/src/test/java/com/ning/billing/account/dao/AccountDaoTestBase.java
@@ -24,6 +24,7 @@ import org.testng.annotations.BeforeClass;
import com.ning.billing.account.AccountTestSuiteWithEmbeddedDB;
import com.ning.billing.util.callcontext.InternalCallContextFactory;
import com.ning.billing.util.clock.ClockMock;
+import com.ning.billing.util.clock.DefaultClock;
import com.ning.billing.util.svcsapi.bus.InternalBus;
import com.ning.billing.util.svcsapi.bus.BusService;
import com.ning.billing.util.bus.DefaultBusService;
@@ -54,7 +55,7 @@ public abstract class AccountDaoTestBase extends AccountTestSuiteWithEmbeddedDB
// Health check test to make sure MySQL is setup properly
accountDao.test(internalCallContext);
- accountEmailDao = new AuditedAccountEmailDao(dbi);
+ accountEmailDao = new AuditedAccountEmailDao(dbi, new DefaultClock());
// Health check test to make sure MySQL is setup properly
accountEmailDao.test(internalCallContext);
} catch (Throwable t) {
diff --git a/account/src/test/java/com/ning/billing/account/dao/TestAccountDao.java b/account/src/test/java/com/ning/billing/account/dao/TestAccountDao.java
index 0a6b546..3b005ce 100644
--- a/account/src/test/java/com/ning/billing/account/dao/TestAccountDao.java
+++ b/account/src/test/java/com/ning/billing/account/dao/TestAccountDao.java
@@ -40,6 +40,7 @@ import com.ning.billing.account.api.MutableAccountData;
import com.ning.billing.catalog.api.Currency;
import com.ning.billing.mock.MockAccountBuilder;
import com.ning.billing.util.api.TagApiException;
+import com.ning.billing.util.clock.DefaultClock;
import com.ning.billing.util.customfield.CustomField;
import com.ning.billing.util.customfield.StringCustomField;
import com.ning.billing.util.customfield.dao.AuditedCustomFieldDao;
@@ -146,7 +147,7 @@ public class TestAccountDao extends AccountDaoTestBase {
final UUID accountId = UUID.randomUUID();
final List<CustomField> customFields = new ArrayList<CustomField>();
customFields.add(new StringCustomField(fieldName, fieldValue));
- final CustomFieldDao customFieldDao = new AuditedCustomFieldDao(dbi);
+ final CustomFieldDao customFieldDao = new AuditedCustomFieldDao(dbi, new DefaultClock());
customFieldDao.saveEntities(accountId, ObjectType.ACCOUNT, customFields, internalCallContext);
final Map<String, CustomField> customFieldMap = customFieldDao.loadEntities(accountId, ObjectType.ACCOUNT, internalCallContext);
@@ -163,7 +164,7 @@ public class TestAccountDao extends AccountDaoTestBase {
final TagDefinitionSqlDao tagDescriptionDao = dbi.onDemand(TagDefinitionSqlDao.class);
tagDescriptionDao.create(definition, internalCallContext);
- final TagDao tagDao = new AuditedTagDao(dbi, tagEventBuilder, bus);
+ final TagDao tagDao = new AuditedTagDao(dbi, tagEventBuilder, bus, new DefaultClock());
tagDao.insertTag(account.getId(), ObjectType.ACCOUNT, definition.getId(), internalCallContext);
final Map<String, Tag> tagMap = tagDao.loadEntities(account.getId(), ObjectType.ACCOUNT, internalCallContext);
diff --git a/analytics/src/test/java/com/ning/billing/analytics/TestBusinessTagRecorder.java b/analytics/src/test/java/com/ning/billing/analytics/TestBusinessTagRecorder.java
index 7e2d9cf..a38ba20 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/TestBusinessTagRecorder.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/TestBusinessTagRecorder.java
@@ -42,6 +42,7 @@ import com.ning.billing.catalog.DefaultCatalogService;
import com.ning.billing.catalog.api.CatalogService;
import com.ning.billing.catalog.api.Currency;
import com.ning.billing.catalog.io.VersionedCatalogLoader;
+import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.config.CatalogConfig;
import com.ning.billing.entitlement.alignment.PlanAligner;
import com.ning.billing.entitlement.api.svcs.DefaultEntitlementInternalApi;
@@ -77,6 +78,7 @@ public class TestBusinessTagRecorder extends AnalyticsTestSuiteWithEmbeddedDB {
@BeforeMethod(groups = "slow")
public void setUp() throws Exception {
+ final Clock clock = new ClockMock();
final IDBI dbi = helper.getDBI();
accountTagSqlDao = dbi.onDemand(BusinessAccountTagSqlDao.class);
final BusinessInvoiceTagSqlDao invoiceTagSqlDao = dbi.onDemand(BusinessInvoiceTagSqlDao.class);
@@ -84,8 +86,7 @@ public class TestBusinessTagRecorder extends AnalyticsTestSuiteWithEmbeddedDB {
subscriptionTransitionTagSqlDao = dbi.onDemand(BusinessSubscriptionTransitionTagSqlDao.class);
eventBus = new InMemoryInternalBus();
final AccountDao accountDao = new AuditedAccountDao(dbi, eventBus, new InternalCallContextFactory(dbi, new ClockMock()));
- final AccountEmailDao accountEmailDao = new AuditedAccountEmailDao(dbi);
- final DefaultClock clock = new DefaultClock();
+ final AccountEmailDao accountEmailDao = new AuditedAccountEmailDao(dbi, clock);
callContextFactory = new DefaultCallContextFactory(clock);
final InternalCallContextFactory internalCallContextFactory = new InternalCallContextFactory(dbi, clock);
accountApi = new DefaultAccountInternalApi(accountDao, accountEmailDao);
diff --git a/api/src/main/java/com/ning/billing/util/audit/AuditLog.java b/api/src/main/java/com/ning/billing/util/audit/AuditLog.java
index 1544931..44a39c7 100644
--- a/api/src/main/java/com/ning/billing/util/audit/AuditLog.java
+++ b/api/src/main/java/com/ning/billing/util/audit/AuditLog.java
@@ -18,8 +18,10 @@ package com.ning.billing.util.audit;
import org.joda.time.DateTime;
+import com.ning.billing.util.entity.Entity;
-public interface AuditLog {
+
+public interface AuditLog extends Entity {
/**
* Get the type of change for this log entry
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/AuditedEntitlementDao.java b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/AuditedEntitlementDao.java
index 98e3f9a..333d56a 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/AuditedEntitlementDao.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/AuditedEntitlementDao.java
@@ -63,9 +63,12 @@ import com.ning.billing.entitlement.events.user.ApiEventCancel;
import com.ning.billing.entitlement.events.user.ApiEventChange;
import com.ning.billing.entitlement.events.user.ApiEventType;
import com.ning.billing.entitlement.exceptions.EntitlementError;
+import com.ning.billing.util.audit.ChangeType;
import com.ning.billing.util.callcontext.InternalCallContext;
import com.ning.billing.util.callcontext.InternalTenantContext;
import com.ning.billing.util.clock.Clock;
+import com.ning.billing.util.dao.EntityAudit;
+import com.ning.billing.util.dao.TableName;
import com.ning.billing.util.entity.dao.EntitySqlDao;
import com.ning.billing.util.entity.dao.EntitySqlDaoTransactionWrapper;
import com.ning.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper;
@@ -202,7 +205,6 @@ public class AuditedEntitlementDao implements EntitlementDao {
final BundleSqlDao bundleSqlDao = entitySqlDaoWrapperFactory.become(BundleSqlDao.class);
final String bundleId = subscription.getBundleId().toString();
bundleSqlDao.updateBundleLastSysTime(bundleId, clock.getUTCNow().toDate(), context);
-
return null;
}
});
@@ -217,7 +219,6 @@ public class AuditedEntitlementDao implements EntitlementDao {
final UUID subscriptionId = subscription.getId();
cancelNextPhaseEventFromTransaction(subscriptionId, transactional, context);
transactional.insertEvent(nextPhase, context);
-
recordFutureNotificationFromTransaction(transactional,
nextPhase.getEffectiveDate(),
new EntitlementNotificationKey(nextPhase.getId()),
@@ -279,7 +280,6 @@ public class AuditedEntitlementDao implements EntitlementDao {
final SubscriptionSqlDao transactional = entitySqlDaoWrapperFactory.become(SubscriptionSqlDao.class);
transactional.insertSubscription(subscription, context);
- // STEPH batch as well
final EntitlementEventSqlDao eventsDaoFromSameTransaction = entitySqlDaoWrapperFactory.become(EntitlementEventSqlDao.class);
for (final EntitlementEvent cur : initialEvents) {
eventsDaoFromSameTransaction.insertEvent(cur, context);
@@ -288,12 +288,10 @@ public class AuditedEntitlementDao implements EntitlementDao {
new EntitlementNotificationKey(cur.getId()),
context);
}
-
// Notify the Bus of the latest requested change, if needed
if (initialEvents.size() > 0) {
notifyBusOfRequestedChange(eventsDaoFromSameTransaction, subscription, initialEvents.get(initialEvents.size() - 1), context);
}
-
return null;
}
});
@@ -359,7 +357,6 @@ public class AuditedEntitlementDao implements EntitlementDao {
if (cancelledEvent != null) {
final String cancelledEventId = cancelledEvent.getId().toString();
transactional.unactiveEvent(cancelledEventId, context);
-
for (final EntitlementEvent cur : uncancelEvents) {
transactional.insertEvent(cur, context);
recordFutureNotificationFromTransaction(transactional,
@@ -389,7 +386,6 @@ public class AuditedEntitlementDao implements EntitlementDao {
for (final EntitlementEvent cur : changeEvents) {
transactional.insertEvent(cur, context);
-
recordFutureNotificationFromTransaction(transactional,
cur.getEffectiveDate(),
new EntitlementNotificationKey(cur.getId()),
@@ -409,7 +405,6 @@ public class AuditedEntitlementDao implements EntitlementDao {
final UUID subscriptionId = subscription.getId();
cancelFutureEventsFromTransaction(subscriptionId, transactional, context);
transactional.insertEvent(cancelEvent, context);
-
recordFutureNotificationFromTransaction(transactional,
cancelEvent.getEffectiveDate(),
new EntitlementNotificationKey(cancelEvent.getId(), seqId),
@@ -682,7 +677,6 @@ public class AuditedEntitlementDao implements EntitlementDao {
final SubscriptionData subData = curSubscription.getData();
for (final EntitlementEvent curEvent : curSubscription.getInitialEvents()) {
transactional.insertEvent(curEvent, context);
-
recordFutureNotificationFromTransaction(transactional,
curEvent.getEffectiveDate(),
new EntitlementNotificationKey(curEvent.getId()),
diff --git a/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/BundleSqlDao.sql.stg b/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/BundleSqlDao.sql.stg
index 7e41f60..2ac9ebc 100644
--- a/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/BundleSqlDao.sql.stg
+++ b/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/BundleSqlDao.sql.stg
@@ -1,20 +1,15 @@
-group BundleSqlDao;
+group BundleSqlDao: EntitySqlDao;
-CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
-AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"
-
-fields(prefix) ::= <<
- <prefix>id,
- <prefix>external_key,
- <prefix>account_id,
- <prefix>last_sys_update_date,
- <prefix>account_record_id,
- <prefix>tenant_record_id
+tableFields(prefix) ::= <<
+ <prefix>external_key
+, <prefix>account_id
+, <prefix>last_sys_update_date
>>
-insertBundle() ::= <<
- insert into bundles (<fields()>)
- values (:id, :externalKey, :accountId, :lastSysUpdateDate, :accountRecordId, :tenantRecordId);
+tableValues() ::= <<
+ :externalKey
+, :accountId
+, :lastSysUpdateDate
>>
updateBundleLastSysTime() ::= <<
@@ -61,36 +56,3 @@ getBundleFromAccount() ::= <<
<AND_CHECK_TENANT()>
;
>>
-
-getRecordId() ::= <<
- SELECT record_id
- FROM bundles
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
->>
-
-getById() ::= <<
- SELECT <fields()>
- FROM bundles
- WHERE id = :id <AND_CHECK_TENANT()>
- ;
->>
-
-auditFields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<auditFields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
diff --git a/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/EntitlementEventSqlDao.sql.stg b/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/EntitlementEventSqlDao.sql.stg
index 9a16aca..20b3721 100644
--- a/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/EntitlementEventSqlDao.sql.stg
+++ b/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/EntitlementEventSqlDao.sql.stg
@@ -1,27 +1,40 @@
-group EventSqlDao;
-
-CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
-AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"
+group EventSqlDao: EntitySqlDao;
+
+
+tableFields(prefix) ::= <<
+ <prefix> event_type
+, <prefix> user_type
+, <prefix> requested_date
+, <prefix> effective_date
+, <prefix> subscription_id
+, <prefix> plan_name
+, <prefix> phase_name
+, <prefix> price_list_name
+, <prefix> user_token
+, <prefix> current_version
+, <prefix> is_active
+, <prefix> created_by
+, <prefix> created_date
+, <prefix> updated_by
+, <prefix> updated_date
+>>
-fields(prefix) ::= <<
- <prefix>id,
- <prefix>event_type,
- <prefix>user_type,
- <prefix>requested_date,
- <prefix>effective_date,
- <prefix>subscription_id,
- <prefix>plan_name,
- <prefix>phase_name,
- <prefix>price_list_name,
- <prefix>user_token,
- <prefix>current_version,
- <prefix>is_active,
- <prefix>created_by,
- <prefix>created_date,
- <prefix>updated_by,
- <prefix>updated_date,
- <prefix>account_record_id,
- <prefix>tenant_record_id
+tableValues() ::= <<
+ :eventType
+, :userType
+, :requested_date
+, :effective_date
+, :subscription_id
+, :plan_name
+, :phase_name
+, :price_list_name
+, :user_token
+, :current_version
+, :is_active
+, :created_by
+, :created_date
+, :updated_by
+, :updated_date
>>
getEventById() ::= <<
@@ -33,29 +46,6 @@ getEventById() ::= <<
;
>>
-insertEvent() ::= <<
- insert into subscription_events (<fields()>)
- values (
- :id
- , :eventType
- , :userType
- , :requestedDate
- , :effectiveDate
- , :subscriptionId
- , :planName
- , :phaseName
- , :priceListName
- , :userToken
- , :currentVersion
- , :isActive
- , :userName
- , :createdDate
- , :userName
- , :updatedDate
- , :accountRecordId
- , :tenantRecordId
- );
->>
updateVersion() ::= <<
update subscription_events
@@ -117,38 +107,3 @@ getEventsForSubscription() ::= <<
, record_id asc
;
>>
-
-getRecordId() ::= <<
- SELECT record_id
- FROM subscription_events
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
->>
-
-getById() ::= <<
- SELECT record_id, <fields()>
- FROM subscription_events
- WHERE id = :id <AND_CHECK_TENANT()>
- ;
->>
-
-auditFields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<auditFields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
-
-
diff --git a/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/SubscriptionSqlDao.sql.stg b/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/SubscriptionSqlDao.sql.stg
index 2b08da3..58022e9 100644
--- a/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/SubscriptionSqlDao.sql.stg
+++ b/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/SubscriptionSqlDao.sql.stg
@@ -1,62 +1,34 @@
-group SubscriptionSqlDao;
+group SubscriptionSqlDao: EntitySqlDao;
-CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
-AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"
-fields(prefix) ::= <<
- <prefix>id,
- <prefix>bundle_id,
- <prefix>category,
- <prefix>start_date,
- <prefix>bundle_start_date,
- <prefix>active_version,
- <prefix>charged_through_date,
- <prefix>paid_through_date,
- <prefix>created_by,
- <prefix>created_date,
- <prefix>updated_by,
- <prefix>updated_date,
- <prefix>account_record_id,
- <prefix>tenant_record_id
+tableFields(prefix) ::= <<
+ <prefix>bundle_id
+, <prefix>category
+, <prefix>start_date
+, <prefix>bundle_start_date
+, <prefix>active_version
+, <prefix>charged_through_date
+, <prefix>paid_through_date
+, <prefix>created_by
+, <prefix>created_date
+, <prefix>updated_by
+, <prefix>updated_date
>>
-insertSubscription() ::= <<
- insert into subscriptions (<fields()>)
- values (
- :id
- , :bundleId
- , :category
- , :startDate
- , :bundleStartDate
- , :activeVersion
- , :chargedThroughDate
- , :paidThroughDate
- , :userName
- , :createdDate
- , :userName
- , :updatedDate
- , :accountRecordId
- , :tenantRecordId
- );
+tableValues() ::= <<
+ :bundleId
+, :category
+, :startDate
+, :bundleStartDate
+, :activeVersion
+, :chargedThroughDate
+, :paidThroughDate
+, :createdBy
+, :createdDate
+, :updatedBy
+, :updatedDate
>>
-getSubscriptionFromId() ::= <<
- select
- id
- , bundle_id
- , category
- , start_date
- , bundle_start_date
- , active_version
- , charged_through_date
- , paid_through_date
- , created_date
- , updated_date
- from subscriptions
- where id = :id
- <AND_CHECK_TENANT()>
- ;
->>
getSubscriptionsFromBundleId() ::= <<
select
@@ -109,36 +81,3 @@ updateForRepair() ::= <<
<AND_CHECK_TENANT()>
;
>>
-
-getRecordId() ::= <<
- SELECT record_id
- FROM subscriptions
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
->>
-
-getById() ::= <<
- SELECT record_id, <fields()>
- FROM subscriptions
- WHERE id = :id <AND_CHECK_TENANT()>
- ;
->>
-
-auditFields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<auditFields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
diff --git a/invoice/src/main/java/com/ning/billing/invoice/dao/AuditedInvoiceDao.java b/invoice/src/main/java/com/ning/billing/invoice/dao/AuditedInvoiceDao.java
index 27d9da4..8a10ec0 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/dao/AuditedInvoiceDao.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/dao/AuditedInvoiceDao.java
@@ -272,9 +272,7 @@ public class AuditedInvoiceDao implements InvoiceDao {
@Override
public Void inTransaction(final EntitySqlDaoWrapperFactory<EntitySqlDao> entitySqlDaoWrapperFactory) throws Exception {
final InvoicePaymentSqlDao transactional = entitySqlDaoWrapperFactory.become(InvoicePaymentSqlDao.class);
-
transactional.notifyOfPayment(invoicePayment, context);
-
return null;
}
});
@@ -581,7 +579,6 @@ public class AuditedInvoiceDao implements InvoiceDao {
if (invoiceIdForExternalCharge == null) {
final Invoice invoiceForExternalCharge = new DefaultInvoice(accountId, effectiveDate, effectiveDate, currency);
transactional.create(invoiceForExternalCharge, context);
-
invoiceIdForExternalCharge = invoiceForExternalCharge.getId();
}
@@ -632,7 +629,6 @@ public class AuditedInvoiceDao implements InvoiceDao {
if (invoiceIdForCredit == null) {
final Invoice invoiceForCredit = new DefaultInvoice(accountId, effectiveDate, effectiveDate, currency);
transactional.create(invoiceForCredit, context);
-
invoiceIdForCredit = invoiceForCredit.getId();
}
@@ -747,7 +743,6 @@ public class AuditedInvoiceDao implements InvoiceDao {
final InvoiceItem nextCBAAdjItem = new CreditBalanceAdjInvoiceItem(invoiceFollowing.getId(), invoice.getAccountId(), context.getCreatedDate().toLocalDate(),
cbaItem.getId(), positiveCBAAdjItemAmount, cbaItem.getCurrency());
invoiceItemSqlDao.create(nextCBAAdjItem, context);
-
if (positiveRemainderToAdjust.compareTo(BigDecimal.ZERO) == 0) {
break;
}
diff --git a/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoiceItemSqlDao.sql.stg b/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoiceItemSqlDao.sql.stg
index ec2bcd4..209a3af 100644
--- a/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoiceItemSqlDao.sql.stg
+++ b/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoiceItemSqlDao.sql.stg
@@ -1,52 +1,41 @@
-group InvoiceItemSqlDao;
-
-CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
-AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"
-
-fields(prefix) ::= <<
- <prefix>id,
- <prefix>type,
- <prefix>invoice_id,
- <prefix>account_id,
- <prefix>bundle_id,
- <prefix>subscription_id,
- <prefix>plan_name,
- <prefix>phase_name,
- <prefix>start_date,
- <prefix>end_date,
- <prefix>amount,
- <prefix>rate,
- <prefix>currency,
- <prefix>linked_item_id,
- <prefix>created_by,
- <prefix>created_date,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-getById() ::= <<
- SELECT <fields()>
- FROM invoice_items
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
+group InvoiceItemSqlDao: EntitySqlDao;
+
+tableFields(prefix) ::= <<
+ <prefix>type
+, <prefix>invoice_id
+, <prefix>account_id
+, <prefix>bundle_id
+, <prefix>subscription_id
+, <prefix>plan_name
+, <prefix>phase_name
+, <prefix>start_date
+, <prefix>end_date
+, <prefix>amount
+, <prefix>rate
+, <prefix>currency
+, <prefix>linked_item_id
+, <prefix>created_by
+, <prefix>created_date
+>>
+
+tableValues() ::= <<
+ :type
+, :invoiceId
+, :accountId
+, :bundleId
+, :subscriptionId
+, :planName
+, :phaseName
+, :startDate
+, :endDate
+, :amount
+, :rate
+, :currency
+, :linkedItemId
+, :createdBy
+, :createdDate
>>
-getByRecordId() ::= <<
- SELECT <fields()>
- FROM invoice_items
- WHERE record_id = :recordId
- <AND_CHECK_TENANT()>
- ;
->>
-
-getRecordId() ::= <<
- SELECT record_id
- FROM invoice_items
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
->>
getInvoiceItemsByInvoice() ::= <<
SELECT <fields()>
@@ -71,49 +60,3 @@ getInvoiceItemsBySubscription() ::= <<
<AND_CHECK_TENANT()>
;
>>
-
-create() ::= <<
- INSERT INTO invoice_items(<fields()>)
- VALUES(:id, :type, :invoiceId, :accountId, :bundleId, :subscriptionId, :planName, :phaseName, :startDate, :endDate,
- :amount, :rate, :currency, :linkedItemId, :userName, :createdDate, :accountRecordId, :tenantRecordId);
->>
-
-batchCreateFromTransaction() ::= <<
- INSERT INTO invoice_items(<fields()>)
- VALUES(:id, :type,:invoiceId, :accountId, :bundleId, :subscriptionId, :planName, :phaseName, :startDate, :endDate,
- :amount, :rate, :currency, :linkedItemId, :userName, :createdDate, :accountRecordId, :tenantRecordId);
->>
-
-getRecordIds() ::= <<
- SELECT record_id, id
- FROM invoice_items
- WHERE invoice_id = :invoiceId
- <AND_CHECK_TENANT()>
- ;
->>
-
-auditFields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<auditFields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
-
-test() ::= <<
- SELECT 1
- FROM invoice_items
- WHERE <CHECK_TENANT()>
- ;
->>
-;
diff --git a/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoicePaymentSqlDao.sql.stg b/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoicePaymentSqlDao.sql.stg
index 77139a9..335974b 100644
--- a/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoicePaymentSqlDao.sql.stg
+++ b/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoicePaymentSqlDao.sql.stg
@@ -1,34 +1,30 @@
-group InvoicePayment;
-
-CHECK_TENANT(prefix) ::= "<prefix>tenant_record_id = :tenantRecordId"
-AND_CHECK_TENANT(prefix) ::= "AND <CHECK_TENANT(prefix)>"
-
-invoicePaymentFields(prefix) ::= <<
- <prefix>id,
- <prefix>type,
- <prefix>invoice_id,
- <prefix>payment_id,
- <prefix>payment_date,
- <prefix>amount,
- <prefix>currency,
- <prefix>payment_cookie_id,
- <prefix>linked_invoice_payment_id,
- <prefix>created_by,
- <prefix>created_date,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-create() ::= <<
- INSERT INTO invoice_payments(<invoicePaymentFields()>)
- VALUES(:id, :type, :invoiceId, :paymentId, :paymentDate, :amount, :currency,
- :paymentCookieId, :linkedInvoicePaymentId, :userName, :createdDate, :accountRecordId, :tenantRecordId);
->>
-
-batchCreateFromTransaction() ::= <<
- INSERT INTO invoice_payments(<invoicePaymentFields()>)
- VALUES(:id, :type, :invoiceId, :paymentId, :paymentDate, :amount, :currency,
- :paymentCookieId, :linkedInvoicePaymentId, :userName, :createdDate, :accountRecordId, :tenantRecordId);
+group InvoicePayment: EntitySqlDao;
+
+
+tableFields(prefix) ::= <<
+ <prefix>type
+, <prefix>invoice_id
+, <prefix>payment_id
+, <prefix>payment_date
+, <prefix>amount
+, <prefix>currency
+, <prefix>payment_cookie_id
+, <prefix>linked_invoice_payment_id
+, <prefix>created_by
+, <prefix>created_date
+>>
+
+tableValues() ::= <<
+ :type
+, :invoiceId
+, :paymentId
+, :paymentDate
+, :amount
+, :currency
+, :paymentCookieId
+, :linkedInvoicePaymentId
+, :createdBy
+, :createdDate
>>
getByPaymentId() ::= <<
@@ -39,20 +35,6 @@ getByPaymentId() ::= <<
;
>>
-get() ::= <<
- SELECT <invoicePaymentFields()>
- FROM invoice_payments
- <AND_CHECK_TENANT()>
- ;
->>
-
-getById() ::= <<
- SELECT <invoicePaymentFields()>
- FROM invoice_payments
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
->>
getPaymentsForCookieId() ::= <<
SELECT <invoicePaymentFields()>
@@ -84,44 +66,6 @@ getInvoicePayments() ::= <<
;
>>
-getRecordId() ::= <<
- SELECT record_id
- FROM invoice_payments
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
->>
-
-getRecordIds() ::= <<
- SELECT record_id, id
- FROM invoice_payments
- WHERE invoice_id = :invoiceId
- <AND_CHECK_TENANT()>
- ;
->>
-
-auditFields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<auditFields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
-
-test() ::= <<
- SELECT 1 FROM invoice_payments where <CHECK_TENANT()>;
->>
-
getRemainingAmountPaid() ::= <<
SELECT SUM(amount)
FROM invoice_payments
@@ -158,4 +102,4 @@ getChargebacksByPaymentId() ::= <<
<AND_CHECK_TENANT()>
;
>>
-;
+
diff --git a/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoiceSqlDao.sql.stg b/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoiceSqlDao.sql.stg
index 1cba076..65a683f 100644
--- a/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoiceSqlDao.sql.stg
+++ b/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoiceSqlDao.sql.stg
@@ -1,26 +1,25 @@
-group InvoiceDao;
+group InvoiceDao: EntitySqlDao;
-CHECK_TENANT(prefix) ::= "<prefix>tenant_record_id = :tenantRecordId"
-AND_CHECK_TENANT(prefix) ::= "AND <CHECK_TENANT(prefix)>"
-invoiceFields(prefix) ::= <<
- <prefix>id,
- <prefix>account_id,
- <prefix>invoice_date,
- <prefix>target_date,
- <prefix>currency,
- <prefix>migrated,
- <prefix>created_by,
- <prefix>created_date,
- <prefix>account_record_id,
- <prefix>tenant_record_id
+tableFields(prefix) ::= <<
+ <prefix>account_id
+, <prefix>invoice_date
+, <prefix>target_date
+, <prefix>currency
+, <prefix>migrated
+, <prefix>created_by
+, <prefix>created_date
>>
-get() ::= <<
- SELECT record_id as invoice_number, <invoiceFields()>
- FROM invoices
- WHERE <CHECK_TENANT()>
- ORDER BY target_date ASC;
+
+tableValues(prefix) ::= <<
+ <prefix>account_id
+ <prefix>invoice_date
+ <prefix>target_date
+ <prefix>currency
+ <prefix>migrated
+ <prefix>created_by
+ <prefix>created_date
>>
getInvoicesByAccount() ::= <<
@@ -57,27 +56,6 @@ getInvoicesBySubscription() ::= <<
;
>>
-getById() ::= <<
- SELECT record_id as invoice_number, <invoiceFields()>
- FROM invoices
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
->>
-
-getByRecordId() ::= <<
- SELECT record_id as invoice_number, <invoiceFields()>
- FROM invoices
- WHERE record_id = :recordId
- <AND_CHECK_TENANT()>
- ;
->>
-
-create() ::= <<
- INSERT INTO invoices(<invoiceFields()>)
- VALUES (:id, :accountId, :invoiceDate, :targetDate, :currency, :migrated, :userName, :createdDate, :accountRecordId, :tenantRecordId);
->>
-
getInvoiceIdByPaymentId() ::= <<
SELECT i.id
FROM invoices i, invoice_payments ip
@@ -86,38 +64,3 @@ getInvoiceIdByPaymentId() ::= <<
<AND_CHECK_TENANT("i.")>
<AND_CHECK_TENANT("ip.")>
>>
-
-
-getRecordId() ::= <<
- SELECT record_id
- FROM invoices
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
->>
-
-auditFields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<auditFields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
-
-test() ::= <<
- SELECT 1
- FROM invoices
- WHERE <CHECK_TENANT()>
- ;
->>
-;
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAuditLogJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAuditLogJson.java
index e7784f2..b9829e8 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAuditLogJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAuditLogJson.java
@@ -80,7 +80,7 @@ public class TestAuditLogJson extends JaxrsTestSuite {
final TableName tableName = TableName.ACCOUNT_EMAIL_HISTORY;
final long recordId = Long.MAX_VALUE;
final ChangeType changeType = ChangeType.DELETE;
- final EntityAudit entityAudit = new EntityAudit(tableName, recordId, changeType);
+ final EntityAudit entityAudit = new EntityAudit(tableName, recordId, changeType, null);
final AuditLog auditLog = new DefaultAuditLog(entityAudit, callContext);
diff --git a/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateSqlDao.java b/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateSqlDao.java
index c9260dc..9e33d3d 100644
--- a/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateSqlDao.java
+++ b/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateSqlDao.java
@@ -130,13 +130,13 @@ public interface BlockingStateSqlDao extends BlockingStateDao, CloseMe, Transmog
@Override
public void bind(@SuppressWarnings("rawtypes") final SQLStatement stmt, final Bind bind, final DefaultBlockingState state) {
stmt.bind("id", state.getId().toString());
- stmt.bind("blockable_id", state.getBlockedId().toString());
+ stmt.bind("blockableId", state.getBlockedId().toString());
stmt.bind("state", state.getStateName().toString());
stmt.bind("type", state.getType().toString());
stmt.bind("service", state.getService().toString());
- stmt.bind("block_change", state.isBlockChange());
- stmt.bind("block_entitlement", state.isBlockEntitlement());
- stmt.bind("block_billing", state.isBlockBilling());
+ stmt.bind("blockChange", state.isBlockChange());
+ stmt.bind("blockEntitlement", state.isBlockEntitlement());
+ stmt.bind("blockBilling", state.isBlockBilling());
}
}
diff --git a/junction/src/main/resources/com/ning/billing/junction/dao/BlockingStateSqlDao.sql.stg b/junction/src/main/resources/com/ning/billing/junction/dao/BlockingStateSqlDao.sql.stg
index 9a9077d..0cfcd63 100644
--- a/junction/src/main/resources/com/ning/billing/junction/dao/BlockingStateSqlDao.sql.stg
+++ b/junction/src/main/resources/com/ning/billing/junction/dao/BlockingStateSqlDao.sql.stg
@@ -1,7 +1,30 @@
-group BlockingStateSqlDao;
+group BlockingStateSqlDao: EntitySqlDao;
-CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
-AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"
+
+tableFields(prefix) ::= <<
+ <prefix>id
+, <prefix>blockable_id
+, <prefix>state
+, <prefix>type
+, <prefix>service
+, <prefix>block_change
+, <prefix>block_entitlement
+, <prefix>block_billing
+, <prefix>created_date
+>>
+
+
+tableValues() ::= <<
+ :id
+, :blockableId
+, :state
+, :type
+, :service
+, :blockChange
+, :blockEntitlement
+, :blockBilling
+, :createdDate
+>>
getBlockingStateFor() ::= <<
select
@@ -43,31 +66,3 @@ getBlockingHistoryFor() ::= <<
order by created_date asc, record_id asc
;
>>
-
-setBlockingState() ::= <<
- insert into blocking_states (
- id
- , blockable_id
- , state
- , type
- , service
- , block_change
- , block_entitlement
- , block_billing
- , created_date
- , account_record_id
- , tenant_record_id
- ) values (
- :id
- , :blockable_id
- , :state
- , :type
- , :service
- , :block_change
- , :block_entitlement
- , :block_billing
- , :created_date
- , :accountRecordId
- , :tenantRecordId
- );
->>
diff --git a/payment/src/main/java/com/ning/billing/payment/dao/AuditedPaymentDao.java b/payment/src/main/java/com/ning/billing/payment/dao/AuditedPaymentDao.java
index b08d704..7ca9634 100644
--- a/payment/src/main/java/com/ning/billing/payment/dao/AuditedPaymentDao.java
+++ b/payment/src/main/java/com/ning/billing/payment/dao/AuditedPaymentDao.java
@@ -16,6 +16,7 @@
package com.ning.billing.payment.dao;
+import java.math.BigDecimal;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -26,8 +27,13 @@ import org.skife.jdbi.v2.IDBI;
import com.ning.billing.payment.api.PaymentStatus;
import com.ning.billing.payment.dao.RefundModelDao.RefundStatus;
import com.ning.billing.payment.retry.PluginFailureRetryService.PluginFailureRetryServiceScheduler;
+import com.ning.billing.util.audit.ChangeType;
import com.ning.billing.util.callcontext.InternalCallContext;
import com.ning.billing.util.callcontext.InternalTenantContext;
+import com.ning.billing.util.clock.Clock;
+import com.ning.billing.util.dao.EntityAudit;
+import com.ning.billing.util.dao.EntityHistory;
+import com.ning.billing.util.dao.TableName;
import com.ning.billing.util.entity.dao.EntitySqlDao;
import com.ning.billing.util.entity.dao.EntitySqlDaoTransactionWrapper;
import com.ning.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper;
@@ -42,14 +48,16 @@ public class AuditedPaymentDao implements PaymentDao {
private final PaymentAttemptSqlDao paymentAttemptSqlDao;
private final PaymentMethodSqlDao paymentMethodSqlDao;
private final RefundSqlDao refundSqlDao;
+ private final Clock clock;
@Inject
- public AuditedPaymentDao(final IDBI dbi, final PluginFailureRetryServiceScheduler timedoutSchduler) {
+ public AuditedPaymentDao(final IDBI dbi, final PluginFailureRetryServiceScheduler timedoutSchduler, final Clock clock) {
this.paymentSqlDao = dbi.onDemand(PaymentSqlDao.class);
this.paymentAttemptSqlDao = dbi.onDemand(PaymentAttemptSqlDao.class);
this.paymentMethodSqlDao = dbi.onDemand(PaymentMethodSqlDao.class);
this.refundSqlDao = dbi.onDemand(RefundSqlDao.class);
this.transactionalSqlDao = new EntitySqlDaoTransactionalJdbiWrapper(dbi);
+ this.clock = clock;
}
@Override
@@ -77,6 +85,7 @@ public class AuditedPaymentDao implements PaymentDao {
final PaymentSqlDao transactional = entitySqlDaoWrapperFactory.become(PaymentSqlDao.class);
transactional.insertPayment(payment, context);
+
entitySqlDaoWrapperFactory.become(PaymentAttemptSqlDao.class).insertPaymentAttempt(attempt, context);
return transactional.getPayment(payment.getId().toString(), context);
@@ -122,6 +131,7 @@ public class AuditedPaymentDao implements PaymentDao {
private PaymentMethodModelDao insertPaymentMethodInTransaction(final EntitySqlDaoWrapperFactory<EntitySqlDao> entitySqlDaoWrapperFactory, final PaymentMethodModelDao paymentMethod, final InternalCallContext context) {
final PaymentMethodSqlDao transactional = entitySqlDaoWrapperFactory.become(PaymentMethodSqlDao.class);
transactional.insertPaymentMethod(paymentMethod, context);
+
return transactional.getPaymentMethod(paymentMethod.getId().toString(), context);
}
@@ -188,7 +198,6 @@ public class AuditedPaymentDao implements PaymentDao {
@Override
public void updateRefundStatus(final UUID refundId, final RefundStatus refundStatus, final InternalCallContext context) {
transactionalSqlDao.execute(new EntitySqlDaoTransactionWrapper<Void>() {
-
@Override
public Void inTransaction(final EntitySqlDaoWrapperFactory<EntitySqlDao> entitySqlDaoWrapperFactory) throws Exception {
entitySqlDaoWrapperFactory.become(RefundSqlDao.class).updateStatus(refundId.toString(), refundStatus.toString(), context);
diff --git a/payment/src/main/resources/com/ning/billing/payment/dao/PaymentAttemptSqlDao.sql.stg b/payment/src/main/resources/com/ning/billing/payment/dao/PaymentAttemptSqlDao.sql.stg
index 0d2d50c..7e28a03 100644
--- a/payment/src/main/resources/com/ning/billing/payment/dao/PaymentAttemptSqlDao.sql.stg
+++ b/payment/src/main/resources/com/ning/billing/payment/dao/PaymentAttemptSqlDao.sql.stg
@@ -1,23 +1,31 @@
-group PaymentAttemptSqlDao;
-
-CHECK_TENANT(prefix) ::= "<prefix>tenant_record_id = :tenantRecordId"
-AND_CHECK_TENANT(prefix) ::= "AND <CHECK_TENANT(prefix)>"
+group PaymentAttemptSqlDao: EntitySqlDao;
+
+
+tableFields(prefix) ::= <<
+ <prefix>payment_id
+, <prefix>gateway_error_code
+, <prefix>gateway_error_msg
+, <prefix>processing_status
+, <prefix>requested_amount
+, <prefix>created_by
+, <prefix>created_date
+, <prefix>updated_by
+, <prefix>updated_date
+>>
-paymentAttemptFields(prefix) ::= <<
- <prefix>id,
- <prefix>payment_id,
- <prefix>gateway_error_code,
- <prefix>gateway_error_msg,
- <prefix>processing_status,
- <prefix>requested_amount,
- <prefix>created_by,
- <prefix>created_date,
- <prefix>updated_by,
- <prefix>updated_date,
- <prefix>account_record_id,
- <prefix>tenant_record_id
+tableValues() ::= <<
+ :paymentId
+, :gatewayErrorCode
+, :gatewayErrorMsg
+, :processingStatus
+, :requestedAmount
+, :createdBy
+, :createdDate
+, :updatedBy
+, :updatedDate
>>
+
insertPaymentAttempt() ::= <<
INSERT INTO payment_attempts (<paymentAttemptFields()>)
VALUES (:id, :paymentId, :gatewayErrorCode, :gatewayErrorMsg, :processingStatus, :requestedAmount, :userName,
@@ -60,39 +68,6 @@ updatePaymentAttemptStatus() ::= <<
;
>>
-getRecordId() ::= <<
- SELECT record_id
- FROM payment_attempts
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
->>
-
-getByRecordId() ::= <<
- SELECT <paymentAttemptFields("pa.")>
- , pa.created_date as effective_date
- , p.account_id as account_id
- , p.invoice_id as invoice_id
- FROM payment_attempts pa join payments p
- WHERE pa.record_id = :recordId
- AND pa.payment_id = p.id
- <AND_CHECK_TENANT("pa.")>
- <AND_CHECK_TENANT("p.")>
- ;
->>
-
-getById() ::= <<
- SELECT <paymentAttemptFields("pa.")>
- , pa.created_date as effective_date
- , p.account_id as account_id
- , p.invoice_id as invoice_id
- FROM payment_attempts pa join payments p
- WHERE pa.id = :id
- AND pa.payment_id = p.id
- <AND_CHECK_TENANT("pa.")>
- <AND_CHECK_TENANT("p.")>
- ;
->>
getPaymentAttemptIdFromPaymentId() ::= <<
SELECT id
@@ -101,57 +76,3 @@ getPaymentAttemptIdFromPaymentId() ::= <<
<AND_CHECK_TENANT()>
;
>>
-
-historyFields(prefix) ::= <<
- <prefix>record_id,
- <prefix>id,
- <prefix>payment_id,
- <prefix>gateway_error_code,
- <prefix>gateway_error_msg,
- <prefix>processing_status,
- <prefix>requested_amount,
- <prefix>created_by,
- <prefix>created_date,
- <prefix>updated_by,
- <prefix>updated_date,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertHistoryFromTransaction() ::= <<
- INSERT INTO payment_attempt_history (<historyFields()>)
- VALUES (:recordId, :id, :paymentId, :gatewayErrorCode, :gatewayErrorMsg, :processingStatus, :requestedAmount,
- :userName, :createdDate, :userName, :updatedDate, :accountRecordId, :tenantRecordId);
->>
-
-getHistoryRecordId() ::= <<
- SELECT MAX(history_record_id)
- FROM payment_attempt_history
- WHERE record_id = :recordId
- <AND_CHECK_TENANT()>
- ;
->>
-
-auditFields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<auditFields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
-
-
-
-
-
-
diff --git a/payment/src/main/resources/com/ning/billing/payment/dao/PaymentMethodSqlDao.sql.stg b/payment/src/main/resources/com/ning/billing/payment/dao/PaymentMethodSqlDao.sql.stg
index 8de2123..57d142e 100644
--- a/payment/src/main/resources/com/ning/billing/payment/dao/PaymentMethodSqlDao.sql.stg
+++ b/payment/src/main/resources/com/ning/billing/payment/dao/PaymentMethodSqlDao.sql.stg
@@ -1,27 +1,30 @@
-group PaymentMethodSqlDao;
+group PaymentMethodSqlDao: EntitySqlDao;
-CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
-AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"
-paymentMethodFields(prefix) ::= <<
- <prefix>id,
- <prefix>account_id,
- <prefix>plugin_name,
- <prefix>is_active,
- <prefix>external_id,
- <prefix>created_by,
- <prefix>created_date,
- <prefix>updated_by,
- <prefix>updated_date,
- <prefix>account_record_id,
- <prefix>tenant_record_id
+tableFields(prefix) ::= <<
+ <prefix>account_id
+, <prefix>plugin_name
+, <prefix>is_active
+, <prefix>external_id
+, <prefix>created_by
+, <prefix>created_date
+, <prefix>updated_by
+, <prefix>updated_date
>>
-insertPaymentMethod() ::= <<
- INSERT INTO payment_methods (<paymentMethodFields()>)
- VALUES (:id, :accountId, :pluginName , :isActive, :externalId, :userName, :createdDate, :userName, :createdDate, :accountRecordId, :tenantRecordId);
+tableValues() ::= <<
+ :account_id
+, :plugin_name
+, :is_active
+, :external_id
+, :created_by
+, :created_date
+, :updated_by
+, :updated_date
>>
+historyTableName() ::= "payment_method_history"
+
markPaymentMethodAsDeleted() ::= <<
UPDATE payment_methods
SET is_active = 0
@@ -38,14 +41,6 @@ unmarkPaymentMethodAsDeleted() ::= <<
;
>>
-getPaymentMethod() ::= <<
- SELECT <paymentMethodFields()>
- FROM payment_methods
- WHERE id = :id AND is_active = 1
- <AND_CHECK_TENANT()>
- ;
->>
-
getPaymentMethodIncludedDelete() ::= <<
SELECT <paymentMethodFields()>
FROM payment_methods
@@ -59,71 +54,3 @@ getPaymentMethods() ::= <<
<AND_CHECK_TENANT()>
;
>>
-
-getRecordId() ::= <<
- SELECT record_id
- FROM payment_methods
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
->>
-
-getByRecordId() ::= <<
- SELECT <paymentMethodFields()>
- FROM payment_methods
- WHERE record_id = :recordId <AND_CHECK_TENANT()>;
->>
-
-getById() ::= <<
- SELECT <paymentMethodFields()>
- FROM payment_methods
- WHERE id = :id <AND_CHECK_TENANT()>;
->>
-
-historyFields(prefix) ::= <<
- <prefix>record_id,
- <prefix>id,
- <prefix>account_id,
- <prefix>plugin_name,
- <prefix>is_active,
- <prefix>external_id,
- <prefix>created_by,
- <prefix>created_date,
- <prefix>updated_by,
- <prefix>updated_date,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertHistoryFromTransaction() ::= <<
- INSERT INTO payment_method_history (<historyFields()>)
- VALUES (:recordId, :id, :accountId, :pluginName , :isActive, :externalId ,:userName, :createdDate, :userName, :createdDate, :accountRecordId, :tenantRecordId);
->>
-
-getHistoryRecordId() ::= <<
- SELECT MAX(history_record_id)
- FROM payment_method_history
- WHERE record_id = :recordId
- <AND_CHECK_TENANT()>
- ;
->>
-
-auditFields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<auditFields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
-
-
diff --git a/payment/src/main/resources/com/ning/billing/payment/dao/PaymentSqlDao.sql.stg b/payment/src/main/resources/com/ning/billing/payment/dao/PaymentSqlDao.sql.stg
index c789dd4..9ea7322 100644
--- a/payment/src/main/resources/com/ning/billing/payment/dao/PaymentSqlDao.sql.stg
+++ b/payment/src/main/resources/com/ning/billing/payment/dao/PaymentSqlDao.sql.stg
@@ -1,35 +1,41 @@
-group PaymentSqlDao;
-
-CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
-AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"
-
-paymentFields(prefix) ::= <<
- <prefix>id,
- <prefix>account_id,
- <prefix>invoice_id,
- <prefix>payment_method_id,
- <prefix>amount,
- <prefix>effective_date,
- <prefix>currency,
- <prefix>payment_status,
- <prefix>ext_first_payment_ref_id,
- <prefix>ext_second_payment_ref_id,
- <prefix>created_by,
- <prefix>created_date,
- <prefix>updated_by,
- <prefix>updated_date,
- <prefix>account_record_id,
- <prefix>tenant_record_id
+group PaymentSqlDao: EntitySqlDao;
+
+
+tableFields(prefix) ::= <<
+ <prefix>account_id
+, <prefix>invoice_id
+, <prefix>payment_method_id
+, <prefix>amount
+, <prefix>effective_date
+, <prefix>currency
+, <prefix>payment_status
+, <prefix>ext_first_payment_ref_id
+, <prefix>ext_second_payment_ref_id
+, <prefix>created_by
+, <prefix>created_date
+, <prefix>updated_by
+, <prefix>updated_date
>>
-insertPayment() ::= <<
- INSERT INTO payments (<paymentFields()>)
- VALUES (:id, :accountId, :invoiceId, :paymentMethodId, :amount, :effectiveDate, :currency, :paymentStatus,
- :extFirstPaymentRefId, :extSecondPaymentRefId, :userName, :createdDate, :userName, :createdDate, :accountRecordId, :tenantRecordId);
+tableValues() ::= <<
+ :account_id
+, :invoice_id
+, :payment_method_id
+, :amount
+, :effective_date
+, :currency
+, :payment_status
+, :ext_first_payment_ref_id
+, :ext_second_payment_ref_id
+, :created_by
+, :created_date
+, :updated_by
+, :updated_date
>>
+
getPayment() ::= <<
- SELECT <paymentFields()>
+ SELECT <tableFields()>
, record_id as payment_number
FROM payments
WHERE id = :id
@@ -83,76 +89,5 @@ updatePaymentAmount() ::= <<
;
>>
-getRecordId() ::= <<
- SELECT record_id
- FROM payments
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
->>
-
-getByRecordId() ::= <<
- SELECT <paymentFields()>, record_id as payment_number
- FROM payments
- WHERE record_id = :recordId <AND_CHECK_TENANT()>;
->>
-
-getById() ::= <<
- SELECT <paymentFields()>, record_id as payment_number
- FROM payments
- WHERE id = :id <AND_CHECK_TENANT()>;
->>
-
-historyFields(prefix) ::= <<
- <prefix>record_id,
- <prefix>id,
- <prefix>account_id,
- <prefix>invoice_id,
- <prefix>payment_method_id,
- <prefix>amount,
- <prefix>effective_date,
- <prefix>currency,
- <prefix>payment_status,
- <prefix>ext_first_payment_ref_id,
- <prefix>ext_second_payment_ref_id,
- <prefix>created_by,
- <prefix>created_date,
- <prefix>updated_by,
- <prefix>updated_date,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertHistoryFromTransaction() ::= <<
- INSERT INTO payment_history (<historyFields()>)
- VALUES (:recordId, :id, :accountId, :invoiceId, :paymentMethodId, :amount, :effectiveDate, :currency, :paymentStatus,
- :extFirstPaymentRefId, :extSecondPaymentRefId, :userName, :createdDate, :userName, :updatedDate, :accountRecordId, :tenantRecordId);
->>
-
-
-getHistoryRecordId() ::= <<
- SELECT MAX(history_record_id)
- FROM payment_history
- WHERE record_id = :recordId
- <AND_CHECK_TENANT()>
- ;
->>
-
-auditFields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<auditFields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
+historyTableName() ::= "payment_history"
diff --git a/payment/src/main/resources/com/ning/billing/payment/dao/RefundSqlDao.sql.stg b/payment/src/main/resources/com/ning/billing/payment/dao/RefundSqlDao.sql.stg
index 295cb8c..2f9f7e7 100644
--- a/payment/src/main/resources/com/ning/billing/payment/dao/RefundSqlDao.sql.stg
+++ b/payment/src/main/resources/com/ning/billing/payment/dao/RefundSqlDao.sql.stg
@@ -1,4 +1,4 @@
-group RefundSqlDao;
+group RefundSqlDao : EntitySqlDao;
CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"
@@ -57,71 +57,4 @@ getRefundsForAccount() ::= <<
;
>>
-getRecordId() ::= <<
- SELECT record_id
- FROM refunds
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
->>
-
-getByRecordId() ::= <<
- SELECT <refundFields()>
- FROM refunds
- WHERE record_id = :recordId <AND_CHECK_TENANT()>;
->>
-
-getById() ::= <<
- SELECT <refundFields()>
- FROM refunds
- WHERE id = :id <AND_CHECK_TENANT()>;
->>
-
-historyFields(prefix) ::= <<
- <prefix>record_id,
- <prefix>id,
- <prefix>account_id,
- <prefix>payment_id,
- <prefix>amount,
- <prefix>currency,
- <prefix>is_adjusted,
- <prefix>refund_status,
- <prefix>created_by,
- <prefix>created_date,
- <prefix>updated_by,
- <prefix>updated_date,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertHistoryFromTransaction() ::= <<
- INSERT INTO refund_history (<historyFields()>)
- VALUES (:recordId, :id, :accountId, :paymentId, :amount, :currency, :isAdjusted, :refundStatus, :userName,
- :createdDate, :userName, :createdDate, :accountRecordId, :tenantRecordId);
->>
-
-getHistoryRecordId() ::= <<
- SELECT MAX(history_record_id)
- FROM payment_method_history
- WHERE record_id = :recordId
- <AND_CHECK_TENANT()>
- ;
->>
-auditFields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<auditFields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
diff --git a/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java b/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java
index e279a76..d62af59 100644
--- a/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java
+++ b/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java
@@ -54,10 +54,8 @@ public class TestPaymentDao extends PaymentTestSuiteWithEmbeddedDB {
@BeforeSuite(groups = "slow")
public void setup() throws IOException {
clock = new DefaultClock();
-
setupDb();
-
- paymentDao = new AuditedPaymentDao(dbi, null);
+ paymentDao = new AuditedPaymentDao(dbi, null, clock);
}
private void setupDb() {
diff --git a/util/src/main/java/com/ning/billing/util/audit/dao/DefaultAuditDao.java b/util/src/main/java/com/ning/billing/util/audit/dao/DefaultAuditDao.java
index de92fc6..926ddfd 100644
--- a/util/src/main/java/com/ning/billing/util/audit/dao/DefaultAuditDao.java
+++ b/util/src/main/java/com/ning/billing/util/audit/dao/DefaultAuditDao.java
@@ -65,21 +65,21 @@ public class DefaultAuditDao implements AuditDao {
final List<AuditLog> auditLogs = new ArrayList<AuditLog>();
// Look at the history table and gather all the history_record_id for that objectId
- final List<Long> recordIds = auditSqlDao.getHistoryRecordIdsForTable(tableName.getHistoryTableName().getTableName().toLowerCase(),
+ final List<Long> targetRecordIds = auditSqlDao.getHistoryRecordIdsForTable(tableName.getHistoryTableName().getTableName().toLowerCase(),
objectId.toString(), context);
- if (recordIds == null) {
+ if (targetRecordIds == null) {
return auditLogs;
} else {
- for (final Long recordId : recordIds) {
- auditLogs.addAll(getAuditLogsForRecordId(tableName.getHistoryTableName(), recordId, auditLevel, context));
+ for (final Long targetRecordId : targetRecordIds) {
+ auditLogs.addAll(getAuditLogsForRecordId(tableName.getHistoryTableName(), targetRecordId, auditLevel, context));
}
return auditLogs;
}
}
- private List<AuditLog> getAuditLogsForRecordId(final TableName tableName, final Long recordId, final AuditLevel auditLevel, final InternalTenantContext context) {
- final List<AuditLog> allAuditLogs = auditSqlDao.getAuditLogsForRecordId(tableName, recordId, context);
+ private List<AuditLog> getAuditLogsForRecordId(final TableName tableName, final Long targetRecordId, final AuditLevel auditLevel, final InternalTenantContext context) {
+ final List<AuditLog> allAuditLogs = auditSqlDao.getAuditLogsForTargetRecordId(tableName, targetRecordId, context);
if (AuditLevel.FULL.equals(auditLevel)) {
return allAuditLogs;
} else if (AuditLevel.MINIMAL.equals(auditLevel) && allAuditLogs.size() > 0) {
diff --git a/util/src/main/java/com/ning/billing/util/audit/DefaultAuditLog.java b/util/src/main/java/com/ning/billing/util/audit/DefaultAuditLog.java
index ebc7dfd..233cd32 100644
--- a/util/src/main/java/com/ning/billing/util/audit/DefaultAuditLog.java
+++ b/util/src/main/java/com/ning/billing/util/audit/DefaultAuditLog.java
@@ -21,20 +21,15 @@ import org.joda.time.DateTime;
import com.ning.billing.util.callcontext.CallContext;
import com.ning.billing.util.dao.EntityAudit;
-public class DefaultAuditLog implements AuditLog {
+public class DefaultAuditLog extends EntityAudit implements AuditLog {
- private final EntityAudit entityAudit;
private final CallContext callContext;
public DefaultAuditLog(final EntityAudit entityAudit, final CallContext callContext) {
- this.entityAudit = entityAudit;
+ super(entityAudit.getId(), entityAudit.getTableName(), entityAudit.getTargetRecordId(), entityAudit.getChangeType(), entityAudit.getCreatedDate());
this.callContext = callContext;
}
- @Override
- public ChangeType getChangeType() {
- return entityAudit.getChangeType();
- }
@Override
public String getUserName() {
@@ -68,38 +63,10 @@ public class DefaultAuditLog implements AuditLog {
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
- sb.append("DefaultAuditLog");
- sb.append("{entityAudit=").append(entityAudit);
+ sb.append("DefaultAuditLog {");
+ sb.append(super.toString());
sb.append(", callContext=").append(callContext);
sb.append('}');
return sb.toString();
}
-
- @Override
- public boolean equals(final Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- final DefaultAuditLog that = (DefaultAuditLog) o;
-
- if (callContext != null ? !callContext.equals(that.callContext) : that.callContext != null) {
- return false;
- }
- if (entityAudit != null ? !entityAudit.equals(that.entityAudit) : that.entityAudit != null) {
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = entityAudit != null ? entityAudit.hashCode() : 0;
- result = 31 * result + (callContext != null ? callContext.hashCode() : 0);
- return result;
- }
}
diff --git a/util/src/main/java/com/ning/billing/util/customfield/dao/AuditedCustomFieldDao.java b/util/src/main/java/com/ning/billing/util/customfield/dao/AuditedCustomFieldDao.java
index 1f66082..da14fa8 100644
--- a/util/src/main/java/com/ning/billing/util/customfield/dao/AuditedCustomFieldDao.java
+++ b/util/src/main/java/com/ning/billing/util/customfield/dao/AuditedCustomFieldDao.java
@@ -20,6 +20,7 @@ import org.skife.jdbi.v2.IDBI;
import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
import com.ning.billing.util.callcontext.InternalTenantContext;
+import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.customfield.CustomField;
import com.ning.billing.util.dao.AuditedCollectionDaoBase;
import com.ning.billing.util.dao.TableName;
@@ -32,7 +33,8 @@ public class AuditedCustomFieldDao extends AuditedCollectionDaoBase<CustomField,
private final CustomFieldSqlDao dao;
@Inject
- public AuditedCustomFieldDao(final IDBI dbi) {
+ public AuditedCustomFieldDao(final IDBI dbi, final Clock clock) {
+ super(clock);
dao = dbi.onDemand(CustomFieldSqlDao.class);
}
@@ -93,7 +95,7 @@ public class AuditedCustomFieldDao extends AuditedCollectionDaoBase<CustomField,
// List<Mapper> recordIds = customFieldSqlDao.getRecordIds(objectId.toString(), objectType);
// Map<UUID, Long> recordIdMap = new HashMap<UUID, Long>();
// for (Mapper recordId : recordIds) {
- // recordIdMap.put(recordId.getId(), recordId.getRecordId());
+ // recordIdMap.put(recordId.getId(), recordId.getTargetRecordId());
// }
//
// customFieldSqlDao.batchDeleteFromTransaction(objectId.toString(), objectType, existingFields, context);
diff --git a/util/src/main/java/com/ning/billing/util/customfield/StringCustomField.java b/util/src/main/java/com/ning/billing/util/customfield/StringCustomField.java
index 4458801..4a3bf51 100644
--- a/util/src/main/java/com/ning/billing/util/customfield/StringCustomField.java
+++ b/util/src/main/java/com/ning/billing/util/customfield/StringCustomField.java
@@ -21,7 +21,7 @@ import java.util.UUID;
import com.ning.billing.util.entity.Entity;
import com.ning.billing.util.entity.EntityBase;
-public class StringCustomField extends EntityBase implements CustomField, Entity {
+public class StringCustomField extends EntityBase implements CustomField {
private final String name;
private String value;
diff --git a/util/src/main/java/com/ning/billing/util/dao/AuditBinder.java b/util/src/main/java/com/ning/billing/util/dao/AuditBinder.java
index 179a670..51d4c4d 100644
--- a/util/src/main/java/com/ning/billing/util/dao/AuditBinder.java
+++ b/util/src/main/java/com/ning/billing/util/dao/AuditBinder.java
@@ -37,8 +37,9 @@ public @interface AuditBinder {
return new Binder<AuditBinder, EntityAudit>() {
@Override
public void bind(final SQLStatement q, final AuditBinder bind, final EntityAudit audit) {
+ q.bind("id", audit.getId().toString());
q.bind("tableName", audit.getTableName().toString());
- q.bind("recordId", audit.getRecordId());
+ q.bind("targetRecordId", audit.getTargetRecordId());
q.bind("changeType", audit.getChangeType().toString());
}
};
diff --git a/util/src/main/java/com/ning/billing/util/dao/AuditedCollectionDaoBase.java b/util/src/main/java/com/ning/billing/util/dao/AuditedCollectionDaoBase.java
index 4a204b7..69b4f30 100644
--- a/util/src/main/java/com/ning/billing/util/dao/AuditedCollectionDaoBase.java
+++ b/util/src/main/java/com/ning/billing/util/dao/AuditedCollectionDaoBase.java
@@ -24,12 +24,14 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
+import org.joda.time.DateTime;
import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
import com.ning.billing.ObjectType;
import com.ning.billing.util.audit.ChangeType;
import com.ning.billing.util.callcontext.InternalCallContext;
import com.ning.billing.util.callcontext.InternalTenantContext;
+import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.entity.Entity;
import com.ning.billing.util.entity.collection.dao.UpdatableEntityCollectionSqlDao;
@@ -37,6 +39,13 @@ import com.google.common.collect.Sets;
public abstract class AuditedCollectionDaoBase<T extends Entity, V> implements AuditedCollectionDao<T> {
+
+ protected final Clock clock;
+
+ public AuditedCollectionDaoBase( final Clock clock) {
+ this.clock = clock;
+ }
+
/**
* Returns equivalence object for the entities, so that dao
* can figure out if entities have changed (UPDATE statement) or
@@ -191,7 +200,7 @@ public abstract class AuditedCollectionDaoBase<T extends Entity, V> implements A
for (final EntityHistory<T> history : histories) {
final Long recordId = history.getValue();
final Long historyRecordId = historyRecordIds.get(recordId);
- audits.add(new EntityAudit(getTableName(context), historyRecordId, history.getChangeType()));
+ audits.add(new EntityAudit(getTableName(context), historyRecordId, history.getChangeType(), clock.getUTCNow()));
}
return audits;
diff --git a/util/src/main/java/com/ning/billing/util/dao/AuditLogMapper.java b/util/src/main/java/com/ning/billing/util/dao/AuditLogMapper.java
index 94e8e92..418ce29 100644
--- a/util/src/main/java/com/ning/billing/util/dao/AuditLogMapper.java
+++ b/util/src/main/java/com/ning/billing/util/dao/AuditLogMapper.java
@@ -34,18 +34,19 @@ public class AuditLogMapper extends MapperBase implements ResultSetMapper<AuditL
@Override
public AuditLog map(final int index, final ResultSet r, final StatementContext ctx) throws SQLException {
+ final UUID id = getUUID(r, "id");
final String tableName = r.getString("table_name");
- final long recordId = r.getLong("record_id");
+ final long targetRecordId = r.getLong("target_record_id");
final String changeType = r.getString("change_type");
- final DateTime changeDate = getDateTime(r, "change_date");
+ final DateTime createdDate = getDateTime(r, "created_date");
final String changedBy = r.getString("changed_by");
final String reasonCode = r.getString("reason_code");
final String comments = r.getString("comments");
final UUID userToken = getUUID(r, "user_token");
- final EntityAudit entityAudit = new EntityAudit(TableName.valueOf(tableName), recordId, ChangeType.valueOf(changeType));
+ final EntityAudit entityAudit = new EntityAudit(id, TableName.valueOf(tableName), targetRecordId, ChangeType.valueOf(changeType), createdDate);
// TODO - we have the tenant_record_id but not the tenant id here
- final CallContext callContext = new DefaultCallContext(null, changedBy, changeDate, reasonCode, comments, userToken);
+ final CallContext callContext = new DefaultCallContext(null, changedBy, createdDate, reasonCode, comments, userToken);
return new DefaultAuditLog(entityAudit, callContext);
}
}
diff --git a/util/src/main/java/com/ning/billing/util/dao/AuditSqlDao.java b/util/src/main/java/com/ning/billing/util/dao/AuditSqlDao.java
index a4540b6..5ec8499 100644
--- a/util/src/main/java/com/ning/billing/util/dao/AuditSqlDao.java
+++ b/util/src/main/java/com/ning/billing/util/dao/AuditSqlDao.java
@@ -44,9 +44,9 @@ public interface AuditSqlDao {
@InternalTenantContextBinder final InternalCallContext context);
@SqlQuery
- public List<AuditLog> getAuditLogsForRecordId(@TableNameBinder final TableName tableName,
- @Bind("recordId") final long recordId,
- @InternalTenantContextBinder final InternalTenantContext context);
+ public List<AuditLog> getAuditLogsForTargetRecordId(@TableNameBinder final TableName tableName,
+ @Bind("targetRecordId") final long targetRecordId,
+ @InternalTenantContextBinder final InternalTenantContext context);
@SqlQuery
public Long getRecordId(@Bind("id") final String id, @InternalTenantContextBinder final InternalTenantContext context);
diff --git a/util/src/main/java/com/ning/billing/util/dao/EntityAudit.java b/util/src/main/java/com/ning/billing/util/dao/EntityAudit.java
index 25930c7..a76d208 100644
--- a/util/src/main/java/com/ning/billing/util/dao/EntityAudit.java
+++ b/util/src/main/java/com/ning/billing/util/dao/EntityAudit.java
@@ -16,28 +16,48 @@
package com.ning.billing.util.dao;
+import java.util.UUID;
+
+import org.joda.time.DateTime;
+
import com.ning.billing.util.audit.ChangeType;
+import com.ning.billing.util.entity.EntityBase;
-public class EntityAudit {
+public class EntityAudit extends EntityBase {
+
private final TableName tableName;
- private final Long recordId;
+ private final Long targetRecordId;
private final ChangeType changeType;
- public EntityAudit(final TableName tableName, final Long recordId, final ChangeType changeType) {
+ public EntityAudit(final UUID entityId, final TableName tableName, final Long targetRecordId, final ChangeType changeType, final DateTime createdDate) {
+ super(entityId, createdDate, null);
this.tableName = tableName;
- this.recordId = recordId;
+ this.targetRecordId = targetRecordId;
this.changeType = changeType;
+
+ }
+ public EntityAudit(final TableName tableName, final Long targetRecordId, final ChangeType changeType, final DateTime createdDate) {
+ this(UUID.randomUUID(), tableName, targetRecordId, changeType, createdDate);
}
public TableName getTableName() {
return tableName;
}
- public Long getRecordId() {
- return recordId;
+ public Long getTargetRecordId() {
+ return targetRecordId;
}
public ChangeType getChangeType() {
return changeType;
}
+
+ @Override
+ public String toString() {
+ return "EntityAudit{" +
+ "tableName=" + tableName +
+ ", targetRecordId=" + targetRecordId +
+ ", changeType=" + changeType +
+ '}';
+ }
}
diff --git a/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDaoWrapperInvocationHandler.java b/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDaoWrapperInvocationHandler.java
index 218e285..7502ef7 100644
--- a/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDaoWrapperInvocationHandler.java
+++ b/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDaoWrapperInvocationHandler.java
@@ -228,7 +228,8 @@ public class EntitySqlDaoWrapperInvocationHandler<T extends EntitySqlDao<U>, U e
}
private void insertAudits(final TableName tableName, final Long historyRecordId, final ChangeType changeType, final InternalCallContext context) {
- final EntityAudit audit = new EntityAudit(tableName, historyRecordId, changeType);
+ // STEPH can we trust context or should we use Clock?
+ final EntityAudit audit = new EntityAudit(tableName, historyRecordId, changeType, context.getCreatedDate());
sqlDao.insertAuditFromTransaction(audit, context);
}
}
diff --git a/util/src/main/java/com/ning/billing/util/tag/dao/AuditedTagDao.java b/util/src/main/java/com/ning/billing/util/tag/dao/AuditedTagDao.java
index 9c0e632..4638e3b 100644
--- a/util/src/main/java/com/ning/billing/util/tag/dao/AuditedTagDao.java
+++ b/util/src/main/java/com/ning/billing/util/tag/dao/AuditedTagDao.java
@@ -36,6 +36,7 @@ import com.ning.billing.util.api.TagDefinitionApiException;
import com.ning.billing.util.audit.ChangeType;
import com.ning.billing.util.callcontext.InternalCallContext;
import com.ning.billing.util.callcontext.InternalTenantContext;
+import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.dao.AuditedCollectionDaoBase;
import com.ning.billing.util.dao.EntityAudit;
import com.ning.billing.util.dao.EntityHistory;
@@ -61,7 +62,8 @@ public class AuditedTagDao extends AuditedCollectionDaoBase<Tag, Tag> implements
private final InternalBus bus;
@Inject
- public AuditedTagDao(final IDBI dbi, final TagEventBuilder tagEventBuilder, final InternalBus bus) {
+ public AuditedTagDao(final IDBI dbi, final TagEventBuilder tagEventBuilder, final InternalBus bus, final Clock clock) {
+ super(clock);
this.tagEventBuilder = tagEventBuilder;
this.bus = bus;
this.tagSqlDao = dbi.onDemand(TagSqlDao.class);
diff --git a/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg
index 9c6ff53..bc67f46 100644
--- a/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg
@@ -1,12 +1,5 @@
-group CustomFieldSqlDao;
+group CustomFieldSqlDao : EntitySqlDao;
-CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
-AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"
-
-insertFromTransaction() ::= <<
- INSERT INTO custom_fields(id, object_id, object_type, field_name, field_value, created_by, created_date, updated_by, updated_date, account_record_id, tenant_record_id)
- VALUES (:id, :objectId, :objectType, :fieldName, :fieldValue, :userName, :createdDate, :userName, :updatedDate, :accountRecordId, :tenantRecordId);
->>
updateFromTransaction() ::= <<
UPDATE custom_fields
@@ -23,76 +16,3 @@ deleteFromTransaction() ::= <<
;
>>
-load() ::= <<
- SELECT id, object_id, object_type, field_name, field_value, created_by, created_date, updated_by, updated_date
- FROM custom_fields
- WHERE object_id = :objectId AND object_type = :objectType
- <AND_CHECK_TENANT()>
- ;
->>
-
-getRecordIds() ::= <<
- SELECT record_id, id
- FROM custom_fields
- WHERE object_id = :objectId AND object_type = :objectType
- <AND_CHECK_TENANT()>
- ;
->>
-
-historyFields(prefix) ::= <<
- <prefix>record_id,
- <prefix>id,
- <prefix>object_id,
- <prefix>object_type,
- <prefix>field_name,
- <prefix>field_value,
- <prefix>updated_by,
- <prefix>date,
- <prefix>change_type,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-addHistoryFromTransaction() ::= <<
- INSERT INTO custom_field_history(<historyFields()>)
- VALUES(:recordId, :id, :objectId, :objectType, :fieldName, :fieldValue, :userName, :updatedDate, :changeType, :accountRecordId, :tenantRecordId);
->>
-
-getMaxHistoryRecordId() ::= <<
- SELECT MAX(history_record_id)
- FROM custom_field_history
- WHERE <CHECK_TENANT()>
- ;
->>
-
-getHistoryRecordIds() ::= <<
- SELECT history_record_id, record_id
- FROM custom_field_history
- WHERE history_record_id > :maxHistoryRecordId
- <AND_CHECK_TENANT()>
- ;
->>
-
-auditFields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<auditFields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
-
-test() ::= <<
- SELECT 1 FROM custom_fields WHERE <CHECK_TENANT()>;
->>
-;
-
diff --git a/util/src/main/resources/com/ning/billing/util/dao/AuditSqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/dao/AuditSqlDao.sql.stg
index 7bf93e4..2c237e7 100644
--- a/util/src/main/resources/com/ning/billing/util/dao/AuditSqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/dao/AuditSqlDao.sql.stg
@@ -1,30 +1,13 @@
-group AuditSqlDao;
+group AuditSqlDao : EntitySqlDao;
CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"
-fields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<fields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
getAuditLogsForRecordId() ::= <<
- SELECT <fields()>
+ SELECT <auditTableFields()>
FROM audit_log
- WHERE record_id = :recordId
+ WHERE target_record_id = :targetRecordId
AND table_name = :tableName
<AND_CHECK_TENANT()>
ORDER BY change_date ASC
diff --git a/util/src/main/resources/com/ning/billing/util/dao/EntitySqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/dao/EntitySqlDao.sql.stg
index da86faf..6d3b9e4 100644
--- a/util/src/main/resources/com/ning/billing/util/dao/EntitySqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/dao/EntitySqlDao.sql.stg
@@ -50,8 +50,10 @@ allTableFields(prefix) ::= <<
, <tenantRecordIdField(prefix)>
>>
+/** TODO history tables should not start with history_record_id, instead: record_id, id, target_record_id **/
allHistoryTableFields(prefix) ::= <<
- <recordIdField(prefix)>
+ <historyRecordIdField(prefix)>
+, <recordIdField(prefix)>
, <idField(prefix)>
, <historyTableFields(prefix)>
<if(accountRecordIdField(prefix))>, <accountRecordIdField(prefix)><endif>
@@ -68,28 +70,32 @@ allHistoryTableValues() ::= <<
auditTableName() ::= "audit_log"
+
auditTableFields(prefix) ::= <<
- <prefix>table_name
-, <prefix>record_id
+ <prefix>id
+, <prefix>table_name
+, <prefix>target_record_id
, <prefix>change_type
-, <prefix>change_date
, <prefix>changed_by
, <prefix>reason_code
, <prefix>comments
, <prefix>user_token
+, <prefix>created_date
, <accountRecordIdField(prefix)>
, <tenantRecordIdField(prefix)>
>>
+
auditTableValues(prefix) ::= <<
- :table_name
-, :record_id
-, :change_type
-, :change_date
-, :changed_by
-, :reason_code
-, :comments
-, :user_token
+ :id
+, :tableName
+, :targetRecordId
+, :changeType
+, :changedBy
+, :reasonCode
+, :comment
+, :userToken
+, :createdDate
, <accountRecordIdValue()>
, <tenantRecordIdValue()>
>>
@@ -170,4 +176,4 @@ values (
<auditTableValues()>
)
;
->>
\ No newline at end of file
+>>
diff --git a/util/src/main/resources/com/ning/billing/util/ddl.sql b/util/src/main/resources/com/ning/billing/util/ddl.sql
index 980d9c9..25758e8 100644
--- a/util/src/main/resources/com/ning/billing/util/ddl.sql
+++ b/util/src/main/resources/com/ning/billing/util/ddl.sql
@@ -150,20 +150,21 @@ CREATE INDEX claimed_notifications_tenant_account_record_id ON claimed_notificat
DROP TABLE IF EXISTS audit_log;
CREATE TABLE audit_log (
- id int(11) unsigned NOT NULL AUTO_INCREMENT,
+ record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+ id char(36) NOT NULL,
table_name varchar(50) NOT NULL,
- record_id int(11) NOT NULL,
+ target_record_id int(11) NOT NULL,
change_type char(6) NOT NULL,
- change_date datetime NOT NULL,
changed_by varchar(50) NOT NULL,
reason_code varchar(255) DEFAULT NULL,
comments varchar(255) DEFAULT NULL,
user_token char(36),
+ created_date datetime NOT NULL,
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
- PRIMARY KEY(id)
+ PRIMARY KEY(record_id)
) ENGINE=innodb;
-CREATE INDEX audit_log_fetch_record ON audit_log(table_name, record_id);
+CREATE INDEX audit_log_fetch_target_record_id ON audit_log(table_name, target_record_id);
CREATE INDEX audit_log_user_name ON audit_log(changed_by);
CREATE INDEX audit_log_tenant_account_record_id ON audit_log(tenant_record_id, account_record_id);
diff --git a/util/src/main/resources/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.sql.stg
index 0a869f5..151c68d 100644
--- a/util/src/main/resources/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.sql.stg
@@ -1,7 +1,5 @@
-group TagDefinitionDao;
+group TagDefinitionDao : EntitySqlDao;
-CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
-AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"
fields(prefix) ::= <<
<prefix>id,
@@ -14,26 +12,6 @@ fields(prefix) ::= <<
<prefix>tenant_record_id
>>
-get() ::= <<
- SELECT <fields()>
- FROM tag_definitions
- WHERE <CHECK_TENANT()>
- ;
->>
-
-create() ::= <<
- INSERT INTO tag_definitions(<fields()>)
- VALUES(:id, :name, :description, :userName, :createdDate, :userName, :updatedDate, :tenantRecordId);
->>
-
-load() ::= <<
- SELECT <fields()>
- FROM tag_definitions
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
->>
-
deleteTagDefinition() ::= <<
DELETE FROM tag_definitions
@@ -57,73 +35,3 @@ getByName() ::= <<
;
>>
-getRecordId() ::= <<
- SELECT record_id
- FROM tag_definitions
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
->>
-
-getByRecordId() ::= <<
- SELECT <fields()>
- FROM tag_definitions
- WHERE record_id = :recordId <AND_CHECK_TENANT()>
- ;
->>
-
-getHistoryRecordId() ::= <<
- SELECT MAX(history_record_id)
- FROM tag_definition_history
- WHERE record_id = :recordId <AND_CHECK_TENANT()>;
->>
-
-getById() ::= <<
- SELECT <fields()>
- FROM tag_definitions
- WHERE id = :id
- <AND_CHECK_TENANT()>
- ;
->>
-
-getByIds(tag_definition_ids) ::= <<
- SELECT <fields()>
- FROM tag_definitions
- WHERE id IN (<tag_definition_ids: {id | :id_<i0>}; separator="," >)
- <AND_CHECK_TENANT()>
->>
-
-auditFields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
-
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<auditFields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
-
-historyFields() ::= <<
- record_id,
- id,
- name,
- created_by,
- description,
- change_type,
- updated_by,
- date,
- tenant_record_id
->>
-
-addHistoryFromTransaction() ::= <<
- INSERT INTO tag_definition_history(<historyFields()>)
- VALUES (:recordId, :id, :name, :userName, :description, :changeType, :userName, :createdDate, :tenantRecordId);
->>
diff --git a/util/src/main/resources/com/ning/billing/util/tag/dao/TagSqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/tag/dao/TagSqlDao.sql.stg
index a1a674d..d738ae8 100644
--- a/util/src/main/resources/com/ning/billing/util/tag/dao/TagSqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/tag/dao/TagSqlDao.sql.stg
@@ -89,18 +89,6 @@ getHistoryRecordIds() ::= <<
;
>>
-auditFields(prefix) ::= <<
- <prefix>table_name,
- <prefix>record_id,
- <prefix>change_type,
- <prefix>change_date,
- <prefix>changed_by,
- <prefix>reason_code,
- <prefix>comments,
- <prefix>user_token,
- <prefix>account_record_id,
- <prefix>tenant_record_id
->>
load() ::= <<
SELECT <fields()>
@@ -109,10 +97,6 @@ load() ::= <<
<AND_CHECK_TENANT()>;
>>
-insertAuditFromTransaction() ::= <<
- INSERT INTO audit_log(<auditFields()>)
- VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken, :accountRecordId, :tenantRecordId);
->>
test() ::= <<
SELECT 1 FROM tags WHERE <CHECK_TENANT()>;
diff --git a/util/src/test/java/com/ning/billing/util/audit/TestDefaultAuditLog.java b/util/src/test/java/com/ning/billing/util/audit/TestDefaultAuditLog.java
index a6fa217..db78585 100644
--- a/util/src/test/java/com/ning/billing/util/audit/TestDefaultAuditLog.java
+++ b/util/src/test/java/com/ning/billing/util/audit/TestDefaultAuditLog.java
@@ -37,7 +37,7 @@ public class TestDefaultAuditLog extends UtilTestSuite {
final TableName tableName = TableName.ACCOUNT_EMAIL_HISTORY;
final long recordId = Long.MAX_VALUE;
final ChangeType changeType = ChangeType.DELETE;
- final EntityAudit entityAudit = new EntityAudit(tableName, recordId, changeType);
+ final EntityAudit entityAudit = new EntityAudit(tableName, recordId, changeType, null);
final UUID tenantId = UUID.randomUUID();
final String userName = UUID.randomUUID().toString();
@@ -61,7 +61,7 @@ public class TestDefaultAuditLog extends UtilTestSuite {
final TableName tableName = TableName.ACCOUNT_EMAIL_HISTORY;
final long recordId = Long.MAX_VALUE;
final ChangeType changeType = ChangeType.DELETE;
- final EntityAudit entityAudit = new EntityAudit(tableName, recordId, changeType);
+ final EntityAudit entityAudit = new EntityAudit(tableName, recordId, changeType, null);
final UUID tenantId = UUID.randomUUID();
final String userName = UUID.randomUUID().toString();
diff --git a/util/src/test/java/com/ning/billing/util/customfield/api/TestDefaultCustomFieldUserApi.java b/util/src/test/java/com/ning/billing/util/customfield/api/TestDefaultCustomFieldUserApi.java
index 79afb13..ad9e6a4 100644
--- a/util/src/test/java/com/ning/billing/util/customfield/api/TestDefaultCustomFieldUserApi.java
+++ b/util/src/test/java/com/ning/billing/util/customfield/api/TestDefaultCustomFieldUserApi.java
@@ -31,6 +31,7 @@ import com.ning.billing.ObjectType;
import com.ning.billing.util.UtilTestSuiteWithEmbeddedDB;
import com.ning.billing.util.callcontext.InternalCallContextFactory;
import com.ning.billing.util.clock.ClockMock;
+import com.ning.billing.util.clock.DefaultClock;
import com.ning.billing.util.customfield.CustomField;
import com.ning.billing.util.customfield.StringCustomField;
import com.ning.billing.util.customfield.dao.AuditedCustomFieldDao;
@@ -45,7 +46,7 @@ public class TestDefaultCustomFieldUserApi extends UtilTestSuiteWithEmbeddedDB {
@BeforeMethod(groups = "slow")
public void setUp() throws Exception {
final InternalCallContextFactory internalCallContextFactory = new InternalCallContextFactory(getMysqlTestingHelper().getDBI(), new ClockMock());
- final CustomFieldDao customFieldDao = new AuditedCustomFieldDao(getMysqlTestingHelper().getDBI());
+ final CustomFieldDao customFieldDao = new AuditedCustomFieldDao(getMysqlTestingHelper().getDBI(), new DefaultClock());
customFieldUserApi = new DefaultCustomFieldUserApi(internalCallContextFactory, customFieldDao);
}
diff --git a/util/src/test/java/com/ning/billing/util/customfield/TestFieldStore.java b/util/src/test/java/com/ning/billing/util/customfield/TestFieldStore.java
index 24fcde1..3f10449 100644
--- a/util/src/test/java/com/ning/billing/util/customfield/TestFieldStore.java
+++ b/util/src/test/java/com/ning/billing/util/customfield/TestFieldStore.java
@@ -29,6 +29,7 @@ import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.ObjectType;
import com.ning.billing.dbi.MysqlTestingHelper;
import com.ning.billing.util.UtilTestSuiteWithEmbeddedDB;
+import com.ning.billing.util.clock.DefaultClock;
import com.ning.billing.util.customfield.dao.AuditedCustomFieldDao;
import com.ning.billing.util.customfield.dao.CustomFieldDao;
import com.ning.billing.util.customfield.dao.CustomFieldSqlDao;
@@ -46,7 +47,7 @@ public class TestFieldStore extends UtilTestSuiteWithEmbeddedDB {
protected void setup() throws IOException {
try {
dbi = helper.getDBI();
- customFieldDao = new AuditedCustomFieldDao(dbi);
+ customFieldDao = new AuditedCustomFieldDao(dbi, new DefaultClock());
} catch (Throwable t) {
log.error("Setup failed", t);
fail(t.toString());