2019-05-13 19:59:28 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of morm
|
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2021-03-09 18:10:34 +01:00
|
|
|
* Copyright (c) 2019-2021, Tomasz Sowa
|
2019-05-13 19:59:28 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef headerfile_morm_modelenv
|
|
|
|
#define headerfile_morm_modelenv
|
|
|
|
|
|
|
|
#include "modeldata.h"
|
2019-05-21 17:51:13 +02:00
|
|
|
#include "cursorhelper.h"
|
|
|
|
#include "finderhelper.h"
|
2019-09-11 20:16:22 +02:00
|
|
|
#include "fieldvaluehelper.h"
|
2019-05-13 19:59:28 +02:00
|
|
|
#include "morm_types.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace morm
|
|
|
|
{
|
|
|
|
|
2019-08-22 20:33:35 +02:00
|
|
|
|
2021-03-10 16:20:11 +01:00
|
|
|
|
|
|
|
|
2019-05-13 19:59:28 +02:00
|
|
|
class ModelEnv
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2019-09-13 20:17:02 +02:00
|
|
|
// global objects to the whole models tree
|
|
|
|
// (values are copied to child models)
|
2019-05-13 19:59:28 +02:00
|
|
|
ModelData * model_data;
|
2019-05-21 17:51:13 +02:00
|
|
|
FinderHelper * finder_helper;
|
|
|
|
CursorHelper * cursor_helper;
|
2019-09-18 17:28:06 +02:00
|
|
|
int model_work_mode;
|
|
|
|
int model_work_submode;
|
2019-09-13 20:17:02 +02:00
|
|
|
bool dump_mode;
|
|
|
|
|
2021-05-20 16:25:01 +02:00
|
|
|
pt::WTextStream schema_name;
|
|
|
|
pt::WTextStream table_name;
|
2019-05-21 19:24:12 +02:00
|
|
|
int table_index;
|
2021-05-13 19:32:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* optional additional table name
|
|
|
|
* used in eq(), neq(), ... methods in Finder
|
|
|
|
*/
|
|
|
|
const wchar_t * table2_name;
|
|
|
|
int table2_index;
|
|
|
|
|
|
|
|
|
2019-08-22 20:33:35 +02:00
|
|
|
int field_index;
|
2021-03-09 18:10:34 +01:00
|
|
|
bool was_primary_key_read;
|
|
|
|
bool has_primary_key_set;
|
2019-05-21 19:24:12 +02:00
|
|
|
|
2021-05-13 19:32:31 +02:00
|
|
|
|
2019-09-04 18:02:18 +02:00
|
|
|
std::vector<const wchar_t *> * set_field_name_helper;
|
2019-09-11 20:16:22 +02:00
|
|
|
std::vector<FieldValueHelper> * field_value_helper_tab;
|
2019-05-21 19:24:12 +02:00
|
|
|
|
2019-05-13 19:59:28 +02:00
|
|
|
|
|
|
|
ModelEnv()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
~ModelEnv()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ModelEnv(const ModelEnv & e)
|
|
|
|
{
|
2021-04-14 16:21:10 +02:00
|
|
|
copy_global_objects(e);
|
|
|
|
|
2019-05-13 19:59:28 +02:00
|
|
|
table_index = e.table_index;
|
2021-05-13 19:32:31 +02:00
|
|
|
table2_index = e.table2_index;
|
2019-09-04 18:02:18 +02:00
|
|
|
set_field_name_helper = e.set_field_name_helper;
|
2019-09-11 20:16:22 +02:00
|
|
|
field_value_helper_tab = e.field_value_helper_tab;
|
2019-08-22 20:33:35 +02:00
|
|
|
field_index = e.field_index;
|
2021-03-09 18:10:34 +01:00
|
|
|
was_primary_key_read = e.was_primary_key_read;
|
|
|
|
has_primary_key_set = e.has_primary_key_set;
|
2019-08-22 20:33:35 +02:00
|
|
|
|
2021-03-11 12:22:37 +01:00
|
|
|
// schema_name and table_name don't have to be copied
|
2021-05-13 19:32:31 +02:00
|
|
|
table2_name = nullptr;
|
2019-05-13 19:59:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-21 19:24:12 +02:00
|
|
|
void copy_global_objects(const ModelEnv & e)
|
|
|
|
{
|
|
|
|
model_data = e.model_data;
|
|
|
|
finder_helper = e.finder_helper;
|
|
|
|
cursor_helper = e.cursor_helper;
|
|
|
|
|
2019-09-18 17:28:06 +02:00
|
|
|
model_work_mode = e.model_work_mode;
|
|
|
|
model_work_submode = e.model_work_submode;
|
2019-09-13 20:17:02 +02:00
|
|
|
dump_mode = e.dump_mode;
|
2019-05-21 19:24:12 +02:00
|
|
|
}
|
|
|
|
|
2019-09-18 17:55:42 +02:00
|
|
|
|
2019-05-13 19:59:28 +02:00
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
model_data = nullptr;
|
2019-05-21 17:51:13 +02:00
|
|
|
finder_helper = nullptr;
|
|
|
|
cursor_helper = nullptr;
|
2019-09-18 17:28:06 +02:00
|
|
|
model_work_mode = MORM_MODEL_WORK_MODE_NONE;
|
|
|
|
model_work_submode = MORM_MODEL_WORK_SUBMODE_NONE;
|
2019-09-13 20:17:02 +02:00
|
|
|
dump_mode = false;
|
2021-03-11 12:22:37 +01:00
|
|
|
schema_name.clear();
|
2019-05-21 19:24:12 +02:00
|
|
|
table_name.clear();
|
2021-05-13 19:32:31 +02:00
|
|
|
table2_name = nullptr;
|
2019-05-21 19:24:12 +02:00
|
|
|
table_index = 0;
|
2021-05-13 19:32:31 +02:00
|
|
|
table2_index = 0;
|
2019-09-04 18:02:18 +02:00
|
|
|
set_field_name_helper = nullptr;
|
2019-09-11 20:16:22 +02:00
|
|
|
field_value_helper_tab = nullptr;
|
2019-08-22 20:33:35 +02:00
|
|
|
field_index = 0;
|
2021-03-09 18:10:34 +01:00
|
|
|
was_primary_key_read = false;
|
|
|
|
has_primary_key_set = false;
|
2019-05-13 19:59:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 12:22:37 +01:00
|
|
|
void add_table_name_to_finder_helper()
|
|
|
|
{
|
|
|
|
if( finder_helper )
|
|
|
|
{
|
|
|
|
table_index = finder_helper->add_join_table(table_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
table_index = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-13 19:59:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|