database_test_object.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2009, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 // Author(s): Matei Ciocarlie
36 
37 #ifndef _DATABASE_TEST_OBJECT_H_
38 #define _DATABASE_TEST_OBJECT_H_
39 
41 
42 namespace database_interface {
43 
45 
49 {
50  public:
51  //primary key, an integer
53  //fields testing various conversions
57  //binary field
59  //field from a different table
61 
63 
70  void initFields()
71  {
72  //set the primary key
74  //and the rest of the fields
75  fields_.push_back(&double_field_);
76  fields_.push_back(&string_field_);
77  fields_.push_back(&tags_field_);
78  fields_.push_back(&binary_field_);
79  fields_.push_back(&foreign_field_);
80 
81  //foreign keys
82  foreign_keys_.insert( std::pair<std::string, DBFieldBase*>("test_object_foreign", &pk_field_) );
83 
84  //sequences
85  pk_field_.setSequenceName("pk_field_sequence");
86  }
87 
89 
95  {
98  //the fields that are usually used:
99  //primary key id_ only syncs from database; it has a sequence which is used by default on insertions
101  //binary field does not sync by default
104  }
105 
107 
111  pk_field_(DBFieldBase::TEXT, this, "pk_field", "test_object", true),
112  double_field_(DBFieldBase::TEXT, this, "double_field", "test_object", true),
113  string_field_(DBFieldBase::TEXT, this, "string_field", "test_object", true),
114  tags_field_(DBFieldBase::TEXT, this, "tags_field", "test_object", true),
115  binary_field_(DBFieldBase::BINARY, this, "binary_field", "test_object", true),
116  foreign_field_(DBFieldBase::TEXT, this, "foreign_field", "test_object_foreign", true)
117 
118  {
119  initFields();
120  initPermissions();
121  }
122 
124 
128  pk_field_(this, &other->pk_field_),
129  double_field_(this, &other->double_field_),
130  string_field_(this, &other->string_field_),
131  tags_field_(this, &other->tags_field_),
132  binary_field_(this, &other->binary_field_),
133  foreign_field_(this, &other->foreign_field_)
134  {
135  initFields();
136  //no need to call initPermissions() since field permissions are copied over from other
137  }
138 
139 
140 };
141 
142 } //namespace
143 
144 #endif
void setWriteToDatabase(bool sync)
Definition: db_field.h:139
DatabaseTestObject()
Constructs the fields, then calls initFields() followed by initPermissions()
std::map< std::string, DBFieldBase * > foreign_keys_
List of foreign keys in OTHER tables that reference our PRIMARY KEY.
Definition: db_class.h:83
void setReadFromDatabase(bool sync)
Definition: db_field.h:136
Specialized version for std::string data type, trivial conversion to/from string. ...
Definition: db_field.h:424
The base class for a field of a class stored in the database, corresponding to a column in a table...
Definition: db_field.h:72
The base class for all C++ classes that can be stored in the database.
Definition: db_class.h:64
The C++ version of an object stored in a database.
DatabaseTestObject(const DatabaseTestObject *other)
Copy-constructs the fields based on the copied instance fields, then calls initFields() ...
void setAllFieldsReadFromDatabase(bool sync)
Definition: db_class.h:125
void initPermissions()
Initializes permissions for the fields.
void setAllFieldsWriteToDatabase(bool sync)
Definition: db_class.h:134
void setSequenceName(std::string seq)
Definition: db_field.h:153
std::vector< DBFieldBase * > fields_
The addresses of all the other fields.
Definition: db_class.h:79
void initFields()
Places all the fields in the fields_ vector and sets foreign keys and sequences.
DBField< std::vector< std::string > > tags_field_
DBField< std::vector< char > > binary_field_
DBFieldBase * primary_key_field_
The address of the field that acts as a primary key.
Definition: db_class.h:76


database_interface
Author(s): Matei Ciocarlie and Lorenz Mosenlechner
autogenerated on Mon Mar 2 2015 01:31:34