1 /*
2 Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #ifndef NdbSchemaCon_H
26 #define NdbSchemaCon_H
27
28 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
29
30 #include <ndb_types.h>
31 #include "NdbError.hpp"
32 #include <NdbSchemaOp.hpp>
33
34 class NdbSchemaOp;
35 class Ndb;
36 class NdbApiSignal;
37
38 /**
39 * @class NdbSchemaCon
40 * @brief Represents a schema transaction.
41 *
42 * When creating a new table,
43 * the first step is to get a NdbSchemaCon object to represent
44 * the schema transaction.
45 * This is done by calling Ndb::startSchemaTransaction.
46 *
47 * The next step is to get a NdbSchemaOp object by calling
48 * NdbSchemaCon::getNdbSchemaOp.
49 * The NdbSchemaOp object then has methods to define the table and
50 * its attributes.
51 *
52 * Finally, the NdbSchemaCon::execute method inserts the table
53 * into the database.
54 *
55 * @note Currently only one table can be added per transaction.
56 * @note Deprecated, use NdbDictionary
57 */
58 class NdbSchemaCon
59 {
60 friend class Ndb;
61 friend class NdbSchemaOp;
62
63 public:
64
65 static
startSchemaTrans(Ndb * pNdb)66 NdbSchemaCon* startSchemaTrans(Ndb* pNdb){
67 return new NdbSchemaCon(pNdb);
68 }
69
70 static
closeSchemaTrans(NdbSchemaCon * pSchCon)71 void closeSchemaTrans(NdbSchemaCon* pSchCon){
72 delete pSchCon;
73 }
74
75
76 /**
77 * Execute a schema transaction.
78 *
79 * @return 0 if successful otherwise -1.
80 */
81 int execute();
82
83 /**
84 * Get a schemaoperation.
85 *
86 * @note Currently, only one operation per transaction is allowed.
87 *
88 * @return Pointer to a NdbSchemaOp or NULL if unsuccessful.
89 */
90 NdbSchemaOp* getNdbSchemaOp();
91
92 /**
93 * Get the latest error
94 *
95 * @return Error object.
96 */
97 const NdbError & getNdbError() const;
98
99 private:
100
101 /******************************************************************************
102 * These are the create and delete methods of this class.
103 *****************************************************************************/
104
105 NdbSchemaCon(Ndb* aNdb);
106 ~NdbSchemaCon();
107
108 /******************************************************************************
109 * These are the private methods of this class.
110 *****************************************************************************/
111
112 void release(); // Release all schemaop in schemaCon
113
114 /***************************************************************************
115 * These methods are service methods to other classes in the NDBAPI.
116 ***************************************************************************/
117
118 int checkMagicNumber(); // Verify correct object
119 int receiveDICTTABCONF(NdbApiSignal* aSignal);
120 int receiveDICTTABREF(NdbApiSignal* aSignal);
121
122
123 int receiveCREATE_INDX_CONF(NdbApiSignal*);
124 int receiveCREATE_INDX_REF(NdbApiSignal*);
125 int receiveDROP_INDX_CONF(NdbApiSignal*);
126 int receiveDROP_INDX_REF(NdbApiSignal*);
127
128
129 /*****************************************************************************
130 * These are the private variables of this class.
131 *****************************************************************************/
132
133
134 NdbError theError; // Errorcode
135 Ndb* theNdb; // Pointer to Ndb object
136
137 NdbSchemaOp* theFirstSchemaOpInList; // First operation in operation list.
138 int theMagicNumber; // Magic number
139 };
140
141 inline
142 int
checkMagicNumber()143 NdbSchemaCon::checkMagicNumber()
144 {
145 if (theMagicNumber != 0x75318642)
146 return -1;
147 return 0;
148 }//NdbSchemaCon::checkMagicNumber()
149
150
151
152 #endif
153 #endif
154
155
156