HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_ORMColumn.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_ORMColumn.h
7  *
8  * COMMENTS:
9  *
10  *
11  */
12 
13 #ifndef __UT_ORMCOLUMN_H__
14 #define __UT_ORMCOLUMN_H__
15 
16 #include "UT_API.h"
17 
18 #include "UT_StringArray.h"
19 #include "UT_StringHolder.h"
20 #include "UT_DateTimeField.h"
21 
22 class UT_SqlStatement;
23 
25 {
26 public:
27  enum class Type
28  {
29  Error,
30  Nullptr,
31  String,
32  Int32,
33  Int64,
34  Bool,
35  Real,
36  DateTime,
37  Blob
38  };
39 
41  {
42  Empty = 0,
43  PrimaryKey = 1 << 1,
44  Unique = 1 << 2,
45  NotNull = 1 << 3,
46  ForeignKey = 1 << 4,
47  AutoIncrement = 1 << 5
48  };
49 
50  enum OnDelete
51  {
52  DoNothing = 0,
54  SetNull
55  };
56 
57  UT_ORMColumn() = default;
59  const UT_StringHolder& name,
60  Type type,
61  unsigned props = Properties::Empty,
62  OnDelete on_delete = OnDelete::DoNothing)
63  : myName(name), myType(type), myProperties(props), myOnDelete(on_delete)
64  {
65  }
66 
67  bool operator==(const UT_ORMColumn& rhs) const
68  {
69  return myName == rhs.myName && myType == rhs.myType
70  && myProperties == rhs.myProperties &&
71  myOnDelete == rhs.myOnDelete;
72  }
73  bool operator!=(const UT_ORMColumn& rhs) const { return !(*this == rhs); }
74 
75  void sql(const UT_SqlStatement& stmt, UT_WorkBuffer& wbuf);
76 
77  Type type() const { return myType; }
79  {
80  myName = name;
81  return *this;
82  }
83  const UT_StringHolder& name() const { return myName; }
84  UT_ORMColumn& setNotNull(bool not_null)
85  {
86  if (not_null)
87  myProperties |= Properties::NotNull;
88  else
89  myProperties &= ~Properties::NotNull;
90  return *this;
91  }
92  bool isNotNull() const { return myProperties & Properties::NotNull; }
94  {
95  if (pk)
96  myProperties |= Properties::PrimaryKey;
97  else
98  myProperties &= ~Properties::PrimaryKey;
99  return *this;
100  }
101  bool isPrimaryKey() const
102  {
103  return (myProperties & Properties::PrimaryKey)
104  || (myProperties & Properties::Unique);
105  }
107  {
108  if (upk)
109  myProperties |= Properties::Unique;
110  else
111  myProperties &= ~Properties::Unique;
112  return *this;
113  }
114  bool isUnique() const { return myProperties & Properties::Unique; }
116  {
117  if (inc)
118  myProperties |= Properties::AutoIncrement;
119  else
120  myProperties &= ~Properties::AutoIncrement;
121  return *this;
122  }
123  bool isAutoIncrement() const
124  {
125  return myProperties & Properties::AutoIncrement;
126  }
127 
128  unsigned properties() const { return myProperties; }
129 
130  OnDelete onDelete() const { return myOnDelete; }
131  void setOnDelete(OnDelete ondelete) { myOnDelete = ondelete; }
132 
133  const UT_StringHolder& typeString(const UT_SqlStatement& cursor) const;
134  static const UT_StringHolder& typeToString(Type type);
135 
136  bool isForeignKey() const { return myProperties & Properties::ForeignKey; }
138  const UT_StringHolder& table_name,
139  const UT_StringHolder& col)
140  {
141  myProperties |= ForeignKey;
142  myForeignTable = table_name;
143  myForeignColumns.clear();
144  myForeignColumns.emplace_back(col);
145  }
147  const UT_StringHolder& table_name,
148  const UT_StringArray& cols)
149  {
150  myProperties |= ForeignKey;
151  myForeignTable = table_name;
152  myForeignColumns = cols;
153  }
154  const UT_StringHolder& foreignTable() const { return myForeignTable; }
155  const UT_StringArray& foreignColumns() const { return myForeignColumns; }
156 
157 protected:
158  unsigned myProperties = Properties::Empty;
159  OnDelete myOnDelete = OnDelete::DoNothing;
162 
165 };
166 
167 template <typename T>
170 {
172 }
173 
174 
175 template <>
176 inline UT_ORMColumn::Type
178 {
180 }
181 template <>
182 inline UT_ORMColumn::Type
184 {
186 }
187 template <>
188 inline UT_ORMColumn::Type
190 {
192 }
193 template <>
194 inline UT_ORMColumn::Type
196 {
198 }
199 
200 template<>
201 inline UT_ORMColumn::Type
203 {
205 }
206 
207 template<>
208 inline UT_ORMColumn::Type
210 {
212 }
213 
214 #endif // __UT_ORMCOLUMN_H__
UT_StringHolder myName
Definition: UT_ORMColumn.h:161
const UT_StringHolder & name() const
Definition: UT_ORMColumn.h:83
UT_ORMColumn(const UT_StringHolder &name, Type type, unsigned props=Properties::Empty, OnDelete on_delete=OnDelete::DoNothing)
Definition: UT_ORMColumn.h:58
UT_ORMColumn::Type UTsqlOrmColumnType< const char * >()
Definition: UT_ORMColumn.h:195
UT_ORMColumn & setAutoIncrement(bool inc)
Definition: UT_ORMColumn.h:115
UT_ORMColumn::Type UTsqlOrmColumnType< int >()
Definition: UT_ORMColumn.h:177
OnDelete myOnDelete
Definition: UT_ORMColumn.h:159
void setOnDelete(OnDelete ondelete)
Definition: UT_ORMColumn.h:131
const UT_StringHolder & foreignTable() const
Definition: UT_ORMColumn.h:154
SYS_FORCE_INLINE void clear()
UT_ORMColumn::Type UTsqlOrmColumnType< UT_StringHolder >()
Definition: UT_ORMColumn.h:189
UT_StringArray myForeignColumns
Definition: UT_ORMColumn.h:164
#define UT_API
Definition: UT_API.h:14
UT_ORMColumn::Type UTsqlOrmColumnType()
Definition: UT_ORMColumn.h:169
bool isUnique() const
Definition: UT_ORMColumn.h:114
UT_StringHolder myForeignTable
Definition: UT_ORMColumn.h:163
bool isForeignKey() const
Definition: UT_ORMColumn.h:136
bool isAutoIncrement() const
Definition: UT_ORMColumn.h:123
Type type() const
Definition: UT_ORMColumn.h:77
bool operator!=(const UT_ORMColumn &rhs) const
Definition: UT_ORMColumn.h:73
UT_ORMColumn & setUnique(bool upk)
Definition: UT_ORMColumn.h:106
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER typedef long long unsigned int Int64
Int64 - unsigned 64-bit integer.
Definition: ImathInt64.h:37
UT_ORMColumn & setNotNull(bool not_null)
Definition: UT_ORMColumn.h:84
UT_ORMColumn & setName(const UT_StringHolder &name)
Definition: UT_ORMColumn.h:78
GLuint const GLchar * name
Definition: glcorearb.h:786
void setAsForeignKey(const UT_StringHolder &table_name, const UT_StringArray &cols)
Definition: UT_ORMColumn.h:146
bool operator==(const UT_ORMColumn &rhs) const
Definition: UT_ORMColumn.h:67
OnDelete onDelete() const
Definition: UT_ORMColumn.h:130
bool isNotNull() const
Definition: UT_ORMColumn.h:92
const UT_StringArray & foreignColumns() const
Definition: UT_ORMColumn.h:155
Error
Definition: oidn.hpp:577
UT_ORMColumn & setPrimaryKey(bool pk)
Definition: UT_ORMColumn.h:93
UT_ORMColumn::Type UTsqlOrmColumnType< int64 >()
Definition: UT_ORMColumn.h:183
unsigned myProperties
Definition: UT_ORMColumn.h:158
UT_ORMColumn::Type UTsqlOrmColumnType< UT_DateTimeField >()
Definition: UT_ORMColumn.h:209
UT_ORMColumn::Type UTsqlOrmColumnType< bool >()
Definition: UT_ORMColumn.h:202
unsigned properties() const
Definition: UT_ORMColumn.h:128
bool isPrimaryKey() const
Definition: UT_ORMColumn.h:101
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