Menu

[r71]: / cms / trunk / data.cpp  Maximize  Restore  History

Download this file

132 lines (117 with data), 2.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "data.h"
#include <cppcms/global_config.h>
using namespace std;
auto_ptr<Options> options;
auto_ptr<Comments> comments;
auto_ptr<Approved> approved;
auto_ptr<Posts> posts;
auto_ptr<Users> users;
auto_ptr<Texts_Collector> texts;
auto_ptr<Environment> env;
void db_initall()
{
env=auto_ptr<Environment>(new Environment(global_config.sval( "bdb.path" ).c_str()));
options=auto_ptr<Options>(new Options(*env));
comments=auto_ptr<Comments>(new Comments(*env));
approved=auto_ptr<Approved>(new Approved(*env));
posts=auto_ptr<Posts>(new Posts(*env));
users=auto_ptr<Users>(new Users(*env));
texts=auto_ptr<Texts_Collector>(new Texts_Collector(*env,"texts.db"));
}
void db_openall()
{
env->open();
options->open();
comments->open();
approved->open();
posts->open();
users->open();
texts->open();
}
void db_createall()
{
env->create();
options->create();
comments->create();
approved->create();
posts->create();
users->create();
texts->create();
}
void db_closeall()
{
options->close();
comments->close();
approved->close();
posts->close();
users->close();
texts->close();
env->close();
}
static void db_base_setup()
{
string username,password;
cout<<"Blog owner username:";
cin>>username;
cout<<"Blog owner password:";
cin>>password;
user_t u;
u.username=username.c_str();
u.password=password.c_str();
users->id.add(u);
option_t op;
op.id=BLOG_TITLE;
op.value="CppBlog";
options->insert(op);
op.id=BLOG_DESCRIPTION;
op.value="Yet another CppBlog";
options->insert(op);
post_t post;
post.author_id=u.id;
post.is_open=true;
post.publish=time(NULL);
post.abstract_id=texts->add("This is first article in the blog.");
post.content_id=texts->add(
"This is only sample article, you can "
"edit it, remove it and do anything you with.");
post.title="Hello World!";
posts->id.add(post);
comment_t comment;
comment.author_id=u.id;
comment.moderated=true;
comment.post_id=post.id;
comment.publish_time=time(NULL);
comment.content_id=texts->add("This is sample comment in the blog.");
comments->id.add(comment);
}
int db_configure()
{
try {
db_initall();
db_createall();
db_base_setup();
db_closeall();
return 0;
}
catch(DbException &e){
cerr<<e.what();
return 1;
}
catch(std::exception &e){
cerr<<e.what();
return 1;
}
}
#ifdef CONFIG_ONLY
int main(int argc, char **argv)
{
try {
global_config.load(argc,argv);
return db_configure();
}
catch(HTTP_Error &e) {
cerr<<e.get();
return 1;
}
}
#endif
MongoDB Logo MongoDB