Skip to content

Commit

Permalink
Work towards compatibility with PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
marksimu committed Jul 9, 2015
1 parent 4feaf91 commit f8ee917
Show file tree
Hide file tree
Showing 21 changed files with 60 additions and 46 deletions.
5 changes: 5 additions & 0 deletions account/pom.xml
Expand Up @@ -48,6 +48,11 @@
<artifactId>guice</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jayway.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
Expand Down
Expand Up @@ -38,9 +38,9 @@ and t.is_active
>>

markEmailAsDeleted() ::= <<
update <tableName()> t
set t.is_active = 0
where <idField("t.")> = :id
<AND_CHECK_TENANT("t.")>
update <tableName()>
set is_active = false
where <idField("")> = :id
<AND_CHECK_TENANT("")>
;
>>
Expand Up @@ -60,8 +60,8 @@ select <allTableFields()>
from <tableName()>
where parent_phase_name = :parentPhaseName
and currency = :currency
and (fixed_price = :fixedPrice or (fixed_price is null and :fixedPrice is null))
and (recurring_price = :recurringPrice or (recurring_price is null and :recurringPrice is null))
and (fixed_price = :fixedPrice or coalesce(fixed_price, :fixedPrice) is null)
and (recurring_price = :recurringPrice or coalesce(recurring_price, :recurringPrice) is null)
and tenant_record_id = :tenantRecordId
;
>>
Expand Down
Expand Up @@ -95,7 +95,7 @@ and is_active
unactiveEvent() ::= <<
update
<tableName()>
set is_active = 0
set is_active = false
where id = :id
<AND_CHECK_TENANT()>
;
Expand Down
Expand Up @@ -91,7 +91,7 @@ public void removeAutoPayOffEntry(final UUID accountId) {
dbi.withHandle(new HandleCallback<Void>() {
@Override
public Void withHandle(final Handle handle) throws Exception {
handle.execute("update _invoice_payment_control_plugin_auto_pay_off set is_active = 0 where account_id = ?", accountId.toString());
handle.execute("update _invoice_payment_control_plugin_auto_pay_off set is_active = false where account_id = ?", accountId.toString());
return null;
}
});
Expand Down
Expand Up @@ -32,7 +32,7 @@ tableValues() ::= <<

markPaymentMethodAsDeleted(id) ::= <<
update <tableName()>
set is_active = 0
set is_active = false
, updated_by = :updatedBy
, updated_date = :createdDate
where id = :id
Expand All @@ -42,7 +42,7 @@ where id = :id

unmarkPaymentMethodAsDeleted(id) ::= <<
update <tableName()>
set is_active = 1
set is_active = true
, updated_by = :updatedBy
, updated_date = :createdDate
where id = :id
Expand All @@ -54,7 +54,7 @@ getByExternalKey() ::= <<
select <allTableFields()>
from <tableName()>
where external_key = :externalKey
and is_active = 1
and is_active = true
<AND_CHECK_TENANT()>
;
>>
Expand All @@ -79,7 +79,7 @@ select
<allTableFields()>
from <tableName()>
where account_id = :accountId
and is_active = 1
and is_active = true
;
>>

Expand All @@ -103,9 +103,9 @@ select
<allTableFields("t.")>
from <tableName()> t
where t.plugin_name = :pluginName
and t.is_active = 1
and t.is_active = true
order by t.record_id
limit :offset, :rowCount
limit :rowCount offset :offset
;
>>

Expand All @@ -114,6 +114,6 @@ select
count(1) as count
from <tableName()> t
where t.plugin_name = :pluginName
and t.is_active = 1
and t.is_active = true
;
>>
Expand Up @@ -89,7 +89,7 @@ from <tableName()> t
join payment_methods pm on pm.id = t.payment_method_id
where pm.plugin_name = :pluginName
order by t.record_id asc
limit :offset, :rowCount
limit :rowCount offset :offset
;
>>

Expand Down
Expand Up @@ -72,7 +72,7 @@ join payments p on p.id = t.payment_id
join payment_methods pm on pm.id = p.payment_method_id
where pm.plugin_name = :pluginName
order by record_id
limit :offset, :rowCount
limit :rowCount offset :offset
;
>>

Expand Down
Expand Up @@ -63,7 +63,7 @@ id = :id
unactiveEvent() ::= <<
update <tableName()>
set
is_active = 0
is_active = false
, updated_by = :createdBy
, updated_date = :createdDate
where
Expand All @@ -75,7 +75,7 @@ id = :id
reactiveEvent() ::= <<
update <tableName()>
set
is_active = 1
is_active = true
, updated_by = :createdBy
, updated_date = :createdDate
where
Expand All @@ -92,7 +92,7 @@ select <allTableFields()>
from <tableName()>
where
subscription_id = :subscriptionId
and is_active = 1
and is_active = true
and effective_date > :now
<AND_CHECK_TENANT()>
<defaultOrderBy()>
Expand All @@ -105,7 +105,7 @@ select <allTableFields()>
from <tableName()>
where
subscription_id = :subscriptionId
and is_active = 1
and is_active = true
<AND_CHECK_TENANT()>
<defaultOrderBy()>
;
Expand All @@ -117,7 +117,7 @@ select <allTableFields()>
from <tableName()>
where
account_record_id = :accountRecordId
and is_active = 1
and is_active = true
and effective_date > :now
<AND_CHECK_TENANT()>
<defaultOrderBy()>
Expand Down
Expand Up @@ -40,9 +40,9 @@ and t.is_active
>>

markTenantKeyAsDeleted() ::= <<
update <tableName()> t
set t.is_active = 0
where t.id = :id
<AND_CHECK_TENANT("t.")>
update <tableName()>
set is_active = false
where id = :id
<AND_CHECK_TENANT("")>
;
>>
Expand Up @@ -31,6 +31,7 @@ and record_date >= :startDate
and record_date \< :endDate
and unit_type = :unitType
<AND_CHECK_TENANT()>
order by <recordIdField()> ASC
;
>>

Expand All @@ -42,6 +43,7 @@ where subscription_id = :subscriptionId
and record_date >= :startDate
and record_date \< :endDate
<AND_CHECK_TENANT()>
order by <recordIdField()> ASC
;
>>

Expand All @@ -53,6 +55,7 @@ where account_record_id = :accountRecordId
and record_date >= :startDate
and record_date \< :endDate
<AND_CHECK_TENANT()>
order by <recordIdField()> ASC
;
>>

Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.killbill.commons.locker.GlobalLocker;
import org.killbill.commons.locker.memory.MemoryGlobalLocker;
import org.killbill.commons.locker.mysql.MySqlGlobalLocker;
import org.killbill.commons.locker.postgresql.PostgreSQLGlobalLocker;

import com.google.inject.Provides;
import com.google.inject.Singleton;
Expand All @@ -43,6 +44,8 @@ public GlobalLockerModule(final KillbillConfigSource configSource) {
protected GlobalLocker provideGlobalLocker(final DataSource dataSource, final EmbeddedDB embeddedDB) throws IOException {
if (EmbeddedDB.DBEngine.MYSQL.equals(embeddedDB.getDBEngine())) {
return new MySqlGlobalLocker(dataSource);
} else if (EmbeddedDB.DBEngine.POSTGRESQL.equals(embeddedDB.getDBEngine())) {
return new PostgreSQLGlobalLocker(dataSource);
} else {
return new MemoryGlobalLocker();
}
Expand Down
Expand Up @@ -31,10 +31,10 @@ tableValues() ::= <<
historyTableName() ::= "custom_field_history"

markTagAsDeleted() ::= <<
update <tableName()> t
set t.is_active = 0
where <idField("t.")> = :id
<AND_CHECK_TENANT("t.")>
update <tableName()>
set is_active = false
where <idField("")> = :id
<AND_CHECK_TENANT("")>
;
>>

Expand Down
Expand Up @@ -154,7 +154,7 @@ from <tableName()> t
where <CHECK_TENANT("t.")>
<andCheckSoftDeletionWithComma("t.")>
order by t.<orderBy>
limit :offset, :rowCount
limit :rowCount offset :offset
;
>>

Expand Down Expand Up @@ -270,7 +270,7 @@ from <tableName()> t
where (<searchQuery("t.")>)
<AND_CHECK_TENANT("t.")>
order by <recordIdField("t.")> ASC
limit :offset, :rowCount
limit :rowCount offset :offset
;
>>

Expand Down
Expand Up @@ -62,7 +62,7 @@ and is_active

invalidate() ::= <<
update <tableName()>
set is_active = 0
set is_active = false
where
username = :username
and role_name = :roleName
Expand Down
Expand Up @@ -75,7 +75,7 @@ and is_active

invalidate() ::= <<
update <tableName()>
set is_active = 0
set is_active = false
where
username = :username
;
Expand Down
Expand Up @@ -31,10 +31,10 @@ accountRecordIdValueWithComma() ::= ""
historyTableName() ::= "tag_definition_history"

markTagDefinitionAsDeleted() ::= <<
update <tableName()> t
set t.is_active = 0
where <idField("t.")> = :id
<AND_CHECK_TENANT("t.")>
update <tableName()>
set is_active = false
where <idField("")> = :id
<AND_CHECK_TENANT("")>
;
>>

Expand Down
Expand Up @@ -29,10 +29,10 @@ tableValues() ::= <<
historyTableName() ::= "tag_history"

markTagAsDeleted() ::= <<
update <tableName()> t
set t.is_active = 0
where <idField("t.")> = :id
<AND_CHECK_TENANT("t.")>
update <tableName()>
set is_active = false
where <idField("")> = :id
<AND_CHECK_TENANT("")>
;
>>

Expand Down Expand Up @@ -116,7 +116,7 @@ join (<userAndSystemTagDefinitions()>) td on td.id = t.tag_definition_id
where (<searchQuery(tagAlias="t.", tagDefinitionAlias="td.")>)
<AND_CHECK_TENANT("t.")>
order by <recordIdField("t.")> ASC
limit :offset, :rowCount
limit :rowCount offset :offset
;
>>

Expand Down
Expand Up @@ -38,6 +38,7 @@
import org.killbill.commons.locker.GlobalLocker;
import org.killbill.commons.locker.memory.MemoryGlobalLocker;
import org.killbill.commons.locker.mysql.MySqlGlobalLocker;
import org.killbill.commons.locker.postgresql.PostgreSQLGlobalLocker;
import org.killbill.notificationq.api.NotificationQueueService;
import org.skife.jdbi.v2.IDBI;
import org.slf4j.Logger;
Expand Down Expand Up @@ -93,6 +94,8 @@ public void beforeClass() throws Exception {

if (DBEngine.MYSQL.equals(helper.getDBEngine())) {
Assert.assertTrue(locker instanceof MySqlGlobalLocker);
} else if (DBEngine.POSTGRESQL.equals(helper.getDBEngine())) {
Assert.assertTrue(locker instanceof PostgreSQLGlobalLocker);
} else {
Assert.assertTrue(locker instanceof MemoryGlobalLocker);
}
Expand Down
Expand Up @@ -121,7 +121,7 @@ private void insertTagDefinition() throws IOException {
public Void withHandle(final Handle handle) throws Exception {
// Note: we always create an accounts table, see MysqlTestingHelper
handle.execute("insert into tag_definitions (record_id, id, name, description, is_active, created_date, created_by, updated_date, updated_by, tenant_record_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
tagDefinitionRecordId, tagDefinitionId.toString(), "tagdef", "nothing", 1, new Date(), "i", new Date(), "j", 0);
tagDefinitionRecordId, tagDefinitionId.toString(), "tagdef", "nothing", true, new Date(), "i", new Date(), "j", 0);
return null;
}
});
Expand All @@ -133,7 +133,7 @@ private void insertTag() throws IOException {
public Void withHandle(final Handle handle) throws Exception {
// Note: we always create an accounts table, see MysqlTestingHelper
handle.execute("insert into tags (record_id, id, tag_definition_id, object_id, object_type, is_active, created_date, created_by, updated_date, updated_by, account_record_id, tenant_record_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
tagRecordId, tagId.toString(), tagDefinitionId.toString(), accountId.toString(), "ACCOUNT", 1, new Date(), "i", new Date(), "j", accountRecordId, 0);
tagRecordId, tagId.toString(), tagDefinitionId.toString(), accountId.toString(), "ACCOUNT", true, new Date(), "i", new Date(), "j", accountRecordId, 0);
return null;
}
});
Expand Down
Expand Up @@ -125,7 +125,7 @@ public void testCheckQueries() throws Exception {
"from kombucha t\r?\n" +
"where t.tenant_record_id = :tenantRecordId\r?\n" +
"order by t.record_id\r?\n" +
"limit :offset, :rowCount\r?\n" +
"limit :rowCount offset :offset\r?\n" +
";");
assertPattern(kombucha.getInstanceOf("test").toString(), "select\r?\n" +
" t.record_id\r?\n" +
Expand Down

0 comments on commit f8ee917

Please sign in to comment.