HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_ORMOperation.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_ORMOperation.h
7  *
8  * COMMENTS:
9  *
10  *
11  */
12 
13 #ifndef __UT_ORMOPERATION_H__
14 #define __UT_ORMOPERATION_H__
15 
16 #include "UT_API.h"
17 
18 #include "UT_Array.h"
19 #include "UT_ErrorCode.h"
20 #include "UT_ORMColumn.h"
21 #include "UT_StringHolder.h"
22 #include "UT_UniquePtr.h"
23 
24 class UT_SqlStatement;
25 class UT_WorkBuffer;
26 class UT_JSONValue;
28 
30 {
31 public:
32  virtual ~UT_IORMOperation() = default;
33  UT_IORMOperation(const UT_IORMOperation&) = default;
34  UT_IORMOperation& operator=(const UT_IORMOperation&) = default;
35 
36  virtual const UT_StringHolder& name() const = 0;
37  virtual void sql(const UT_SqlStatement& stmt, UT_WorkBuffer& wbuf) = 0;
38  virtual void upgrade(UT_SqlStatement& stmt, UT_ErrorCode& ec) = 0;
39  virtual void apply(
41  UT_ErrorCode& ec)
42  = 0;
43 
44 protected:
45  UT_IORMOperation() = default;
46 
47 private:
48 };
49 
51 {
52 public:
53  UT_ORMCreateTableOperation() = default;
54  explicit UT_ORMCreateTableOperation(const UT_StringHolder& table_name)
55  : myTableName(table_name)
56  {
57  }
58 
59  const UT_StringHolder& name() const override;
60  void sql(const UT_SqlStatement& stmt, UT_WorkBuffer& wbuf) override;
61  void upgrade(UT_SqlStatement& stmt, UT_ErrorCode& ec) override;
63  override;
64 
66  {
67  myTableName = table_name;
68  return *this;
69  }
71  {
72  myFields.emplace_back(std::move(field));
73  return *this;
74  }
76  const UT_StringHolder& name,
78  const UT_StringHolder& foreign_table,
79  const UT_StringHolder& foreign_col,
80  unsigned props = UT_ORMColumn::Properties::Empty)
81  {
82  UT_ORMColumn field(name, type, props);
83  field.setAsForeignKey(foreign_table, foreign_col);
84  exint i = myFields.emplace_back(std::move(field));
85  return myFields[i];
86  }
88  const UT_StringHolder& name,
90  UT_ORMColumn::Properties props = UT_ORMColumn::Properties::Empty)
91  {
92  exint i = myFields.emplace_back(name, type, props);
93  return myFields[i];
94  }
96  const UT_StringHolder& name,
98  UT_ORMColumn::Properties props = UT_ORMColumn::Properties::Empty)
99  {
100  exint i = myFields.emplace_back(
101  name, type, props | UT_ORMColumn::Properties::AutoIncrement);
102  return myFields[i];
103  }
104 
105 private:
106  UT_StringHolder myTableName;
107  UT_Array<UT_ORMColumn> myFields;
108 };
109 
111 {
112 public:
113  UT_ORMDropTableOperation() = default;
114  explicit UT_ORMDropTableOperation(const UT_StringHolder& table_name)
115  : myTableName(table_name)
116  {
117  }
118 
119  const UT_StringHolder& name() const override;
120  void sql(const UT_SqlStatement& stmt, UT_WorkBuffer& wbuf) override;
121  void upgrade(UT_SqlStatement& stmt, UT_ErrorCode& ec) override;
123  override;
124 
125 private:
126  UT_StringHolder myTableName;
127 };
128 
130 {
131 public:
132  UT_ORMAddFieldOperation() = default;
134  const UT_StringHolder& table_name,
135  UT_ORMColumn&& field)
136  : myTableName(table_name), myField(std::move(field))
137  {
138  }
139 
140  const UT_StringHolder& name() const override;
141  void sql(const UT_SqlStatement& stmt, UT_WorkBuffer& wbuf) override;
142  void upgrade(UT_SqlStatement& stmt, UT_ErrorCode& ec) override;
144  override;
145 
146 private:
147  UT_StringHolder myTableName;
148  UT_ORMColumn myField;
149 };
150 
152 {
153 public:
154  UT_ORMRemoveFieldOperation() = default;
156  const UT_StringHolder& table_name,
157  const UT_StringHolder& field_name)
158  : myTableName(table_name), myFieldName(field_name)
159  {
160  }
161 
162  const UT_StringHolder& name() const override;
163  void sql(const UT_SqlStatement& stmt, UT_WorkBuffer& wbuf) override;
164  void upgrade(UT_SqlStatement& stmt, UT_ErrorCode& ec) override;
166  override;
167 
168 private:
169  UT_StringHolder myTableName;
170  UT_StringHolder myFieldName;
171 };
172 
174 {
175 public:
176  UT_ORMRenameFieldOperation() = default;
178  const UT_StringHolder& table_name,
179  const UT_StringHolder& from_name,
180  const UT_StringHolder& to_name)
181  : myTableName(table_name), myFromName(from_name), myToName(to_name)
182  {
183  }
184 
185  const UT_StringHolder& name() const override;
186  void sql(const UT_SqlStatement& stmt, UT_WorkBuffer& wbuf) override;
187  void upgrade(UT_SqlStatement& stmt, UT_ErrorCode& ec) override;
189  override;
190 
191 private:
192  UT_StringHolder myTableName;
193  UT_StringHolder myFromName;
194  UT_StringHolder myToName;
195 };
196 
197 #endif // __UT_ORMOPERATION_H__
UT_ORMRemoveFieldOperation(const UT_StringHolder &table_name, const UT_StringHolder &field_name)
int64 exint
Definition: SYS_Types.h:125
#define UT_API
Definition: UT_API.h:14
UT_ORMCreateTableOperation & addField(UT_ORMColumn &&field)
virtual void upgrade(UT_SqlStatement &stmt, UT_ErrorCode &ec)=0
virtual void apply(UT_ORMMigrationChangeNotifier &notifier, UT_ErrorCode &ec)=0
virtual void sql(const UT_SqlStatement &stmt, UT_WorkBuffer &wbuf)=0
UT_ORMColumn & addForeignField(const UT_StringHolder &name, UT_ORMColumn::Type type, const UT_StringHolder &foreign_table, const UT_StringHolder &foreign_col, unsigned props=UT_ORMColumn::Properties::Empty)
UT_ORMColumn & addField(const UT_StringHolder &name, UT_ORMColumn::Type type, UT_ORMColumn::Properties props=UT_ORMColumn::Properties::Empty)
UT_ORMCreateTableOperation & setTableName(const UT_StringHolder &table_name)
UT_ORMColumn & addAutoField(const UT_StringHolder &name, UT_ORMColumn::Type type, UT_ORMColumn::Properties props=UT_ORMColumn::Properties::Empty)
GLuint const GLchar * name
Definition: glcorearb.h:786
std::error_code UT_ErrorCode
Definition: UT_ErrorCode.h:20
UT_ORMAddFieldOperation(const UT_StringHolder &table_name, UT_ORMColumn &&field)
virtual const UT_StringHolder & name() const =0
UT_ORMDropTableOperation(const UT_StringHolder &table_name)
LeafData & operator=(const LeafData &)=delete
UT_ORMCreateTableOperation(const UT_StringHolder &table_name)
UT_ORMRenameFieldOperation(const UT_StringHolder &table_name, const UT_StringHolder &from_name, const UT_StringHolder &to_name)
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
type
Definition: core.h:1059
void setAsForeignKey(const UT_StringHolder &table_name, const UT_StringHolder &col)
Definition: UT_ORMColumn.h:137
GLenum GLuint GLsizei const GLenum * props
Definition: glcorearb.h:2525