28#include <boost/date_time/gregorian/gregorian.hpp>
49 boost::gregorian::date birthday,
50 const char *familySituation
61 d.Set(familySituation);
80 std::cout <<
"Object " << o <<
" \n"
81 " Name: " << *name <<
" \n"
82 " Birthday: \'" << *birthday <<
"\" \n"
83 " Family_Situation: " << *family << std::endl;
95 boost::gregorian::date birthday,
96 const char *familySituation,
127 std::cout <<
" Salary: " << *salary <<
" \n"
160 std::cout <<
"Object " << o <<
"\n"
161 " Name: " << *name <<
" \n"
162 " Staff: \"" << *staff <<
"\"\n";
169 const char * schema_file =
"/tmp/tutorial.oks";
170 const char * data_file =
"/tmp/tutorial.okd";
175 !strcmp(argv[1],
"--help") ||
176 !strcmp(argv[1],
"-help") ||
177 !strcmp(argv[1],
"--h") ||
178 !strcmp(argv[1],
"-h")
181 std::cout <<
"Usage: " << argv[0] <<
" [new_schema new_data]\n";
186 schema_file = argv[1];
193 std::cout <<
"[OKS TUTORIAL]: Creating OKS kernel...\n";
195 OksKernel kernel(
false,
false,
false,
false);
197 std::cout <<
"[OKS TUTORIAL]: Done creating OKS kernel\n\n";
205 std::cout <<
"[OKS TUTORIAL]: Creating new schema file...\n";
209 std::cout <<
"[OKS TUTORIAL]: Done creating new schema file...\n\n"
210 "[OKS TUTORIAL]: Define database class schema...\n\n"
211 " ********** ************ 1..1 **************\n"
212 " * Person *<|------* Employee *--------<>* Department *\n"
213 " ********** ************ 0..N **************\n\n";
220 "It is a class to describe a person",
232 "A string to describe person name",
243 "A date to describe person birthday",
247 Person->
add(PersonBirthday);
254 "Single,Married,Widow(er)",
256 "A enumeration to describe a person family state",
266 "It is a class to describe an employee",
277 "An integer to describe employee salary",
289 "A employee works at one and only one department"
293 Employee->
add(EmployeeSalary);
294 Employee->
add(WorksAt);
301 "It is a class to describe a department",
312 "A string to describe department name",
324 "A department has zero or many employess"
327 Department->
add(DepartmentName);
328 Department->
add(DepartmentStaff);
333 std::cout <<
"[OKS TUTORIAL]: Saves created OKS schema file...\n";
340 std::cout <<
"[OKS TUTORIAL]: Creating new data file...\n";
342 OksFile * data_h = kernel.
new_data(data_file,
"OKS TUTORIAL DATA FILE");
361 setPersonValues(person1,
"Peter", boost::gregorian::from_string(
"1960/02/01"),
"Married");
362 setPersonValues(person2,
"Mick", boost::gregorian::from_string(
"1956-09-01"),
"Single");
363 setPersonValues(person3,
"Julia", boost::gregorian::from_string(
"2000-May-25"),
"Single");
368 setEmployeeValues(employee1,
"Alexander", boost::gregorian::from_string(
"1972/05/12"),
"Single", 3540) ;
369 setEmployeeValues(employee2,
"Michel", boost::gregorian::from_string(
"1963/01/28"),
"Married", 4950) ;
370 setEmployeeValues(employee3,
"Maria", boost::gregorian::from_string(
"1951/08/18"),
"Widow(er)", 4020) ;
391 std::cout <<
"\n[OKS TUTORIAL]: Database contains the following data:\n";
405 std::cout <<
"\n[OKS TUTORIAL]: Saves created OKS data file...\n";
410 std::cout <<
"[OKS TUTORIAL]: Done with saving created OKS data file\n";
418 std::cout <<
"\n[OKS TUTORIAL]: Start database querying tests\n\n";
424 std::cout <<
"[QUERY]: Start simple database querying...\n";
428 boost::gregorian::date aDate(boost::gregorian::from_string(
"1960/01/01"));
434 std::cout <<
"[QUERY]: Looking for persons were born after " << aDate <<
" ...\n\n";
442 std::cout <<
"[QUERY]: Query \'" << query
443 <<
"\'\n founds the following objects in class \'"
444 << Person->
get_name() <<
"\' and subclasses:\n";
446 for(OksObject::List::iterator i = queryResult->begin(); i != queryResult->end(); ++i) {
449 std::cout <<
" - " << o <<
" was born " << *d << std::endl;
458 std::cout <<
"[QUERY]: Done with simple database querying\n\n";
462 std::cout <<
"[QUERY]: Start database querying with logical function...\n";
468 boost::gregorian::date lowDate(boost::gregorian::from_string(
"1960/01/01"));
469 boost::gregorian::date highDate(boost::gregorian::from_string(
"1970/01/01"));
476 OksQuery query(
true, andExpression);
481 std::cout <<
"[QUERY]: Looking for persons were born between " << lowDate
482 <<
" and " << highDate <<
" ...\n\n";
490 std::cout <<
"[QUERY]: Query \'" << query
491 <<
"\'\n founds the following objects in class \'"
492 << Person->
get_name() <<
"\' and subclasses:\n";
494 for(OksObject::List::iterator i = queryResult->begin(); i != queryResult->end(); ++i) {
497 std::cout <<
" - " << o <<
" was born " << *d << std::endl;
506 std::cout <<
"[QUERY]: Done database querying with logical function\n\n";
512 std::cout <<
"[QUERY]: Start database querying with relationship expression...\n";
518 boost::gregorian::date aDate(boost::gregorian::from_string(
"1971/01/01"));
519 const char * departmentName =
"IT Department";
526 OksQuery query(
true, andExpression);
531 std::cout <<
"[QUERY]: Looking for employee were born after " << aDate
532 <<
" and works at department " << departmentName <<
" ...\n\n";
540 std::cout <<
"[QUERY]: Query \'" << query
541 <<
"\'\n founds the following objects in class \'"
542 << Employee->
get_name() <<
"\' and subclasses:\n";
544 for(OksObject::List::iterator i = queryResult->begin(); i != queryResult->end(); ++i) {
547 std::cout <<
" - " << o <<
" was born " << *d << std::endl;
556 std::cout <<
"[QUERY]: Done database querying with relationship expression...\n";
559 std::cout <<
"\n[OKS TUTORIAL]: Done with database querying tests\n\n";
566 catch (
const std::exception & ex) {
567 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.
OksData * GetRelationshipValue(const std::string &) const
Get value of relationship by name.
std::list< OksObject * > List
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