20 #include <basic/database/sql_utils.hh>
21 #include <basic/options/option.hh>
22 #include <basic/options/keys/inout.OptionKeys.gen.hh>
23 #include <basic/resource_manager/ResourceManager.hh>
24 #include <basic/resource_manager/util.hh>
29 #include <utility/exit.hh>
30 #include <utility/sql_database/DatabaseSessionManager.hh>
31 #include <utility/tag/Tag.hh>
37 #include <utility/vector0.hh>
38 #include <utility/vector1.hh>
43 namespace task_operations {
45 using basic::database::get_db_session;
46 using basic::database::check_statement_sanity;
47 using basic::database::safely_prepare_statement;
48 using basic::database::safely_read_from_database;
55 using cppdb::statement;
59 using std::stringstream;
60 using utility::sql_database::sessionOP;
65 database_table_(
"resfiles"),
70 utility::sql_database::sessionOP db_session,
71 string const & database_table) :
73 database_table_(database_table),
74 db_session_(db_session)
79 database_table_(src.database_table_),
80 db_session_(src.db_session_)
98 stringstream sql_stmt;
101 <<
" WHERE tag='" << tag <<
"';";
102 string sql(sql_stmt.str());
103 check_statement_sanity(sql);
104 statement select_stmt(safely_prepare_statement(sql,
db_session_));
105 result res(safely_read_from_database(select_stmt));
109 <<
"Unable to locate resfile for job distributor input tag '"
110 << tag <<
"' in the database." << endl;
111 throw utility::excn::EXCN_Msg_Exception(error_message.str());
120 <<
"Failed to process resfile stored for input tag '" << tag <<
"'" << endl
121 <<
"RESFILE:" << endl
123 throw utility::excn::EXCN_Msg_Exception(error_message.str());
129 utility::sql_database::sessionOP db_session
147 using namespace basic::resource_manager;
149 if(tag->hasOption(
"db")){
150 utility_exit_with_message(
151 "The 'db' tag has been deprecated. Please use 'database_name' instead.");
154 if(tag->hasOption(
"db_mode")){
155 utility_exit_with_message(
156 "The 'db_mode' tag has been deprecated. "
157 "Please use the 'database_mode' instead.");
160 if(tag->hasOption(
"database_table")){
162 }
else if(tag->hasOption(
"table")){
166 if(tag->hasOption(
"resource_description")){
167 std::string resource_description = tag->getOption<
string>(
"resource_description");
168 if(!ResourceManager::get_instance()->has_resource_with_description(
169 resource_description))
171 throw utility::excn::EXCN_Msg_Exception
172 (
"You specified a resource_description of " + resource_description +
173 " for ReadResfileFromDB, but the ResourceManager doesn't have a resource with that description" );
175 db_session_ = get_resource< utility::sql_database::session >( resource_description );
178 db_session_ = basic::database::parse_database_connection(tag);