Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Index.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 basic/database/schema_generator/Index.cc
11 ///
12 /// @brief Index class for the schema generator framework
13 /// @author Matthew O'Meara (mattjomeara@gmail.com)
14 
18 
19 // Basic Headers
20 #include <basic/Tracer.hh>
21 #include <platform/types.hh>
22 
23 // Utility Headers
24 #include <utility/exit.hh>
26 
27 //C++ Headers
28 #include <string>
29 #include <sstream>
30 
31 static THREAD_LOCAL basic::Tracer TR( "utility.sql_database.Index" );
32 
33 namespace basic {
34 namespace database {
35 namespace schema_generator {
36 
37 using platform::Size;
38 using std::string;
39 using std::stringstream;
40 using utility::vector1;
41 
43  Column column,
44  bool unique
45 ) :
46  unique_(unique),
47  columns_()
48 {
49  columns_.push_back(column);
50 }
51 
53  Columns columns,
54  bool unique
55 ) :
56  unique_(unique),
57  columns_(columns)
58 {}
59 
61  Index const & src
62 ) :
63  unique_(src.unique_),
64  columns_(src.columns_)
65 {}
66 
67 Columns
69  return this->columns_;
70 }
71 
72 string
74  string const & table_name,
76 ) const {
77  stringstream s;
78 
79  switch(db_session->get_db_mode()) {
81  break;
83  break;
85  s << "CREATE ";
86  if ( unique_ ) {
87  s << "UNIQUE ";
88  }
89  s << "INDEX IF NOT EXISTS\n\t";
90  s << table_name;
91  for ( Size i=1; i <= columns_.size(); ++i ) {
92  s << "_" << columns_[i].name();
93  }
94  s << " ON\n\t";
95  s << " " << table_name << " ( ";
96  for ( Size i=1; i <= columns_.size(); ++i ) {
97  if ( i != 1 ) {
98  s << ", ";
99  }
100  s << columns_[i].name();
101  }
102  s << " );\n";
103 
104  break;
105  }
106  default :
108  "Unrecognized database mode: '" + name_from_database_mode(db_session->get_db_mode()) + "'");
109  return ""; // just here to remove warning; lame ~Labonte
110  }
111 
112  return s.str();
113 }
114 
115 
116 } // schema_generator
117 } // namespace database
118 } // namespace utility
#define utility_exit_with_message(m)
Exit with file + line + message.
Definition: exit.hh:47
#define THREAD_LOCAL
std::string print(std::string const &table_name, utility::sql_database::sessionOP db_session) const
Definition: Index.cc:73
std::string name_from_database_mode(DatabaseMode::e database_mode)
Definition: types.cc:83
Index class for the schema generator framework.
static THREAD_LOCAL basic::Tracer TR("utility.sql_database.Index")
tuple database
Program exit functions and macros.
Tracer IO system.
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
std::string & unique(std::string &s)
Remove Repeat Characters from a Possibly Unsorted string Preserving Order.
Column class for the schema generator framework.
Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for ...
Definition: Tracer.hh:134
std::size_t Size
Definition: types.hh:37
platform::Size Size
Definition: random.fwd.hh:30
pointer::shared_ptr< session > sessionOP
Index(Column column, bool unique=true)
Definition: Index.cc:42