← Back to team overview

zeitgeist team mailing list archive

[Merge] lp:~zeitgeist/zeitgeist/bb-payload into lp:~zeitgeist/zeitgeist/bluebird

 

Seif Lotfy has proposed merging lp:~zeitgeist/zeitgeist/bb-payload into lp:~zeitgeist/zeitgeist/bluebird.

Requested reviews:
  Zeitgeist Framework Team (zeitgeist)

For more details, see:
https://code.launchpad.net/~zeitgeist/zeitgeist/bb-payload/+merge/75826

started payload insertion and retrieval development
however translating payloads to variants is not yet workin
-- 
https://code.launchpad.net/~zeitgeist/zeitgeist/bb-payload/+merge/75826
Your team Zeitgeist Framework Team is requested to review the proposed merge of lp:~zeitgeist/zeitgeist/bb-payload into lp:~zeitgeist/zeitgeist/bluebird.
=== modified file 'src/datamodel.vala'
--- src/datamodel.vala	2011-09-16 09:15:06 +0000
+++ src/datamodel.vala	2011-09-16 22:13:18 +0000
@@ -379,6 +379,7 @@
             {
                 Variant payload_variant = Variant.new_from_data<ByteArray> (
                     new VariantType ("ay"), payload.data, false, payload);
+                // FIXME: somehow adding the payload_variant is not working
                 vb.add_value (payload_variant);
             }
             vb.close ();

=== modified file 'src/engine.vala'
--- src/engine.vala	2011-09-16 15:17:08 +0000
+++ src/engine.vala	2011-09-16 22:13:18 +0000
@@ -106,7 +106,16 @@
                     stmt.column_int (EventViewRows.ACTOR));
                 event.origin = stmt.column_text (
                     EventViewRows.EVENT_ORIGIN_URI);
-                // FIXME: load payload
+                
+                // Load payload
+                unowned uint8[] data = (uint8[]) 
+                    stmt.column_blob(EventViewRows.PAYLOAD);
+                data.length = stmt.column_bytes(EventViewRows.PAYLOAD);
+                if (data != null)
+                {
+                    event.payload = new ByteArray();
+                    event.payload.append(data);
+                }
                 events.insert (event_id, event);
             }
 
@@ -567,9 +576,6 @@
     {
         event.id = ++last_id;
 
-        // FIXME: store the payload
-        // payload_id = store_payload (event);
-
         // Make sure all the URIs, texts and storage are inserted
         {
             var uris = new GenericArray<string> ();
@@ -630,6 +636,8 @@
             }
         }
 
+        var payload_id = store_payload (event);
+
         // FIXME: Should we add something just like TableLookup but with LRU
         //        for those? Or is embedding the query faster? Needs testing!
 
@@ -648,7 +656,9 @@
             manifestations_table.get_id (event.manifestation));
         insert_stmt.bind_int64 (5, actors_table.get_id (event.actor));
         insert_stmt.bind_text (6, event.origin);
-        insert_stmt.bind_int64 (7, 0 /*payload_id*/);
+        if (payload_id == null)
+            payload_id = 0;
+        insert_stmt.bind_int64 (7, payload_id);
 
         for (int i = 0; i < event.num_subjects(); ++i)
         {
@@ -1067,7 +1077,7 @@
         return subwhere;
     }
 
-    private void handle_move_event(Event event)
+    private void handle_move_event (Event event)
     {
         for (int i = 0; i < event.subjects.length; i++)
         {
@@ -1086,7 +1096,34 @@
                 }
             }
         }
-    }
+     }
+
+     private int64? store_payload (Event event)
+     {
+        /** 
+        * TODO: Right now payloads are not unique and every event has its
+        * own one. We could optimize this to store those which are repeated
+        * for different events only once, especially considering that
+        * events cannot be modified once they've been inserted.
+        */
+        if (event.payload != null)
+        {
+            int rc;
+            //unowned string foo = (string) event.payload.data;
+            //stdout.printf("%s\n", foo);
+            unowned Sqlite.Statement payload_insertion_stmt =
+                database.payload_insertion_stmt;
+            payload_insertion_stmt.reset();
+            payload_insertion_stmt.bind_blob(1, event.payload, 
+                event.payload.data.length);
+            if ((rc = payload_insertion_stmt.step()) != Sqlite.DONE)
+                if (rc != Sqlite.CONSTRAINT)
+                    warning ("SQL error: %d, %s\n", rc, db.errmsg ());
+            return database.database.last_insert_rowid();
+        }
+        else
+            return null;
+     }
 
 }
 

=== modified file 'src/sql.vala'
--- src/sql.vala	2011-09-15 22:15:58 +0000
+++ src/sql.vala	2011-09-16 22:13:18 +0000
@@ -55,6 +55,7 @@
         public Sqlite.Statement event_insertion_stmt;
         public Sqlite.Statement id_retrieval_stmt;
         public Sqlite.Statement move_handling_stmt;
+        public Sqlite.Statement payload_insertion_stmt;
 
         // The DB should be accessible from engine for statement preperations
         //  as well as allowing extensions to add tables to it.
@@ -249,6 +250,13 @@
             """;
             rc = database.prepare_v2 (sql, -1, out move_handling_stmt);
             assert_query_success (rc, "Move handling error");
+            
+            // Payload insertion statment
+            sql = """
+                INSERT INTO payload (value) VALUES (?)
+            """;
+            rc = database.prepare_v2 (sql, -1, out payload_insertion_stmt);
+            assert_query_success (rc, "Payload insertion query error");
         }
 
         protected static void update_callback (Sqlite.Action action,


Follow ups