Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

StorageView that stores entire Thing in column.

  • Loading branch information...
commit c1d7e73acb340e70c1b6c5f6fe59651114f46c14 1 parent 4111c73
Brian Simpson bsimpson63 authored committed
Showing with 55 additions and 0 deletions.
  1. +55 −0 r2/r2/lib/db/tdb_cassandra.py
55 r2/r2/lib/db/tdb_cassandra.py
View
@@ -1247,6 +1247,61 @@ def _set_values(cls, row_key, col_values,
# can we be smarter here?
thing_cache.delete(cls._cache_key_id(row_key))
+# if cjson is installed, use it. it's faster.
+try:
+ import cjson as json
+except ImportError:
+ import json
+else:
+ json.dumps, json.loads = json.encode, json.decode
+
+class StorageView(View):
+ """Store the entire underlying object inside the View column."""
+
+ # Do we need to check for _dirty?
+
+ @classmethod
+ def _thing_dumper(cls, thing):
+ serialize_fn = cls._view_of._serialize_column
+ serialized_columns = dict((attr, serialize_fn(attr, val)) for
+ (attr, val) in thing._orig.iteritems())
+ dump = json.dumps(serialized_columns)
+ return dump
+
+ @classmethod
+ def _thing_loader(cls, _id, dump):
+ serialized_columns = json.loads(dump)
+ obj = cls._view_of._from_serialized_columns(_id, serialized_columns)
+ return obj
+
+ @classmethod
+ def _obj_to_column(cls, objs):
+ objs = tup(objs)
+ columns = []
+ for o in objs:
+ _id = o._id
+ dump = cls._thing_dumper(o)
+ columns.append({_id: dump})
+
+ if len(columns) == 1:
+ return columns[0]
+ else:
+ return columns
+
+ @classmethod
+ def _column_to_obj(cls, columns):
+ columns = tup(columns)
+ objs = []
+ for column in columns:
+ _id, dump = column.items()[0]
+ obj = cls._thing_loader(_id, dump)
+ objs.append(obj)
+
+ if len(objs) == 1:
+ return objs[0]
+ else:
+ return objs
+
def schema_report():
manager = get_manager()
print manager.describe_keyspace(keyspace)
Please sign in to comment.
Something went wrong with that request. Please try again.