killbill-memoizeit
Changes
entitlement/src/main/resources/com/ning/billing/entitlement/dao/BlockingStateSqlDao.sql.stg 12(+8 -4)
subscription/src/main/resources/com/ning/billing/subscription/engine/dao/BundleSqlDao.sql.stg 6(+3 -3)
subscription/src/main/resources/com/ning/billing/subscription/engine/dao/SubscriptionEventSqlDao.sql.stg 13(+7 -6)
Details
diff --git a/entitlement/src/main/resources/com/ning/billing/entitlement/dao/BlockingStateSqlDao.sql.stg b/entitlement/src/main/resources/com/ning/billing/entitlement/dao/BlockingStateSqlDao.sql.stg
index 484b8fd..e160450 100644
--- a/entitlement/src/main/resources/com/ning/billing/entitlement/dao/BlockingStateSqlDao.sql.stg
+++ b/entitlement/src/main/resources/com/ning/billing/entitlement/dao/BlockingStateSqlDao.sql.stg
@@ -5,6 +5,10 @@ tableName() ::= "blocking_states"
andCheckSoftDeletionWithComma(prefix) ::= "and <prefix>is_active"
+defaultOrderBy(prefix) ::= <<
+order by <prefix>effective_date ASC, <recordIdField(prefix)> ASC
+>>
+
tableFields(prefix) ::= <<
<prefix>blockable_id
, <prefix>type
@@ -71,8 +75,8 @@ getBlockingState() ::= <<
group by service
) tmp
on t.record_id = tmp.record_id
- order by t.effective_date, t.record_id asc
- ;
+ <defaultOrderBy()>
+ ;
>>
getBlockingHistoryForService() ::= <<
@@ -84,7 +88,7 @@ where blockable_id = :blockableId
and service = :service
and is_active
<AND_CHECK_TENANT()>
-order by effective_date, record_id asc
+<defaultOrderBy()>
;
>>
@@ -96,7 +100,7 @@ from
where blockable_id = :blockableId
and is_active
<AND_CHECK_TENANT()>
-order by effective_date, record_id asc
+<defaultOrderBy()>
;
>>
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 15c73bb..17692e2 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
@@ -56,7 +56,7 @@ where pa.payment_id = :paymentId
and p.id = :paymentId
<AND_CHECK_TENANT("pa.")>
<AND_CHECK_TENANT("p.")>
-order by effective_date asc
+<defaultOrderBy("pa.")>
;
>>
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 6ad9b50..871d641 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
@@ -5,6 +5,10 @@ extraTableFieldsWithComma(prefix) ::= <<
, <prefix>record_id as payment_number
>>
+defaultOrderBy(prefix) ::= <<
+order by <prefix>effective_date ASC, <recordIdField(prefix)> ASC
+>>
+
tableFields(prefix) ::= <<
<prefix>account_id
, <prefix>invoice_id
@@ -48,6 +52,7 @@ select <allTableFields()>
from payments
where account_id = :accountId
<AND_CHECK_TENANT()>
+<defaultOrderBy()>
;
>>
@@ -57,6 +62,7 @@ select <allTableFields()>
from payments
where invoice_id = :invoiceId
<AND_CHECK_TENANT()>
+<defaultOrderBy()>
;
>>
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 aa8daa6..4efb97d 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
@@ -49,6 +49,7 @@ select <allTableFields()>
from <tableName()>
where payment_id = :paymentId
<AND_CHECK_TENANT()>
+<defaultOrderBy()>
;
>>
@@ -57,5 +58,6 @@ select <allTableFields()>
from <tableName()>
where account_id = :accountId
<AND_CHECK_TENANT()>
+<defaultOrderBy()>
;
>>
diff --git a/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/BundleSqlDao.sql.stg b/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/BundleSqlDao.sql.stg
index 390af6f..b026267 100644
--- a/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/BundleSqlDao.sql.stg
+++ b/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/BundleSqlDao.sql.stg
@@ -42,7 +42,7 @@ from bundles
where
external_key = :externalKey
<AND_CHECK_TENANT()>
-order by record_id asc
+<defaultOrderBy()>
;
>>
@@ -53,7 +53,7 @@ where
external_key = :externalKey
and account_id = :accountId
<AND_CHECK_TENANT()>
-order by record_id asc
+<defaultOrderBy()>
;
>>
@@ -63,6 +63,6 @@ from bundles
where
account_id = :accountId
<AND_CHECK_TENANT()>
-order by record_id asc
+<defaultOrderBy()>
;
>>
diff --git a/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/SubscriptionEventSqlDao.sql.stg b/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/SubscriptionEventSqlDao.sql.stg
index 3008da9..4550610 100644
--- a/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/SubscriptionEventSqlDao.sql.stg
+++ b/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/SubscriptionEventSqlDao.sql.stg
@@ -8,6 +8,11 @@ extraTableFieldsWithComma(prefix) ::= <<
, <prefix>record_id as total_ordering
>>
+defaultOrderBy(prefix) ::= <<
+order by <prefix>effective_date ASC, <recordIdField(prefix)> ASC
+>>
+
+
tableFields(prefix) ::= <<
<prefix> event_type
, <prefix> user_type
@@ -90,9 +95,7 @@ subscription_id = :subscriptionId
and is_active = 1
and effective_date > :now
<AND_CHECK_TENANT()>
-order by
-effective_date asc
-, record_id asc
+<defaultOrderBy()>
;
>>
@@ -104,9 +107,7 @@ where
subscription_id = :subscriptionId
and is_active = 1
<AND_CHECK_TENANT()>
-order by
-effective_date asc
-, record_id asc
+<defaultOrderBy()>
;
>>
diff --git a/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/SubscriptionSqlDao.sql.stg b/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/SubscriptionSqlDao.sql.stg
index 378afef..ad122a2 100644
--- a/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/SubscriptionSqlDao.sql.stg
+++ b/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/SubscriptionSqlDao.sql.stg
@@ -37,6 +37,7 @@ select
from <tableName()>
where bundle_id = :bundleId
<AND_CHECK_TENANT()>
+<defaultOrderBy()>
;
>>
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 2f8b857..1a91d2f 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
@@ -35,6 +35,7 @@ where
object_id = :objectId
and object_type = :objectType
<AND_CHECK_TENANT()>
+<defaultOrderBy()>
;
>>
diff --git a/util/src/main/resources/com/ning/billing/util/entity/dao/EntitySqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/entity/dao/EntitySqlDao.sql.stg
index 297a502..64a66fd 100644
--- a/util/src/main/resources/com/ning/billing/util/entity/dao/EntitySqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/entity/dao/EntitySqlDao.sql.stg
@@ -31,6 +31,10 @@ andCheckSoftDeletionWithComma(prefix) ::= ""
/** Add extra fields for SELECT queries **/
extraTableFieldsWithComma(prefix) ::= ""
+defaultOrderBy(prefix) ::= <<
+order by <recordIdField(prefix)> ASC
+>>
+
/****************** To override in each EntitySqlDao template file <end> *****************************/
@@ -143,6 +147,7 @@ select
from <tableName()> t
where <CHECK_TENANT("t.")>
<andCheckSoftDeletionWithComma("t.")>
+<defaultOrderBy("t.")>
;
>>
@@ -194,6 +199,7 @@ from <tableName()> t
where <accountRecordIdField("t.")> \<=\> :accountRecordId
<andCheckSoftDeletionWithComma("t.")>
<AND_CHECK_TENANT("t.")>
+<defaultOrderBy("t.")>
;
>>
@@ -334,7 +340,7 @@ where t.target_record_id = :targetRecordId
and t.table_name = :tableName
<andCheckSoftDeletionWithComma("t.")>
<AND_CHECK_TENANT("t.")>
-order by <recordIdField("t.")> ASC
+<defaultOrderBy("t.")>
;
>>
@@ -352,7 +358,7 @@ join (
) history_record_ids on t.target_record_id = history_record_ids.record_id
where t.table_name = :tableName
<AND_CHECK_TENANT("t.")>
-order by <recordIdField("t.")> ASC
+<defaultOrderBy("t.")>
;
>>
diff --git a/util/src/test/java/com/ning/billing/util/dao/TestStringTemplateInheritance.java b/util/src/test/java/com/ning/billing/util/dao/TestStringTemplateInheritance.java
index 1306cfe..df148e1 100644
--- a/util/src/test/java/com/ning/billing/util/dao/TestStringTemplateInheritance.java
+++ b/util/src/test/java/com/ning/billing/util/dao/TestStringTemplateInheritance.java
@@ -112,6 +112,7 @@ public class TestStringTemplateInheritance extends UtilTestSuiteNoDB {
", t.tenant_record_id\n" +
"from kombucha t\n" +
"where t.tenant_record_id = :tenantRecordId\n" +
+ "order by t.record_id ASC\n" +
";");
Assert.assertEquals(kombucha.getInstanceOf("get", ImmutableMap.<String, String>of("orderBy", "recordId", "offset", "3", "rowCount", "12")).toString(), "select SQL_CALC_FOUND_ROWS\n" +
" t.record_id\n" +