iinq.c File Reference
#include <stdio.h>
#include "iinq.h"
#include "../dictionary/bpp_tree/bpp_tree_handler.h"

Description

This code contains definitions for iinq functions.

Author
IonDB Project
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1.Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2.Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3.Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file iinq.c.

Include dependency graph for iinq.c:

Functions

ion_err_t iinq_create_source (char *schema_file_name, ion_key_type_t key_type, ion_key_size_t key_size, ion_value_size_t value_size)
 
ion_err_t iinq_open_source (char *schema_file_name, ion_dictionary_t *dictionary, ion_dictionary_handler_t *handler)
 
ion_status_t iinq_insert (char *schema_file_name, ion_key_t key, ion_value_t value)
 
ion_status_t iinq_update (char *schema_file_name, ion_key_t key, ion_value_t value)
 
ion_status_t iinq_delete (char *schema_file_name, ion_key_t key)
 
ion_err_t iinq_drop (char *schema_file_name)
 

Function Documentation

ion_err_t iinq_create_source ( char *  schema_file_name,
ion_key_type_t  key_type,
ion_key_size_t  key_size,
ion_value_size_t  value_size 
)

Definition at line 42 of file iinq.c.

47  {
49  FILE *schema_file;
52 
53  dictionary.handler = &handler;
54 
55  error = ion_init_master_table();
56 
57  if (err_ok != error) {
58  return error;
59  }
60 
61  /* Load the handler. */
62  bpptree_init(&handler);
63 
64  /* If the file exists, fail. */
65  if (NULL != (schema_file = fopen(schema_file_name, "rb"))) {
66  if (0 != fclose(schema_file)) {
67  return err_file_close_error;
68  }
69 
71  }
72  /* Otherwise, we are creating the dictionary for the first time. */
73  else if (NULL != (schema_file = fopen(schema_file_name, "w+b"))) {
74  if (0 != fseek(schema_file, 0, SEEK_SET)) {
75  return err_file_bad_seek;
76  }
77 
78  error = ion_master_table_create_dictionary(&handler, &dictionary, key_type, key_size, value_size, -1);
79 
80  if (err_ok != error) {
81  return error;
82  }
83 
84  if (1 != fwrite(&dictionary.instance->id, sizeof(dictionary.instance->id), 1, schema_file)) {
85  return err_file_read_error;
86  }
87 
88  if (0 != fclose(schema_file)) {
89  return err_file_close_error;
90  }
91 
92  ion_close_dictionary(&dictionary);
93 
94  error = err_ok;
95  }
96  else {
97  error = err_file_open_error;
98  }
99 
101 
102  return error;
103 }
ion_err_t ion_master_table_create_dictionary(ion_dictionary_handler_t *handler, ion_dictionary_t *dictionary, ion_key_type_t key_type, ion_key_size_t key_size, ion_value_size_t value_size, ion_dictionary_size_t dictionary_size)
Creates a dictionary through use of the master table.
ion_dictionary_handler_t * handler
ion_dictionary_parent_t * instance
char ion_err_t
The error type used to store error codes.
Definition: kv_system.h:226
A dictionary contains information regarding an instance of the storage element and the associated han...
ion_dictionary_id_t id
ion_err_t ion_close_dictionary(ion_dictionary_t *dictionary)
Closes a given dictionary.
ion_err_t ion_init_master_table(void)
Opens the master table.
void bpptree_init(ion_dictionary_handler_t *handler)
Registers a specific handler for a dictionary instance.
ion_err_t ion_close_master_table(void)
Closes the master table.
#define error(rc)
Definition: bpp_tree.c:139
A dictionary_handler is responsible for dealing with the specific interface for an underlying diction...

Here is the call graph for this function:

ion_status_t iinq_delete ( char *  schema_file_name,
ion_key_t  key 
)

Definition at line 216 of file iinq.c.

219  {
223  ion_dictionary_handler_t handler;
224 
225  dictionary.handler = &handler;
226 
227  error = iinq_open_source(schema_file_name, &dictionary, &handler);
228 
229  if (err_ok != error) {
230  status = ION_STATUS_ERROR(error);
231  goto RETURN;
232  }
233 
234  status = dictionary_delete(&dictionary, key);
235  error = ion_close_dictionary(&dictionary);
236 
237  if ((err_ok == status.error) && (err_ok != error)) {
238  status.error = error;
239  }
240 
241 RETURN: return status;
242 }
#define ION_STATUS_ERROR(error)
Definition: kv_system.h:110
ion_dictionary_handler_t * handler
#define key(k)
Definition: bpp_tree.c:75
ion_err_t error
Definition: kv_system.h:291
ion_status_t dictionary_delete(ion_dictionary_t *dictionary, ion_key_t key)
Delete a value given a key.
Definition: dictionary.c:199
char ion_err_t
The error type used to store error codes.
Definition: kv_system.h:226
A dictionary contains information regarding an instance of the storage element and the associated han...
ion_err_t ion_close_dictionary(ion_dictionary_t *dictionary)
Closes a given dictionary.
#define error(rc)
Definition: bpp_tree.c:139
ion_err_t iinq_open_source(char *schema_file_name, ion_dictionary_t *dictionary, ion_dictionary_handler_t *handler)
Definition: iinq.c:106
#define ION_STATUS_INITIALIZE
Definition: kv_system.h:107
A dictionary_handler is responsible for dealing with the specific interface for an underlying diction...
A status object that describes the result of a dictionary operation.
Definition: kv_system.h:290

Here is the call graph for this function:

ion_err_t iinq_drop ( char *  schema_file_name)

Definition at line 245 of file iinq.c.

247  {
250  ion_dictionary_handler_t handler;
251 
252  dictionary.handler = &handler;
253 
254  error = iinq_open_source(schema_file_name, &dictionary, &handler);
255 
256  if (err_ok != error) {
257  return error;
258  }
259 
260  error = dictionary_delete_dictionary(&dictionary);
261 
262  fremove(schema_file_name);
263 
264  return error;
265 }
ion_dictionary_handler_t * handler
#define fremove(x)
Definition: kv_system.h:56
char ion_err_t
The error type used to store error codes.
Definition: kv_system.h:226
A dictionary contains information regarding an instance of the storage element and the associated han...
ion_err_t dictionary_delete_dictionary(ion_dictionary_t *dictionary)
Destroys dictionary.
Definition: dictionary.c:178
#define error(rc)
Definition: bpp_tree.c:139
ion_err_t iinq_open_source(char *schema_file_name, ion_dictionary_t *dictionary, ion_dictionary_handler_t *handler)
Definition: iinq.c:106
A dictionary_handler is responsible for dealing with the specific interface for an underlying diction...

Here is the call graph for this function:

ion_status_t iinq_insert ( char *  schema_file_name,
ion_key_t  key,
ion_value_t  value 
)

Definition at line 156 of file iinq.c.

160  {
164  ion_dictionary_handler_t handler;
165 
166  dictionary.handler = &handler;
167 
168  error = iinq_open_source(schema_file_name, &dictionary, &handler);
169 
170  if (err_ok != error) {
171  status = ION_STATUS_ERROR(error);
172  goto RETURN;
173  }
174 
175  status = dictionary_insert(&dictionary, key, value);
176  error = ion_close_dictionary(&dictionary);
177 
178  if ((err_ok == status.error) && (err_ok != error)) {
179  status.error = error;
180  }
181 
182 RETURN: return status;
183 }
#define ION_STATUS_ERROR(error)
Definition: kv_system.h:110
ion_dictionary_handler_t * handler
#define key(k)
Definition: bpp_tree.c:75
ion_err_t error
Definition: kv_system.h:291
ion_status_t dictionary_insert(ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
Insert a value into a dictionary.
Definition: dictionary.c:151
char ion_err_t
The error type used to store error codes.
Definition: kv_system.h:226
A dictionary contains information regarding an instance of the storage element and the associated han...
ion_err_t ion_close_dictionary(ion_dictionary_t *dictionary)
Closes a given dictionary.
#define error(rc)
Definition: bpp_tree.c:139
ion_err_t iinq_open_source(char *schema_file_name, ion_dictionary_t *dictionary, ion_dictionary_handler_t *handler)
Definition: iinq.c:106
#define ION_STATUS_INITIALIZE
Definition: kv_system.h:107
A dictionary_handler is responsible for dealing with the specific interface for an underlying diction...
A status object that describes the result of a dictionary operation.
Definition: kv_system.h:290

Here is the call graph for this function:

ion_err_t iinq_open_source ( char *  schema_file_name,
ion_dictionary_t dictionary,
ion_dictionary_handler_t handler 
)

Definition at line 106 of file iinq.c.

110  {
112  FILE *schema_file;
114 
115  error = ion_init_master_table();
116 
117  if (err_ok != error) {
118  return error;
119  }
120 
121  /* Load the handler. */
122  bpptree_init(handler);
123 
124  /* If the schema file already exists. */
125  if (NULL != (schema_file = fopen(schema_file_name, "rb"))) {
126  if (0 != fseek(schema_file, 0, SEEK_SET)) {
127  return err_file_bad_seek;
128  }
129 
130  if (1 != fread(&id, sizeof(id), 1, schema_file)) {
131  return err_file_read_error;
132  }
133 
134  error = ion_open_dictionary(handler, dictionary, id);
135 
136  if (err_ok != error) {
137  return error;
138  }
139 
140  if (0 != fclose(schema_file)) {
141  return err_file_close_error;
142  }
143 
144  error = err_ok;
145  }
146  else {
147  error = err_file_open_error;
148  }
149 
151 
152  return error;
153 }
unsigned int ion_dictionary_id_t
A type used to identify dictionaries, specifically in the master table.
char ion_err_t
The error type used to store error codes.
Definition: kv_system.h:226
ion_err_t ion_init_master_table(void)
Opens the master table.
void bpptree_init(ion_dictionary_handler_t *handler)
Registers a specific handler for a dictionary instance.
ion_err_t ion_open_dictionary(ion_dictionary_handler_t *handler, ion_dictionary_t *dictionary, ion_dictionary_id_t id)
Finds the target dictionary and opens it.
ion_err_t ion_close_master_table(void)
Closes the master table.
#define error(rc)
Definition: bpp_tree.c:139

Here is the call graph for this function:

Here is the caller graph for this function:

ion_status_t iinq_update ( char *  schema_file_name,
ion_key_t  key,
ion_value_t  value 
)

Definition at line 186 of file iinq.c.

190  {
194  ion_dictionary_handler_t handler;
195 
196  dictionary.handler = &handler;
197 
198  error = iinq_open_source(schema_file_name, &dictionary, &handler);
199 
200  if (err_ok != error) {
201  status = ION_STATUS_ERROR(error);
202  goto RETURN;
203  }
204 
205  status = dictionary_update(&dictionary, key, value);
206  error = ion_close_dictionary(&dictionary);
207 
208  if ((err_ok == status.error) && (err_ok != error)) {
209  status.error = error;
210  }
211 
212 RETURN: return status;
213 }
#define ION_STATUS_ERROR(error)
Definition: kv_system.h:110
ion_dictionary_handler_t * handler
#define key(k)
Definition: bpp_tree.c:75
ion_status_t dictionary_update(ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
Update all records with a given key.
Definition: dictionary.c:169
ion_err_t error
Definition: kv_system.h:291
char ion_err_t
The error type used to store error codes.
Definition: kv_system.h:226
A dictionary contains information regarding an instance of the storage element and the associated han...
ion_err_t ion_close_dictionary(ion_dictionary_t *dictionary)
Closes a given dictionary.
#define error(rc)
Definition: bpp_tree.c:139
ion_err_t iinq_open_source(char *schema_file_name, ion_dictionary_t *dictionary, ion_dictionary_handler_t *handler)
Definition: iinq.c:106
#define ION_STATUS_INITIALIZE
Definition: kv_system.h:107
A dictionary_handler is responsible for dealing with the specific interface for an underlying diction...
A status object that describes the result of a dictionary operation.
Definition: kv_system.h:290

Here is the call graph for this function: