Author: justi9
Date: 2010-07-28 17:41:21 -0400 (Wed, 28 Jul 2010)
New Revision: 4160
Added:
mgmt/newdata/rosemary/python/rosemary/sqlfilter.py
Modified:
mgmt/newdata/cumin/python/cumin/grid/submission.py
mgmt/newdata/cumin/python/cumin/main.py
mgmt/newdata/cumin/python/cumin/messaging/broker.py
mgmt/newdata/cumin/python/cumin/model.py
mgmt/newdata/cumin/python/cumin/sqladapter.py
mgmt/newdata/mint/python/mint/update.py
mgmt/newdata/rosemary/python/rosemary/model.py
mgmt/newdata/rosemary/python/rosemary/sqloperation.py
mgmt/newdata/rosemary/python/rosemary/sqlquery.py
mgmt/newdata/rosemary/python/rosemary/util.py
Log:
* Support aggregate object deletes
* Add a no-delete policy for collectors
* The above required refactoring rosemary metadata init
* Make sql filters stand apart from SqlQuery, and make filters a
feature of the base SqlOperation
* Some renaming in rosemary
Modified: mgmt/newdata/cumin/python/cumin/grid/submission.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/grid/submission.py 2010-07-28 17:12:53 UTC (rev 4159)
+++ mgmt/newdata/cumin/python/cumin/grid/submission.py 2010-07-28 21:41:21 UTC (rev 4160)
@@ -34,11 +34,12 @@
self.add_join(jobserver, submission.jobserverRef, jobserver._id)
- FreshnessFilter(self.query, submission)
+ filter = FreshnessFilter(submission)
+ self.query.add_filter(filter)
-class FreshnessFilter(SqlQueryFilter):
- def __init__(self, query, cls):
- super(FreshnessFilter, self).__init__(query)
+class FreshnessFilter(SqlFilter):
+ def __init__(self, cls):
+ super(FreshnessFilter, self).__init__()
table = cls.sql_table
Modified: mgmt/newdata/cumin/python/cumin/main.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/main.py 2010-07-28 17:12:53 UTC (rev 4159)
+++ mgmt/newdata/cumin/python/cumin/main.py 2010-07-28 21:41:21 UTC (rev 4160)
@@ -252,7 +252,8 @@
enqueues_col = samples_table._columns_by_name["msgTotalEnqueues"]
when = "now() - interval '600 seconds'"
- SqlComparisonFilter(subquery, updated_col, when, ">=")
+ filter = SqlComparisonFilter(updated_col, when, ">=")
+ subquery.add_filter(filter)
columns = list()
columns.append(parent_col)
@@ -265,7 +266,7 @@
options.sort_ascending = False
options.group_column = "%s, %s, %s" %
("\"Queue\".name", "\"Queue\"._id",
"\"Vhost\".\"_brokerRef_id\"")
- having = SqlComparisonFilter(None, "count(1)", "1",
">")
+ having = SqlComparisonFilter("count(1)", "1",
">")
options.group_having.append(having)
try:
@@ -296,10 +297,10 @@
self.adapter.vhost_id_field = ObjectSqlField \
(self.adapter, self.cls.vhostRef)
- SqlComparisonFilter(self.adapter.query,
- self.cls.msgDepth.sql_column,
- "null",
- "is not")
+ filter = SqlComparisonFilter(self.cls.msgDepth.sql_column,
+ "null",
+ "is not")
+ self.adapter.query.add_filter(filter)
class NameColumn(ObjectLinkColumn):
def render_cell_href(self, session, record):
@@ -331,10 +332,10 @@
def init(self):
super(TopSystemTable, self).init()
- SqlComparisonFilter(self.adapter.query,
- self.cls.loadAverage1Min.sql_column,
- "null",
- "is not")
+ filter = SqlComparisonFilter(self.cls.loadAverage1Min.sql_column,
+ "null",
+ "is not")
+ self.adapter.query.add_filter(filter)
class TopSubmissionTable(TopTable):
def __init__(self, app, name):
@@ -356,10 +357,13 @@
table = self.cls.sql_table
- SqlComparisonFilter(self.adapter.query, table.Running, "0",
">")
- SqlComparisonFilter(self.adapter.query, table._qmf_update_time,
- "now() - interval '60 seconds'",
">=")
+ filter = SqlComparisonFilter(table.Running, "0", ">")
+ self.adapter.query.add_filter(filter)
+ filter = SqlComparisonFilter(table._qmf_update_time,
+ "now() - interval '60 seconds'",
">=")
+ self.adapter.query.add_filter(filter)
+
class NameColumn(ObjectLinkColumn):
def render_cell_href(self, session, record):
# XXX fix this when submission has collector ref
Modified: mgmt/newdata/cumin/python/cumin/messaging/broker.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/messaging/broker.py 2010-07-28 17:12:53 UTC (rev
4159)
+++ mgmt/newdata/cumin/python/cumin/messaging/broker.py 2010-07-28 21:41:21 UTC (rev
4160)
@@ -39,11 +39,12 @@
this = mapping.sql_table._group_id
that = "%(group_id)s"
- SqlComparisonFilter(subquery, this, that)
+ filter = SqlComparisonFilter(this, that)
+ subquery.add_filter(filter)
text = subquery.emit(("1",))
- self.group_filter = SqlExistenceFilter(None, text)
+ self.group_filter = SqlExistenceFilter(text)
def get_sql_options(self, options):
sql_options = super(BrokerData, self).get_sql_options(options)
Modified: mgmt/newdata/cumin/python/cumin/model.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/model.py 2010-07-28 17:12:53 UTC (rev 4159)
+++ mgmt/newdata/cumin/python/cumin/model.py 2010-07-28 21:41:21 UTC (rev 4160)
@@ -485,10 +485,12 @@
self.columns = columns
self.query.filters = list()
- SqlComparisonFilter(self.query, parent_col, self.parent_id, "=")
+ filter = SqlComparisonFilter(parent_col, self.parent_id, "=")
+ self.query.add_filter(filter)
when = "now() - interval '%i seconds'" % int(secs + secs2)
- SqlComparisonFilter(self.query, updated_col, when, ">=")
+ filter = SqlComparisonFilter(updated_col, when, ">=")
+ self.query.add_filter(filter)
when2 = ""
if secs2:
when2 = "now() - interval '%i seconds'" % int(secs2)
@@ -518,15 +520,18 @@
self.columns = columns
self.query.filters = list()
- SqlComparisonFilter(self.query, parent_col, self.parent_id, "=")
+ filter = SqlComparisonFilter(parent_col, self.parent_id, "=")
+ self.query.add_filter(filter)
if not delta:
when = "now() - interval '%i seconds'" % int(secs + secs2)
- SqlComparisonFilter(self.query, updated_col, when, ">=")
+ filter = SqlComparisonFilter(updated_col, when, ">=")
+ self.query.add_filter(filter)
when2 = ""
if secs2:
when2 = "now() - interval '%i seconds'" % int(secs2)
- SqlComparisonFilter(self.query, updated_col, when2, "<=")
+ filter = SqlComparisonFilter(updated_col, when2, "<=")
+ self.query.add_filter(filter)
options = SqlQueryOptions()
Modified: mgmt/newdata/cumin/python/cumin/sqladapter.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/sqladapter.py 2010-07-28 17:12:53 UTC (rev 4159)
+++ mgmt/newdata/cumin/python/cumin/sqladapter.py 2010-07-28 21:41:21 UTC (rev 4160)
@@ -92,7 +92,8 @@
assert attr
value = "%%(%s)s" % attr.name
- SqlComparisonFilter(self.query, attr.sql_column, value)
+ filter = SqlComparisonFilter(attr.sql_column, value)
+ self.query.add_filter(filter)
class ObjectSqlField(SqlField):
def __init__(self, adapter, attr):
Modified: mgmt/newdata/mint/python/mint/update.py
===================================================================
--- mgmt/newdata/mint/python/mint/update.py 2010-07-28 17:12:53 UTC (rev 4159)
+++ mgmt/newdata/mint/python/mint/update.py 2010-07-28 21:41:21 UTC (rev 4160)
@@ -282,7 +282,7 @@
statements = list()
- sql = cls.sql_insert.emit(object_columns)
+ sql = cls.sql_insert_object.emit(object_columns)
statements.append(sql)
if sample_columns:
@@ -322,7 +322,7 @@
if object_columns:
object_columns.append(cls.sql_table._qmf_update_time)
- sql = cls.sql_update.emit(object_columns)
+ sql = cls.sql_update_object.emit(object_columns)
statements.append(sql)
if sample_columns:
@@ -510,12 +510,13 @@
if cls._storage == "none":
continue
- for obj in cls.get_selection(cursor, _qmf_agent_id=agent_id):
- obj.delete(cursor)
+ if cls is self.model.com_redhat_grid.Collector:
+ continue
- self.model.print_event(3, "Deleted %s", obj)
- stats.deleted += 1
+ count = cls.delete_selection(cursor, _qmf_agent_id=agent_id)
+ stats.deleted += count
+
class AgentDelete(AgentUpdate):
def do_process(self, cursor, stats):
try:
@@ -525,7 +526,7 @@
agent.delete()
- self.delete_agent_objects(cursor, stats, agent)
+ self.delete_agent_objects(cursor, stats, agent.id)
class UpdateDropped(Exception):
pass
Modified: mgmt/newdata/rosemary/python/rosemary/model.py
===================================================================
--- mgmt/newdata/rosemary/python/rosemary/model.py 2010-07-28 17:12:53 UTC (rev 4159)
+++ mgmt/newdata/rosemary/python/rosemary/model.py 2010-07-28 21:41:21 UTC (rev 4160)
@@ -75,6 +75,9 @@
for pkg in self._packages:
pkg.init()
+ for pkg in self._packages:
+ pkg.init_references()
+
class RosemaryPackage(object):
def __init__(self, model, name):
self._model = model
@@ -116,6 +119,10 @@
for cls in self._classes:
cls.init()
+ def init_references(self):
+ for cls in self._classes:
+ cls.init_references()
+
def __repr__(self):
args = (self.__class__.__name__, self._name)
return "%s(%s)" % args
@@ -158,56 +165,10 @@
self._indexes = list()
self._indexes_by_name = dict()
- self.add_sql()
-
self._id = RosemaryAttribute(self, "_id")
- self._id.sql_column = self.sql_table.key_column
self.add_headers()
- def add_sql(self):
- # Main table
-
- name = "%s_id_seq" % self._name
- self.sql_sequence = SqlSequence(self._package.sql_schema, name)
-
- self.sql_table = SqlTable(self._package.sql_schema, self._name)
-
- id_col = SqlColumn(self.sql_table, "_id", sql_int8)
- self.sql_table.key_column = id_col
-
- name = "%s_pk" % self._name
- SqlPrimaryKeyConstraint(self.sql_table, name, (id_col,))
-
- self.sql_get_new_id = SqlGetNewId(self.sql_table, self.sql_sequence)
- self.sql_select = SqlQuery(self.sql_table)
- self.sql_select_by_id = SqlSelectItem(self.sql_table)
- self.sql_select_by_qmf_id = SqlSelectItemByQmfId(self.sql_table)
-
- self.sql_insert = SqlInsertItem(self.sql_table)
- self.sql_update = SqlUpdateItem(self.sql_table)
- self.sql_delete = SqlDeleteItem(self.sql_table)
-
- # Stats table
-
- name = "%s_samples" % self._name
- self.sql_samples_table = SqlTable(self._package.sql_schema, name)
-
- name = "_parent_id"
- parent_col = SqlColumn(self.sql_samples_table, name, sql_int8)
- parent_col.foreign_key_column = id_col
-
- table = self.sql_samples_table
- name = "%s_fk" % parent_col.name
- constraint = SqlForeignKeyConstraint(table, name, parent_col, id_col)
- constraint.on_delete = "cascade"
-
- name = "_qmf_update_time"
- SqlColumn(self.sql_samples_table, name, sql_timestamp)
-
- self.sql_samples_insert = SqlInsertItemStats(self.sql_samples_table)
- self.sql_samples_delete = SqlDeleteItemStats(self.sql_samples_table)
-
def add_headers(self):
name = "_qmf_agent_id"
self._qmf_agent_id = RosemaryHeader(self, name, sql_text)
@@ -236,14 +197,6 @@
self._qmf_session_id.optional = True
self._qmf_delete_time.optional = True
- def add_constraints(self):
- name = "%s_qmf_id_uq" % self._name
- cols = (self._qmf_agent_id.sql_column,
- self._qmf_object_id.sql_column,
- self._qmf_session_id.sql_column)
-
- SqlUniqueConstraint(self.sql_table, name, cols)
-
def load(self, elem, groups_by_name):
log.debug("Loading %s", self)
@@ -311,12 +264,13 @@
if not self._title:
self._title = generate_title(self._name)
+ self.add_sql_entities()
+
+ self._id.sql_column = self.sql_table.key_column
+
for hdr in self._headers:
hdr.init()
- for ref in self._references:
- ref.init()
-
for prop in self._properties:
prop.init()
@@ -329,23 +283,78 @@
for idx in self._indexes:
idx.init()
- self.add_constraints()
+ self.add_sql_constraints()
+ self.add_sql_operations()
+ def init_references(self):
+ for ref in self._references:
+ ref.init()
+
+ def add_sql_entities(self):
+ # Main table
+
+ name = "%s_id_seq" % self._name
+ self.sql_sequence = SqlSequence(self._package.sql_schema, name)
+
+ self.sql_table = SqlTable(self._package.sql_schema, self._name)
+
+ id_col = SqlColumn(self.sql_table, "_id", sql_int8)
+ self.sql_table.key_column = id_col
+
+ name = "%s_pk" % self._name
+ SqlPrimaryKeyConstraint(self.sql_table, name, (id_col,))
+
+ # Stats table
+
+ name = "%s_samples" % self._name
+ self.sql_samples_table = SqlTable(self._package.sql_schema, name)
+
+ name = "_parent_id"
+ parent_col = SqlColumn(self.sql_samples_table, name, sql_int8)
+ parent_col.foreign_key_column = id_col
+
+ table = self.sql_samples_table
+ name = "%s_fk" % parent_col.name
+ constraint = SqlForeignKeyConstraint(table, name, parent_col, id_col)
+ constraint.on_delete = "cascade"
+
+ name = "_qmf_update_time"
+ SqlColumn(self.sql_samples_table, name, sql_timestamp)
+
+ def add_sql_constraints(self):
+ name = "%s_qmf_id_uq" % self._name
+ cols = (self._qmf_agent_id.sql_column,
+ self._qmf_object_id.sql_column,
+ self._qmf_session_id.sql_column)
+
+ SqlUniqueConstraint(self.sql_table, name, cols)
+
+ def add_sql_operations(self):
+ self.sql_get_new_id = SqlGetNewId(self.sql_table, self.sql_sequence)
+ self.sql_select_by_id = SqlSelectObject(self.sql_table)
+ self.sql_select_by_qmf_id = SqlSelectObjectByQmfId(self.sql_table)
+
+ self.sql_insert_object = SqlInsertObject(self.sql_table)
+ self.sql_update_object = SqlUpdateObject(self.sql_table)
+ self.sql_delete_object = SqlDeleteObject(self.sql_table)
+
+ table = self.sql_samples_table
+
+ self.sql_samples_insert = SqlInsertObjectSamples(table)
+ self.sql_samples_delete = SqlDeleteObjectSamples(table)
+
def get_object(self, cursor, **criteria):
columns = self.sql_table._columns
- options = SqlQueryOptions()
+ sql = SqlSelect(self.sql_table)
for name in criteria:
# XXX need to translate ref=obj args here
column = self.sql_table._columns_by_name[name]
- value = "%%(%s)s" % name
- filter = SqlComparisonFilter(None, column, value)
+ sql.add_filter(SqlValueFilter(column))
- options.filters.append(filter)
+ sql.execute(cursor, columns, criteria)
- self.sql_select.execute(cursor, columns, criteria, options)
-
record = cursor.fetchone()
if not record:
@@ -361,19 +370,16 @@
selection = list()
columns = self.sql_table._columns
- options = SqlQueryOptions()
+ sql = SqlSelect(self.sql_table)
for name in criteria:
# XXX need to translate ref=obj args here
column = self.sql_table._columns_by_name[name]
- value = "%%(%s)s" % name
- filter = SqlComparisonFilter(None, column, value)
+ sql.add_filter(SqlValueFilter(column))
- options.filters.append(filter)
-
- self.sql_select.execute(cursor, columns, criteria, options)
-
+ sql.execute(cursor, columns, criteria)
+
for record in cursor.fetchall():
obj = RosemaryObject(self, None)
@@ -420,7 +426,6 @@
assert obj._id, obj
columns = self.sql_table._columns
-
self.sql_select_by_id.execute(cursor, columns, obj.__dict__)
values = cursor.fetchone()
@@ -462,9 +467,9 @@
columns = self.sql_table._columns
if obj._sync_time:
- self.sql_update.execute(cursor, columns, obj.__dict__)
+ self.sql_update_object.execute(cursor, columns, obj.__dict__)
else:
- self.sql_insert.execute(cursor, columns, obj.__dict__)
+ self.sql_insert_object.execute(cursor, columns, obj.__dict__)
obj._sync_time = datetime.now()
@@ -481,11 +486,19 @@
assert isinstance(obj, RosemaryObject)
assert obj._id
- self.sql_delete.execute(cursor, (), obj.__dict__)
+ self.sql_delete_object.execute(cursor, (), obj.__dict__)
- def delete_selection(self, cursor, **kwargs):
- pass # XXX
+ def delete_selection(self, cursor, **criteria):
+ sql = SqlDelete(self.sql_table)
+ for name in criteria:
+ column = self.sql_table._columns_by_name[name]
+ sql.add_filter(SqlValueFilter(column))
+
+ sql.execute(cursor, (), criteria)
+
+ return cursor.rowcount
+
def __repr__(self):
args = (self.__class__.__name__, self._package._name, self._name)
return "%s(%s,%s)" % args
@@ -592,7 +605,7 @@
name = "%s_fk" % col.name
SqlForeignKeyConstraint(col.table, name, col, col.foreign_key_column)
-
+
class RosemaryProperty(RosemaryAttribute):
def __init__(self, cls, name):
super(RosemaryProperty, self).__init__(cls, name)
Added: mgmt/newdata/rosemary/python/rosemary/sqlfilter.py
===================================================================
--- mgmt/newdata/rosemary/python/rosemary/sqlfilter.py (rev 0)
+++ mgmt/newdata/rosemary/python/rosemary/sqlfilter.py 2010-07-28 21:41:21 UTC (rev 4160)
@@ -0,0 +1,34 @@
+from util import *
+
+log = logging.getLogger("rosemary.sqlfilter")
+
+class SqlFilter(object):
+ pass
+
+class SqlComparisonFilter(SqlFilter):
+ def __init__(self, this, that, operator="="):
+ super(SqlComparisonFilter, self).__init__()
+
+ assert isinstance(operator, str)
+
+ self.this = getattr(this, "identifier", this)
+ self.that = getattr(that, "identifier", that)
+ self.operator = operator
+
+ def emit(self):
+ return "%s %s %s" % (self.this, self.operator, self.that)
+
+class SqlValueFilter(SqlComparisonFilter):
+ def __init__(self, this, operator="="):
+ that = "%%(%s)s" % this.name
+ super(SqlValueFilter, self).__init__(this, that, operator)
+
+class SqlExistenceFilter(SqlFilter):
+ def __init__(self, subquery, operator="exists"):
+ super(SqlExistenceFilter, self).__init__()
+
+ self.subquery = subquery
+ self.operator = operator
+
+ def emit(self):
+ return "%s (%s)" % (self.operator, self.subquery)
Modified: mgmt/newdata/rosemary/python/rosemary/sqloperation.py
===================================================================
--- mgmt/newdata/rosemary/python/rosemary/sqloperation.py 2010-07-28 17:12:53 UTC (rev
4159)
+++ mgmt/newdata/rosemary/python/rosemary/sqloperation.py 2010-07-28 21:41:21 UTC (rev
4160)
@@ -1,3 +1,4 @@
+from sqlfilter import *
from sqlmodel import *
from util import *
@@ -6,7 +7,14 @@
class SqlOperation(object):
def __init__(self, table):
self.table = table # XXX consider making this "relation" or
"object"
+ self.filters = list()
+ def add_filter(self, filter):
+ self.filters.append(filter)
+
+ def get_filter_exprs(self):
+ return " and ".join([x.emit() for x in self.filters])
+
def execute(self, cursor, columns, values=None, options=None):
text = self.emit(columns, options)
@@ -25,6 +33,9 @@
if self.table._schema._model._model.sql_logging_enabled:
self.log_sql(cursor, text, values)
+ def emit(self, columns, options=None):
+ raise Exception("Not implemented")
+
def log_sql(self, cursor, text, values):
log.debug("Sql text: %s", text)
log.debug("Sql values:")
@@ -46,37 +57,43 @@
def emit(self, columns, options=None):
return "select nextval('%s')" % self.sequence.identifier
-class SqlSelectItem(SqlOperation):
+class SqlSelect(SqlOperation):
def emit(self, columns, options=None):
+ tokens = list()
+
cols = ", ".join([x.identifier for x in columns])
table = getattr(self.table, "identifier", self.table)
- return "select %s from %s where _id = %%(_id)s" % (cols, table)
+ tokens.append("select %s from %s" % (cols, table))
-class SqlSelectItemByQmfId(SqlOperation):
- def emit(self, columns, options=None):
- cols = ", ".join([x.identifier for x in columns])
- table = getattr(self.table, "identifier", self.table)
+ if self.filters:
+ tokens.append("where %s" % self.get_filter_exprs())
- exprs = list()
- exprs.append("_qmf_agent_id = %(_qmf_agent_id)s")
- exprs.append("_qmf_object_id = %(_qmf_object_id)s")
- exprs = " and ".join(exprs)
+ return " ".join(tokens)
- return "select %s from %s where %s" % (cols, table, exprs)
+class SqlSelectObject(SqlSelect):
+ def __init__(self, table):
+ super(SqlSelectObject, self).__init__(table)
-class SqlInsertItem(SqlOperation):
+ self.add_filter(SqlValueFilter(self.table._id))
+
+class SqlSelectObjectByQmfId(SqlSelect):
+ def __init__(self, table):
+ super(SqlSelectObjectByQmfId, self).__init__(table)
+
+ self.add_filter(SqlValueFilter(self.table._qmf_agent_id))
+ self.add_filter(SqlValueFilter(self.table._qmf_object_id))
+
+class SqlInsertObject(SqlOperation):
def emit(self, columns, options=None):
table = getattr(self.table, "identifier", self.table)
names = [x.name for x in columns]
cols = ", ".join(["\"%s\"" % x for x in names])
vals = ", ".join(["%%(%s)s" % x for x in names])
- args = (table, cols, vals)
+ return "insert into %s (%s) values (%s)" % (table, cols, vals)
- return "insert into %s (%s) values (%s)" % args
-
-class SqlInsertItemStats(SqlOperation):
+class SqlInsertObjectSamples(SqlOperation):
def emit(self, columns, options=None):
table = getattr(self.table, "identifier", self.table)
names = [x.name for x in columns]
@@ -92,26 +109,53 @@
return "insert into %s (%s) values (%s)" % (table, cols, vals)
-class SqlUpdateItem(SqlOperation):
+class SqlUpdate(SqlOperation):
def emit(self, columns, options=None):
+ tokens = list()
+
table = getattr(self.table, "identifier", self.table)
exprs = ["\"%s\" = %%(%s)s" % (x.name, x.name)
for x in columns
if x is not self.table.key_column]
exprs = ", ".join(exprs)
- return "update %s set %s where _id = %%(_id)s" % (table, exprs)
+ tokens.append("update %s set %s" % (table, exprs))
-class SqlDeleteItem(SqlOperation):
- def emit(self, columns, options=None):
- table = getattr(self.table, "identifier", self.table)
+ if self.filters:
+ tokens.append("where %s" % self.get_filter_exprs())
- return "delete from %s where _id = %%(_id)s" % table
+ return " ".join(tokens)
-class SqlDeleteItemStats(SqlOperation):
+class SqlUpdateObject(SqlUpdate):
+ def __init__(self, table):
+ super(SqlUpdateObject, self).__init__(table)
+
+ self.add_filter(SqlValueFilter(self.table._id))
+
+class SqlDelete(SqlOperation):
def emit(self, columns, options=None):
+ tokens = list()
+
table = getattr(self.table, "identifier", self.table)
- expr = "_qmf_update_time < now() - interval '%(seconds)s
seconds'"
+ tokens.append("delete from %s" % table)
- return "delete from %s where %s" % (table, expr)
+ if self.filters:
+ tokens.append("where %s" % self.get_filter_exprs())
+
+ return " ".join(tokens)
+
+class SqlDeleteObject(SqlDelete):
+ def __init__(self, table):
+ super(SqlDeleteObject, self).__init__(table)
+
+ self.add_filter(SqlValueFilter(self.table._id))
+
+class SqlDeleteObjectSamples(SqlDelete):
+ def __init__(self, table):
+ super(SqlDeleteObjectSamples, self).__init__(table)
+
+ this = self.table._qmf_update_time
+ that = "now() - interval '%(seconds)s seconds'"
+
+ self.add_filter(SqlComparisonFilter(this, that, "<"))
Modified: mgmt/newdata/rosemary/python/rosemary/sqlquery.py
===================================================================
--- mgmt/newdata/rosemary/python/rosemary/sqlquery.py 2010-07-28 17:12:53 UTC (rev 4159)
+++ mgmt/newdata/rosemary/python/rosemary/sqlquery.py 2010-07-28 21:41:21 UTC (rev 4160)
@@ -13,7 +13,6 @@
self.group_by = self.GroupBy()
self.joins = list()
- self.filters = list()
def emit(self, columns, options=None):
tokens = list()
@@ -32,16 +31,17 @@
for join in self.joins:
tokens.append(join.emit())
- filters = list()
+ exprs = list()
if self.filters:
- filters.extend([x.emit() for x in self.filters])
+ exprs.extend([x.emit() for x in self.filters])
+ # XXX get rid of this
if options and options.filters:
- filters.extend([x.emit() for x in options.filters])
+ exprs.extend([x.emit() for x in options.filters])
- if filters:
- tokens.append("where %s" % " and ".join(filters))
+ if exprs:
+ tokens.append("where %s" % " and ".join(exprs))
if options:
if options.group_column:
@@ -121,37 +121,3 @@
args = (self.table, self.this, self.that)
return "left outer join %s on %s = %s" % args
-
-class SqlQueryFilter(object):
- def __init__(self, query):
- if query:
- assert isinstance(query, SqlQuery), query
-
- self.query = query
-
- if self.query:
- assert self not in self.query.filters
- self.query.filters.append(self)
-
-class SqlComparisonFilter(SqlQueryFilter):
- def __init__(self, query, this, that, operator="="):
- super(SqlComparisonFilter, self).__init__(query)
-
- assert isinstance(operator, str)
-
- self.this = getattr(this, "identifier", this)
- self.that = getattr(that, "identifier", that)
- self.operator = operator
-
- def emit(self):
- return "%s %s %s" % (self.this, self.operator, self.that)
-
-class SqlExistenceFilter(SqlQueryFilter):
- def __init__(self, query, subquery, operator="exists"):
- super(SqlExistenceFilter, self).__init__(query)
-
- self.subquery = subquery
- self.operator = operator
-
- def emit(self):
- return "%s (%s)" % (self.operator, self.subquery)
Modified: mgmt/newdata/rosemary/python/rosemary/util.py
===================================================================
--- mgmt/newdata/rosemary/python/rosemary/util.py 2010-07-28 17:12:53 UTC (rev 4159)
+++ mgmt/newdata/rosemary/python/rosemary/util.py 2010-07-28 21:41:21 UTC (rev 4160)
@@ -2,7 +2,10 @@
import os
import sys
+from pprint import pprint
+
try:
from xml.etree.ElementTree import *
except ImportError:
from elementtree.ElementTree import *
+