28#include <boost/date_time/gregorian/gregorian.hpp>
48 boost::gregorian::date birthday,
49 const char* familySituation
60 d.Set(familySituation);
77 std::cout <<
"Object " << o
86 << *family << std::endl;
96 boost::gregorian::date birthday,
97 const char* familySituation,
126 std::cout <<
" Salary: " << *salary
157 std::cout <<
"Object " << o
169 const char* schema_file =
"/tmp/tutorial.oks";
170 const char* data_file =
"/tmp/tutorial.okd";
173 (!strcmp(argv[1],
"--help") || !strcmp(argv[1],
"-help") || !strcmp(argv[1],
"--h") || !strcmp(argv[1],
"-h"))) {
174 std::cout <<
"Usage: " << argv[0] <<
" [new_schema new_data]\n";
179 schema_file = argv[1];
185 std::cout <<
"[OKS TUTORIAL]: Creating OKS kernel...\n";
187 OksKernel kernel(
false,
false,
false,
false);
189 std::cout <<
"[OKS TUTORIAL]: Done creating OKS kernel\n\n";
195 std::cout <<
"[OKS TUTORIAL]: Creating new schema file...\n";
199 std::cout <<
"[OKS TUTORIAL]: Done creating new schema file...\n\n"
200 "[OKS TUTORIAL]: Define database class schema...\n\n"
201 " ********** ************ 1..1 **************\n"
202 " * Person *<|------* Employee *--------<>* Department *\n"
203 " ********** ************ 0..N **************\n\n";
207 OksClass* Person =
new OksClass(
"Person",
"It is a class to describe a person",
false, &kernel);
215 Person->
add(PersonBirthday);
220 "Single,Married,Widow(er)",
222 "A enumeration to describe a person family state",
227 OksClass* Employee =
new OksClass(
"Employee",
"It is a class to describe an employee",
false, &kernel);
239 "A employee works at one and only one department");
242 Employee->
add(EmployeeSalary);
243 Employee->
add(WorksAt);
247 OksClass* Department =
new OksClass(
"Department",
"It is a class to describe a department",
false, &kernel);
259 "A department has zero or many employess");
261 Department->
add(DepartmentName);
262 Department->
add(DepartmentStaff);
266 std::cout <<
"[OKS TUTORIAL]: Saves created OKS schema file...\n";
272 std::cout <<
"[OKS TUTORIAL]: Creating new data file...\n";
274 OksFile* data_h = kernel.
new_data(data_file,
"OKS TUTORIAL DATA FILE");
291 setPersonValues(person1,
"Peter", boost::gregorian::from_string(
"1960/02/01"),
"Married");
292 setPersonValues(person2,
"Mick", boost::gregorian::from_string(
"1956-09-01"),
"Single");
293 setPersonValues(person3,
"Julia", boost::gregorian::from_string(
"2000-May-25"),
"Single");
297 setEmployeeValues(employee1,
"Alexander", boost::gregorian::from_string(
"1972/05/12"),
"Single", 3540);
298 setEmployeeValues(employee2,
"Michel", boost::gregorian::from_string(
"1963/01/28"),
"Married", 4950);
299 setEmployeeValues(employee3,
"Maria", boost::gregorian::from_string(
"1951/08/18"),
"Widow(er)", 4020);
317 std::cout <<
"\n[OKS TUTORIAL]: Database contains the following data:\n";
330 std::cout <<
"\n[OKS TUTORIAL]: Saves created OKS data file...\n";
334 std::cout <<
"[OKS TUTORIAL]: Done with saving created OKS data file\n";
340 std::cout <<
"\n[OKS TUTORIAL]: Start database querying tests\n\n";
345 std::cout <<
"[QUERY]: Start simple database querying...\n";
349 boost::gregorian::date aDate(boost::gregorian::from_string(
"1960/01/01"));
354 std::cout <<
"[QUERY]: Looking for persons were born after " << aDate <<
" ...\n\n";
361 std::cout <<
"[QUERY]: Query \'" << query <<
"\'\n founds the following objects in class \'"
362 << Person->
get_name() <<
"\' and subclasses:\n";
364 for (OksObject::List::iterator i = queryResult->begin(); i != queryResult->end(); ++i) {
367 std::cout <<
" - " << o <<
" was born " << *d << std::endl;
375 std::cout <<
"[QUERY]: Done with simple database querying\n\n";
379 std::cout <<
"[QUERY]: Start database querying with logical function...\n";
384 boost::gregorian::date lowDate(boost::gregorian::from_string(
"1960/01/01"));
385 boost::gregorian::date highDate(boost::gregorian::from_string(
"1970/01/01"));
392 OksQuery query(
true, andExpression);
396 std::cout <<
"[QUERY]: Looking for persons were born between " << lowDate <<
" and " << highDate <<
" ...\n\n";
403 std::cout <<
"[QUERY]: Query \'" << query <<
"\'\n founds the following objects in class \'"
404 << Person->
get_name() <<
"\' and subclasses:\n";
406 for (OksObject::List::iterator i = queryResult->begin(); i != queryResult->end(); ++i) {
409 std::cout <<
" - " << o <<
" was born " << *d << std::endl;
417 std::cout <<
"[QUERY]: Done database querying with logical function\n\n";
422 std::cout <<
"[QUERY]: Start database querying with relationship expression...\n";
427 boost::gregorian::date aDate(boost::gregorian::from_string(
"1971/01/01"));
428 const char* departmentName =
"IT Department";
436 OksQuery query(
true, andExpression);
440 std::cout <<
"[QUERY]: Looking for employee were born after " << aDate <<
" and works at department "
441 << departmentName <<
" ...\n\n";
448 std::cout <<
"[QUERY]: Query \'" << query <<
"\'\n founds the following objects in class \'"
449 << Employee->
get_name() <<
"\' and subclasses:\n";
451 for (OksObject::List::iterator i = queryResult->begin(); i != queryResult->end(); ++i) {
454 std::cout <<
" - " << o <<
" was born " << *d << std::endl;
462 std::cout <<
"[QUERY]: Done database querying with relationship expression...\n";
465 std::cout <<
"\n[OKS TUTORIAL]: Done with database querying tests\n\n";
471 }
catch (
const std::exception& ex) {
472 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
OksAttribute(const std::string &name, OksClass *p=nullptr)
OKS attribute simple constructor.
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
OksClass(const std::string &name, OksKernel *kernel, bool transient=false)
Create OKS class.
OksObject::List * execute_query(OksQuery *query) const
Execute query.
OksComparator(const OksAttribute *a, OksData *v, OksQuery::Comparator f)
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.
OksObject(const OksClass *oks_class, const char *object_id=0, bool skip_init=false)
OKS object constructor.
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 *)
OksRelationshipExpression(const OksRelationship *r, OksQueryExpression *q, bool b=false)
OksRelationship(const std::string &name, OksClass *p=nullptr)
OKS relationship simple constructor.
int main(int argc, char *argv[])
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)
void setDepartmentValues(OksObject *o, const char *name)
void printPerson(const OksObject *o)
void printDepartment(const OksObject *o)
union dunedaq::oks::OksData::Data data