database_test_object.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2009, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the Willow Garage nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 
00035 // Author(s): Matei Ciocarlie
00036 
00037 #ifndef _DATABASE_TEST_OBJECT_H_
00038 #define _DATABASE_TEST_OBJECT_H_
00039 
00040 #include "database_interface/db_class.h"
00041 
00042 namespace database_interface {
00043 
00045 
00048 class DatabaseTestObject : public DBClass
00049 {
00050  public:
00051   //primary key, an integer
00052   DBField<int> pk_field_;
00053   //fields testing various conversions
00054   DBField<double> double_field_;
00055   DBField<std::string> string_field_;
00056   DBField< std::vector<std::string> > tags_field_;
00057   //binary field
00058   DBField< std::vector<char> > binary_field_;
00059   //field from a different table
00060   DBField<int> foreign_field_;
00061 
00063 
00070   void initFields()
00071   {
00072     //set the primary key
00073     primary_key_field_ = &pk_field_;
00074     //and the rest of the fields
00075     fields_.push_back(&double_field_);
00076     fields_.push_back(&string_field_);
00077     fields_.push_back(&tags_field_);
00078     fields_.push_back(&binary_field_);
00079     fields_.push_back(&foreign_field_);
00080 
00081     //foreign keys
00082     foreign_keys_.insert( std::pair<std::string, DBFieldBase*>("test_object_foreign", &pk_field_) );
00083     
00084     //sequences
00085     pk_field_.setSequenceName("pk_field_sequence");
00086   }
00087 
00089 
00094   void initPermissions()
00095   {
00096     setAllFieldsReadFromDatabase(true);
00097     setAllFieldsWriteToDatabase(true);
00098     //the fields that are usually used:
00099     //primary key id_ only syncs from database; it has a sequence which is used by default on insertions
00100     pk_field_.setWriteToDatabase(false);
00101     //binary field does not sync by default
00102     binary_field_.setReadFromDatabase(false);
00103     binary_field_.setWriteToDatabase(false);
00104   }
00105 
00107 
00110  DatabaseTestObject()  : 
00111     pk_field_(DBFieldBase::TEXT, this, "pk_field", "test_object", true),
00112     double_field_(DBFieldBase::TEXT, this, "double_field", "test_object", true),
00113     string_field_(DBFieldBase::TEXT, this, "string_field", "test_object", true),
00114     tags_field_(DBFieldBase::TEXT, this, "tags_field", "test_object", true),
00115     binary_field_(DBFieldBase::BINARY, this, "binary_field", "test_object", true),
00116     foreign_field_(DBFieldBase::TEXT, this, "foreign_field", "test_object_foreign", true)
00117 
00118   {
00119     initFields();
00120     initPermissions();
00121   }
00122 
00124 
00127  DatabaseTestObject(const DatabaseTestObject *other) : 
00128     pk_field_(this, &other->pk_field_),
00129     double_field_(this, &other->double_field_),
00130     string_field_(this, &other->string_field_),
00131     tags_field_(this, &other->tags_field_),
00132     binary_field_(this, &other->binary_field_),
00133     foreign_field_(this, &other->foreign_field_)
00134       {
00135         initFields();
00136         //no need to call initPermissions() since field permissions are copied over from other
00137       }
00138 
00139 
00140 };
00141 
00142 } //namespace
00143 
00144 #endif


sql_database
Author(s): Matei Ciocarlie and Lorenz Mosenlechner
autogenerated on Fri Aug 28 2015 13:11:16