def testMergeAddIndexElsewhereDelete(self): main = self.view self.loadCineguide(main, False) k = main.findPath('//CineGuide/KHepburn') m1 = k.movies.first() m2 = k.movies.next(m1) m3 = k.movies.next(m2) m3.set = Set((k, 'movies')) main.commit() view = self.rep.createView('view') k = view.findPath('//CineGuide/KHepburn') m1 = k.movies.first() m1.delete() view.commit() k = main.findPath('//CineGuide/KHepburn') m1 = k.movies.first() m2 = k.movies.next(m1) m3 = k.movies.next(m2) m = k.movies.last() m.set = Set((m3, 'set')) m.set.addIndex('new', 'numeric') main.commit(None) self.assert_(main.check(), 'main view did not check out')
def _sourcesChanged_(self, op): sources = self.sources sourceCount = len(sources) if sourceCount == 0: set = EmptySet() elif sourceCount == 1: set = getattr(self, self.__collection__) source = sources.first() if isinstance(set, Difference): if set._left[0] == source.itsUUID: set = Set(source) else: set = EmptySet() else: set = Set(source) elif sourceCount == 2: a, b = self.sources set = Difference(a, b) else: raise ValueError, 'too many sources' setattr(self, self.__collection__, set) return set
def testMergeNewSubIndex(self): def mergeFn(code, item, attribute, newValue): if code == MergeError.DELETE: return True return getattr(item, attribute) main = self.view self.loadCineguide(main, False) k = main.findPath('//CineGuide/KHepburn') k.movies.addIndex('t', 'value', attribute='title') main.commit() view = self.rep.createView('view') movies = view.findPath('//CineGuide/KHepburn').movies m1 = movies.first() m2 = movies.next(m1) m1.title = 'Foo' m2.title = 'Bar' view.commit() k = main.findPath('//CineGuide/KHepburn') actor = k.itsKind.newItem('actor', k.itsParent) actor.born = k.born actor.name = "an actor" actor.set = Set((k, 'movies')) actor.set.addIndex('t', 'subindex', superindex=(k, 'movies', 't')) main.commit(mergeFn) self.assert_(main.check(), 'main view did not check out')
def testMergeConflictKeepChangeNewIndex(self): def mergeFn(code, item, attribute, newValue): if code == MergeError.DELETE: return True return newValue main = self.view self.loadCineguide(main, False) movies = main.findPath('//CineGuide/KHepburn').movies m1 = movies.first() m2 = movies.next(m1) m3 = movies.next(m2) main.commit() view = self.rep.createView('view') movies = view.findPath('//CineGuide/KHepburn').movies m1 = movies.first() m2 = movies.next(m1) m3 = movies.next(m2) m1.title = 'View Changed Title' m3.set = Set((movies._owner(), 'movies')) m3.set.addIndex('t', 'attribute', attribute='title') view.commit() movies = main.findPath('//CineGuide/KHepburn').movies m1 = movies.first() m2 = movies.next(m1) m3 = movies.next(m2) m1.title = 'Main Changed Title' main.commit(mergeFn) self.assert_(main.check(), 'main view did not check out')
def _sourcesChanged_(self, op): source = self.source if source is None: set = EmptySet() else: set = Set(source) setattr(self, self.__collection__, set) return set
def _sourcesChanged_(self, op): source = self.source if source is None: set = EmptySet() elif isinstance(source, WrapperCollection): # bug 5899 - alpha2 workaround: When SmartCollections are # wrapped with IntersectionCollection/UnionCollection, # they drop the trash. So we artificially insert it back trash = schema.ns('osaf.pim', self.itsView).trashCollection for item, attribute in source.iterSources(True): if item is trash and attribute == trash.__collection__: set = Set(source) break else: set = Difference(source, trash) else: set = Set(source) setattr(self, self.__collection__, set) return set
def testRefreshDelete2(self): m = movie('movie', self.cineguide, self.movie) w = self.m4.writers.last() m.set = Set(KindSet(w.itsKind)) m.set.addIndex('n', 'numeric') size = len(m.set) self.assert_(w.itsUUID in m.set) view = self.rep.createView("other") view.findPath('//CineGuide/m4').writers.last().delete() view.commit() self.view.refresh() self.assert_(w.itsUUID not in m.set) self.assert_(len(m.set) == size - 1)
def _sourcesChanged_(self, op): sources = self.sources sourceCount = len(sources) # For now, when we join collections with Union, we pull trash # out of the equation with withoutTrash() if sourceCount == 0: set = EmptySet() elif sourceCount == 1: set = Set(sources.first().withoutTrash()) elif sourceCount == 2: left, right = sources set = Union(left.withoutTrash(), right.withoutTrash()) else: set = MultiUnion(*(source.withoutTrash() for source in sources)) setattr(self, self.__collection__, set) return set