~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/model/distroseriesparent.py

Merge db-devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
    ]
12
12
 
13
13
from storm.locals import (
 
14
    Bool,
14
15
    Int,
15
16
    Reference,
 
17
    SQL,
16
18
    Storm,
17
 
    Bool,
18
19
    )
19
20
from zope.interface import implements
20
21
 
 
22
from canonical.database.enumcol import EnumCol
21
23
from canonical.launchpad.interfaces.lpstorm import (
22
24
    IMasterStore,
23
25
    IStore,
26
28
    IDistroSeriesParent,
27
29
    IDistroSeriesParentSet,
28
30
    )
 
31
from lp.registry.interfaces.pocket import PackagePublishingPocket
29
32
 
30
33
 
31
34
class DistroSeriesParent(Storm):
43
46
 
44
47
    initialized = Bool(allow_none=False)
45
48
 
 
49
    is_overlay = Bool(allow_none=False, default=False)
 
50
 
 
51
    pocket = EnumCol(
 
52
        dbName='pocket', notNull=False,
 
53
        schema=PackagePublishingPocket)
 
54
 
 
55
    component_id = Int(name='component', allow_none=True)
 
56
    component = Reference(component_id, 'Component.id')
 
57
 
46
58
 
47
59
class DistroSeriesParentSet:
48
60
    """See `IDistroSeriesParentSet`."""
49
61
    implements(IDistroSeriesParentSet)
50
62
    title = "Cross reference of parent and derived distroseries."
51
63
 
52
 
    def new(self, derived_series, parent_series, initialized):
 
64
    def new(self, derived_series, parent_series, initialized,
 
65
            is_overlay=False, pocket=None, component=None):
53
66
        """Make and return a new `DistroSeriesParent`."""
54
67
        store = IMasterStore(DistroSeriesParent)
55
68
        dsp = DistroSeriesParent()
56
69
        dsp.derived_series = derived_series
57
70
        dsp.parent_series = parent_series
58
71
        dsp.initialized = initialized
 
72
        dsp.is_overlay = is_overlay
 
73
        dsp.pocket = pocket
 
74
        dsp.component = component
59
75
        store.add(dsp)
60
76
        return dsp
61
77
 
72
88
        return store.find(
73
89
            DistroSeriesParent,
74
90
            DistroSeriesParent.parent_series_id == parent_series.id)
 
91
 
 
92
    def getFlattenedOverlayTree(self, derived_series):
 
93
        """See `IDistroSeriesParentSet`."""
 
94
        self.getByDerivedSeries(derived_series)
 
95
        rec_overlay_query = '''
 
96
            RECURSIVE t_parents(parent_series) AS (
 
97
                SELECT parent_series
 
98
                FROM DistroSeriesParent
 
99
                WHERE derived_series=? AND
 
100
                    is_overlay = True
 
101
            UNION ALL
 
102
                SELECT dsp.parent_series
 
103
                FROM DistroSeriesParent dsp, t_parents p
 
104
                WHERE dsp.derived_series = p.parent_series AND
 
105
                    dsp.is_overlay = True
 
106
        ) '''
 
107
        store = IStore(DistroSeriesParent)
 
108
        # XXX: rvb 2011-05-20 bug=785733: Order by DSD.id for now.
 
109
        # Once the ordering is specified in the database, it should
 
110
        # be used to sort the results.
 
111
        return store.with_(
 
112
            SQL(rec_overlay_query, (derived_series.id, ))).find(
 
113
                DistroSeriesParent,
 
114
                SQL('DistroSeriesParent.parent_series IN '
 
115
                    '(SELECT parent_series FROM t_parents)')
 
116
                ).order_by(DistroSeriesParent.id)