Revision cf341da4 pithos/backends/lib/sqlalchemy/node.py

b/pithos/backends/lib/sqlalchemy/node.py
46 46

  
47 47
ROOTNODE  = 0
48 48

  
49
( SERIAL, NODE, HASH, SIZE, SOURCE, MTIME, MUSER, UUID, CLUSTER ) = range(9)
49
( SERIAL, NODE, HASH, SIZE, TYPE, SOURCE, MTIME, MUSER, UUID, CLUSTER ) = range(10)
50

  
51
( MATCH_PREFIX, MATCH_EXACT ) = range(2)
50 52

  
51 53
inf = float('inf')
52 54

  
......
90 92
    'node'      : 1,
91 93
    'hash'      : 2,
92 94
    'size'      : 3,
93
    'source'    : 4,
94
    'mtime'     : 5,
95
    'muser'     : 6,
96
    'uuid'      : 7,
97
    'cluster'   : 8
95
    'type'      : 4,
96
    'source'    : 5,
97
    'mtime'     : 6,
98
    'muser'     : 7,
99
    'uuid'      : 8,
100
    'cluster'   : 9
98 101
}
99 102

  
100 103

  
......
157 160
                                         onupdate='CASCADE')))
158 161
        columns.append(Column('hash', String(255)))
159 162
        columns.append(Column('size', BigInteger, nullable=False, default=0))
163
        columns.append(Column('type', String(255), nullable=False, default=''))
160 164
        columns.append(Column('source', Integer))
161 165
        columns.append(Column('mtime', DECIMAL(precision=16, scale=6)))
162 166
        columns.append(Column('muser', String(255), nullable=False, default=''))
......
229 233
    def node_get_versions(self, node, keys=(), propnames=_propnames):
230 234
        """Return the properties of all versions at node.
231 235
           If keys is empty, return all properties in the order
232
           (serial, node, hash, size, source, mtime, muser, uuid, cluster).
236
           (serial, node, hash, size, type, source, mtime, muser, uuid, cluster).
233 237
        """
234 238
        
235 239
        s = select([self.versions.c.serial,
236 240
                    self.versions.c.node,
237 241
                    self.versions.c.hash,
238 242
                    self.versions.c.size,
243
                    self.versions.c.type,
239 244
                    self.versions.c.source,
240 245
                    self.versions.c.mtime,
241 246
                    self.versions.c.muser,
......
488 493
                    self.versions.c.node,
489 494
                    self.versions.c.hash,
490 495
                    self.versions.c.size,
496
                    self.versions.c.type,
491 497
                    self.versions.c.source,
492 498
                    self.versions.c.mtime,
493 499
                    self.versions.c.muser,
......
550 556
        mtime = max(mtime, r[2])
551 557
        return (count, size, mtime)
552 558
    
553
    def version_create(self, node, hash, size, source, muser, uuid, cluster=0):
559
    def version_create(self, node, hash, size, type, source, muser, uuid, cluster=0):
554 560
        """Create a new version from the given properties.
555 561
           Return the (serial, mtime) of the new version.
556 562
        """
557 563
        
558 564
        mtime = time()
559
        s = self.versions.insert().values(node=node, hash=hash, size=size, source=source,
565
        s = self.versions.insert().values(node=node, hash=hash, size=size, type=type, source=source,
560 566
                                          mtime=mtime, muser=muser, uuid=uuid, cluster=cluster)
561 567
        serial = self.conn.execute(s).inserted_primary_key[0]
562 568
        self.statistics_update_ancestors(node, 1, size, mtime, cluster)
......
565 571
    def version_lookup(self, node, before=inf, cluster=0):
566 572
        """Lookup the current version of the given node.
567 573
           Return a list with its properties:
568
           (serial, node, hash, size, source, mtime, muser, uuid, cluster)
574
           (serial, node, hash, size, type, source, mtime, muser, uuid, cluster)
569 575
           or None if the current version is not found in the given cluster.
570 576
        """
571 577
        
572 578
        v = self.versions.alias('v')
573 579
        s = select([v.c.serial, v.c.node, v.c.hash,
574
                    v.c.size, v.c.source, v.c.mtime,
575
                    v.c.muser, v.c.uuid, v.c.cluster])
580
                    v.c.size, v.c.type, v.c.source,
581
                    v.c.mtime, v.c.muser, v.c.uuid,
582
                    v.c.cluster])
576 583
        c = select([func.max(self.versions.c.serial)],
577 584
            self.versions.c.node == node)
578 585
        if before != inf:
......
590 597
        """Return a sequence of values for the properties of
591 598
           the version specified by serial and the keys, in the order given.
592 599
           If keys is empty, return all properties in the order
593
           (serial, node, hash, size, source, mtime, muser, uuid, cluster).
600
           (serial, node, hash, size, type, source, mtime, muser, uuid, cluster).
594 601
        """
595 602
        
596 603
        v = self.versions.alias()
597 604
        s = select([v.c.serial, v.c.node, v.c.hash,
598
                    v.c.size, v.c.source, v.c.mtime,
599
                    v.c.muser, v.c.uuid, v.c.cluster], v.c.serial == serial)
605
                    v.c.size, v.c.type, v.c.source,
606
                    v.c.mtime, v.c.muser, v.c.uuid,
607
                    v.c.cluster], v.c.serial == serial)
600 608
        rp = self.conn.execute(s)
601 609
        r = rp.fetchone()
602 610
        rp.close()
......
748 756
        s = s.where(a.c.domain == domain)
749 757
        s = s.where(n.c.node == v.c.node)
750 758
        conj = []
751
        for x in pathq:
752
            conj.append(n.c.path.like(self.escape_like(x) + '%', escape='\\'))
759
        for path, match in pathq:
760
            if match == MATCH_PREFIX:
761
                conj.append(n.c.path.like(self.escape_like(path) + '%', escape='\\'))
762
            elif match == MATCH_EXACT:
763
                conj.append(n.c.path == path)
753 764
        if conj:
754 765
            s = s.where(or_(*conj))
755 766
        rp = self.conn.execute(s)
......
826 837
        s = s.where(n.c.node == v.c.node)
827 838
        s = s.where(and_(n.c.path > bindparam('start'), n.c.path < nextling))
828 839
        conj = []
829
        for x in pathq:
830
            conj.append(n.c.path.like(self.escape_like(x) + '%', escape='\\'))
840
        for path, match in pathq:
841
            if match == MATCH_PREFIX:
842
                conj.append(n.c.path.like(self.escape_like(path) + '%', escape='\\'))
843
            elif match == MATCH_EXACT:
844
                conj.append(n.c.path == path)
831 845
        if conj:
832 846
            s = s.where(or_(*conj))
833 847
        

Also available in: Unified diff