2021-05-13 12:11:59 +00:00
package com.alttd.chat.database ;
2021-05-11 17:21:48 +00:00
2021-08-08 12:52:42 +00:00
import com.alttd.chat.managers.ChatUserManager ;
2021-08-04 13:07:16 +00:00
import com.alttd.chat.managers.PartyManager ;
2021-06-02 17:55:55 +00:00
import com.alttd.chat.objects.ChatUser ;
2021-07-27 16:46:58 +00:00
import com.alttd.chat.objects.Mail ;
2021-06-02 17:55:55 +00:00
import com.alttd.chat.objects.Party ;
2021-08-08 20:07:47 +00:00
import com.alttd.chat.objects.PartyUser ;
2021-08-08 11:30:57 +00:00
import com.alttd.chat.objects.channels.Channel ;
2021-08-08 09:36:06 +00:00
import com.alttd.chat.util.ALogger ;
2021-05-11 17:21:48 +00:00
2022-01-29 22:21:35 +00:00
import java.sql.* ;
2021-06-23 18:05:47 +00:00
import java.util.* ;
2021-08-08 09:36:06 +00:00
import java.util.List ;
2021-05-11 17:21:48 +00:00
public class Queries {
//Create Tables
public static void createTables ( ) {
List < String > tables = new ArrayList < > ( ) ;
tables . add ( " CREATE TABLE IF NOT EXISTS ignored_users (`uuid` VARCHAR(36) NOT NULL, `ignored_uuid` VARCHAR(36) NOT NULL, PRIMARY KEY (`uuid`, `ignored_uuid`)) " ) ;
tables . add ( " CREATE TABLE IF NOT EXISTS parties (`id` INT NOT NULL AUTO_INCREMENT, `owner_uuid` VARCHAR(36) NOT NULL, `party_name` VARCHAR(36) NOT NULL, `password` VARCHAR(36), PRIMARY KEY (`id`)) " ) ;
2021-08-08 11:30:57 +00:00
tables . add ( " CREATE TABLE IF NOT EXISTS chat_users (`uuid` VARCHAR(36) NOT NULL, `party_id` INT NOT NULL, `toggled_channel` VARCHAR(36) NULL DEFAULT NULL, PRIMARY KEY (`uuid`)) " ) ;
2022-01-29 22:21:35 +00:00
tables . add ( " CREATE TABLE IF NOT EXISTS mails (`id` INT NOT NULL AUTO_INCREMENT, `uuid` VARCHAR(36) NOT NULL, `sender` VARCHAR(36) NOT NULL, `message` VARCHAR(256) NOT NULL, `sendtime` BIGINT default 0, `readtime` BIGINT default 0, PRIMARY KEY (`id`)) " ) ;
2021-05-11 17:21:48 +00:00
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
for ( String query : tables ) {
connection . prepareStatement ( query ) . execute ( ) ;
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
}
//-----------------------------------------
2021-05-12 21:59:19 +00:00
//Nicknames
2021-05-11 17:21:48 +00:00
2021-05-12 21:59:19 +00:00
public static String getNickname ( UUID uuid ) {
2021-05-15 10:34:19 +00:00
// View has been created.
2021-05-12 21:59:19 +00:00
String query = " SELECT nickname FROM nicknames WHERE uuid = ? " ;
2021-05-11 17:21:48 +00:00
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
2021-05-12 21:59:19 +00:00
PreparedStatement statement = connection . prepareStatement ( query ) ;
statement . setString ( 1 , uuid . toString ( ) ) ;
2021-05-11 17:21:48 +00:00
2021-05-12 21:59:19 +00:00
ResultSet resultSet = statement . executeQuery ( ) ;
if ( resultSet . next ( ) ) {
return resultSet . getString ( " nickname " ) ;
2021-05-11 17:21:48 +00:00
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
return null ;
}
//-----------------------------------------
//Ignore
2021-06-23 18:05:47 +00:00
/ * *
* returns the UUID of all players this player has ignored .
*
* @param uuid the player who ignored the other players
2021-07-28 18:42:09 +00:00
* @return List < UUID >
2021-06-23 18:05:47 +00:00
* /
2021-07-28 18:42:09 +00:00
public static List < UUID > getIgnoredUsers ( UUID uuid ) {
List < UUID > uuids = new ArrayList < > ( ) ;
2021-06-23 18:05:47 +00:00
String query = " SELECT * FROM ignored_users WHERE uuid = ? " ;
2021-05-11 17:21:48 +00:00
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
2021-06-23 18:05:47 +00:00
PreparedStatement statement = connection . prepareStatement ( query ) ;
2021-05-11 17:21:48 +00:00
2021-06-23 18:05:47 +00:00
statement . setString ( 1 , uuid . toString ( ) ) ;
ResultSet resultSet = statement . executeQuery ( ) ;
2021-05-11 17:21:48 +00:00
while ( resultSet . next ( ) ) {
UUID ignoredUuid = UUID . fromString ( resultSet . getString ( " ignored_uuid " ) ) ;
uuids . add ( ignoredUuid ) ;
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
2021-06-23 18:05:47 +00:00
return uuids ;
2021-05-11 17:21:48 +00:00
}
public static void ignoreUser ( UUID uuid , UUID ignoredUuid ) {
//TODO this should be called from a function that already adds the user to the live ignored list, so this just adds it to the database
String query = " INSERT INTO ignored_users (uuid, ignored_uuid) VALUES (?, ?) " ;
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
PreparedStatement statement = connection . prepareStatement ( query ) ;
statement . setString ( 1 , uuid . toString ( ) ) ;
statement . setString ( 2 , ignoredUuid . toString ( ) ) ;
statement . execute ( ) ;
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
}
public static void unIgnoreUser ( UUID uuid , UUID ignoredUuid ) {
//TODO this should be called from a function that already removes the user from the live ignored list, so this just removes it from the database
String query = " DELETE FROM ignored_users WHERE uuid = ? AND ignored_uuid = ? " ;
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
PreparedStatement statement = connection . prepareStatement ( query ) ;
statement . setString ( 1 , uuid . toString ( ) ) ;
statement . setString ( 2 , ignoredUuid . toString ( ) ) ;
statement . execute ( ) ;
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
}
//-----------------------------------------
//Party
2021-08-04 13:07:16 +00:00
public static void loadParties ( ) {
2021-05-11 17:21:48 +00:00
String query = " SELECT * FROM parties " ;
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
ResultSet resultSet = connection . prepareStatement ( query ) . executeQuery ( ) ;
while ( resultSet . next ( ) ) {
int id = resultSet . getInt ( " id " ) ;
UUID ownerUuid = UUID . fromString ( resultSet . getString ( " owner_uuid " ) ) ;
String partyName = resultSet . getString ( " party_name " ) ;
String password = resultSet . getString ( " password " ) ;
2021-08-04 13:07:16 +00:00
PartyManager . addParty ( new Party ( id , ownerUuid , partyName , password ) ) ;
2021-05-11 17:21:48 +00:00
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
2021-08-08 09:36:06 +00:00
loadPartyUsers ( ) ;
}
private static void loadPartyUsers ( ) {
String query = " SELECT chat_users.party_id, chat_users.uuid, nicknames.nickname, utility_users.Username " +
" FROM chat_users " +
" LEFT OUTER JOIN nicknames ON chat_users.UUID = nicknames.uuid " +
" LEFT OUTER JOIN utility_users ON chat_users.uuid = utility_users.UUID " +
" WHERE party_id != -1 " ;
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
ResultSet resultSet = connection . prepareStatement ( query ) . executeQuery ( ) ;
while ( resultSet . next ( ) ) {
int id = resultSet . getInt ( " party_id " ) ;
UUID uuid = UUID . fromString ( resultSet . getString ( " uuid " ) ) ;
2021-08-08 20:07:47 +00:00
String displayName = resultSet . getString ( " nickname " ) ;
if ( displayName = = null | | displayName . isEmpty ( ) ) {
displayName = resultSet . getString ( " Username " ) ;
}
String playerName = resultSet . getString ( " Username " ) ;
2021-08-08 09:36:06 +00:00
Party party = PartyManager . getParty ( id ) ;
if ( party = = null ) {
ALogger . warn ( " Unable to retrieve party: " + id ) ;
continue ;
}
2021-08-08 20:07:47 +00:00
party . putPartyUser ( new PartyUser ( uuid , displayName , playerName ) ) ;
2021-08-08 09:36:06 +00:00
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
2021-05-11 17:21:48 +00:00
}
2021-08-08 11:30:57 +00:00
public static void loadPartyUsers ( int id ) {
String query = " SELECT chat_users.uuid, nicknames.nickname, utility_users.Username " +
" FROM chat_users " +
" LEFT OUTER JOIN nicknames ON chat_users.UUID = nicknames.uuid " +
" LEFT OUTER JOIN utility_users ON chat_users.uuid = utility_users.UUID " +
" WHERE party_id = ? " ;
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
PreparedStatement preparedStatement = connection . prepareStatement ( query ) ;
preparedStatement . setInt ( 1 , id ) ;
ResultSet resultSet = preparedStatement . executeQuery ( ) ;
Party party = PartyManager . getParty ( id ) ;
if ( party = = null ) {
ALogger . warn ( " Tried to load invalid party " ) ;
return ;
}
party . resetPartyUsers ( ) ;
while ( resultSet . next ( ) ) {
UUID uuid = UUID . fromString ( resultSet . getString ( " uuid " ) ) ;
2021-08-08 20:07:47 +00:00
String displayName = resultSet . getString ( " nickname " ) ;
if ( displayName = = null | | displayName . isEmpty ( ) ) {
displayName = resultSet . getString ( " Username " ) ;
}
String playerName = resultSet . getString ( " Username " ) ;
2021-08-08 11:30:57 +00:00
2021-08-08 20:07:47 +00:00
party . putPartyUser ( new PartyUser ( uuid , displayName , playerName ) ) ;
2021-08-08 11:30:57 +00:00
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
}
2021-05-11 17:21:48 +00:00
public static Party addParty ( UUID partyOwner , String partyName , String password ) {
String query = " INSERT INTO parties (owner_uuid, party_name, password) VALUES (?, ?, ?) " ;
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
PreparedStatement statement = connection . prepareStatement ( query ) ;
statement . setString ( 1 , partyOwner . toString ( ) ) ;
statement . setString ( 2 , partyName ) ;
statement . setString ( 3 , password . isEmpty ( ) ? null : password ) ;
statement . execute ( ) ;
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
return getParty ( partyOwner , partyName , password ) ;
}
private static Party getParty ( UUID partyOwner , String partyName , String password ) {
String query = " SELECT * FROM parties WHERE owner_uuid = ? AND party_name = ? " ;
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
PreparedStatement statement = connection . prepareStatement ( query ) ;
statement . setString ( 1 , partyOwner . toString ( ) ) ;
statement . setString ( 2 , partyName ) ;
ResultSet resultSet = statement . executeQuery ( ) ;
if ( resultSet . next ( ) ) {
int id = resultSet . getInt ( " id " ) ;
return new Party ( id , partyOwner , partyName , password ) ;
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
return null ;
}
public static void setPartyOwner ( UUID uuid , int id ) {
setStringWhereId ( " UPDATE parties set owner_uuid = ? WHERE id = ? " , uuid . toString ( ) , id ) ;
}
public static void setPartyName ( String name , int id ) {
setStringWhereId ( " UPDATE parties set party_name = ? WHERE id = ? " , name , id ) ;
}
public static void setPartyPassword ( String password , int id ) {
setStringWhereId ( " UPDATE parties set password = ? WHERE id = ? " , password , id ) ;
}
private static void setStringWhereId ( String query , String string , int id ) {
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
PreparedStatement statement = connection . prepareStatement ( query ) ;
statement . setString ( 1 , string ) ;
statement . setInt ( 2 , id ) ;
statement . execute ( ) ;
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
}
2021-08-08 09:36:06 +00:00
public static void addPartyUser ( ChatUser user ) {
String query = " UPDATE chat_users SET party_id = ? WHERE uuid = ? " ;
2021-05-11 17:21:48 +00:00
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
PreparedStatement statement = connection . prepareStatement ( query ) ;
2021-08-08 09:36:06 +00:00
statement . setInt ( 1 , user . getPartyId ( ) ) ;
statement . setString ( 2 , user . getUuid ( ) . toString ( ) ) ;
2021-05-11 17:21:48 +00:00
statement . execute ( ) ;
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
}
2022-01-31 02:06:52 +00:00
public static void removeAllPartyUsers ( ArrayList < PartyUser > partyUsers ) {
String query = " UPDATE chat_users SET party_id = -1 WHERE uuid = ? " ;
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
PreparedStatement statement = connection . prepareStatement ( query ) ;
for ( PartyUser partyUser : partyUsers ) {
statement . setString ( 1 , partyUser . getUuid ( ) . toString ( ) ) ;
statement . addBatch ( ) ;
}
statement . executeBatch ( ) ;
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
}
2021-08-08 09:36:06 +00:00
public static void removePartyUser ( UUID uuid ) {
String query = " UPDATE chat_users SET party_id = -1 WHERE uuid = ? " ;
2021-05-11 17:21:48 +00:00
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
2021-08-08 09:36:06 +00:00
PreparedStatement statement = connection . prepareStatement ( query ) ;
2021-05-11 17:21:48 +00:00
2021-08-08 09:36:06 +00:00
statement . setString ( 1 , uuid . toString ( ) ) ;
2021-05-11 17:21:48 +00:00
2021-08-08 09:36:06 +00:00
statement . execute ( ) ;
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
}
2021-05-11 17:21:48 +00:00
2021-08-08 09:36:06 +00:00
public static void removeParty ( int id ) {
String deleteParty = " DELETE FROM parties WHERE id = ? " ;
String updateUsers = " UPDATE chat_users SET party_id = -1 WHERE party_id = ? " ;
2021-05-14 00:33:23 +00:00
2021-08-08 09:36:06 +00:00
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
PreparedStatement statement = connection . prepareStatement ( deleteParty ) ;
2021-05-14 00:33:23 +00:00
2021-08-08 09:36:06 +00:00
statement . setInt ( 1 , id ) ;
statement . execute ( ) ;
2021-05-11 17:21:48 +00:00
2021-08-08 09:36:06 +00:00
statement = connection . prepareStatement ( updateUsers ) ;
2021-05-11 17:21:48 +00:00
2021-08-08 09:36:06 +00:00
statement . setInt ( 1 , id ) ;
statement . execute ( ) ;
2021-05-11 17:21:48 +00:00
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
}
2021-08-08 09:36:06 +00:00
//-----------------------------------------
2021-07-27 16:46:58 +00:00
public static ChatUser loadChatUser ( UUID uuid ) { //TODO Get parties from cache somewhere
String query = " SELECT * FROM chat_users WHERE uuid = ? " ;
ChatUser user = null ;
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
PreparedStatement statement = connection . prepareStatement ( query ) ;
statement . setString ( 1 , uuid . toString ( ) ) ;
ResultSet resultSet = statement . executeQuery ( ) ;
while ( resultSet . next ( ) ) {
int partyId = resultSet . getInt ( " party_id " ) ;
2021-08-08 11:30:57 +00:00
String toggledChannel = resultSet . getString ( " toggled_channel " ) ;
Channel channel = toggledChannel = = null ? null : Channel . getChatChannel ( toggledChannel ) ;
user = new ChatUser ( uuid , partyId , channel ) ;
2022-01-28 16:04:54 +00:00
// ChatUserManager.addUser(user);
2021-07-27 16:46:58 +00:00
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
return user ;
}
2021-08-08 11:30:57 +00:00
public static void setToggledChannel ( Channel channel , UUID uuid ) {
String sql = " UPDATE chat_users set toggled_channel = ? WHERE uuid = ? " ;
2021-05-11 17:21:48 +00:00
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
2021-08-08 11:30:57 +00:00
PreparedStatement statement = connection . prepareStatement ( sql ) ;
2021-05-11 17:21:48 +00:00
2021-08-08 11:30:57 +00:00
statement . setString ( 1 , channel . getChannelName ( ) ) ;
2021-05-11 17:21:48 +00:00
statement . setString ( 2 , uuid . toString ( ) ) ;
statement . execute ( ) ;
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
}
//-----------------------------------------
2021-07-27 16:46:58 +00:00
2021-07-28 18:42:09 +00:00
public static List < Mail > getMails ( UUID uuid ) {
List < Mail > mails = new ArrayList < > ( ) ;
2021-07-27 16:46:58 +00:00
String query = " SELECT * FROM mails where uuid = ? " ;
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
PreparedStatement statement = connection . prepareStatement ( query ) ;
statement . setString ( 1 , uuid . toString ( ) ) ;
ResultSet resultSet = statement . executeQuery ( ) ;
while ( resultSet . next ( ) ) {
2022-01-29 22:21:35 +00:00
int id = resultSet . getInt ( " id " ) ;
UUID fromUUID = UUID . fromString ( resultSet . getString ( " sender " ) ) ;
2021-07-27 16:46:58 +00:00
String message = resultSet . getString ( " message " ) ;
long sendTime = resultSet . getLong ( " sendtime " ) ;
long readTime = resultSet . getLong ( " readtime " ) ;
2022-01-29 22:21:35 +00:00
mails . add ( new Mail ( id , uuid , fromUUID , sendTime , readTime , message ) ) ;
2021-07-27 16:46:58 +00:00
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
return mails ;
}
public static void saveUser ( ChatUser user ) {
2021-08-08 11:30:57 +00:00
String query = " INSERT INTO chat_users (uuid, party_id, toggled_channel) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE party_id = ?, toggled_channel = ? " ;
2021-07-27 16:46:58 +00:00
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
PreparedStatement statement = connection . prepareStatement ( query ) ;
2021-08-08 11:30:57 +00:00
Channel toggledChannel = user . getToggledChannel ( ) ;
2021-07-27 16:46:58 +00:00
statement . setString ( 1 , user . getUuid ( ) . toString ( ) ) ;
statement . setInt ( 2 , user . getPartyId ( ) ) ;
2021-08-08 11:30:57 +00:00
statement . setString ( 3 , toggledChannel = = null ? null : toggledChannel . getChannelName ( ) ) ;
statement . setInt ( 4 , user . getPartyId ( ) ) ;
statement . setString ( 5 , toggledChannel = = null ? null : toggledChannel . getChannelName ( ) ) ;
2021-07-27 16:46:58 +00:00
statement . execute ( ) ;
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
}
2021-08-01 01:20:49 +00:00
public static String getDisplayName ( UUID uuid ) {
String nickname = getNickname ( uuid ) ;
if ( nickname ! = null ) return nickname ;
2021-08-01 02:21:33 +00:00
HashSet < String > userNames = getUserNames ( List . of ( uuid ) ) ;
return userNames . isEmpty ( ) ? null : userNames . iterator ( ) . next ( ) ;
}
2021-08-01 01:20:49 +00:00
2021-08-01 02:21:33 +00:00
public static HashSet < String > getUserNames ( List < UUID > uuid ) {
StringBuilder query = new StringBuilder ( " SELECT Username FROM utility_users WHERE uuid IN ( " ) ;
if ( uuid . isEmpty ( ) ) return new HashSet < > ( ) ;
query . append ( " ?, " . repeat ( uuid . size ( ) ) ) ;
query . delete ( query . length ( ) - 2 , query . length ( ) ) ;
query . append ( " ) " ) ;
HashSet < String > userNames = new HashSet < > ( ) ;
2021-08-01 01:20:49 +00:00
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
2021-08-01 02:21:33 +00:00
PreparedStatement statement = connection . prepareStatement ( query . toString ( ) ) ;
2021-08-01 01:20:49 +00:00
2021-08-01 02:21:33 +00:00
for ( int i = 0 ; i < uuid . size ( ) ; i + + ) {
statement . setString ( i + 1 , uuid . get ( i ) . toString ( ) ) ;
}
2021-08-01 01:20:49 +00:00
ResultSet resultSet = statement . executeQuery ( ) ;
2021-08-01 02:21:33 +00:00
while ( resultSet . next ( ) ) {
userNames . add ( resultSet . getString ( " Username " ) ) ;
2021-08-01 01:20:49 +00:00
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
2021-08-01 02:21:33 +00:00
return userNames ;
2021-08-01 01:20:49 +00:00
}
2022-01-29 13:53:47 +00:00
public static UUID getPlayerUUID ( String playerName ) {
String query = " SELECT UUID FROM utility_users WHERE Username = ? " ;
UUID uuid = null ;
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
PreparedStatement statement = connection . prepareStatement ( query ) ;
statement . setString ( 1 , playerName ) ;
ResultSet resultSet = statement . executeQuery ( ) ;
while ( resultSet . next ( ) ) {
uuid = UUID . fromString ( resultSet . getString ( " UUID " ) ) ;
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
return uuid ;
}
2022-01-29 22:21:35 +00:00
public static int insertMail ( Mail mail ) {
String query = " INSERT INTO mails (uuid , sender, message, sendtime, readtime) VALUES (?, ?, ?, ?, ?) " ;
int id = 0 ;
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
PreparedStatement statement = connection . prepareStatement ( query , Statement . RETURN_GENERATED_KEYS ) ;
statement . setString ( 1 , mail . getUuid ( ) . toString ( ) ) ;
statement . setString ( 2 , mail . getSender ( ) . toString ( ) ) ;
statement . setString ( 3 , mail . getMessage ( ) ) ;
statement . setLong ( 4 , mail . getSendTime ( ) ) ;
statement . setLong ( 5 , mail . getReadTime ( ) ) ;
statement . execute ( ) ;
ResultSet rs = statement . getGeneratedKeys ( ) ;
if ( rs . next ( ) ) {
id = rs . getInt ( 1 ) ;
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
return id ;
}
public static void markMailRead ( Mail mail ) {
String query = " INSERT INTO mails (Id, uuid , sender, message, sendtime, readtime) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE readtime = ? " ;
try {
Connection connection = DatabaseConnection . getConnection ( ) ;
PreparedStatement statement = connection . prepareStatement ( query ) ;
statement . setInt ( 1 , mail . getId ( ) ) ;
statement . setString ( 2 , mail . getUuid ( ) . toString ( ) ) ;
statement . setString ( 3 , mail . getSender ( ) . toString ( ) ) ;
statement . setString ( 4 , mail . getMessage ( ) ) ;
statement . setLong ( 5 , mail . getSendTime ( ) ) ;
statement . setLong ( 6 , mail . getReadTime ( ) ) ;
statement . setLong ( 7 , mail . getReadTime ( ) ) ;
statement . execute ( ) ;
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
}
2021-05-11 17:21:48 +00:00
}