]> jfr.im git - irc/rizon/acid.git/blob - vizon/src/main/java/net/rizon/acid/plugins/vizon/db/VizonUser.java
Merge branch 'vizon' into 'master'
[irc/rizon/acid.git] / vizon / src / main / java / net / rizon / acid / plugins / vizon / db / VizonUser.java
1 /*
2 * Copyright (c) 2017, orillion <orillion@rizon.net>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
25 */
26 package net.rizon.acid.plugins.vizon.db;
27
28 import java.sql.ResultSet;
29 import java.sql.SQLException;
30 import java.sql.Timestamp;
31 import java.time.LocalDateTime;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 /**
36 *
37 * @author orillion <orillion@rizon.net>
38 */
39 public class VizonUser
40 {
41 private static final Logger logger = LoggerFactory.getLogger(VizonUser.class);
42
43 private final int id;
44 private final String nick;
45 private String vhost;
46 private boolean eligible;
47 private boolean bold;
48 private LocalDateTime obtained;
49 private int obtainedId;
50 private int expires;
51 private int multiplier;
52 private boolean jackpot;
53 private boolean permanent;
54 private int days;
55
56 public static VizonUser fromResultSet(ResultSet rs)
57 {
58 try
59 {
60 int id = rs.getInt("id");
61 String nick = rs.getString("nick");
62 String vhost = rs.getString("vhost");
63 boolean eligible = rs.getBoolean("eligible");
64 boolean bold = rs.getBoolean("bold");
65 int expires = rs.getInt("expires");
66 Timestamp obtained = rs.getTimestamp("obtained");
67 int obtainedId = rs.getInt("obtained_id");
68 int multiplier = rs.getInt("multiplier");
69 boolean jackpot = rs.getBoolean("jackpot");
70 boolean permanent = rs.getBoolean("permanent");
71 int days = rs.getInt("days");
72
73 LocalDateTime date = null;
74
75 if (obtained != null)
76 {
77 date = obtained.toLocalDateTime();
78 }
79
80 return new VizonUser(
81 id,
82 nick,
83 vhost,
84 eligible,
85 bold,
86 date,
87 obtainedId,
88 expires,
89 multiplier,
90 jackpot,
91 permanent,
92 days);
93 }
94 catch (SQLException ex)
95 {
96 logger.warn("Unable to construct VizonUser from ResultSet", ex);
97 return null;
98 }
99 }
100
101
102 private VizonUser(
103 int id,
104 String nick,
105 String vhost,
106 boolean eligible,
107 boolean bold,
108 LocalDateTime obtained,
109 int obtainedId,
110 int expires,
111 int multiplier,
112 boolean jackpot,
113 boolean permanent,
114 int days)
115 {
116 this.id = id;
117 this.nick = nick;
118 this.vhost = vhost;
119 this.eligible = eligible;
120 this.bold = bold;
121 this.obtained = obtained;
122 this.obtainedId = obtainedId;
123 this.expires = expires;
124 this.multiplier = multiplier;
125 this.jackpot = jackpot;
126 this.permanent = permanent;
127 this.days = days;
128 }
129
130 public int getId()
131 {
132 return id;
133 }
134
135 public String getNick()
136 {
137 return nick;
138 }
139
140 public String getVhost()
141 {
142 return vhost;
143 }
144
145 public boolean isEligible()
146 {
147 return eligible;
148 }
149
150 public boolean isBold()
151 {
152 return bold;
153 }
154
155 public LocalDateTime getObtained()
156 {
157 return obtained;
158 }
159
160 public int getExpires()
161 {
162 return expires;
163 }
164
165 public boolean isJackpot()
166 {
167 return jackpot;
168 }
169
170 public boolean isPermanent()
171 {
172 return permanent;
173 }
174
175 public int getDays()
176 {
177 return days;
178 }
179
180 public void addDays(int days)
181 {
182 this.days += days;
183 }
184
185 public int getMultiplier()
186 {
187 return multiplier;
188 }
189
190 public void incrementMultiplier()
191 {
192 multiplier++;
193 }
194
195 public void resetMultiplier()
196 {
197 multiplier = 0;
198 }
199
200 public void setBold(boolean bold)
201 {
202 this.bold = bold;
203 }
204
205 public void setVhost(String vhost)
206 {
207 this.vhost = vhost;
208 }
209
210 public void setEligible(boolean eligible)
211 {
212 this.eligible = eligible;
213 }
214
215 public void setObtained(LocalDateTime obtained)
216 {
217 this.obtained = obtained;
218 }
219
220 public void setExpires(int expires)
221 {
222 this.expires = expires;
223 }
224
225 public void setJackpot(boolean jackpot)
226 {
227 this.jackpot = jackpot;
228 }
229
230 public void setPermanent(boolean permanent)
231 {
232 this.permanent = permanent;
233 }
234
235 public int getObtainedId()
236 {
237 return this.obtainedId;
238 }
239
240 public void setObtainedId(int drawingId)
241 {
242 this.obtainedId = drawingId;
243 }
244
245 }