Пример #1
0
static void
run_test (void)
{
    int i;
    QofSession *sess;
    QofBook *book;
    QofInstance *ent;
    QofCollection *col;
    QofIdType type;
    GncGUID guid;

    sess = get_random_session ();
    book = qof_session_get_book (sess);
    do_test ((NULL != book), "book not created");

    col = qof_book_get_collection (book, "asdf");
    type = qof_collection_get_type (col);

    for (i = 0; i < NENT; i++)
    {
        ent = static_cast<QofInstance*>(g_object_new(QOF_TYPE_INSTANCE, NULL));
        guid_replace(&guid);
        ent = static_cast<QofInstance*>(g_object_new(QOF_TYPE_INSTANCE,
                                                     "guid", &guid, NULL));
        do_test ((NULL == qof_collection_lookup_entity (col, &guid)),
                 "duplicate guid");
        ent->e_type = type;
        qof_collection_insert_entity (col, ent);
        do_test ((NULL != qof_collection_lookup_entity (col, &guid)),
                 "guid not found");
    }

    /* Make valgrind happy -- destroy the session. */
    qof_session_destroy(sess);
}
Пример #2
0
gboolean
qof_instance_copy_coll(QofSession *new_session, QofCollection *entity_coll)
{
    QofInstanceCopyData qecd;

    g_return_val_if_fail(new_session, FALSE);
    if (!entity_coll)
    {
        return FALSE;
    }
    qof_event_suspend();
    qecd.param_list = NULL;
    qecd.new_session = new_session;
    qof_book_set_partial(qof_session_get_book(qecd.new_session));
    qof_collection_foreach(entity_coll, qof_instance_coll_foreach, &qecd);
    qof_class_param_foreach(qof_collection_get_type(entity_coll),
                            qof_instance_param_cb, &qecd);
    qof_collection_foreach(entity_coll, qof_instance_coll_copy, &qecd);
    if (qecd.param_list != NULL)
    {
        g_slist_free(qecd.param_list);
    }
    qof_event_resume();
    return TRUE;
}
Пример #3
0
static void
grand_setDescend(mygrand *g, QofCollection *coll)
{
    g_return_if_fail(g || coll);
    if (0 != safe_strcmp(qof_collection_get_type(coll), CHILD_MODULE_NAME))
    {
        return;
    }
    qof_collection_foreach(coll, descend_cb, g);
}
Пример #4
0
/* Returns a displayable name to represent this object */
gchar* qof_instance_get_display_name(const QofInstance* inst)
{
    g_return_val_if_fail( inst != NULL, NULL );

    if ( QOF_INSTANCE_GET_CLASS(inst)->get_display_name != NULL )
    {
        return QOF_INSTANCE_GET_CLASS(inst)->get_display_name(inst);
    }
    else
    {
        /* Not implemented - return default string */
        return g_strdup_printf("Object %s %p",
                               qof_collection_get_type(qof_instance_get_collection(inst)),
                               inst);
    }
}
Пример #5
0
void
qof_instance_init_data (QofInstance *inst, QofIdType type, QofBook *book)
{
    QofInstancePrivate *priv;
    QofCollection *col;
    QofIdType col_type;

    g_return_if_fail(QOF_IS_INSTANCE(inst));
    priv = GET_PRIVATE(inst);
    g_return_if_fail(!priv->book);

    priv->book = book;
    col = qof_book_get_collection (book, type);
    g_return_if_fail(col != NULL);

    /* XXX We passed redundant info to this routine ... but I think that's
     * OK, it might eliminate programming errors. */

    col_type = qof_collection_get_type(col);
    if (safe_strcmp(col_type, type))
    {
        PERR ("attempt to insert \"%s\" into \"%s\"", type, col_type);
        return;
    }
    priv = GET_PRIVATE(inst);
    inst->e_type = CACHE_INSERT (type);

    do
    {
        guid_new(&priv->guid);

        if (NULL == qof_collection_lookup_entity (col, &priv->guid))
            break;

        PWARN("duplicate id created, trying again");
    }
    while (1);

    priv->collection = col;

    qof_collection_insert_entity (col, inst);
}
Пример #6
0
gboolean
qof_instance_copy_coll_r(QofSession *new_session, QofCollection *coll)
{
    struct recurse_s store;
    gboolean success;

    if ((!new_session) || (!coll))
    {
        return FALSE;
    }
    store.session = new_session;
    success = TRUE;
    store.success = success;
    store.ent_list = NULL;
    store.ref_list = qof_class_get_referenceList(qof_collection_get_type(coll));
    success = qof_instance_copy_coll(new_session, coll);
    if (success)
    {
        qof_collection_foreach(coll, recurse_ent_cb, &store);
    }
    return success;
}