Exemplo n.º 1
0
/* functions implementing storage api */
static int
librdf_storage_trees_init(librdf_storage* storage, const char *name,
                         librdf_hash* options)
{
  const int index_spo_option = librdf_hash_get_as_boolean(options, "index-spo") > 0;
  const int index_sop_option = librdf_hash_get_as_boolean(options, "index-sop") > 0;
  const int index_ops_option = librdf_hash_get_as_boolean(options, "index-ops") > 0;
  const int index_pso_option = librdf_hash_get_as_boolean(options, "index-pso") > 0;

  librdf_storage_trees_instance* context=(librdf_storage_trees_instance*)LIBRDF_CALLOC(
    librdf_storage_trees_instance, 1, sizeof(librdf_storage_trees_instance));

  if(!context) {
    if(options)
      librdf_free_hash(options);
    return 1;
  }

  librdf_storage_set_instance(storage, context);

#ifdef RDF_STORAGE_TREES_WITH_CONTEXTS
  /* Support contexts if option given */
  if (librdf_hash_get_as_boolean(options, "contexts") > 0) {
    context->contexts=librdf_new_avltree(librdf_storage_trees_graph_compare,
      librdf_storage_trees_graph_free);
  } else {
    context->contexts=NULL;
  }
#endif

  /* No indexing options given, index all by default */
  if (!index_spo_option && !index_sop_option && !index_ops_option && !index_pso_option) {
    context->index_sop=1;
    context->index_ops=1;
    context->index_pso=1;
  } else {
    /* spo is always indexed, option just exists so user can
     * specifically /only/ index spo */
    context->index_sop=index_sop_option;
    context->index_ops=index_ops_option;
    context->index_pso=index_pso_option;
  }
  
  context->graph = librdf_storage_trees_graph_new(storage, NULL);
  
  /* no more options, might as well free them now */
  if(options)
    librdf_free_hash(options);

  return 0;
}
Exemplo n.º 2
0
/**
 * librdf_storage_trees_context_remove_statement:
 * @storage: #librdf_storage object
 * @context_node: #librdf_node object
 * @statement: #librdf_statement statement to remove
 *
 * Remove a statement from a storage context.
 * 
 * Return value: non 0 on failure
 **/
static int
librdf_storage_trees_context_remove_statement(librdf_storage* storage, 
                                              librdf_node* context_node,
                                              librdf_statement* statement) 
{
  librdf_storage_trees_instance* context=(librdf_storage_trees_instance*)storage->instance;
  librdf_storage_trees_graph* key=librdf_storage_trees_graph_new(storage, context_node);
  librdf_storage_trees_graph* graph=(librdf_storage_trees_graph*)
    librdf_avltree_search(context->contexts, &key);
  librdf_storage_trees_graph_free(key);
  if (graph) {
    return librdf_storage_trees_remove_statement_internal(graph, statement);
  } else {
    return -1;
  }
}
Exemplo n.º 3
0
/**
 * librdf_storage_trees_context_add_statement:
 * @storage: #librdf_storage object
 * @context_node: #librdf_node object
 * @statement: #librdf_statement statement to add
 *
 * Add a statement to a storage context.
 * 
 * Return value: non 0 on failure
 **/
static int
librdf_storage_trees_context_add_statement(librdf_storage* storage,
                                           librdf_node* context_node,
                                           librdf_statement* statement) 
{
  librdf_storage_trees_context* context=(librdf_storage_trees_context*)storage->context;
  
  librdf_storage_trees_graph* key=librdf_storage_trees_graph_new(storage, context_node);
  librdf_storage_trees_graph* graph=(librdf_storage_trees_graph*)
    librdf_avltree_search(context->contexts, key);
  
  if(graph) {
    librdf_storage_trees_graph_free(key);
  } else {
    librdf_avltree_add(context->contexts, key);
    graph=key;
  }
    
  return librdf_storage_trees_add_statement_internal(storage, graph, statement);
}