1 /*
2  * Copyright 2015-2018 HuntLabs.cn
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 module hunt.sql.dialect.mysql.ast.expr.MySqlUserName;
17 
18 import hunt.sql.ast.SQLName;
19 import hunt.sql.ast.SQLObject;
20 import hunt.sql.dialect.mysql.visitor.MySqlASTVisitor;
21 import hunt.sql.util.FnvHash;
22 import hunt.sql.dialect.mysql.ast.expr.MySqlExprImpl;
23 // //import hunt.lang.common;
24 import hunt.sql.dialect.mysql.ast.MySqlObjectImpl;
25 import hunt.util.Common;
26 
27 
28 import hunt.collection;
29 
30 public class MySqlUserName : MySqlExprImpl , SQLName {
31 
32     alias accept0 = MySqlObjectImpl.accept0;
33 
34     private string userName;
35     private string host;
36     private string identifiedBy;
37 
38     private long   userNameHashCod64;
39     private long   _hashCode64;
40 
41     public string getUserName() {
42         return userName;
43     }
44 
45     public void setUserName(string userName) {
46         this.userName = userName;
47 
48         this._hashCode64 = 0;
49         this.userNameHashCod64 = 0;
50     }
51 
52     public string getHost() {
53         return host;
54     }
55 
56     public void setHost(string host) {
57         this.host = host;
58 
59         this._hashCode64 = 0;
60         this.userNameHashCod64 = 0;
61     }
62 
63     override
64     public void accept0(MySqlASTVisitor visitor) {
65         visitor.visit(this);
66         visitor.endVisit(this);
67     }
68 
69     public string getSimpleName() {
70         return userName ~ '@' ~ host;
71     }
72 
73     public string getIdentifiedBy() {
74         return identifiedBy;
75     }
76 
77     public void setIdentifiedBy(string identifiedBy) {
78         this.identifiedBy = identifiedBy;
79     }
80 
81     override public string toString() {
82         return getSimpleName();
83     }
84 
85     override public MySqlUserName clone() {
86         MySqlUserName x = new MySqlUserName();
87 
88         x.userName     = userName;
89         x.host         = host;
90         x.identifiedBy = identifiedBy;
91 
92         return x;
93     }
94 
95     override
96     public List!(SQLObject) getChildren() {
97         return Collections.emptyList!(SQLObject)();
98     }
99 
100     public long nameHashCode64() {
101         if (userNameHashCod64 == 0
102                 && userName !is null) {
103             userNameHashCod64 = FnvHash.hashCode64(userName);
104         }
105         return userNameHashCod64;
106     }
107 
108     override
109     public long hashCode64() {
110         if (_hashCode64 == 0) {
111             if (host !is null) {
112                 long hash = FnvHash.hashCode64(host);
113                 hash ^= '@';
114                 hash *= 0x100000001b3L;
115                 hash = FnvHash.hashCode64(hash, userName);
116 
117                 _hashCode64 = hash;
118             } else {
119                 _hashCode64 = nameHashCode64();
120             }
121         }
122 
123         return _hashCode64;
124     }
125 }