Major update : views
This commit is contained in:
@ -515,8 +515,8 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
index_t nb_elements_per_line,
|
||||
const char* elements_names,
|
||||
const char* avl_name,
|
||||
const char* comments,
|
||||
bool referring)
|
||||
const char* comments
|
||||
)
|
||||
{
|
||||
OBIDMS_column_p new_column;
|
||||
OBIDMS_column_directory_p column_directory;
|
||||
@ -531,8 +531,6 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
index_t minimum_line_count;
|
||||
OBIType_t returned_data_type;
|
||||
OBIType_t stored_data_type;
|
||||
index_t returned_nb_elements_per_line;
|
||||
index_t stored_nb_elements_per_line;
|
||||
|
||||
new_column = NULL;
|
||||
|
||||
@ -547,7 +545,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
obidebug(1, "\nCan't create column because of empty column name");
|
||||
return NULL;
|
||||
}
|
||||
if ((data_type < 1) || (data_type > 6))
|
||||
if ((data_type < 1) || (data_type > 7))
|
||||
{
|
||||
obidebug(1, "\nCan't create column because of invalid data type");
|
||||
return NULL;
|
||||
@ -559,21 +557,14 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
}
|
||||
|
||||
returned_data_type = data_type;
|
||||
if ((data_type == OBI_STR) || (data_type == OBI_SEQ) || referring)
|
||||
if ((data_type == OBI_STR) || (data_type == OBI_SEQ))
|
||||
// stored data is indices referring to data stored elsewhere
|
||||
stored_data_type = OBI_IDX;
|
||||
else
|
||||
stored_data_type = returned_data_type;
|
||||
|
||||
returned_nb_elements_per_line = nb_elements_per_line;
|
||||
if (referring)
|
||||
// stored data is indices referring to lines in another column
|
||||
stored_nb_elements_per_line = 1;
|
||||
else
|
||||
stored_nb_elements_per_line = returned_nb_elements_per_line;
|
||||
|
||||
// The initial line count should be between the minimum (corresponding to the page size) and the maximum allowed
|
||||
minimum_line_count = get_line_count_per_page(stored_data_type, stored_nb_elements_per_line);
|
||||
minimum_line_count = get_line_count_per_page(stored_data_type, nb_elements_per_line);
|
||||
if (nb_lines > MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
obidebug(1, "\nCan't create column because of line count greater than the maximum allowed (%d)", MAXIMUM_LINE_COUNT);
|
||||
@ -583,12 +574,12 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
nb_lines = minimum_line_count;
|
||||
|
||||
// The number of elements names should be equal to the number of elements per line
|
||||
if ((elements_names == NULL) && (returned_nb_elements_per_line > 1))
|
||||
if ((elements_names == NULL) && (nb_elements_per_line > 1))
|
||||
{
|
||||
obidebug(1, "\nCan't create column because no elements names were given for a number of elements per line greater than 1");
|
||||
return NULL;
|
||||
}
|
||||
else if ((elements_names != NULL) && (returned_nb_elements_per_line > 1))
|
||||
else if ((elements_names != NULL) && (nb_elements_per_line > 1))
|
||||
{
|
||||
char* token;
|
||||
index_t n = 0;
|
||||
@ -605,7 +596,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if ((returned_nb_elements_per_line == 1) && (strcmp(elements_names, column_name) != 0))
|
||||
else if ((nb_elements_per_line == 1) && (strcmp(elements_names, column_name) != 0))
|
||||
{
|
||||
obidebug(1, "\nCan't create column because the element name does not match the column name");
|
||||
return NULL;
|
||||
@ -622,7 +613,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
|
||||
// Calculate the size needed
|
||||
header_size = obi_get_platform_header_size();
|
||||
data_size = obi_array_sizeof(stored_data_type, nb_lines, stored_nb_elements_per_line);
|
||||
data_size = obi_array_sizeof(stored_data_type, nb_lines, nb_elements_per_line);
|
||||
file_size = header_size + data_size;
|
||||
|
||||
// Get the latest version number
|
||||
@ -708,22 +699,19 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new_column->writable = true;
|
||||
new_column->writable = true;
|
||||
|
||||
header = new_column->header;
|
||||
header->header_size = header_size;
|
||||
header->data_size = data_size;
|
||||
header->line_count = nb_lines;
|
||||
header->lines_used = 0;
|
||||
header->stored_nb_elements_per_line = stored_nb_elements_per_line;
|
||||
header->returned_nb_elements_per_line = returned_nb_elements_per_line;
|
||||
header->nb_elements_per_line = nb_elements_per_line;
|
||||
header->stored_data_type = stored_data_type;
|
||||
header->returned_data_type = returned_data_type;
|
||||
header->creation_date = time(NULL);
|
||||
header->version = version_number;
|
||||
header->cloned_from = -1;
|
||||
header->referring = referring;
|
||||
header->referred_column_version = -1;
|
||||
|
||||
obi_column_set_elements_names(new_column, elements_names);
|
||||
|
||||
@ -780,7 +768,7 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
column_directory = obi_open_column_directory(dms, column_name);
|
||||
if (column_directory == NULL)
|
||||
{
|
||||
obidebug(1, "\nError opening a column directory structure");
|
||||
//obidebug(1, "\nError opening a column directory structure");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -818,7 +806,7 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
if (column_file_descriptor < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError opening column file");
|
||||
//obidebug(1, "\nError opening column file");
|
||||
free(column_file_name);
|
||||
return NULL;
|
||||
}
|
||||
@ -854,7 +842,7 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
MAP_PRIVATE,
|
||||
column_file_descriptor,
|
||||
0
|
||||
);
|
||||
);
|
||||
|
||||
if (column->header == MAP_FAILED)
|
||||
{
|
||||
@ -872,7 +860,7 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
MAP_PRIVATE,
|
||||
column_file_descriptor,
|
||||
header_size
|
||||
);
|
||||
);
|
||||
|
||||
if (column->data == MAP_FAILED)
|
||||
{
|
||||
@ -884,7 +872,7 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
column->writable = false;
|
||||
column->writable = false;
|
||||
|
||||
// If the data type is OBI_STR or OBI_SEQ, the associated AVL tree is opened
|
||||
if (((column->header)->returned_data_type == OBI_STR) || ((column->header)->returned_data_type == OBI_SEQ))
|
||||
@ -901,18 +889,6 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
column->avl = avl;
|
||||
}
|
||||
|
||||
if ((column->header)->referring)
|
||||
{
|
||||
column->referred_column = obi_open_column(dms, column_name, (column->header)->referred_column_version);
|
||||
if (column->referred_column == NULL)
|
||||
{
|
||||
obidebug(1, "\nError opening a referred column");
|
||||
obi_close_column(column);
|
||||
close(column_file_descriptor);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
close(column_file_descriptor);
|
||||
|
||||
// Add in the list of opened columns and set column counter to 1
|
||||
@ -925,9 +901,9 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
|
||||
|
||||
OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
OBIDMS_column_p line_selection,
|
||||
const char* column_name,
|
||||
obiversion_t version_number,
|
||||
bool referring,
|
||||
bool clone_data)
|
||||
{
|
||||
OBIDMS_column_p column_to_clone;
|
||||
@ -935,6 +911,10 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
index_t nb_lines;
|
||||
index_t nb_elements_per_line;
|
||||
OBIType_t data_type;
|
||||
size_t line_size;
|
||||
index_t i, index;
|
||||
|
||||
obidebug(1, "\nline_selection == NULL = %d\n", (line_selection == NULL));
|
||||
|
||||
column_to_clone = obi_open_column(dms, column_name, version_number);
|
||||
if (column_to_clone == NULL)
|
||||
@ -944,25 +924,11 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// A referring column can't be cloned
|
||||
if ((column_to_clone->header)->referring)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError: can't clone a referring column");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data_type = (column_to_clone->header)->returned_data_type;
|
||||
|
||||
nb_elements_per_line = (column_to_clone->header)->returned_nb_elements_per_line;
|
||||
nb_elements_per_line = (column_to_clone->header)->nb_elements_per_line;
|
||||
|
||||
if (clone_data && referring)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError: can't clone the data when creating a referring column");
|
||||
return NULL;
|
||||
}
|
||||
else if (clone_data)
|
||||
if (clone_data)
|
||||
nb_lines = (column_to_clone->header)->line_count;
|
||||
else
|
||||
nb_lines = get_line_count_per_page(data_type, nb_elements_per_line); // minimum line count corresponding to one memory page
|
||||
@ -974,8 +940,8 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
nb_elements_per_line,
|
||||
(column_to_clone->header)->elements_names,
|
||||
(column_to_clone->header)->avl_name,
|
||||
(column_to_clone->header)->comments,
|
||||
referring);
|
||||
(column_to_clone->header)->comments
|
||||
);
|
||||
|
||||
if (new_column == NULL)
|
||||
{
|
||||
@ -989,24 +955,29 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
|
||||
(new_column->header)->cloned_from = (column_to_clone->header)->version;
|
||||
|
||||
if (referring)
|
||||
{
|
||||
if ((column_to_clone->header)->referring)
|
||||
(new_column->header)->referred_column_version = (column_to_clone->header)->referred_column_version;
|
||||
else
|
||||
(new_column->header)->referred_column_version = (column_to_clone->header)->version;
|
||||
}
|
||||
|
||||
if (clone_data)
|
||||
if (clone_data && (line_selection == NULL))
|
||||
{
|
||||
memcpy(new_column->data, column_to_clone->data, (column_to_clone->header)->data_size);
|
||||
(new_column->header)->lines_used = (column_to_clone->header)->lines_used;
|
||||
}
|
||||
else if (clone_data && (line_selection != NULL))
|
||||
{
|
||||
obidebug(1, "\nCloning data from line selection\n");
|
||||
line_size = obi_sizeof((new_column->header)->stored_data_type) * (new_column->header)->nb_elements_per_line;
|
||||
fprintf(stderr, "\nline size = %ld\n", line_size);
|
||||
for (i=0; i<((line_selection->header)->lines_used); i++)
|
||||
{
|
||||
index = *(((index_t*) (line_selection->data)) + i);
|
||||
fprintf(stderr, "\nindex = %lld, i = %lld\n", index, i);
|
||||
memcpy((new_column->data)+(i*line_size), (column_to_clone->data)+(index*line_size), line_size);
|
||||
fprintf(stderr, "\nmemcpied\n");
|
||||
}
|
||||
(new_column->header)->lines_used = (line_selection->header)->lines_used;
|
||||
obidebug(1, "\nCloned data from line selection\n");
|
||||
}
|
||||
|
||||
// close column_to_clone or store the pointer if it's referred
|
||||
if (referring)
|
||||
new_column->referred_column = column_to_clone;
|
||||
else if (obi_close_column(column_to_clone) < 0)
|
||||
// Close column_to_clone
|
||||
if (obi_close_column(column_to_clone) < 0)
|
||||
{
|
||||
obidebug(1, "\nError closing a column that has been cloned");
|
||||
// TODO return NULL or not?
|
||||
@ -1049,9 +1020,6 @@ int obi_close_column(OBIDMS_column_p column)
|
||||
}
|
||||
}
|
||||
|
||||
if ((column->header)->referring)
|
||||
obi_close_column(column->referred_column);
|
||||
|
||||
// If the data type is OBI_STR or OBI_SEQ, the associated AVL tree is closed
|
||||
if (((column->header)->returned_data_type == OBI_STR) || ((column->header)->returned_data_type == OBI_SEQ))
|
||||
{
|
||||
@ -1095,8 +1063,8 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it nece
|
||||
char* column_file_name;
|
||||
|
||||
// Compute the new line count = the number of lines used rounded to the nearest greater multiple of page size greater than 0
|
||||
multiple = ceil((double) (ONE_IF_ZERO((column->header)->lines_used) * (column->header)->stored_nb_elements_per_line * obi_sizeof((column->header)->stored_data_type)) / (double) getpagesize());
|
||||
new_line_count = floor((((int) multiple) * getpagesize()) / ((column->header)->stored_nb_elements_per_line * obi_sizeof((column->header)->stored_data_type)));
|
||||
multiple = ceil((double) (ONE_IF_ZERO((column->header)->lines_used) * (column->header)->nb_elements_per_line * obi_sizeof((column->header)->stored_data_type)) / (double) getpagesize());
|
||||
new_line_count = floor((((int) multiple) * getpagesize()) / ((column->header)->nb_elements_per_line * obi_sizeof((column->header)->stored_data_type)));
|
||||
|
||||
// Check that it is actually greater than the current number of lines allocated in the file, otherwise no need to truncate
|
||||
if ((column->header)->line_count == new_line_count)
|
||||
@ -1131,7 +1099,7 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it nece
|
||||
}
|
||||
|
||||
// Truncate the column file
|
||||
data_size = obi_array_sizeof((column->header)->stored_data_type, new_line_count, (column->header)->stored_nb_elements_per_line);
|
||||
data_size = obi_array_sizeof((column->header)->stored_data_type, new_line_count, (column->header)->nb_elements_per_line);
|
||||
file_size = (column->header)->header_size + data_size;
|
||||
if (ftruncate(column_file_descriptor, file_size) < 0)
|
||||
{
|
||||
@ -1262,8 +1230,11 @@ int obi_enlarge_column(OBIDMS_column_p column)
|
||||
|
||||
int obi_truncate_and_close_column(OBIDMS_column_p column)
|
||||
{
|
||||
if (obi_truncate_column_to_lines_used(column) < 0)
|
||||
return -1;
|
||||
if (column->writable) // TODO discuss
|
||||
{
|
||||
if (obi_truncate_column_to_lines_used(column) < 0)
|
||||
return -1;
|
||||
}
|
||||
if (obi_close_column(column) < 0)
|
||||
return -1;
|
||||
|
||||
@ -1277,8 +1248,8 @@ void obi_ini_to_NA_values(OBIDMS_column_p column,
|
||||
{
|
||||
index_t i, start, end, nb_elements;
|
||||
|
||||
nb_elements = nb_lines*((column->header)->stored_nb_elements_per_line);
|
||||
start = first_line_nb*((column->header)->stored_nb_elements_per_line);
|
||||
nb_elements = nb_lines*((column->header)->nb_elements_per_line);
|
||||
start = first_line_nb*((column->header)->nb_elements_per_line);
|
||||
end = start + nb_elements;
|
||||
|
||||
switch ((column->header)->stored_data_type) {
|
||||
@ -1476,35 +1447,3 @@ char* obi_column_format_date(time_t date)
|
||||
return formatted_time;
|
||||
}
|
||||
|
||||
|
||||
// TODO put in separate file ?
|
||||
// warning for the dependency and for the fact that it's always added at the next line (or not cuz might not be a good idea?)
|
||||
int obi_grep_line(OBIDMS_column_p referring_column, index_t line_to_grep)
|
||||
{
|
||||
// Check that the column is referring another
|
||||
if (!((referring_column->header)->referring))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError: Grepping a line can only be done with a referring column");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if the file needs to be enlarged
|
||||
if ((referring_column->header)->lines_used == (referring_column->header)->line_count)
|
||||
{
|
||||
// Enlarge the file
|
||||
if (obi_enlarge_column(referring_column) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set the value
|
||||
*(((index_t*) (referring_column->data)) + (referring_column->header)->lines_used) = line_to_grep;
|
||||
|
||||
// Update lines used
|
||||
((referring_column->header)->lines_used)++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user