Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve #74 #79

Merged
merged 61 commits into from
Feb 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
f52fba1
started with issue #74 belongs_to
Jan 5, 2017
4d17cf4
belongs to progress
Jan 6, 2017
4835954
merged object_ptr, has_one and belongs_to into object_pointer class
Jan 6, 2017
eafe6e3
belongs_to progress
Jan 6, 2017
e3b1023
updated belongs_to strategy
Jan 6, 2017
433ce36
removed obsolete relation analyzing in prototype_node
Jan 6, 2017
8bac3c7
replaced is_internal with object_holder_type
Jan 8, 2017
9aca6b0
belongs to progress
Jan 9, 2017
963bc7f
belongs to progress
Jan 9, 2017
2e3562a
split object-inserter, deleter and node analyzer into seperate files
Jan 10, 2017
189b911
belongs_to progress
Jan 10, 2017
5f507b8
belongs_to progress
Jan 11, 2017
ae2cae8
node analyzer has many progress
Jan 12, 2017
71503d4
belongs_to progress
Jan 12, 2017
d6597ef
belongs_to progress: insertion
Jan 13, 2017
05c99fa
belongs_to test adaptions
Jan 13, 2017
bb05719
hans_many remove and remove_if progress
Jan 13, 2017
f0697b8
added remove and remove_if for has_may list
Jan 14, 2017
bf07696
has many remove progress
Jan 15, 2017
cbff4ba
added has many remove and remove if
Jan 16, 2017
953234d
added quiet flag to test suite
Jan 16, 2017
472031e
added generic remove for has many
Jan 16, 2017
aaf5421
started has_many_deleter
Jan 16, 2017
2f55fb1
belongs_to progress
Jan 16, 2017
7f5f8d3
belongs_to progress
Jan 17, 2017
4161468
added detach for persistence
Jan 18, 2017
f36232a
introduced object store observer and persistence observer
Jan 19, 2017
0786761
object store observer progress
Jan 23, 2017
32dfa1b
observer progress
Jan 24, 2017
848036e
observer progress
Jan 25, 2017
6b417d4
observer progress
Jan 25, 2017
9de1581
observer progress
Jan 26, 2017
a57f44c
observer progress
Jan 26, 2017
178308a
changes
Jan 27, 2017
6c3bba0
belongs_to progress
Jan 30, 2017
da02388
attach node restructuring
Jan 31, 2017
4b934ee
store attach progress
Jan 31, 2017
f643871
has many transaction update
Feb 1, 2017
84033ce
orm belongs to progress
Feb 1, 2017
4683409
belongs_to progress
Feb 2, 2017
175be7b
belongs to todos
Feb 2, 2017
3a04b33
added more attach methods accepting a node
Feb 2, 2017
401ad86
node analyzer progress
Feb 3, 2017
87944c4
more query update tests
Feb 4, 2017
9cba472
fixed sqlite prepared statement date parsing
Feb 4, 2017
0dd4b78
belongs to for win progress
Feb 5, 2017
efdb933
fixed vs compile
Feb 6, 2017
a196542
added inserter and deleter to has many list
Feb 9, 2017
697d431
many to many preparations
Feb 12, 2017
146f3cf
many to many progress
Feb 13, 2017
4460ba3
adjusted mssql datatype for varchar
Feb 14, 2017
59bd30e
many to many progress
Feb 14, 2017
4c3d4ae
node analyzing progress
Feb 14, 2017
b95c3e1
mssql parameter size adjustments for sqlcolumns
Feb 15, 2017
e60fe79
register correct prototype node when serializing has_many
Feb 15, 2017
021fe06
handle potential memory leak when creating prototype node
Feb 15, 2017
716460a
enhanced observer and has_many_to_many test
Feb 15, 2017
c1bc5b6
fixed clang issues
Feb 15, 2017
529b181
reenabled tmp iterator in list
Feb 15, 2017
f97839d
removed default move constructors for has many list
Feb 15, 2017
7937a82
removed has many iterator move constructors
Feb 16, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions belongs_to.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
has_many<employee> <-> belongs_to<department>
===================================================

```
struct employee
{
oos::belongs_to<department> dep;

template < class S >
void serialize(S &s)
{
s.serialize("department", dep);
}
};

struct department
{
oos::has_many<employee> emps;

template < class S >
void serialize(S &s)
{
s.serialize("employee", emps);
}
};

auto george = ostore.insert(new employee("george"));
auto insurance = ostore.insert(new department("insurance"));

insurance->emps.push_back(george);

```

Analyze phase
=============

__Case 1: Department attached first__

* attach department
* prototype "employee" not found; prepare new
* mark as has many relation for "department" member "employees"
* attach employee
* prototype "employee found"
* if employee contains belongs_to for "department" tie prototypes
* else throw error

__Case 2: Employee attached first__

* attach employee
* prototype "department" not found: prepare new
* mark as belongs relation for "employee" member "department"
* attach department
* prototype "department" found
* if department contains has_many for "employee" tie prototypes
* else throw error

Business phase
==============

__Case 1: emplyoee sets a department__

* employee gets object type "department" with member name "employees" from prototype
* employee is added to departments employees container

__Case 2: department adds an employee__

* department gets object type "employee" with member name "department" from prototype
* department is set for employee


TODO
====

1. Add ```object_store::attach<T>(prototype_node, parent, [observer])```
2. Add static
* ```prototype_node::make_node<T>()```
* ```prototype_node::make_relation_node<T>()```
3. Adjust ```node_anaylzer```
21 changes: 13 additions & 8 deletions include/oos/db/mysql/mysql_statement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,33 @@ class mysql_statement : public oos::detail::statement_impl

private:
template < class T >
void bind_value(MYSQL_BIND &bind, enum_field_types type, T value)
void bind_value(std::size_t index, enum_field_types type, T value)
{
// std::cout << "binding [" << value << "] (index: " << index << ")\n";
MYSQL_BIND &bind = host_array[index];
if (bind.buffer == nullptr) {
// allocating memory
bind.buffer = new char[sizeof(T)];
}
*static_cast<T*>(bind.buffer) = value;
bind.buffer_type = type;
bind.buffer_length = sizeof(T);
bind.is_null = 0;
is_null_vector[index] = false;
bind.is_null = &is_null_vector[index];
bind.is_unsigned = std::is_unsigned<T>::value;
}
void bind_value(MYSQL_BIND &bind, enum_field_types type, char x);
void bind_value(MYSQL_BIND &bind, enum_field_types type, unsigned char x);
void bind_value(MYSQL_BIND &bind, enum_field_types type, const oos::date &x);
void bind_value(MYSQL_BIND &bind, enum_field_types type, const oos::time &x);
void bind_value(MYSQL_BIND &bind, enum_field_types type, const char *value, size_t size);
void bind_value(std::size_t index, enum_field_types type, char x);
void bind_value(std::size_t index, enum_field_types type, unsigned char x);
void bind_value(std::size_t index, enum_field_types type, const oos::date &x);
void bind_value(std::size_t index, enum_field_types type, const oos::time &x);
void bind_value(std::size_t index, enum_field_types type, const char *value, size_t size);

void bind_null(std::size_t index);

private:
size_t result_size;
size_t host_size;
std::vector<unsigned long> length_vector;
std::vector<my_bool> is_null_vector;
MYSQL_STMT *stmt_ = nullptr;
MYSQL_BIND *host_array = nullptr;
};
Expand Down
Loading