Revision 059857e2 pithos/backends/lib/sqlalchemy/node.py

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

  
44 44
from pithos.lib.filter import parse_filters
45 45

  
46

  
46 47
ROOTNODE  = 0
47 48

  
48 49
( SERIAL, NODE, HASH, SIZE, SOURCE, MTIME, MUSER, CLUSTER ) = range(8)
......
169 170
                                         ondelete='CASCADE',
170 171
                                         onupdate='CASCADE'),
171 172
                              primary_key=True))
173
        columns.append(Column('domain', String(255), primary_key=True))
172 174
        columns.append(Column('key', String(255), primary_key=True))
173 175
        columns.append(Column('value', String(255)))
174 176
        self.attributes = Table('attributes', metadata, *columns, mysql_engine='InnoDB')
......
647 649
        self.conn.execute(s).close()
648 650
        return hash
649 651
    
650
    def attribute_get(self, serial, keys=()):
652
    def attribute_get(self, serial, domain, keys=()):
651 653
        """Return a list of (key, value) pairs of the version specified by serial.
652 654
           If keys is empty, return all attributes.
653 655
           Othwerise, return only those specified.
......
657 659
            attrs = self.attributes.alias()
658 660
            s = select([attrs.c.key, attrs.c.value])
659 661
            s = s.where(and_(attrs.c.key.in_(keys),
660
                             attrs.c.serial == serial))
662
                             attrs.c.serial == serial,
663
                             attrs.c.domain == domain))
661 664
        else:
662 665
            attrs = self.attributes.alias()
663 666
            s = select([attrs.c.key, attrs.c.value])
664
            s = s.where(attrs.c.serial == serial)
667
            s = s.where(and_(attrs.c.serial == serial,
668
                             attrs.c.domain == domain))
665 669
        r = self.conn.execute(s)
666 670
        l = r.fetchall()
667 671
        r.close()
668 672
        return l
669 673
    
670
    def attribute_set(self, serial, items):
674
    def attribute_set(self, serial, domain, items):
671 675
        """Set the attributes of the version specified by serial.
672 676
           Receive attributes as an iterable of (key, value) pairs.
673 677
        """
......
676 680
        for k, v in items:
677 681
            s = self.attributes.update()
678 682
            s = s.where(and_(self.attributes.c.serial == serial,
683
                             self.attributes.c.domain == domain,
679 684
                             self.attributes.c.key == k))
680 685
            s = s.values(value = v)
681 686
            rp = self.conn.execute(s)
682 687
            rp.close()
683 688
            if rp.rowcount == 0:
684 689
                s = self.attributes.insert()
685
                s = s.values(serial=serial, key=k, value=v)
690
                s = s.values(serial=serial, domain=domain, key=k, value=v)
686 691
                self.conn.execute(s).close()
687 692
    
688
    def attribute_del(self, serial, keys=()):
693
    def attribute_del(self, serial, domain, keys=()):
689 694
        """Delete attributes of the version specified by serial.
690 695
           If keys is empty, delete all attributes.
691 696
           Otherwise delete those specified.
......
696 701
            for key in keys:
697 702
                s = self.attributes.delete()
698 703
                s = s.where(and_(self.attributes.c.serial == serial,
704
                                 self.attributes.c.domain == domain,
699 705
                                 self.attributes.c.key == key))
700 706
                self.conn.execute(s).close()
701 707
        else:
702 708
            s = self.attributes.delete()
703
            s = s.where(self.attributes.c.serial == serial)
709
            s = s.where(and_(self.attributes.c.serial == serial,
710
                             self.attributes.c.domain == domain))
704 711
            self.conn.execute(s).close()
705 712
    
706 713
    def attribute_copy(self, source, dest):
707
        s = select([dest, self.attributes.c.key, self.attributes.c.value],
714
        s = select([dest, self.attributes.c.domain, self.attributes.c.key, self.attributes.c.value],
708 715
            self.attributes.c.serial == source)
709 716
        rp = self.conn.execute(s)
710 717
        attributes = rp.fetchall()
711 718
        rp.close()
712
        for dest, k, v in attributes:
719
        for dest, domain, k, v in attributes:
713 720
            #insert or replace
714 721
            s = self.attributes.update().where(and_(
715 722
                self.attributes.c.serial == dest,
723
                self.attributes.c.domain == domain,
716 724
                self.attributes.c.key == k))
717 725
            rp = self.conn.execute(s, value=v)
718 726
            rp.close()
719 727
            if rp.rowcount == 0:
720 728
                s = self.attributes.insert()
721
                values = {'serial':dest, 'key':k, 'value':v}
729
                values = {'serial':dest, 'domain':domain, 'key':k, 'value':v}
722 730
                self.conn.execute(s, values).close()
723 731
    
724
    def latest_attribute_keys(self, parent, before=inf, except_cluster=0, pathq=[]):
732
    def latest_attribute_keys(self, parent, domain, before=inf, except_cluster=0, pathq=[]):
725 733
        """Return a list with all keys pairs defined
726 734
           for all latest versions under parent that
727 735
           do not belong to the cluster.
......
740 748
        s = s.where(v.c.node.in_(select([self.nodes.c.node],
741 749
            self.nodes.c.parent == parent)))
742 750
        s = s.where(a.c.serial == v.c.serial)
751
        s = s.where(a.c.domain == domain)
743 752
        s = s.where(n.c.node == v.c.node)
744 753
        conj = []
745 754
        for x in pathq:
......
753 762
    
754 763
    def latest_version_list(self, parent, prefix='', delimiter=None,
755 764
                            start='', limit=10000, before=inf,
756
                            except_cluster=0, pathq=[], filterq=[]):
765
                            except_cluster=0, pathq=[], domain=None, filterq=[]):
757 766
        """Return a (list of (path, serial) tuples, list of common prefixes)
758 767
           for the current versions of the paths with the given parent,
759 768
           matching the following criteria.
......
815 824
        s = s.where(v.c.cluster != except_cluster)
816 825
        s = s.where(v.c.node.in_(select([self.nodes.c.node],
817 826
            self.nodes.c.parent == parent)))
818
        if filterq:
827
        if domain and filterq:
819 828
            s = s.where(a.c.serial == v.c.serial)
829
            s = s.where(a.c.domain == domain)
820 830
        
821 831
        s = s.where(n.c.node == v.c.node)
822 832
        s = s.where(and_(n.c.path > bindparam('start'), n.c.path < nextling))
......
827 837
        if conj:
828 838
            s = s.where(or_(*conj))
829 839
        
830
        if filterq:
840
        if domain and filterq:
831 841
            included, excluded, opers = parse_filters(filterq)
832 842
            if included:
833 843
                s = s.where(a.c.key.in_(x for x in included))

Also available in: Unified diff