2013-10-11 23:07:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 - Juan Ferrer Toribio
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sql-holder.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION: sql-holder
|
|
|
|
* @Short_description:
|
|
|
|
* @Title: SqlHolder
|
|
|
|
**/
|
|
|
|
G_DEFINE_TYPE (SqlHolder, sql_holder, SQL_TYPE_OBJECT);
|
|
|
|
|
2013-10-14 11:59:07 +00:00
|
|
|
SqlObject * sql_holder_new (const gchar * id)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
|
|
|
return g_object_new (SQL_TYPE_HOLDER, "id", id, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
|
|
|
|
|
2014-06-05 15:59:35 +00:00
|
|
|
static void sql_holder_render (SqlHolder * self, SqlRender * render, SqlBatch * batch)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-06-05 15:59:35 +00:00
|
|
|
SqlObject * object = batch ? sql_batch_get (batch, self->id) : NULL;
|
2013-10-11 23:07:35 +00:00
|
|
|
|
2014-05-09 11:40:32 +00:00
|
|
|
if (object)
|
|
|
|
sql_render_add_object (render, object);
|
2013-10-11 23:07:35 +00:00
|
|
|
else
|
2014-06-05 15:59:35 +00:00
|
|
|
sql_render_printf (render, "#%s", self->id);
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 15:59:35 +00:00
|
|
|
static void sql_holder_find_holders (SqlHolder * self, SqlBatch * batch)
|
2013-12-16 11:11:47 +00:00
|
|
|
{
|
2014-06-05 15:59:35 +00:00
|
|
|
sql_batch_add (batch, self->id, NULL);
|
2013-12-16 11:11:47 +00:00
|
|
|
}
|
|
|
|
|
2013-10-11 23:07:35 +00:00
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sql_holder_get_id:
|
2014-06-05 15:59:35 +00:00
|
|
|
* @self: the #SqlHolder
|
2013-10-11 23:07:35 +00:00
|
|
|
*
|
|
|
|
* Gets the identifier assigned to the holder.
|
|
|
|
*
|
|
|
|
* Return value: (transfer none): the id
|
|
|
|
**/
|
2014-06-05 15:59:35 +00:00
|
|
|
const gchar * sql_holder_get_id (SqlHolder * self)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-06-05 15:59:35 +00:00
|
|
|
g_return_val_if_fail (SQL_IS_HOLDER (self), NULL);
|
2013-10-11 23:07:35 +00:00
|
|
|
|
2014-06-05 15:59:35 +00:00
|
|
|
return self->id;
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_ID = 1
|
|
|
|
};
|
|
|
|
|
2014-06-05 15:59:35 +00:00
|
|
|
static void sql_holder_set_property (SqlHolder * self, guint id,
|
2013-10-11 23:07:35 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PROP_ID:
|
2014-06-05 15:59:35 +00:00
|
|
|
g_free (self->id);
|
|
|
|
self->id = g_value_dup_string (value);
|
2013-10-11 23:07:35 +00:00
|
|
|
break;
|
2013-10-14 11:59:07 +00:00
|
|
|
default:
|
2014-06-05 15:59:35 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-05 15:59:35 +00:00
|
|
|
static void sql_holder_get_property (SqlHolder * self, guint id,
|
2013-10-11 23:07:35 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PROP_ID:
|
2014-06-05 15:59:35 +00:00
|
|
|
g_value_set_string (value, sql_holder_get_id (self));
|
2013-10-11 23:07:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
2014-06-05 15:59:35 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
|
2014-06-05 15:59:35 +00:00
|
|
|
static void sql_holder_init (SqlHolder * self)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-06-05 15:59:35 +00:00
|
|
|
self->id = NULL;
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 15:59:35 +00:00
|
|
|
static void sql_holder_finalize (SqlHolder * self)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-06-05 15:59:35 +00:00
|
|
|
g_free (self->id);
|
|
|
|
G_OBJECT_CLASS (sql_holder_parent_class)->finalize (G_OBJECT (self));
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sql_holder_class_init (SqlHolderClass * k)
|
|
|
|
{
|
|
|
|
GObjectClass * klass = G_OBJECT_CLASS (k);
|
|
|
|
klass->finalize = (GObjectFinalizeFunc) sql_holder_finalize;
|
|
|
|
klass->set_property = (GObjectSetPropertyFunc) sql_holder_set_property;
|
|
|
|
klass->get_property = (GObjectGetPropertyFunc) sql_holder_get_property;
|
|
|
|
SQL_OBJECT_CLASS (klass)->render = (SqlRenderFunc) sql_holder_render;
|
2013-12-16 11:11:47 +00:00
|
|
|
SQL_OBJECT_CLASS (klass)->find_holders = (SqlObjectFindHoldersFunc) sql_holder_find_holders;
|
2013-10-11 23:07:35 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (klass, PROP_ID,
|
|
|
|
g_param_spec_string ("id"
|
|
|
|
,_("Identifier")
|
|
|
|
,_("The holder identifier")
|
|
|
|
,NULL
|
|
|
|
,G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY
|
|
|
|
));
|
|
|
|
}
|