killbill-memoizeit

Merge remote-tracking branch 'origin/analytics-as-osgi-plugin-support'

4/4/2013 8:01:11 PM

Details

diff --git a/api/src/main/java/com/ning/billing/osgi/api/OSGIKillbill.java b/api/src/main/java/com/ning/billing/osgi/api/OSGIKillbill.java
index 51a72f6..1b5b9bf 100644
--- a/api/src/main/java/com/ning/billing/osgi/api/OSGIKillbill.java
+++ b/api/src/main/java/com/ning/billing/osgi/api/OSGIKillbill.java
@@ -36,6 +36,7 @@ import com.ning.billing.usage.api.UsageUserApi;
 import com.ning.billing.util.api.AuditUserApi;
 import com.ning.billing.util.api.CustomFieldUserApi;
 import com.ning.billing.util.api.ExportUserApi;
+import com.ning.billing.util.api.RecordIdApi;
 import com.ning.billing.util.api.TagUserApi;
 
 /**
@@ -88,6 +89,7 @@ public interface OSGIKillbill {
 
     public JunctionApi getJunctionApi();
 
+    public RecordIdApi getRecordIdApi();
     /**
      * Used by the OSGI bundles to discover their configuration
      *
diff --git a/api/src/main/java/com/ning/billing/util/api/RecordIdApi.java b/api/src/main/java/com/ning/billing/util/api/RecordIdApi.java
new file mode 100644
index 0000000..376056d
--- /dev/null
+++ b/api/src/main/java/com/ning/billing/util/api/RecordIdApi.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2010-2013 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.api;
+
+import java.util.UUID;
+
+import com.ning.billing.ObjectType;
+
+public interface RecordIdApi {
+
+    /**
+     *
+     * This can be used by external plugins to keep the mapping between UUID  and recordId
+     *
+     * @param objectId the uuid of the object
+     * @param objectType the object type
+     * @return the record id associated with that object
+     */
+    Long getRecordId(UUID objectId, ObjectType objectType);
+}
diff --git a/osgi/src/main/java/com/ning/billing/osgi/DefaultOSGIKillbill.java b/osgi/src/main/java/com/ning/billing/osgi/DefaultOSGIKillbill.java
index 67412a9..18014ed 100644
--- a/osgi/src/main/java/com/ning/billing/osgi/DefaultOSGIKillbill.java
+++ b/osgi/src/main/java/com/ning/billing/osgi/DefaultOSGIKillbill.java
@@ -42,6 +42,7 @@ import com.ning.billing.usage.api.UsageUserApi;
 import com.ning.billing.util.api.AuditUserApi;
 import com.ning.billing.util.api.CustomFieldUserApi;
 import com.ning.billing.util.api.ExportUserApi;
+import com.ning.billing.util.api.RecordIdApi;
 import com.ning.billing.util.api.TagUserApi;
 
 public class DefaultOSGIKillbill implements OSGIKillbill {
@@ -66,6 +67,7 @@ public class DefaultOSGIKillbill implements OSGIKillbill {
     private final ExportUserApi exportUserApi;
     private final TagUserApi tagUserApi;
     private final JunctionApi junctionApi;
+    private final RecordIdApi recordIdApi;
 
     private final PluginConfigServiceApi configServiceApi;
 
@@ -90,6 +92,7 @@ public class DefaultOSGIKillbill implements OSGIKillbill {
                                final ExportUserApi exportUserApi,
                                final TagUserApi tagUserApi,
                                final JunctionApi junctionApi,
+                               final RecordIdApi recordIdApi,
                                final PluginConfigServiceApi configServiceApi) {
         this.accountUserApi = accountUserApi;
         this.analyticsSanityApi = analyticsSanityApi;
@@ -111,6 +114,7 @@ public class DefaultOSGIKillbill implements OSGIKillbill {
         this.exportUserApi = exportUserApi;
         this.tagUserApi = tagUserApi;
         this.junctionApi = junctionApi;
+        this.recordIdApi = recordIdApi;
         this.configServiceApi = configServiceApi;
     }
 
@@ -215,6 +219,11 @@ public class DefaultOSGIKillbill implements OSGIKillbill {
     }
 
     @Override
+    public RecordIdApi getRecordIdApi() {
+        return recordIdApi;
+    }
+
+    @Override
     public PluginConfigServiceApi getPluginConfigServiceApi() {
         return configServiceApi;
     }
diff --git a/osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIKillbillAPI.java b/osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIKillbillAPI.java
index 06cdc54..5cc50a7 100644
--- a/osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIKillbillAPI.java
+++ b/osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIKillbillAPI.java
@@ -40,6 +40,7 @@ import com.ning.billing.usage.api.UsageUserApi;
 import com.ning.billing.util.api.AuditUserApi;
 import com.ning.billing.util.api.CustomFieldUserApi;
 import com.ning.billing.util.api.ExportUserApi;
+import com.ning.billing.util.api.RecordIdApi;
 import com.ning.billing.util.api.TagUserApi;
 
 public class OSGIKillbillAPI extends OSGIKillbillLibraryBase implements OSGIKillbill {
@@ -262,6 +263,16 @@ public class OSGIKillbillAPI extends OSGIKillbillLibraryBase implements OSGIKill
     }
 
     @Override
+    public RecordIdApi getRecordIdApi() {
+        return withServiceTracker(killbillTracker, new APICallback<RecordIdApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+            @Override
+            public RecordIdApi executeWithService(final OSGIKillbill service) {
+                return service.getRecordIdApi();
+            }
+        });
+    }
+
+    @Override
     public PluginConfigServiceApi getPluginConfigServiceApi() {
         return withServiceTracker(killbillTracker, new APICallback<PluginConfigServiceApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
             @Override
diff --git a/util/src/main/java/com/ning/billing/util/recordid/DefaultRecordId.java b/util/src/main/java/com/ning/billing/util/recordid/DefaultRecordId.java
new file mode 100644
index 0000000..59458c9
--- /dev/null
+++ b/util/src/main/java/com/ning/billing/util/recordid/DefaultRecordId.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2010-2013 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.recordid;
+
+import java.util.UUID;
+
+import javax.inject.Inject;
+
+import com.ning.billing.ObjectType;
+import com.ning.billing.util.api.RecordIdApi;
+import com.ning.billing.util.cache.Cachable.CacheType;
+import com.ning.billing.util.cache.CacheControllerDispatcher;
+import com.ning.billing.util.dao.NonEntityDao;
+
+public class DefaultRecordId implements RecordIdApi  {
+
+    private final NonEntityDao nonEntityDao;
+    private final CacheControllerDispatcher cacheControllerDispatcher;
+
+    @Inject
+    public DefaultRecordId(final NonEntityDao nonEntityDao, final CacheControllerDispatcher cacheControllerDispatcher) {
+        this.nonEntityDao = nonEntityDao;
+        this.cacheControllerDispatcher = cacheControllerDispatcher;
+    }
+
+
+    @Override
+    public Long getRecordId(final UUID objectId, final ObjectType objectType) {
+        return nonEntityDao.retrieveRecordIdFromObject(objectId, objectType, cacheControllerDispatcher.getCacheController(CacheType.RECORD_ID));
+    }
+}