killbill-aplcache

Changes

Details

diff --git a/analytics/src/main/resources/com/ning/billing/analytics/ddl.sql b/analytics/src/main/resources/com/ning/billing/analytics/ddl.sql
index 4ed57a9..7c93a84 100644
--- a/analytics/src/main/resources/com/ning/billing/analytics/ddl.sql
+++ b/analytics/src/main/resources/com/ning/billing/analytics/ddl.sql
@@ -38,7 +38,7 @@ create table bst (
 , account_record_id int(11) unsigned default null
 , tenant_record_id int(11) unsigned default null
 , primary key(record_id)
-) comment 'Business Subscription Transitions, track bundles lifecycle';
+);
 create index bst_key_index on bst (external_key, requested_timestamp asc);
 create index bst_tenant_account_record_id on bst(tenant_record_id, account_record_id);
 
@@ -61,7 +61,7 @@ create table bac (
 , account_record_id int(11) unsigned default null
 , tenant_record_id int(11) unsigned default null
 , primary key(record_id)
-) comment 'Business ACcounts, keep a record of all accounts';
+);
 create unique index bac_key_index on bac (account_key);
 create index bac_tenant_account_record_id on bac(tenant_record_id, account_record_id);
 
@@ -84,7 +84,7 @@ create table bin (
 , account_record_id int(11) unsigned default null
 , tenant_record_id int(11) unsigned default null
 , primary key(record_id)
-) comment 'Business INvoices, keep a record of generated invoices';
+);
 create unique index bin_key_index on bin (invoice_id);
 create index bin_tenant_account_record_id on bin(tenant_record_id, account_record_id);
 
@@ -111,7 +111,7 @@ create table bii (
 , account_record_id int(11) unsigned default null
 , tenant_record_id int(11) unsigned default null
 , primary key(record_id)
-) comment 'Business Invoice Items, keep a record of all invoice items';
+);
 create unique index bii_key_index on bii (item_id);
 create index bii_tenant_account_record_id on bii(tenant_record_id, account_record_id);
 
@@ -141,7 +141,7 @@ create table bip (
 , account_record_id int(11) unsigned default null
 , tenant_record_id int(11) unsigned default null
 , primary key(record_id)
-) comment 'Business Invoice Payments, track all payments';
+);
 create unique index bip_key_index on bip (payment_id);
 create index bip_tenant_account_record_id on bip(tenant_record_id, account_record_id);
 
@@ -157,7 +157,7 @@ create table bos (
 , account_record_id int(11) unsigned default null
 , tenant_record_id int(11) unsigned default null
 , primary key(record_id)
-) comment 'Business Overdue Status, historical bundles overdue status';
+);
 create index bos_tenant_account_record_id on bos(tenant_record_id, account_record_id);
 
 drop table if exists bac_tags;
@@ -169,7 +169,7 @@ create table bac_tags (
 , account_record_id int(11) unsigned default null
 , tenant_record_id int(11) unsigned default null
 , primary key(record_id)
-) comment 'Tags associated to accounts';
+);
 create index bac_tags_tenant_account_record_id on bac_tags(tenant_record_id, account_record_id);
 
 drop table if exists bac_fields;
@@ -182,7 +182,7 @@ create table bac_fields (
 , account_record_id int(11) unsigned default null
 , tenant_record_id int(11) unsigned default null
 , primary key(record_id)
-) comment 'Custom fields associated to accounts';
+);
 create index bac_fields_tenant_account_record_id on bac_fields(tenant_record_id, account_record_id);
 
 drop table if exists bst_tags;
@@ -195,7 +195,7 @@ create table bst_tags (
 , account_record_id int(11) unsigned default null
 , tenant_record_id int(11) unsigned default null
 , primary key(record_id)
-) comment 'Tags associated to bundles';
+);
 create index bst_tags_tenant_account_record_id on bst_tags(tenant_record_id, account_record_id);
 
 drop table if exists bst_fields;
@@ -209,7 +209,7 @@ create table bst_fields (
 , account_record_id int(11) unsigned default null
 , tenant_record_id int(11) unsigned default null
 , primary key(record_id)
-) comment 'Custom fields associated to bundles';
+);
 create index bst_fields_tenant_account_record_id on bst_fields(tenant_record_id, account_record_id);
 
 drop table if exists bin_tags;
@@ -220,7 +220,7 @@ create table bin_tags (
 , account_record_id int(11) unsigned default null
 , tenant_record_id int(11) unsigned default null
 , primary key(record_id)
-) comment 'Tags associated to invoices';
+);
 create index bin_tags_tenant_account_record_id on bin_tags(tenant_record_id, account_record_id);
 
 drop table if exists bin_fields;
@@ -232,7 +232,7 @@ create table bin_fields (
 , account_record_id int(11) unsigned default null
 , tenant_record_id int(11) unsigned default null
 , primary key(record_id)
-) comment 'Custom fields associated to invoices';
+);
 create index bin_fields_tenant_account_record_id on bin_fields(tenant_record_id, account_record_id);
 
 drop table if exists bip_tags;
@@ -243,7 +243,7 @@ create table bip_tags (
 , account_record_id int(11) unsigned default null
 , tenant_record_id int(11) unsigned default null
 , primary key(record_id)
-) comment 'Tags associated to payments';
+);
 create index bip_tags_tenant_account_record_id on bip_tags(tenant_record_id, account_record_id);
 
 drop table if exists bip_fields;
@@ -255,5 +255,5 @@ create table bip_fields (
 , account_record_id int(11) unsigned default null
 , tenant_record_id int(11) unsigned default null
 , primary key(record_id)
-) comment 'Custom fields associated to payments';
+);
 create index bip_fields_tenant_account_record_id on bip_fields(tenant_record_id, account_record_id);
diff --git a/analytics/src/test/java/com/ning/billing/analytics/AnalyticsTestModule.java b/analytics/src/test/java/com/ning/billing/analytics/AnalyticsTestModule.java
index 8a871e5..bd4e9c6 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/AnalyticsTestModule.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/AnalyticsTestModule.java
@@ -30,11 +30,11 @@ import com.ning.billing.junction.glue.DefaultJunctionModule;
 import com.ning.billing.payment.glue.PaymentModule;
 import com.ning.billing.util.email.EmailModule;
 import com.ning.billing.util.email.templates.TemplateModule;
+import com.ning.billing.util.globallocker.TestGlobalLockerModule;
 import com.ning.billing.util.glue.BusModule;
 import com.ning.billing.util.glue.CallContextModule;
 import com.ning.billing.util.glue.ClockModule;
 import com.ning.billing.util.glue.CustomFieldModule;
-import com.ning.billing.util.glue.GlobalLockerModule;
 import com.ning.billing.util.glue.NotificationQueueModule;
 import com.ning.billing.util.glue.TagStoreModule;
 import com.ning.billing.util.tag.dao.TagDefinitionSqlDao;
@@ -47,7 +47,7 @@ public class AnalyticsTestModule extends AnalyticsModule {
 
         // Need to configure a few more things for the EventBus
         install(new EmailModule());
-        install(new GlobalLockerModule());
+        install(new TestGlobalLockerModule(KillbillTestSuiteWithEmbeddedDB.getDBTestingHelper()));
         install(new ClockModule());
         install(new CallContextModule());
         install(new CustomFieldModule());
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixIntegrationModule.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixIntegrationModule.java
index cd04508..982b63c 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixIntegrationModule.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixIntegrationModule.java
@@ -59,11 +59,11 @@ import com.ning.billing.util.clock.ClockMock;
 import com.ning.billing.util.config.PaymentConfig;
 import com.ning.billing.util.email.EmailModule;
 import com.ning.billing.util.email.templates.TemplateModule;
+import com.ning.billing.util.globallocker.TestGlobalLockerModule;
 import com.ning.billing.util.glue.AuditModule;
 import com.ning.billing.util.glue.BusModule;
 import com.ning.billing.util.glue.CallContextModule;
 import com.ning.billing.util.glue.CustomFieldModule;
-import com.ning.billing.util.glue.GlobalLockerModule;
 import com.ning.billing.util.glue.NotificationQueueModule;
 import com.ning.billing.util.glue.TagStoreModule;
 import com.ning.billing.util.svcsapi.bus.BusService;
@@ -101,7 +101,7 @@ public class BeatrixIntegrationModule extends AbstractModule {
 
         install(new EmailModule());
         install(new CallContextModule());
-        install(new GlobalLockerModule());
+        install(new TestGlobalLockerModule(helper));
         install(new BusModule());
         install(new NotificationQueueModule());
         install(new TagStoreModule());
diff --git a/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java b/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java
index 551e939..961ced2 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java
@@ -839,6 +839,8 @@ public class DefaultInvoiceDao extends EntityDaoBase<InvoiceModelDao, Invoice, I
                 break;
             }
         }
+
+        // TODO Should we send an event on the bus for Analytics?
     }
 
 
diff --git a/invoice/src/test/java/com/ning/billing/invoice/glue/InvoiceModuleWithEmbeddedDb.java b/invoice/src/test/java/com/ning/billing/invoice/glue/InvoiceModuleWithEmbeddedDb.java
index 154b339..79409a5 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/glue/InvoiceModuleWithEmbeddedDb.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/glue/InvoiceModuleWithEmbeddedDb.java
@@ -36,9 +36,9 @@ import com.ning.billing.util.callcontext.DefaultCallContextFactory;
 import com.ning.billing.util.clock.Clock;
 import com.ning.billing.util.clock.DefaultClock;
 import com.ning.billing.util.email.templates.TemplateModule;
+import com.ning.billing.util.globallocker.TestGlobalLockerModule;
 import com.ning.billing.util.glue.BusModule;
 import com.ning.billing.util.glue.CustomFieldModule;
-import com.ning.billing.util.glue.GlobalLockerModule;
 import com.ning.billing.util.glue.TagStoreModule;
 import com.ning.billing.util.notificationq.MockNotificationQueueService;
 import com.ning.billing.util.notificationq.NotificationQueueService;
@@ -80,7 +80,7 @@ public class InvoiceModuleWithEmbeddedDb extends DefaultInvoiceModule {
 
         install(new CatalogModule());
         install(new MockEntitlementModule());
-        install(new GlobalLockerModule());
+        install(new TestGlobalLockerModule(KillbillTestSuiteWithEmbeddedDB.getDBTestingHelper()));
 
         super.configure();
 
diff --git a/invoice/src/test/java/com/ning/billing/invoice/MockModule.java b/invoice/src/test/java/com/ning/billing/invoice/MockModule.java
index e8eaa3c..65b6571 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/MockModule.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/MockModule.java
@@ -40,9 +40,9 @@ import com.ning.billing.util.clock.Clock;
 import com.ning.billing.util.clock.ClockMock;
 import com.ning.billing.util.email.EmailModule;
 import com.ning.billing.util.email.templates.TemplateModule;
+import com.ning.billing.util.globallocker.TestGlobalLockerModule;
 import com.ning.billing.util.glue.BusModule;
 import com.ning.billing.util.glue.CustomFieldModule;
-import com.ning.billing.util.glue.GlobalLockerModule;
 import com.ning.billing.util.glue.NotificationQueueModule;
 import com.ning.billing.util.glue.TagStoreModule;
 import com.ning.billing.util.svcapi.account.AccountInternalApi;
@@ -84,7 +84,7 @@ public class MockModule extends AbstractModule {
         bind(EntitlementInternalApi.class).toInstance(Mockito.mock(EntitlementInternalApi.class));
 
         install(new EmailModule());
-        install(new GlobalLockerModule());
+        install(new TestGlobalLockerModule(helper));
         install(new NotificationQueueModule());
         install(new CatalogModule());
         install(new BusModule());
diff --git a/payment/src/main/resources/com/ning/billing/payment/ddl.sql b/payment/src/main/resources/com/ning/billing/payment/ddl.sql
index fbc1279..155280b 100644
--- a/payment/src/main/resources/com/ning/billing/payment/ddl.sql
+++ b/payment/src/main/resources/com/ning/billing/payment/ddl.sql
@@ -4,9 +4,9 @@ DROP TABLE IF EXISTS payments;
 CREATE TABLE payments (
     record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
     id char(36) NOT NULL,
-    account_id char(36) COLLATE utf8_bin NOT NULL,
-    invoice_id char(36) COLLATE utf8_bin NOT NULL,
-    payment_method_id char(36) COLLATE utf8_bin NOT NULL,    
+    account_id char(36) NOT NULL,
+    invoice_id char(36) NOT NULL,
+    payment_method_id char(36) NOT NULL,
     amount numeric(10,4),
     currency char(3),    
     effective_date datetime,
@@ -20,7 +20,7 @@ CREATE TABLE payments (
     account_record_id int(11) unsigned default null,
     tenant_record_id int(11) unsigned default null,
     PRIMARY KEY (record_id)
-) DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+);
 CREATE UNIQUE INDEX payments_id ON payments(id);
 CREATE INDEX payments_inv ON payments(invoice_id);
 CREATE INDEX payments_accnt ON payments(account_id);
@@ -31,9 +31,9 @@ CREATE TABLE payment_history (
     record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
     id char(36) NOT NULL,
     target_record_id int(11) unsigned NOT NULL,
-    account_id char(36) COLLATE utf8_bin NOT NULL,
-    invoice_id char(36) COLLATE utf8_bin NOT NULL,
-    payment_method_id char(36) COLLATE utf8_bin NOT NULL,    
+    account_id char(36) NOT NULL,
+    invoice_id char(36) NOT NULL,
+    payment_method_id char(36) NOT NULL,
     amount numeric(10,4),
     currency char(3),    
     effective_date datetime,
@@ -48,7 +48,7 @@ CREATE TABLE payment_history (
     account_record_id int(11) unsigned default null,
     tenant_record_id int(11) unsigned default null,
     PRIMARY KEY(record_id)
-) DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+);
 CREATE INDEX payment_history_target_record_id ON payment_history(target_record_id);
 CREATE INDEX payment_history_tenant_account_record_id ON payment_history(tenant_record_id, account_record_id);
 
@@ -56,7 +56,7 @@ DROP TABLE IF EXISTS payment_attempts;
 CREATE TABLE payment_attempts (
     record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
     id char(36) NOT NULL,
-    payment_id char(36) COLLATE utf8_bin NOT NULL,
+    payment_id char(36) NOT NULL,
     gateway_error_code varchar(32),              
     gateway_error_msg varchar(256),
     processing_status varchar(50),
@@ -68,7 +68,7 @@ CREATE TABLE payment_attempts (
     account_record_id int(11) unsigned default null,
     tenant_record_id int(11) unsigned default null,
     PRIMARY KEY (record_id)
-) DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+);
 CREATE UNIQUE INDEX payment_attempts_id ON payment_attempts(id);
 CREATE INDEX payment_attempts_payment ON payment_attempts(payment_id);
 CREATE INDEX payment_attempts_tenant_account_record_id ON payment_attempts(tenant_record_id, account_record_id);
@@ -78,7 +78,7 @@ CREATE TABLE payment_attempt_history (
     record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
     id char(36) NOT NULL,
     target_record_id int(11) unsigned NOT NULL,
-    payment_id char(36) COLLATE utf8_bin NOT NULL,
+    payment_id char(36) NOT NULL,
     gateway_error_code varchar(32),              
     gateway_error_msg varchar(256),
     processing_status varchar(50),
@@ -91,7 +91,7 @@ CREATE TABLE payment_attempt_history (
     account_record_id int(11) unsigned default null,
     tenant_record_id int(11) unsigned default null,
     PRIMARY KEY(record_id)
-) DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+);
 CREATE INDEX payment_attempt_history_target_record_id ON payment_attempt_history(target_record_id);
 CREATE INDEX payment_attempt_history_tenant_account_record_id ON payment_attempt_history(tenant_record_id, account_record_id);
 
@@ -99,7 +99,7 @@ DROP TABLE IF EXISTS payment_methods;
 CREATE TABLE payment_methods (
     record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
     id char(36) NOT NULL,
-    account_id char(36) COLLATE utf8_bin NOT NULL,
+    account_id char(36) NOT NULL,
     plugin_name varchar(20) DEFAULT NULL,
     is_active bool DEFAULT true, 
     external_id varchar(64), 
@@ -110,7 +110,7 @@ CREATE TABLE payment_methods (
     account_record_id int(11) unsigned default null,
     tenant_record_id int(11) unsigned default null,
     PRIMARY KEY (record_id)
-) DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+);
 CREATE UNIQUE INDEX payment_methods_id ON payment_methods(id);
 CREATE INDEX payment_methods_active_accnt ON payment_methods(is_active, account_id);
 CREATE INDEX payment_methods_tenant_account_record_id ON payment_methods(tenant_record_id, account_record_id);
@@ -120,7 +120,7 @@ CREATE TABLE payment_method_history (
     record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
     id char(36) NOT NULL,
     target_record_id int(11) unsigned NOT NULL,
-    account_id char(36) COLLATE utf8_bin NOT NULL,
+    account_id char(36) NOT NULL,
     plugin_name varchar(20) DEFAULT NULL, 
     is_active bool DEFAULT true, 
     external_id varchar(64),                  
@@ -132,7 +132,7 @@ CREATE TABLE payment_method_history (
     account_record_id int(11) unsigned default null,
     tenant_record_id int(11) unsigned default null,
     PRIMARY KEY(record_id)
-) DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+);
 CREATE INDEX payment_method_history_target_record_id ON payment_method_history(target_record_id);
 CREATE INDEX payment_method_history_tenant_account_record_id ON payment_method_history(tenant_record_id, account_record_id);
 
@@ -140,10 +140,10 @@ DROP TABLE IF EXISTS refunds;
 CREATE TABLE refunds (
     record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
     id char(36) NOT NULL,
-    account_id char(36) COLLATE utf8_bin NOT NULL,
-    payment_id char(36) COLLATE utf8_bin NOT NULL,    
+    account_id char(36) NOT NULL,
+    payment_id char(36) NOT NULL,
     amount numeric(10,4),
-    currency char(3),   
+    currency char(3),
     is_adjusted tinyint(1),
     refund_status varchar(50), 
     created_by varchar(50) NOT NULL,
@@ -153,7 +153,7 @@ CREATE TABLE refunds (
     account_record_id int(11) unsigned default null,
     tenant_record_id int(11) unsigned default null,
     PRIMARY KEY (record_id)
-) DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+);
 CREATE UNIQUE INDEX refunds_id ON refunds(id);
 CREATE INDEX refunds_pay ON refunds(payment_id);
 CREATE INDEX refunds_accnt ON refunds(account_id);
@@ -164,10 +164,10 @@ CREATE TABLE refund_history (
     record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
     id char(36) NOT NULL,
     target_record_id int(11) unsigned NOT NULL,
-    account_id char(36) COLLATE utf8_bin NOT NULL,
-    payment_id char(36) COLLATE utf8_bin NOT NULL,    
+    account_id char(36) NOT NULL,
+    payment_id char(36) NOT NULL,
     amount numeric(10,4),
-    currency char(3),   
+    currency char(3),
     is_adjusted tinyint(1),
     refund_status varchar(50), 
     change_type char(6) NOT NULL,
@@ -178,7 +178,7 @@ CREATE TABLE refund_history (
     account_record_id int(11) unsigned default null,
     tenant_record_id int(11) unsigned default null,
     PRIMARY KEY(record_id)
-) DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+);
 CREATE INDEX refund_history_target_record_id ON refund_history(target_record_id);
 CREATE INDEX refund_history_tenant_account_record_id ON refund_history(tenant_record_id, account_record_id);
 
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java b/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java
index a69d0df..715a310 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java
@@ -59,12 +59,12 @@ import com.ning.billing.util.clock.ClockMock;
 import com.ning.billing.util.config.PaymentConfig;
 import com.ning.billing.util.email.EmailModule;
 import com.ning.billing.util.email.templates.TemplateModule;
+import com.ning.billing.util.globallocker.TestGlobalLockerModule;
 import com.ning.billing.util.glue.AuditModule;
 import com.ning.billing.util.glue.BusModule;
 import com.ning.billing.util.glue.CallContextModule;
 import com.ning.billing.util.glue.CustomFieldModule;
 import com.ning.billing.util.glue.ExportModule;
-import com.ning.billing.util.glue.GlobalLockerModule;
 import com.ning.billing.util.glue.NotificationQueueModule;
 import com.ning.billing.util.glue.TagStoreModule;
 import com.ning.http.client.AsyncHttpClient;
@@ -166,7 +166,7 @@ public class TestJaxrsBase extends KillbillClient {
             Modules.override(new com.ning.billing.payment.setup.PaymentModule()).with(new PaymentMockModule());
             */
             install(new EmailModule());
-            install(new GlobalLockerModule());
+            install(new TestGlobalLockerModule(helper));
             install(new CustomFieldModule());
             install(new TagStoreModule());
             install(new AuditModule());
diff --git a/util/src/main/java/com/ning/billing/util/callcontext/InternalCallContextFactory.java b/util/src/main/java/com/ning/billing/util/callcontext/InternalCallContextFactory.java
index 6f065ec..500313b 100644
--- a/util/src/main/java/com/ning/billing/util/callcontext/InternalCallContextFactory.java
+++ b/util/src/main/java/com/ning/billing/util/callcontext/InternalCallContextFactory.java
@@ -243,7 +243,8 @@ public class InternalCallContextFactory {
                     if (values.size() == 0) {
                         return null;
                     } else {
-                        return (Long) values.get(0).get(columnName);
+                        final Object accountRecordId = values.get(0).get(columnName);
+                        return accountRecordId == null ? null : Long.valueOf(accountRecordId.toString());
                     }
                 }
             });
@@ -274,7 +275,8 @@ public class InternalCallContextFactory {
                     if (values.size() == 0) {
                         return null;
                     } else {
-                        return (Long) values.get(0).get(columnName);
+                        final Object tenantRecordId = values.get(0).get(columnName);
+                        return tenantRecordId == null ? null : Long.valueOf(tenantRecordId.toString());
                     }
                 }
             });
diff --git a/util/src/main/java/com/ning/billing/util/glue/GlobalLockerModule.java b/util/src/main/java/com/ning/billing/util/glue/GlobalLockerModule.java
index 7d976f5..c0245ac 100644
--- a/util/src/main/java/com/ning/billing/util/glue/GlobalLockerModule.java
+++ b/util/src/main/java/com/ning/billing/util/glue/GlobalLockerModule.java
@@ -22,6 +22,7 @@ import com.ning.billing.util.globallocker.MySqlGlobalLocker;
 import com.google.inject.AbstractModule;
 
 public class GlobalLockerModule extends AbstractModule {
+
     @Override
     protected void configure() {
         bind(GlobalLocker.class).to(MySqlGlobalLocker.class).asEagerSingleton();
diff --git a/util/src/main/java/com/ning/billing/util/validation/dao/DatabaseSchemaSqlDao.java b/util/src/main/java/com/ning/billing/util/validation/dao/DatabaseSchemaSqlDao.java
index fad2b77..f41e350 100644
--- a/util/src/main/java/com/ning/billing/util/validation/dao/DatabaseSchemaSqlDao.java
+++ b/util/src/main/java/com/ning/billing/util/validation/dao/DatabaseSchemaSqlDao.java
@@ -26,12 +26,12 @@ import org.skife.jdbi.v2.StatementContext;
 import org.skife.jdbi.v2.sqlobject.Bind;
 import org.skife.jdbi.v2.sqlobject.SqlQuery;
 import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
-import org.skife.jdbi.v2.sqlobject.stringtemplate.ExternalizedSqlViaStringTemplate3;
+import org.skife.jdbi.v2.sqlobject.stringtemplate.UseStringTemplate3StatementLocator;
 import org.skife.jdbi.v2.tweak.ResultSetMapper;
 
 import com.ning.billing.util.validation.DefaultColumnInfo;
 
-@ExternalizedSqlViaStringTemplate3
+@UseStringTemplate3StatementLocator
 @RegisterMapper(DatabaseSchemaSqlDao.ColumnInfoMapper.class)
 public interface DatabaseSchemaSqlDao {
 
diff --git a/util/src/main/java/com/ning/billing/util/validation/ValidationManager.java b/util/src/main/java/com/ning/billing/util/validation/ValidationManager.java
index 1392f82..740f88e 100644
--- a/util/src/main/java/com/ning/billing/util/validation/ValidationManager.java
+++ b/util/src/main/java/com/ning/billing/util/validation/ValidationManager.java
@@ -18,6 +18,7 @@ package com.ning.billing.util.validation;
 
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
+import java.sql.Types;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -28,6 +29,7 @@ import com.ning.billing.util.validation.dao.DatabaseSchemaDao;
 import com.google.inject.Inject;
 
 public class ValidationManager {
+
     private final DatabaseSchemaDao dao;
 
     // table name, string name, column info
@@ -126,7 +128,8 @@ public class ValidationManager {
 
     private boolean isValidLengthString(final DefaultColumnInfo columnInfo, final Object value) {
         if (columnInfo.getMaximumLength() != 0) {
-            if (value != null) {
+            // H2 will report a character_maximum_length for decimal
+            if (value != null && value instanceof String) {
                 if (value.toString().length() > columnInfo.getMaximumLength()) {
                     return false;
                 }
@@ -137,7 +140,8 @@ public class ValidationManager {
     }
 
     private boolean isValidLengthChar(final DefaultColumnInfo columnInfo, final Object value) {
-        if (columnInfo.getDataType().equals("char")) {
+        // MySQL reports data_type as Strings, H2 as SQLTypes
+        if (columnInfo.getDataType().equals("char") || columnInfo.getDataType().equals(String.valueOf(Types.CHAR))) {
             if (value == null) {
                 return false;
             } else {
@@ -152,7 +156,8 @@ public class ValidationManager {
 
     private boolean hasValidPrecision(final DefaultColumnInfo columnInfo, final Object value) {
         if (columnInfo.getPrecision() != 0) {
-            if (value != null) {
+            // H2 will report a numeric precision for varchar columns
+            if (value != null && !(value instanceof String)) {
                 final BigDecimal bigDecimalValue = new BigDecimal(value.toString());
                 if (bigDecimalValue.precision() > columnInfo.getPrecision()) {
                     return false;
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 6610aa5..63165e7 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
@@ -290,7 +290,7 @@ select
   <auditTableFields("t.")>
 from <auditTableName()> t
 where t.target_record_id = :targetRecordId
-and t.table_name = :tableName
+and lower(t.table_name) = lower(:tableName)
 <AND_CHECK_TENANT("t.")>
 order by <recordIdField("t.")> ASC
 ;
diff --git a/util/src/test/java/com/ning/billing/dbi/DBTestingHelper.java b/util/src/test/java/com/ning/billing/dbi/DBTestingHelper.java
index 35e3590..65a3e9a 100644
--- a/util/src/test/java/com/ning/billing/dbi/DBTestingHelper.java
+++ b/util/src/test/java/com/ning/billing/dbi/DBTestingHelper.java
@@ -19,11 +19,9 @@ package com.ning.billing.dbi;
 import java.io.IOException;
 import java.util.List;
 
-import org.skife.jdbi.v2.DBI;
 import org.skife.jdbi.v2.Handle;
 import org.skife.jdbi.v2.IDBI;
 import org.skife.jdbi.v2.tweak.HandleCallback;
-import org.skife.jdbi.v2.util.StringMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,7 +37,12 @@ public abstract class DBTestingHelper {
     public static final String USERNAME = "root";
     public static final String PASSWORD = "root";
 
-    // Discover dynamically list of all tables in that database;
+    public enum DBEngine {
+        MYSQL,
+        H2
+    }
+
+    // Discover dynamically list of all tables in that database
     protected List<String> allTables;
     protected IDBI dbiInstance = null;
 
@@ -121,26 +124,6 @@ public abstract class DBTestingHelper {
         });
     }
 
-    public synchronized List<String> fetchAllTables() {
-        if (allTables == null) {
-            final String dbiString = getInformationSchemaJdbcConnectionString();
-            final IDBI cleanupDbi = new DBI(dbiString, USERNAME, PASSWORD);
-
-            final List<String> tables = cleanupDbi.withHandle(new HandleCallback<List<String>>() {
-
-                @Override
-                public List<String> withHandle(final Handle h) throws Exception {
-                    return h.createQuery("select table_name from tables where table_schema = :table_schema and table_type = 'BASE TABLE';")
-                            .bind("table_schema", DB_NAME)
-                            .map(new StringMapper())
-                            .list();
-                }
-            });
-            allTables = tables;
-        }
-        return allTables;
-    }
-
     public void cleanupAllTables() {
         final List<String> tablesToCleanup = fetchAllTables();
         for (final String tableName : tablesToCleanup) {
@@ -164,6 +147,8 @@ public abstract class DBTestingHelper {
         return DB_NAME;
     }
 
+    public abstract DBEngine getDBEngine();
+
     public abstract boolean isUsingLocalInstance();
 
     // For debugging
@@ -172,7 +157,7 @@ public abstract class DBTestingHelper {
     // To create the DBI
     public abstract String getJdbcConnectionString();
 
-    public abstract String getInformationSchemaJdbcConnectionString();
+    public abstract List<String> fetchAllTables();
 
     public abstract void start() throws IOException;
 
diff --git a/util/src/test/java/com/ning/billing/dbi/H2TestingHelper.java b/util/src/test/java/com/ning/billing/dbi/H2TestingHelper.java
index 9717116..8431da7 100644
--- a/util/src/test/java/com/ning/billing/dbi/H2TestingHelper.java
+++ b/util/src/test/java/com/ning/billing/dbi/H2TestingHelper.java
@@ -17,11 +17,19 @@
 package com.ning.billing.dbi;
 
 import java.io.IOException;
+import java.sql.SQLException;
+import java.util.List;
 
+import org.h2.tools.Server;
+import org.skife.jdbi.v2.Handle;
+import org.skife.jdbi.v2.tweak.HandleCallback;
+import org.skife.jdbi.v2.util.StringMapper;
 import org.testng.Assert;
 
 public class H2TestingHelper extends DBTestingHelper {
 
+    private Server server;
+
     static {
         try {
             Class.forName("org.h2.Driver");
@@ -31,6 +39,11 @@ public class H2TestingHelper extends DBTestingHelper {
     }
 
     @Override
+    public DBEngine getDBEngine() {
+        return DBEngine.H2;
+    }
+
+    @Override
     public boolean isUsingLocalInstance() {
         return false;
     }
@@ -42,19 +55,38 @@ public class H2TestingHelper extends DBTestingHelper {
 
     @Override
     public String getJdbcConnectionString() {
-        return "jdbc:h2:mem:" + DB_NAME + ";MODE=MYSQL";
+        return "jdbc:h2:mem:" + DB_NAME + ";MODE=MYSQL;DB_CLOSE_DELAY=-1";
     }
 
     @Override
-    public String getInformationSchemaJdbcConnectionString() {
-        return "jdbc:h2:mem:foo;MODE=MYSQL;SCHEMA_SEARCH_PATH=INFORMATION_SCHEMA";
+    public synchronized List<String> fetchAllTables() {
+        if (allTables == null) {
+            allTables = dbiInstance.withHandle(new HandleCallback<List<String>>() {
+
+                @Override
+                public List<String> withHandle(final Handle h) throws Exception {
+                    return h.createQuery("select table_name from information_schema.tables where table_catalog = :table_catalog and table_type = 'TABLE';")
+                            .bind("table_catalog", DB_NAME)
+                            .map(new StringMapper())
+                            .list();
+                }
+            });
+        }
+        return allTables;
     }
 
     @Override
     public void start() throws IOException {
+        // Start a web server for debugging (http://127.0.0.1:8082/)
+        try {
+            server = Server.createWebServer(new String[]{}).start();
+        } catch (SQLException e) {
+            Assert.fail(e.toString());
+        }
     }
 
     @Override
     public void stop() {
+        server.stop();
     }
 }
diff --git a/util/src/test/java/com/ning/billing/dbi/MysqlTestingHelper.java b/util/src/test/java/com/ning/billing/dbi/MysqlTestingHelper.java
index 52b4be0..97bd3a4 100644
--- a/util/src/test/java/com/ning/billing/dbi/MysqlTestingHelper.java
+++ b/util/src/test/java/com/ning/billing/dbi/MysqlTestingHelper.java
@@ -22,8 +22,12 @@ import java.io.IOException;
 import java.io.PrintStream;
 import java.net.ServerSocket;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
+import org.skife.jdbi.v2.Handle;
+import org.skife.jdbi.v2.tweak.HandleCallback;
+import org.skife.jdbi.v2.util.StringMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.Assert;
@@ -62,6 +66,11 @@ public class MysqlTestingHelper extends DBTestingHelper {
     }
 
     @Override
+    public DBEngine getDBEngine() {
+        return DBEngine.MYSQL;
+    }
+
+    @Override
     public boolean isUsingLocalInstance() {
         return (System.getProperty(USE_LOCAL_DB_PROP) != null);
     }
@@ -77,8 +86,20 @@ public class MysqlTestingHelper extends DBTestingHelper {
     }
 
     @Override
-    public String getInformationSchemaJdbcConnectionString() {
-        return "jdbc:mysql://localhost:" + port + "/information_schema";
+    public synchronized List<String> fetchAllTables() {
+        if (allTables == null) {
+            allTables = dbiInstance.withHandle(new HandleCallback<List<String>>() {
+
+                @Override
+                public List<String> withHandle(final Handle h) throws Exception {
+                    return h.createQuery("select table_name from information_schema.tables where table_schema = :table_schema and table_type = 'BASE TABLE';")
+                            .bind("table_schema", DB_NAME)
+                            .map(new StringMapper())
+                            .list();
+                }
+            });
+        }
+        return allTables;
     }
 
     public void start() throws IOException {
diff --git a/util/src/test/java/com/ning/billing/mock/glue/MockGlobalLockerModule.java b/util/src/test/java/com/ning/billing/mock/glue/MockGlobalLockerModule.java
new file mode 100644
index 0000000..03fd184
--- /dev/null
+++ b/util/src/test/java/com/ning/billing/mock/glue/MockGlobalLockerModule.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2010-2012 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.mock.glue;
+
+import com.ning.billing.util.globallocker.GlobalLocker;
+import com.ning.billing.util.globallocker.MockGlobalLocker;
+
+import com.google.inject.AbstractModule;
+
+public class MockGlobalLockerModule extends AbstractModule {
+
+    @Override
+    protected void configure() {
+        bind(GlobalLocker.class).to(MockGlobalLocker.class).asEagerSingleton();
+    }
+}
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 e17bdd3..76661c2 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
@@ -79,7 +79,7 @@ public class TestDefaultCustomFieldUserApi extends UtilTestSuiteWithEmbeddedDB {
                 final List<Map<String, Object>> values = handle.select("select account_record_id from custom_fields where object_id = ?", accountId.toString());
                 Assert.assertEquals(values.size(), 1);
                 Assert.assertEquals(values.get(0).keySet().size(), 1);
-                Assert.assertEquals(values.get(0).get("account_record_id"), accountRecordId);
+                Assert.assertEquals(Long.valueOf(values.get(0).get("account_record_id").toString()), accountRecordId);
                 return null;
             }
         });
diff --git a/util/src/test/java/com/ning/billing/util/globallocker/TestGlobalLockerModule.java b/util/src/test/java/com/ning/billing/util/globallocker/TestGlobalLockerModule.java
new file mode 100644
index 0000000..5b0acad
--- /dev/null
+++ b/util/src/test/java/com/ning/billing/util/globallocker/TestGlobalLockerModule.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2010-2012 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.util.globallocker;
+
+import com.ning.billing.dbi.DBTestingHelper;
+import com.ning.billing.dbi.DBTestingHelper.DBEngine;
+import com.ning.billing.mock.glue.MockGlobalLockerModule;
+import com.ning.billing.util.glue.GlobalLockerModule;
+
+import com.google.inject.AbstractModule;
+
+public class TestGlobalLockerModule extends AbstractModule {
+
+    private final DBTestingHelper helper;
+
+    public TestGlobalLockerModule(final DBTestingHelper helper) {
+        this.helper = helper;
+    }
+
+    @Override
+    protected void configure() {
+        if (DBEngine.MYSQL.equals(helper.getDBEngine())) {
+            install(new GlobalLockerModule());
+        } else {
+            install(new MockGlobalLockerModule());
+        }
+    }
+}
diff --git a/util/src/test/java/com/ning/billing/util/tag/dao/TestDefaultTagDao.java b/util/src/test/java/com/ning/billing/util/tag/dao/TestDefaultTagDao.java
index 8eba74d..548a65a 100644
--- a/util/src/test/java/com/ning/billing/util/tag/dao/TestDefaultTagDao.java
+++ b/util/src/test/java/com/ning/billing/util/tag/dao/TestDefaultTagDao.java
@@ -89,11 +89,11 @@ public class TestDefaultTagDao extends UtilTestSuiteWithEmbeddedDB {
         List<TagDefinitionModelDao> result = tagDefinitionDao.getByIds(uuids, internalCallContext);
         assertEquals(result.size(), 0);
 
-        final TagDefinitionModelDao defYo = tagDefinitionDao.create("yo", "defintion yo", internalCallContext);
+        final TagDefinitionModelDao defYo = tagDefinitionDao.create(UUID.randomUUID().toString().substring(0, 5), "defintion yo", internalCallContext);
         uuids.add(defYo.getId());
-        final TagDefinitionModelDao defBah = tagDefinitionDao.create("bah", "defintion bah", internalCallContext);
+        final TagDefinitionModelDao defBah = tagDefinitionDao.create(UUID.randomUUID().toString().substring(0, 5), "defintion bah", internalCallContext);
         uuids.add(defBah.getId());
-        final TagDefinitionModelDao defZoo = tagDefinitionDao.create("zoo", "defintion zoo", internalCallContext);
+        final TagDefinitionModelDao defZoo = tagDefinitionDao.create(UUID.randomUUID().toString().substring(0, 5), "defintion zoo", internalCallContext);
         uuids.add(defZoo.getId());
 
         result = tagDefinitionDao.getByIds(uuids, internalCallContext);
@@ -111,7 +111,7 @@ public class TestDefaultTagDao extends UtilTestSuiteWithEmbeddedDB {
     @Test(groups = "slow")
     public void testGetById() throws TagDefinitionApiException {
         // User Tag
-        final TagDefinitionModelDao defYo = tagDefinitionDao.create("yo", "defintion yo", internalCallContext);
+        final TagDefinitionModelDao defYo = tagDefinitionDao.create(UUID.randomUUID().toString().substring(0, 5), "defintion yo", internalCallContext);
         final TagDefinitionModelDao resDefYo = tagDefinitionDao.getById(defYo.getId(), internalCallContext);
         assertEquals(defYo, resDefYo);
 
@@ -130,7 +130,7 @@ public class TestDefaultTagDao extends UtilTestSuiteWithEmbeddedDB {
     @Test(groups = "slow")
     public void testGetByName() throws TagDefinitionApiException {
         // User Tag
-        final TagDefinitionModelDao defYo = tagDefinitionDao.create("yo", "defintion yo", internalCallContext);
+        final TagDefinitionModelDao defYo = tagDefinitionDao.create(UUID.randomUUID().toString().substring(0, 5), "defintion yo", internalCallContext);
         final TagDefinitionModelDao resDefYo = tagDefinitionDao.getByName(defYo.getName(), internalCallContext);
         assertEquals(defYo, resDefYo);