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.EntityFieldInfo;
13 
14 import hunt.entity;
15 import std.format;
16 import std.variant;
17 
18 abstract class EntityFieldInfo : EntityExpression
19 {
20     protected string _joinColumn;
21     protected string _inverseJoinColumn;
22     protected string _joinTable;
23     protected string _joinPrimaryKey;
24     protected ForeignKeyData _foreignKeyData;
25     protected JoinSqlBuild _joinSqlData;
26     // protected ColumnFieldData _columnFieldData;
27     protected Variant _columnFieldData;
28     protected bool _isMainMapped;
29     protected bool _enableJoin = true;
30     protected TypeInfo _typeInfo;
31 
32     private string _fieldName;
33     private bool _nullable = true;
34     private bool _primary;
35     private bool _auto;
36 
37     this(string fieldName, string columnName, string tableName) {
38         super(columnName, tableName);
39         _fieldName = fieldName;
40     }
41 
42     TypeInfo typeInfo() {
43         return _typeInfo;
44     }
45 
46     void setNullable(bool b) {_nullable = b;}
47     bool getNullable() {return _nullable;}
48 
49     void setPrimary(bool b) {_primary = b;}
50     bool getPrimary() {return _primary;}
51 
52     void setAuto(bool b) {_auto = b;}
53     bool getAuto() {return _auto;}
54 
55     bool isMainMapped() {return _isMainMapped;}
56 
57     // deprecated("Using getFieldName instead.")
58     // string getFileldName() {return _fieldName;}
59 
60     string getFieldName() {return _fieldName;}
61     string getJoinColumn() {return _joinColumn;}
62     string getInverseJoinColumn() {return _inverseJoinColumn;}
63     string getJoinTable() {return _joinTable;}
64     string getJoinPrimaryKey() {return _joinPrimaryKey;}
65     ForeignKeyData getForeignKeyData() {return _foreignKeyData;}
66 
67     JoinSqlBuild getJoinSqlData() {return _joinSqlData;}
68 
69     bool isEnableJoin() {return _enableJoin;}
70     void setEnableJoin(bool en) { _enableJoin = en;}
71 
72     Variant getColumnFieldData() {return _columnFieldData;}
73 
74     abstract bool isAggregateType();
75 
76     override string toString() {
77         return format("isPrimary: %s, TableName:%s, FileldName: %s, ColumnName: %s, JoinTable: %s, JoinColumn: %s, ", 
78             _primary, getTableName(), _fieldName, getColumnName(), _joinTable, _joinColumn);
79     }
80 
81 }