55import org .jetbrains .annotations .NotNull ;
66import org .jetbrains .annotations .Nullable ;
77
8- import java .sql .Connection ;
98import java .sql .PreparedStatement ;
109import java .sql .ResultSet ;
1110import java .sql .SQLException ;
@@ -69,8 +68,7 @@ public boolean isAlt() {
6968 public @ NotNull Set <@ NotNull Member > getAlts () {
7069 final @ NotNull Set <@ NotNull Member > alts = new HashSet <>();
7170 try (
72- final @ NotNull Connection conn = SMPCore .getInstance ().db ()
73- .getConnection (); final @ NotNull PreparedStatement stmt = conn .prepareStatement ("SELECT * FROM `members` WHERE `alt_owner` = ?" )
71+ final @ NotNull PreparedStatement stmt = SMPCore .getInstance ().conn .prepareStatement ("SELECT * FROM `members` WHERE `alt_owner` = ?" )
7472 ) {
7573 stmt .setString (1 , uuid .toString ());
7674 final @ NotNull ResultSet rs = stmt .executeQuery ();
@@ -89,8 +87,7 @@ public void unban() {
8987
9088 public void save () {
9189 try (
92- final @ NotNull Connection conn = SMPCore .getInstance ().db ()
93- .getConnection (); final @ NotNull PreparedStatement stmt = conn .prepareStatement ("INSERT OR REPLACE INTO `members` (`uuid`, `nation`, `staff`, `alt_owner`, `added`) VALUES (?, ?, ?, ?, ?)" )
90+ final @ NotNull PreparedStatement stmt = SMPCore .getInstance ().conn .prepareStatement ("INSERT OR REPLACE INTO `members` (`uuid`, `nation`, `staff`, `alt_owner`, `added`) VALUES (?, ?, ?, ?, ?)" )
9491 ) {
9592 stmt .setString (1 , uuid .toString ());
9693 stmt .setString (2 , nationID == null ? null : nationID );
@@ -109,8 +106,7 @@ public void save() {
109106 */
110107 private void remove () {
111108 try (
112- final @ NotNull Connection conn = SMPCore .getInstance ().db ()
113- .getConnection (); final @ NotNull PreparedStatement stmt = conn .prepareStatement ("DELETE FROM `members` WHERE `uuid` = ?" )
109+ final @ NotNull PreparedStatement stmt = SMPCore .getInstance ().conn .prepareStatement ("DELETE FROM `members` WHERE `uuid` = ?" )
114110 ) {
115111 stmt .setString (1 , uuid .toString ());
116112 stmt .executeUpdate ();
@@ -157,8 +153,7 @@ public boolean delete() {
157153
158154 public static @ NotNull Optional <@ NotNull Member > get (final @ NotNull UUID uuid ) {
159155 try (
160- final @ NotNull Connection conn = SMPCore .getInstance ().db ()
161- .getConnection (); final @ NotNull PreparedStatement stmt = conn .prepareStatement ("SELECT * FROM `members` WHERE `uuid` = ? LIMIT 1" )
156+ final @ NotNull PreparedStatement stmt = SMPCore .getInstance ().conn .prepareStatement ("SELECT * FROM `members` WHERE `uuid` = ? LIMIT 1" )
162157 ) {
163158 stmt .setString (1 , uuid .toString ());
164159 final @ NotNull ResultSet rs = stmt .executeQuery ();
@@ -174,8 +169,7 @@ public boolean delete() {
174169 public static @ NotNull Set <@ NotNull Member > get () {
175170 final @ NotNull Set <@ NotNull Member > members = new HashSet <>();
176171 try (
177- final @ NotNull Connection conn = SMPCore .getInstance ().db ()
178- .getConnection (); final @ NotNull PreparedStatement stmt = conn .prepareStatement ("SELECT * FROM `members`" )
172+ final @ NotNull PreparedStatement stmt = SMPCore .getInstance ().conn .prepareStatement ("SELECT * FROM `members`" )
179173 ) {
180174 final @ NotNull ResultSet rs = stmt .executeQuery ();
181175 while (rs .next ()) members .add (new Member (rs ));
@@ -190,8 +184,7 @@ public boolean delete() {
190184 final int offset = (page - 1 ) * limit ;
191185 final @ NotNull Set <@ NotNull Member > members = new HashSet <>();
192186 try (
193- final @ NotNull Connection conn = SMPCore .getInstance ().db ()
194- .getConnection (); final @ NotNull PreparedStatement stmt = conn .prepareStatement ("SELECT * FROM `members` LIMIT ? OFFSET ?" )
187+ final @ NotNull PreparedStatement stmt = SMPCore .getInstance ().conn .prepareStatement ("SELECT * FROM `members` LIMIT ? OFFSET ?" )
195188 ) {
196189 stmt .setInt (1 , limit );
197190 stmt .setInt (2 , offset );
@@ -207,8 +200,7 @@ public boolean delete() {
207200 public static @ NotNull Set <@ NotNull Member > get (final @ NotNull Nation nation ) {
208201 final @ NotNull Set <@ NotNull Member > members = new HashSet <>();
209202 try (
210- final @ NotNull Connection conn = SMPCore .getInstance ().db ()
211- .getConnection (); final @ NotNull PreparedStatement stmt = conn .prepareStatement ("SELECT * FROM `members` WHERE `nation` = ?" )
203+ final @ NotNull PreparedStatement stmt = SMPCore .getInstance ().conn .prepareStatement ("SELECT * FROM `members` WHERE `nation` = ?" )
212204 ) {
213205 stmt .setString (1 , nation .id );
214206 final @ NotNull ResultSet rs = stmt .executeQuery ();
@@ -222,8 +214,7 @@ public boolean delete() {
222214
223215 public static int count () {
224216 try (
225- final @ NotNull Connection conn = SMPCore .getInstance ().db ()
226- .getConnection (); final @ NotNull PreparedStatement stmt = conn .prepareStatement ("SELECT COUNT(*) as `n` FROM `members`" )
217+ final @ NotNull PreparedStatement stmt = SMPCore .getInstance ().conn .prepareStatement ("SELECT COUNT(*) as `n` FROM `members`" )
227218 ) {
228219 final @ NotNull ResultSet rs = stmt .executeQuery ();
229220 rs .next ();
0 commit comments