~therve/storm/twisted-integration

« back to all changes in this revision

Viewing changes to storm/store.py

  • Committer: Thomas Hervé
  • Date: 2009-02-19 11:43:53 UTC
  • mfrom: (181.1.112 storm.trunk)
  • Revision ID: thomas@canonical.com-20090219114353-kn1iujortgoulf20
Merge from trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
        """
68
68
        @param database: The L{storm.database.Database} instance to use.
69
69
        @param cache: The cache to use.  Defaults to a L{Cache} storing up to
70
 
            100 objects at any given time.
 
70
            1000 objects at any given time.
71
71
        """
72
72
        self._event = EventSystem(self)
73
73
        self._connection = database.connect(self._event)
1283
1283
 
1284
1284
        # For now only "Class.attr == var" is supported in args.
1285
1285
        for expr in args:
1286
 
            if (not isinstance(expr, Eq) or
1287
 
                not isinstance(expr.expr1, Column) or
1288
 
                not isinstance(expr.expr2, (Column, Variable))):
 
1286
            if not isinstance(expr, Eq):
1289
1287
                raise FeatureError("Unsupported set expression: %r" %
1290
1288
                                   repr(expr))
 
1289
            elif not isinstance(expr.expr1, Column):
 
1290
                raise FeatureError("Unsupported left operand in set "
 
1291
                                   "expression: %r" % repr(expr.expr1))
 
1292
            elif not isinstance(expr.expr2, (Expr, Variable)):
 
1293
                raise FeatureError("Unsupported right operand in set "
 
1294
                                   "expression: %r" % repr(expr.expr2))
1291
1295
            changes[expr.expr1] = expr.expr2
1292
1296
 
1293
1297
        for key, value in kwargs.items():
1295
1299
            if value is None:
1296
1300
                changes[column] = None
1297
1301
            elif isinstance(value, Expr):
1298
 
                if not isinstance(value, Column):
1299
 
                    raise FeatureError("Unsupported set expression: %r" %
1300
 
                                       repr(value))
1301
1302
                changes[column] = value
1302
1303
            else:
1303
1304
                changes[column] = column.variable_factory(value=value)
1309
1310
        try:
1310
1311
            cached = self.cached()
1311
1312
        except CompileError:
 
1313
            # We are iterating through all objects in memory here, so
 
1314
            # check if the object type matches to avoid trying to
 
1315
            # invalidate a column that does not exist, on an unrelated
 
1316
            # object.
1312
1317
            for obj_info in self._store._iter_alive():
1313
 
                for column in changes:
1314
 
                    obj_info.variables[column].set(AutoReload)
 
1318
                if obj_info.cls_info is self._find_spec.default_cls_info:
 
1319
                    for column in changes:
 
1320
                        obj_info.variables[column].set(AutoReload)
1315
1321
        else:
1316
1322
            changes = changes.items()
1317
1323
            for obj in cached:
1321
1327
                        pass
1322
1328
                    elif isinstance(value, Variable):
1323
1329
                        value = value.get()
 
1330
                    elif isinstance(value, Expr):
 
1331
                        # If the value is an Expression that means we
 
1332
                        # can't compute it by ourselves: we rely on
 
1333
                        # the database to compute it, so just set the
 
1334
                        # value to AutoReload.
 
1335
                        value = AutoReload
1324
1336
                    else:
1325
1337
                        value = variables[value].get()
1326
1338
                    variables[column].set(value)
1455
1467
    def remove(self):
1456
1468
        pass
1457
1469
 
1458
 
    def count(self, column=Undef, distinct=False):
 
1470
    def count(self, expr=Undef, distinct=False):
1459
1471
        return 0
1460
1472
 
1461
1473
    def max(self, column):