Beispiel #1
0
 def __get_entities(self):
     if self._relationship is None:
         ents = list(self._session.iterator(self.entity_class))
     else:
         if self._relationship.children is None:
             ents = list(self._session.iterator(self.entity_class))
             visitor = \
                 get_filter_specification_visitor(EXPRESSION_KINDS.EVAL)()
             self._relationship.specification.accept(visitor)
             ents = visitor.expression(ents)
         else:
             ents = self._relationship.children
     if not self._filter_spec is None:
         visitor = get_filter_specification_visitor(EXPRESSION_KINDS.EVAL)()
         self._filter_spec.accept(visitor)
         ents = visitor.expression(ents)
     # Record the total count of matching entities.
     count = len(ents)
     if not self._order_spec is None:
         visitor = get_order_specification_visitor(EXPRESSION_KINDS.EVAL)()
         self._order_spec.accept(visitor)
         ents = visitor.expression(ents)
     if not self._slice_key is None:
         ents = ents[self._slice_key]
     return ents, count
Beispiel #2
0
 def make_filter_string(cls, filter_specification):
     """
     Converts the given filter specification to a CQL filter expression.
     """
     visitor_cls = get_filter_specification_visitor(EXPRESSION_KINDS.CQL)
     visitor = visitor_cls()
     filter_specification.accept(visitor)
     return str(visitor.expression)
Beispiel #3
0
 def _location_filter_visitor_factory(cls, session): # pylint: disable=W0613
     def location_type_expr(location_type_member):
         return BarcodedLocation.type == location_type_member.name
     custom_clause_factories = {
                         ('type', 'equal_to'): location_type_expr,
                         }
     visitor_cls = get_filter_specification_visitor(EXPRESSION_KINDS.SQL)
     return visitor_cls(BarcodedLocation, custom_clause_factories)
Beispiel #4
0
 def _rack_filter_visitor_factory(cls, session, rack_cls): # pylint: disable=W0613
     def one_location_type_expr(location_type_member):
         value = location_type_member.name
         return Rack.location.has(
                    BarcodedLocation.type == value
                    )
     custom_clause_factories = {
         ('location.type', 'equal_to'): one_location_type_expr,
         }
     visitor_cls = get_filter_specification_visitor(EXPRESSION_KINDS.SQL)
     return visitor_cls(rack_cls, custom_clause_factories)
Beispiel #5
0
    def _tube_filter_visitor_factory(cls, session): # pylint: disable=W0613
        # FIXME: This is necessary because we build our query expressions
        #        from the instrumented attributes of the entity class -
        #        which is Sample, not StockSample.
        def sample_product_id_expr(product_id):
            # Using hidden instrumented attributes pylint: disable=E1101
            return Tube.sample.has(
                and_(StockSample.sample_id == Sample.sample_id,
                     StockSample.molecule_design_pool.has(
                         MoleculeDesignPool.supplier_molecule_designs.any(
                             and_(SupplierMoleculeDesign.product_id ==
                                        product_id,
                                  SupplierMoleculeDesign.supplier_id ==
                                        StockSample.supplier_id,
                                  SupplierMoleculeDesign.is_current)
                                                                   ))))
            # pylint: enable=E1101

        custom_clause_factories = {
            ('sample.product_id', 'equal_to') : sample_product_id_expr,
            }
        visitor_cls = get_filter_specification_visitor(EXPRESSION_KINDS.SQL)
        return visitor_cls(Tube, custom_clause_factories)
Beispiel #6
0
 def filter_by(self, **kw):
     spec = eq(**kw)
     visitor_cls = get_filter_specification_visitor(self.expression_kind)
     vst = visitor_cls(self._entity_class)
     spec.accept(vst)
     return vst.filter_query(self)
Beispiel #7
0
 def _filter_visitor_factory(self):
     """
     Override this to create filter visitors with custom clauses.
     """
     visitor_cls = get_filter_specification_visitor(self.expression_kind)
     return visitor_cls(self.entity_class)
Beispiel #8
0
 def _filter_visitor_factory(self):
     visitor_cls = get_filter_specification_visitor(EXPRESSION_KINDS.SQL)
     return visitor_cls(self.entity_class)
Beispiel #9
0
 def make_filter_string(cls, filter_specification):
     visitor_cls = get_filter_specification_visitor(EXPRESSION_KINDS.CQL)
     visitor = visitor_cls()
     filter_specification.accept(visitor)
     return str(visitor.expression)