Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BatchFeatures.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet;
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file protocols/features/BatchFeatures.cc
11 ///
12 /// @brief
13 /// @author Tim Jacobs
14 
15 // Unit Headers
17 
18 // Project Headers
19 #include <basic/options/keys/parser.OptionKeys.gen.hh>
20 #include <basic/options/option.hh>
21 #include <basic/options/keys/inout.OptionKeys.gen.hh>
22 #include <basic/options/keys/out.OptionKeys.gen.hh>
23 #include <basic/database/sql_utils.hh>
24 #include <core/types.hh>
25 #include <core/svn_version.hh>
26 #include <basic/database/schema_generator/PrimaryKey.hh>
27 #include <basic/database/schema_generator/ForeignKey.hh>
28 #include <basic/database/schema_generator/Column.hh>
29 #include <basic/database/schema_generator/Schema.hh>
30 
31 // Utility Headers
32 #include <utility/sql_database/DatabaseSessionManager.hh>
33 #include <utility/vector1.hh>
34 
35 //Basic Headers
36 #include <basic/Tracer.hh>
37 
38 // External Headers
39 #include <cppdb/frontend.h>
40 
41 // C++ Headers
42 #include <string>
43 #include <sstream>
44 
45 
46 namespace protocols{
47 namespace features{
48 
49 static basic::Tracer TR("protocols.features.BatchFeatures");
50 
51 using std::string;
52 using std::stringstream;
53 using basic::options::OptionKeys::parser::protocol;
54 using basic::options::option;
55 using core::Size;
56 using utility::vector1;
57 using utility::sql_database::sessionOP;
58 using cppdb::statement;
59 using cppdb::result;
60 
62 
65 {}
66 
68 
69 string
70 BatchFeatures::type_name() const { return "BatchFeatures"; }
71 
72 void
73 BatchFeatures::write_schema_to_db(utility::sql_database::sessionOP db_session) const{
74 
75  using namespace basic::database::schema_generator;
76 
77  PrimaryKey batch_id(
78  Column("batch_id", new DbInteger(), false /*not null*/, false /*autoincrement*/));
79 
80  ForeignKey protocol_id(
81  Column("protocol_id", new DbInteger()),
82  "protocols",
83  "protocol_id",
84  true /*defer*/);
85 
86  Column name(Column("name", new DbText()));
87  Column description(Column("description", new DbText()));
88 
89  Schema batches("batches", batch_id);
90  batches.add_foreign_key(protocol_id);
91  batches.add_column(name);
92  batches.add_column(description);
93 
94  batches.write(db_session);
95 }
96 
99  utility::vector1<std::string> dependencies;
100  return dependencies;
101 }
102 
103 
104 
105 string
107  return "";
108 }
109 
110 Size
112  Size batch_id,
113  Size protocol_id,
114  std::string name,
115  std::string description,
116  sessionOP db_session
117 ){
118  TR.Debug
119  << "Writing to batches table with:" << std::endl
120  << "\tbatch_id '" << batch_id << "'" << std::endl
121  << "\tprotocol_id '" << protocol_id << "'" << std::endl
122  << "\tname '" << name << "'" << std::endl
123  << "\tdescription '" << description << "'" << std::endl;
124 
125 
126  //INSERT OR IGNORE probably isnt the best way of dealing with this but i was getting a stupid race condition with MPI before
127  //better designs encouraged.
128  std::string insert_string;
129  switch(db_session->get_db_mode())
130  {
131  case utility::sql_database::DatabaseMode::sqlite3:
132  insert_string = "INSERT OR IGNORE INTO batches (batch_id, protocol_id, name, description) VALUES (?,?,?,?);";
133  break;
134  case utility::sql_database::DatabaseMode::mysql:
135  case utility::sql_database::DatabaseMode::postgres:
136  insert_string = "INSERT IGNORE INTO batches (batch_id, protocol_id, name, description) VALUES (?,?,?,?);";
137  break;
138  default:
139  utility_exit_with_message(
140  "Unrecognized database mode: '" +
141  name_from_database_mode(db_session->get_db_mode()) + "'");
142  break;
143  }
144  cppdb::statement insert_statement = basic::database::safely_prepare_statement(insert_string,db_session);
145  insert_statement.bind(1,batch_id);
146  insert_statement.bind(2,protocol_id);
147  insert_statement.bind(3,name);
148  insert_statement.bind(4,description);
149 
150  basic::database::safely_write_to_database(insert_statement);
151 
152  return 0;
153 }
154 
155 } // features namesapce
156 } // protocols namespace