Ejemplo n.º 1
0
void
gom_resource_build_save_cmd (GomResource *resource,
                             GomAdapter  *adapter)
{
   GomCommandBuilder *builder;
   gboolean has_pkey, is_insert;
   GSList *types = NULL;
   GSList *iter;
   GType resource_type;
   GList *cmds = NULL;

   resource_type = G_TYPE_FROM_INSTANCE(resource);
   g_assert(g_type_is_a(resource_type, GOM_TYPE_RESOURCE));

   builder = g_object_new(GOM_TYPE_COMMAND_BUILDER,
                          "adapter", adapter,
                          NULL);

   has_pkey = has_primary_key(resource);
   if (has_pkey) {
     /* Could be an insert for a non-automatic primary key,
      * or an update */
     is_insert = !resource->priv->is_from_table;
   } else {
     is_insert = TRUE;
   }

   g_object_set_data (G_OBJECT (resource), "is-insert", GINT_TO_POINTER (is_insert));

   do {
      types = g_slist_prepend(types, GINT_TO_POINTER(resource_type));
   } while ((resource_type = g_type_parent(resource_type)) != GOM_TYPE_RESOURCE);

   for (iter = types; iter; iter = iter->next) {
      GomCommand *command;

      resource_type = GPOINTER_TO_INT(iter->data);

      g_object_set(builder,
                   "resource-type", resource_type,
                   NULL);

      if (is_insert) {
         command = gom_command_builder_build_insert(builder, resource);
      } else {
         command = gom_command_builder_build_update(builder, resource);
      }

      if (is_insert && gom_resource_has_dynamic_pkey(resource_type))
        is_insert = FALSE;

      cmds = g_list_prepend (cmds, command);
   }

   cmds = g_list_reverse (cmds);
   g_object_set_data_full (G_OBJECT(resource), "save-commands", cmds, free_save_cmds);

   g_slist_free(types);
   g_object_unref (builder);
}
Ejemplo n.º 2
0
void prototype_node::remove(object_proxy *proxy)
{
  if (proxy == op_first->next()) {
    // adjust left marker
    adjust_left_marker(this, op_first->next_, op_first->next_->next_);
  }
  if (proxy == op_marker->prev()) {
    // adjust right marker
    adjust_right_marker(this, proxy, op_marker->prev_->prev_);
  }
  // unlink object_proxy
  if (proxy->prev()) {
    proxy->prev_->next_ = proxy->next_;
  }
  if (proxy->next()) {
    proxy->next_->prev_ = proxy->prev_;
  }
  proxy->prev_ = nullptr;
  proxy->next_ = nullptr;

  if (has_primary_key()) {
    if (id_map_.erase(proxy->primary_key_) == 0) {
      // couldn't find and erase primary key
    }
  }

  // adjust serializable count for node
  --count;
}
Ejemplo n.º 3
0
static void
pkey_changed_cb (GObject    *gobject,
                 GParamSpec *pspec,
                 gpointer    user_data)
{
  GomResource *resource = (GomResource *) gobject;

  /* Did the developer reset the primary key? */
  if (!has_primary_key(GOM_RESOURCE(resource))) {
     resource->priv->is_from_table = FALSE;
  }
}