mirror of
https://github.com/django/django.git
synced 2025-07-06 02:39:12 +00:00
queryset-refactor: Changed all tree and filter "connections" to "connectors" so
that database connections and constraint connectors look different in the code. George Vilches pointed out this was slightly confusing previously. git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6866 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
4ea96c0468
commit
cc0078494e
@ -257,13 +257,13 @@ class Query(object):
|
||||
params.extend(self.extra_params)
|
||||
return ' '.join(result), tuple(params)
|
||||
|
||||
def combine(self, rhs, connection):
|
||||
def combine(self, rhs, connector):
|
||||
"""
|
||||
Merge the 'rhs' query into the current one (with any 'rhs' effects
|
||||
being applied *after* (that is, "to the right of") anything in the
|
||||
current query. 'rhs' is not modified during a call to this function.
|
||||
|
||||
The 'connection' parameter describes how to connect filters from the
|
||||
The 'connector' parameter describes how to connect filters from the
|
||||
'rhs' query.
|
||||
"""
|
||||
assert self.model == rhs.model, \
|
||||
@ -276,7 +276,7 @@ class Query(object):
|
||||
# Work out how to relabel the rhs aliases, if necessary.
|
||||
change_map = {}
|
||||
used = {}
|
||||
conjunction = (connection == AND)
|
||||
conjunction = (connector == AND)
|
||||
first = True
|
||||
for alias in rhs.tables:
|
||||
if not rhs.alias_map[alias][ALIAS_REFCOUNT]:
|
||||
@ -321,7 +321,7 @@ class Query(object):
|
||||
w.add([alias, pk.column, pk, 'isnull', False], AND)
|
||||
else:
|
||||
w = WhereNode()
|
||||
self.where.add(w, connection)
|
||||
self.where.add(w, connector)
|
||||
|
||||
# Selection columns and extra extensions are those provided by 'rhs'.
|
||||
self.select = []
|
||||
@ -465,7 +465,7 @@ class Query(object):
|
||||
result = []
|
||||
for field in ordering:
|
||||
if field == '?':
|
||||
result.append(self.connection.ops.random_function_sql())
|
||||
result.append(self.connector.ops.random_function_sql())
|
||||
continue
|
||||
if isinstance(field, int):
|
||||
if field < 0:
|
||||
@ -664,7 +664,7 @@ class Query(object):
|
||||
self.fill_related_selections(f.rel.to._meta, alias, cur_depth + 1,
|
||||
used)
|
||||
|
||||
def add_filter(self, filter_expr, connection=AND, negate=False):
|
||||
def add_filter(self, filter_expr, connector=AND, negate=False):
|
||||
"""
|
||||
Add a single filter to the query.
|
||||
"""
|
||||
@ -694,13 +694,13 @@ class Query(object):
|
||||
|
||||
try:
|
||||
field, target, unused, join_list, nullable = self.setup_joins(parts,
|
||||
opts, alias, (connection == AND))
|
||||
opts, alias, (connector == AND))
|
||||
except TypeError, e:
|
||||
if len(parts) != 1 or parts[0] not in self.extra_select:
|
||||
raise e
|
||||
# Filtering on some alias from extra(select=...)
|
||||
self.where.add([None, parts[0], None, lookup_type, value],
|
||||
connection)
|
||||
connector)
|
||||
return
|
||||
col = target.column
|
||||
alias = join_list[-1][-1]
|
||||
@ -724,7 +724,7 @@ class Query(object):
|
||||
# efficient at the database level.
|
||||
self.promote_alias(join_list[-1][0])
|
||||
|
||||
self.where.add([alias, col, field, lookup_type, value], connection)
|
||||
self.where.add([alias, col, field, lookup_type, value], connector)
|
||||
if negate:
|
||||
flag = False
|
||||
for pos, null in enumerate(nullable):
|
||||
@ -750,11 +750,11 @@ class Query(object):
|
||||
|
||||
for child in q_object.children:
|
||||
if isinstance(child, Node):
|
||||
self.where.start_subtree(q_object.connection)
|
||||
self.where.start_subtree(q_object.connector)
|
||||
self.add_q(child)
|
||||
self.where.end_subtree()
|
||||
else:
|
||||
self.add_filter(child, q_object.connection, q_object.negated)
|
||||
self.add_filter(child, q_object.connector, q_object.negated)
|
||||
|
||||
def setup_joins(self, names, opts, alias, dupe_multis):
|
||||
"""
|
||||
|
@ -57,14 +57,14 @@ class WhereNode(tree.Node):
|
||||
sql, params = self.make_atom(child, qn)
|
||||
format = '%s'
|
||||
except EmptyResultSet:
|
||||
if self.connection == AND and not node.negated:
|
||||
if self.connector == AND and not node.negated:
|
||||
# We can bail out early in this particular case (only).
|
||||
raise
|
||||
sql = None
|
||||
if sql:
|
||||
result.append(format % sql)
|
||||
result_params.extend(params)
|
||||
conn = ' %s ' % node.connection
|
||||
conn = ' %s ' % node.connector
|
||||
return conn.join(result), result_params
|
||||
|
||||
def make_atom(self, child, qn):
|
||||
|
@ -11,25 +11,25 @@ class Node(object):
|
||||
connection (the root) with the children being either leaf nodes or other
|
||||
Node instances.
|
||||
"""
|
||||
# Standard connection type. Clients usually won't use this at all and
|
||||
# Standard connector type. Clients usually won't use this at all and
|
||||
# subclasses will usually override the value.
|
||||
default = 'DEFAULT'
|
||||
|
||||
def __init__(self, children=None, connection=None):
|
||||
def __init__(self, children=None, connector=None):
|
||||
self.children = children and children[:] or []
|
||||
self.connection = connection or self.default
|
||||
self.connector = connector or self.default
|
||||
self.subtree_parents = []
|
||||
self.negated = False
|
||||
|
||||
def __str__(self):
|
||||
return '(%s: %s)' % (self.connection, ', '.join([str(c) for c in
|
||||
return '(%s: %s)' % (self.connector, ', '.join([str(c) for c in
|
||||
self.children]))
|
||||
|
||||
def __deepcopy__(self, memodict):
|
||||
"""
|
||||
Utility method used by copy.deepcopy().
|
||||
"""
|
||||
obj = self.__class__(connection=self.connection)
|
||||
obj = self.__class__(connector=self.connector)
|
||||
obj.children = copy.deepcopy(self.children, memodict)
|
||||
obj.subtree_parents = copy.deepcopy(self.subtree_parents, memodict)
|
||||
obj.negated = self.negated
|
||||
@ -56,33 +56,33 @@ class Node(object):
|
||||
def add(self, node, conn_type):
|
||||
"""
|
||||
Adds a new node to the tree. If the conn_type is the same as the root's
|
||||
current connection type, the node is added to the first level.
|
||||
current connector type, the node is added to the first level.
|
||||
Otherwise, the whole tree is pushed down one level and a new root
|
||||
connection is created, connecting the existing tree and the new node.
|
||||
connector is created, connecting the existing tree and the new node.
|
||||
"""
|
||||
if len(self.children) < 2:
|
||||
self.connection = conn_type
|
||||
if self.connection == conn_type:
|
||||
if isinstance(node, Node) and (node.connection == conn_type
|
||||
self.connector = conn_type
|
||||
if self.connector == conn_type:
|
||||
if isinstance(node, Node) and (node.connector == conn_type
|
||||
or len(node) == 1):
|
||||
self.children.extend(node.children)
|
||||
else:
|
||||
self.children.append(node)
|
||||
else:
|
||||
obj = Node(self.children, self.connection)
|
||||
self.connection = conn_type
|
||||
obj = Node(self.children, self.connector)
|
||||
self.connector = conn_type
|
||||
self.children = [obj, node]
|
||||
|
||||
def negate(self):
|
||||
"""
|
||||
Negate the sense of the root connection.
|
||||
Negate the sense of the root connector.
|
||||
|
||||
Interpreting the meaning of this negate is up to client code. This
|
||||
method is useful for implementing "not" arrangements.
|
||||
"""
|
||||
self.children = [NegatedNode(self.children, self.connection,
|
||||
self.children = [NegatedNode(self.children, self.connector,
|
||||
old_state=self.negated)]
|
||||
self.connection = self.default
|
||||
self.connector = self.default
|
||||
|
||||
def start_subtree(self, conn_type):
|
||||
"""
|
||||
@ -91,13 +91,13 @@ class Node(object):
|
||||
connected correctly to any existing nodes in the tree.
|
||||
"""
|
||||
if len(self.children) == 1:
|
||||
self.connection = conn_type
|
||||
elif self.connection != conn_type:
|
||||
self.children = [Node(self.children, self.connection)]
|
||||
self.connection = conn_type
|
||||
self.connector = conn_type
|
||||
elif self.connector != conn_type:
|
||||
self.children = [Node(self.children, self.connector)]
|
||||
self.connector = conn_type
|
||||
|
||||
self.subtree_parents.append(Node(self.children, self.connection))
|
||||
self.connection = self.default
|
||||
self.subtree_parents.append(Node(self.children, self.connector))
|
||||
self.connector = self.default
|
||||
self.children = []
|
||||
|
||||
def end_subtree(self):
|
||||
@ -108,17 +108,17 @@ class Node(object):
|
||||
the current instances state to be the parent.
|
||||
"""
|
||||
obj = self.subtree_parents.pop()
|
||||
node = Node(self.children, self.connection)
|
||||
self.connection = obj.connection
|
||||
node = Node(self.children, self.connector)
|
||||
self.connector = obj.connector
|
||||
self.children = obj.children
|
||||
self.children.append(node)
|
||||
|
||||
class NegatedNode(Node):
|
||||
"""
|
||||
A class that indicates the connection type should be negated (whatever that
|
||||
A class that indicates the connector type should be negated (whatever that
|
||||
means -- it's up to the client) when used by the client code.
|
||||
"""
|
||||
def __init__(self, children=None, connection=None, old_state=True):
|
||||
super(NegatedNode, self).__init__(children, connection)
|
||||
def __init__(self, children=None, connector=None, old_state=True):
|
||||
super(NegatedNode, self).__init__(children, connector)
|
||||
self.negated = not old_state
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user