1 /*
2  * Entity - Entity is an object-relational mapping tool for the D programming language. Referring to the design idea of JPA.
3  *
4  * Copyright (C) 2015-2018  Shanghai Putao Technology Co., Ltd
5  *
6  * Developer: HuntLabs.cn
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11  
12 module hunt.entity.Constant;
13 
14 import hunt.String;
15 // import hunt.database;
16 import std.format;
17 
18 
19 struct Factory
20 {
21     string name;
22 }
23 
24 struct Table {
25     string name;
26     
27     string prefix;
28 }
29 
30 struct Column {
31     string name;
32     bool nullable = true;
33 }
34 
35 struct JoinColumn {
36     string name;
37     string referencedColumnName;
38     bool nullable = true;
39 }
40 
41 struct JoinTable {
42     string name;
43 }
44 
45 // alias InverseJoinColumn = JoinColumn;
46 struct InverseJoinColumn {
47     string name;
48     string referencedColumnName;
49     bool nullable = true;
50 }
51 
52 
53 struct OneToOne {
54     string mappedBy;
55     FetchType fetch = FetchType.EAGER;
56     CascadeType cascade = CascadeType.ALL;
57 }
58 
59 
60 struct ManyToMany {
61     string mappedBy;
62     FetchType fetch = FetchType.LAZY;
63     CascadeType cascade = CascadeType.ALL;
64 }
65 
66 
67 struct OneToMany {
68     string mappedBy;
69     FetchType fetch = FetchType.LAZY;
70     CascadeType cascade = CascadeType.ALL;
71 } 
72 
73 
74 struct ManyToOne {
75     FetchType fetch = FetchType.EAGER;
76     CascadeType cascade = CascadeType.ALL;
77 } 
78 
79 enum {
80     Auto = 0x1,
81     AutoIncrement = 0x1,
82     Id = 0x2,
83     Transient = 0x3
84 }
85 
86 // deprecated("Using Id instead.")
87 alias PrimaryKey = Id;
88 
89 enum OrderBy {
90     ASC = 0,
91     DESC = 1,
92 }
93 enum JoinType {
94     INNER = 0,
95     LEFT = 1,
96     RIGHT = 2,
97 }
98 enum FetchType {
99     LAZY,
100     EAGER
101 }
102 
103 enum CascadeType {
104     PERSIST, 
105     REMOVE,  
106     REFRESH, 
107     MERGE,  
108     ALL,      
109 }
110 
111 
112 class JoinSqlBuild  {
113     string tableName;
114     string joinWhere;
115     JoinType joinType;
116     string[] columnNames;
117 
118     override string toString()
119     {
120         return "(%s, %s, %s, %s)".format(tableName,joinWhere,joinType,columnNames);
121     }
122 }
123 
124 class ForeignKeyData {
125     string columnName;
126     string tableName;
127     string primaryKey;
128 }
129 
130 
131 class LazyData {
132     this(LazyData data) {
133         key = data.key;
134         value = data.value;
135     }
136     this(string key, string value) {
137         this.key = key;
138         this.value = value;
139     }
140     string key;
141     string value;
142 
143     override string toString()
144     {
145         return "(%s, %s)".format(key,value);
146     }
147 }
148 
149 
150