← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:stormify-productlicense into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:stormify-productlicense into launchpad:master.

Commit message:
Convert ProductLicense to Storm

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/446320
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stormify-productlicense into launchpad:master.
diff --git a/lib/lp/registry/model/product.py b/lib/lp/registry/model/product.py
index 3c95e99..b879223 100644
--- a/lib/lp/registry/model/product.py
+++ b/lib/lp/registry/model/product.py
@@ -906,8 +906,10 @@ class Product(
     @cachedproperty
     def _cached_licenses(self):
         """Get the licenses as a tuple."""
-        product_licenses = ProductLicense.selectBy(
-            product=self, orderBy="license"
+        product_licenses = (
+            IStore(ProductLicense)
+            .find(ProductLicense, product=self)
+            .order_by(ProductLicense.license)
         )
         return tuple(
             product_license.license for product_license in product_licenses
@@ -939,8 +941,10 @@ class Product(
                 raise ValueError("%s is not a License." % license)
 
         for license in old_licenses.difference(licenses):
-            product_license = ProductLicense.selectOneBy(
-                product=self, license=license
+            product_license = (
+                IStore(ProductLicense)
+                .find(ProductLicense, product=self, license=license)
+                .one()
             )
             product_license.destroySelf()
 
@@ -1696,9 +1700,9 @@ def get_precached_products(
         cache.commercial_subscription = subscription
     if need_licences:
         for license in IStore(ProductLicense).find(
-            ProductLicense, ProductLicense.productID.is_in(product_ids)
+            ProductLicense, ProductLicense.product_id.is_in(product_ids)
         ):
-            cache = caches[license.productID]
+            cache = caches[license.product_id]
             if license.license not in cache._cached_licenses:
                 cache._cached_licenses.append(license.license)
     if need_projectgroups:
@@ -2140,7 +2144,7 @@ class ProductSet:
                         1,
                         tables=[ProductLicense],
                         where=And(
-                            ProductLicense.productID == Product.id,
+                            ProductLicense.product_id == Product.id,
                             ProductLicense.license.is_in(licenses),
                         ),
                     )
diff --git a/lib/lp/registry/model/productlicense.py b/lib/lp/registry/model/productlicense.py
index 8179e34..3f63b78 100644
--- a/lib/lp/registry/model/productlicense.py
+++ b/lib/lp/registry/model/productlicense.py
@@ -7,19 +7,30 @@ __all__ = [
     "ProductLicense",
 ]
 
-
+from storm.locals import Int, Reference, Store
 from zope.interface import implementer
 
 from lp.registry.interfaces.product import License
 from lp.registry.interfaces.productlicense import IProductLicense
 from lp.services.database.enumcol import DBEnum
-from lp.services.database.sqlbase import SQLBase
-from lp.services.database.sqlobject import ForeignKey
+from lp.services.database.stormbase import StormBase
 
 
 @implementer(IProductLicense)
-class ProductLicense(SQLBase):
+class ProductLicense(StormBase):
     """A product's licence."""
 
-    product = ForeignKey(dbName="product", foreignKey="Product", notNull=True)
+    __storm_table__ = "ProductLicense"
+
+    id = Int(primary=True)
+    product_id = Int(name="product", allow_none=False)
+    product = Reference(product_id, "Product.id")
     license = DBEnum(name="license", allow_none=False, enum=License)
+
+    def __init__(self, product, license):
+        super().__init__()
+        self.product = product
+        self.license = license
+
+    def destroySelf(self):
+        Store.of(self).remove(self)