1 module hunt.sql.ast.SQLStructDataType; 2 3 import hunt.sql.ast.SQLObjectImpl; 4 import hunt.sql.ast.SQLObject; 5 import hunt.sql.ast.SQLDataType; 6 import hunt.sql.ast.SQLName; 7 import hunt.sql.ast.SQLExpr; 8 import hunt.sql.util.FnvHash; 9 import hunt.sql.visitor.SQLASTVisitor; 10 11 import hunt.Boolean; 12 import hunt.collection; 13 14 15 public class SQLStructDataType : SQLObjectImpl , SQLDataType { 16 private string dbType; 17 private List!Field fields; 18 19 public this() { 20 fields = new ArrayList!Field(); 21 } 22 23 public this(string dbType) { 24 this.dbType = dbType; 25 this(); 26 } 27 28 public override string getName() { 29 return "STRUCT"; 30 } 31 32 public override long nameHashCode64() { 33 return FnvHash.Constants.STRUCT; 34 } 35 36 public override void setName(string name) { 37 throw new Exception("UnsupportedOperation"); 38 } 39 40 public override List!SQLExpr getArguments() { 41 return new ArrayList!SQLExpr(); 42 } 43 44 public override Boolean getWithTimeZone() { 45 return Boolean.FALSE; 46 } 47 48 public void setWithTimeZone(Boolean value) { 49 throw new Exception("UnsupportedOperation"); 50 } 51 52 public bool isWithLocalTimeZone() { 53 return false; 54 } 55 56 public void setWithLocalTimeZone(bool value) { 57 throw new Exception("UnsupportedOperation"); 58 } 59 60 public override void setDbType(string dbType) { 61 dbType = dbType; 62 } 63 64 public override string getDbType() { 65 return dbType; 66 } 67 68 protected override void accept0(SQLASTVisitor visitor) { 69 if (visitor.visit(this)) { 70 acceptChild!(SQLStructDataType.Field)(visitor, fields); 71 } 72 visitor.endVisit(this); 73 } 74 75 public override SQLStructDataType clone() { 76 SQLStructDataType x = new SQLStructDataType(dbType); 77 78 foreach (Field field ; fields) { 79 x.addField(field.name, field.dataType.clone()); 80 } 81 82 return x; 83 } 84 85 public List!Field getFields() { 86 return fields; 87 } 88 89 public void addField(SQLName name, SQLDataType dataType) { 90 Field field = new Field(name, dataType); 91 field.setParent(this); 92 fields.add(field); 93 } 94 95 public static class Field : SQLObjectImpl { 96 private SQLName name; 97 private SQLDataType dataType; 98 99 public this(SQLName name, SQLDataType dataType) { 100 setName(name); 101 setDataType(dataType); 102 } 103 104 protected override void accept0(SQLASTVisitor visitor) { 105 if (visitor.visit(this)) { 106 acceptChild(visitor, name); 107 acceptChild(visitor, dataType); 108 } 109 visitor.endVisit(this); 110 } 111 112 public SQLName getName() { 113 return name; 114 } 115 116 public void setName(SQLName x) { 117 if (x !is null) { 118 x.setParent(this); 119 } 120 this.name = x; 121 } 122 123 public SQLDataType getDataType() { 124 return dataType; 125 } 126 127 public void setDataType(SQLDataType x) { 128 if (x !is null) { 129 x.setParent(this); 130 } 131 this.dataType = x; 132 } 133 } 134 }