21#include <boost/date_time/gregorian/gregorian.hpp>
42 boost::gregorian::date birthday,
43 const char *familySituation
54 d.Set(familySituation);
73 std::cout <<
"Object " << o <<
" \n"
74 " Name: " << *name <<
" \n"
75 " Birthday: \'" << *birthday <<
"\" \n"
76 " Family_Situation: " << *family << std::endl;
88 boost::gregorian::date birthday,
89 const char *familySituation,
120 std::cout <<
" Salary: " << *salary <<
" \n"
153 std::cout <<
"Object " << o <<
"\n"
154 " Name: " << *name <<
" \n"
155 " Staff: \"" << *staff <<
"\"\n";
162 const char * schema_file =
"/tmp/tutorial.oks";
163 const char * data_file =
"/tmp/tutorial.okd";
168 !strcmp(argv[1],
"--help") ||
169 !strcmp(argv[1],
"-help") ||
170 !strcmp(argv[1],
"--h") ||
171 !strcmp(argv[1],
"-h")
174 std::cout <<
"Usage: " << argv[0] <<
" [new_schema new_data]\n";
179 schema_file = argv[1];
186 std::cout <<
"[OKS TUTORIAL]: Creating OKS kernel...\n";
188 OksKernel kernel(
false,
false,
false,
false);
190 std::cout <<
"[OKS TUTORIAL]: Done creating OKS kernel\n\n";
198 std::cout <<
"[OKS TUTORIAL]: Creating new schema file...\n";
202 std::cout <<
"[OKS TUTORIAL]: Done creating new schema file...\n\n"
203 "[OKS TUTORIAL]: Define database class schema...\n\n"
204 " ********** ************ 1..1 **************\n"
205 " * Person *<|------* Employee *--------<>* Department *\n"
206 " ********** ************ 0..N **************\n\n";
213 "It is a class to describe a person",
225 "A string to describe person name",
236 "A date to describe person birthday",
240 Person->
add(PersonBirthday);
247 "Single,Married,Widow(er)",
249 "A enumeration to describe a person family state",
259 "It is a class to describe an employee",
270 "An integer to describe employee salary",
282 "A employee works at one and only one department"
286 Employee->
add(EmployeeSalary);
287 Employee->
add(WorksAt);
294 "It is a class to describe a department",
305 "A string to describe department name",
317 "A department has zero or many employess"
320 Department->
add(DepartmentName);
321 Department->
add(DepartmentStaff);
326 std::cout <<
"[OKS TUTORIAL]: Saves created OKS schema file...\n";
333 std::cout <<
"[OKS TUTORIAL]: Creating new data file...\n";
335 OksFile * data_h = kernel.
new_data(data_file,
"OKS TUTORIAL DATA FILE");
354 setPersonValues(person1,
"Peter", boost::gregorian::from_string(
"1960/02/01"),
"Married");
355 setPersonValues(person2,
"Mick", boost::gregorian::from_string(
"1956-09-01"),
"Single");
356 setPersonValues(person3,
"Julia", boost::gregorian::from_string(
"2000-May-25"),
"Single");
361 setEmployeeValues(employee1,
"Alexander", boost::gregorian::from_string(
"1972/05/12"),
"Single", 3540) ;
362 setEmployeeValues(employee2,
"Michel", boost::gregorian::from_string(
"1963/01/28"),
"Married", 4950) ;
363 setEmployeeValues(employee3,
"Maria", boost::gregorian::from_string(
"1951/08/18"),
"Widow(er)", 4020) ;
384 std::cout <<
"\n[OKS TUTORIAL]: Database contains the following data:\n";
398 std::cout <<
"\n[OKS TUTORIAL]: Saves created OKS data file...\n";
403 std::cout <<
"[OKS TUTORIAL]: Done with saving created OKS data file\n";
411 std::cout <<
"\n[OKS TUTORIAL]: Start database querying tests\n\n";
417 std::cout <<
"[QUERY]: Start simple database querying...\n";
421 boost::gregorian::date aDate(boost::gregorian::from_string(
"1960/01/01"));
427 std::cout <<
"[QUERY]: Looking for persons were born after " << aDate <<
" ...\n\n";
435 std::cout <<
"[QUERY]: Query \'" << query
436 <<
"\'\n founds the following objects in class \'"
437 << Person->
get_name() <<
"\' and subclasses:\n";
439 for(OksObject::List::iterator i = queryResult->begin(); i != queryResult->end(); ++i) {
442 std::cout <<
" - " << o <<
" was born " << *d << std::endl;
451 std::cout <<
"[QUERY]: Done with simple database querying\n\n";
455 std::cout <<
"[QUERY]: Start database querying with logical function...\n";
461 boost::gregorian::date lowDate(boost::gregorian::from_string(
"1960/01/01"));
462 boost::gregorian::date highDate(boost::gregorian::from_string(
"1970/01/01"));
469 OksQuery query(
true, andExpression);
474 std::cout <<
"[QUERY]: Looking for persons were born between " << lowDate
475 <<
" and " << highDate <<
" ...\n\n";
483 std::cout <<
"[QUERY]: Query \'" << query
484 <<
"\'\n founds the following objects in class \'"
485 << Person->
get_name() <<
"\' and subclasses:\n";
487 for(OksObject::List::iterator i = queryResult->begin(); i != queryResult->end(); ++i) {
490 std::cout <<
" - " << o <<
" was born " << *d << std::endl;
499 std::cout <<
"[QUERY]: Done database querying with logical function\n\n";
505 std::cout <<
"[QUERY]: Start database querying with relationship expression...\n";
511 boost::gregorian::date aDate(boost::gregorian::from_string(
"1971/01/01"));
512 const char * departmentName =
"IT Department";
519 OksQuery query(
true, andExpression);
524 std::cout <<
"[QUERY]: Looking for employee were born after " << aDate
525 <<
" and works at department " << departmentName <<
" ...\n\n";
533 std::cout <<
"[QUERY]: Query \'" << query
534 <<
"\'\n founds the following objects in class \'"
535 << Employee->
get_name() <<
"\' and subclasses:\n";
537 for(OksObject::List::iterator i = queryResult->begin(); i != queryResult->end(); ++i) {
540 std::cout <<
" - " << o <<
" was born " << *d << std::endl;
549 std::cout <<
"[QUERY]: Done database querying with relationship expression...\n";
552 std::cout <<
"\n[OKS TUTORIAL]: Done with database querying tests\n\n";
559 catch (
const std::exception & ex) {
560 std::cerr <<
"Caught exception:\n" << ex.what() << std::endl;
OKS query logical AND expression class.
static const char * u32_int_type
static const char * string_type
static const char * enum_type
static const char * date_type
void add_super_class(const std::string &name)
void add(OksAttribute *a)
Add attribute.
const std::string & get_name() const noexcept
OksObject::List * execute_query(OksQuery *query) const
Execute query.
OKS query expression comparator class.
Provides interface to the OKS XML schema and data files.
void add_include_file(const std::string &name)
Add include file.
Provides interface to the OKS kernel.
OksFile * new_data(const std::string &name, const std::string &logical_name="", const std::string &type="")
Create OKS data file.
void save_schema(OksFile *file_h, bool force=false, OksFile *true_file_h=0)
Save OKS schema file.
void save_data(OksFile *file_h, bool ignore_bad_objects=false, OksFile *true_file_h=nullptr, bool force_defaults=false)
Save OKS data file.
OksFile * new_schema(const std::string &name)
Create OKS schema file.
void add(OksQueryExpression *q)
OksObject describes instance of OksClass.
void AddRelationshipValue(const std::string &name, OksObject *object)
Add object value to multi-value relationship by name.
std::list< OksObject * > List
OksData * GetRelationshipValue(const std::string &) const
Get value of relationship by name.
void SetRelationshipValue(const std::string &name, OksData *data, bool skip_non_null_check=false)
Set value of relationship by name.
void SetAttributeValue(const std::string &name, OksData *data)
Set value of attribute by name.
const std::string & GetId() const
OksData * GetAttributeValue(const std::string &name) const
Get value of attribute by name.
static bool equal_cmp(const OksData *, const OksData *)
static bool greater_cmp(const OksData *, const OksData *)
static bool less_cmp(const OksData *, const OksData *)
OKS query relationship expression class.
void printEmployee(const OksObject *o)
void setPersonValues(OksObject *o, const char *name, boost::gregorian::date birthday, const char *familySituation)
void setEmployeeValues(OksObject *o, const char *name, boost::gregorian::date birthday, const char *familySituation, uint32_t salary)
int main(int argc, char **argv)
void setDepartmentValues(OksObject *o, const char *name)
void printPerson(const OksObject *o)
void printDepartment(const OksObject *o)
the structure to pass common parameters to various read() methods of OksData and OksObject class
union dunedaq::oks::OksData::Data data