~mapopa/flamerobin/master

« back to all changes in this revision

Viewing changes to src/metadata/server.cpp

  • Committer: Michael Hieke
  • Date: 2004-11-22 11:34:42 UTC
  • Revision ID: git-v1:8153b493d66ee7aae55e7b34e0d7bddacf4999ef
Initial revision

svn path=/trunk/flamerobin/; revision=13

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  The contents of this file are subject to the Initial Developer's Public
 
3
  License Version 1.0 (the "License"); you may not use this file except in
 
4
  compliance with the License. You may obtain a copy of the License here:
 
5
  http://www.flamerobin.org/license.html.
 
6
 
 
7
  Software distributed under the License is distributed on an "AS IS"
 
8
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 
9
  License for the specific language governing rights and limitations under
 
10
  the License.
 
11
 
 
12
  The Original Code is FlameRobin (TM).
 
13
 
 
14
  The Initial Developer of the Original Code is Milan Babuskov.
 
15
 
 
16
  Portions created by the original developer
 
17
  are Copyright (C) 2004 Milan Babuskov.
 
18
 
 
19
  All Rights Reserved.
 
20
 
 
21
  Contributor(s):
 
22
*/
 
23
 
 
24
// For compilers that support precompilation, includes "wx/wx.h".
 
25
#include "wx/wxprec.h"
 
26
 
 
27
#ifdef __BORLANDC__
 
28
    #pragma hdrstop
 
29
#endif
 
30
 
 
31
// for all others, include the necessary headers (this file is usually all you
 
32
// need because it includes almost all "standard" wxWindows headers
 
33
#ifndef WX_PRECOMP
 
34
    #include "wx/wx.h"
 
35
#endif
 
36
 
 
37
#include "server.h"
 
38
//------------------------------------------------------------------------------
 
39
YServer::YServer()
 
40
{
 
41
        typeM = ntServer;
 
42
 
 
43
        hostnameM = "";
 
44
        portM = "3050";
 
45
 
 
46
        databasesM.setParent(this);
 
47
        databasesM.setType(ntServer);
 
48
}
 
49
//------------------------------------------------------------------------------
 
50
bool YServer::getChildren(std::vector<YxMetadataItem *>& temp)
 
51
{
 
52
        return databasesM.getChildren(temp);
 
53
}
 
54
//------------------------------------------------------------------------------
 
55
// returns pointer to object in vector
 
56
YDatabase* YServer::addDatabase(YDatabase& db)
 
57
{
 
58
        YDatabase *temp = databasesM.add(db);
 
59
        temp->setParent(this);                                  // grab it from collection
 
60
        notify();
 
61
        return temp;
 
62
}
 
63
//------------------------------------------------------------------------------
 
64
void YServer::removeDatabase(YDatabase *db)
 
65
{
 
66
        databasesM.remove(db);
 
67
        notify();
 
68
}
 
69
//------------------------------------------------------------------------------
 
70
void YServer::createDatabase(YDatabase *db, std::string extra_params, int dialect)
 
71
{
 
72
        IBPP::Database db1;
 
73
        db1 = IBPP::DatabaseFactory( hostnameM, db->getPath(), db->getUsername(), db->getPassword(),
 
74
                "", db->getCharset(), extra_params);
 
75
        db1->Create(dialect);
 
76
}
 
77
//------------------------------------------------------------------------------
 
78
const YMetadataCollection<YDatabase> *YServer::getDatabases() const
 
79
{
 
80
        return &databasesM;
 
81
};
 
82
//------------------------------------------------------------------------------
 
83
void YServer::createName()              // creates name for the node using hostname and port values
 
84
{
 
85
        nameM = hostnameM;
 
86
        if (portM != "3050")
 
87
                nameM += "/" + portM;
 
88
        databasesM.setName(nameM);
 
89
        notify();
 
90
}
 
91
//------------------------------------------------------------------------------
 
92
std::string YServer::getHostname() const
 
93
{
 
94
        return hostnameM;
 
95
}
 
96
//------------------------------------------------------------------------------
 
97
std::string YServer::getPort() const
 
98
{
 
99
        return portM;
 
100
}
 
101
//------------------------------------------------------------------------------
 
102
bool YServer::hasConnectedDatabase() const
 
103
{
 
104
        for (YMetadataCollection<YDatabase>::const_iterator it = databasesM.begin(); 
 
105
                it != databasesM.end(); ++it)
 
106
        {
 
107
                if ((*it).isConnected())
 
108
                        return true;
 
109
        }
 
110
        return false;
 
111
}
 
112
//------------------------------------------------------------------------------
 
113
void YServer::setHostname(std::string hostname)
 
114
{
 
115
        hostnameM = hostname;
 
116
        createName();
 
117
}
 
118
//------------------------------------------------------------------------------
 
119
void YServer::setPort(std::string port)
 
120
{
 
121
        portM = port;
 
122
        createName();
 
123
}
 
124
//------------------------------------------------------------------------------
 
125
const std::string YServer::getTypeName() const
 
126
{
 
127
        return "SERVER";
 
128
}
 
129
//------------------------------------------------------------------------------
 
130