3030import javax .annotation .Nonnull ;
3131import java .math .BigInteger ;
3232import java .sql .*;
33+ import java .time .Instant ;
3334import java .util .Date ;
3435import java .util .*;
3536import java .util .concurrent .ConcurrentHashMap ;
@@ -242,13 +243,13 @@ public static void loadFromDB(MUCRoom room) {
242243 throw new IllegalArgumentException ("Room " + room .getName () + " was not found in the database." );
243244 }
244245 room .setID (rs .getLong ("roomID" ));
245- room .setCreationDate (rs .getTimestamp ("creationDate" , Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" )) ));
246- room .setModificationDate (rs .getTimestamp ("modificationDate" , Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" )) ));
246+ room .setCreationDate (Date . from ( rs .getObject ("creationDate" , Instant . class ) ));
247+ room .setModificationDate (Date . from ( rs .getObject ("modificationDate" , Instant . class ) ));
247248 room .setNaturalLanguageName (rs .getString ("naturalName" ));
248249 room .setDescription (rs .getString ("description" ));
249- room .setLockedDate (rs .getTimestamp ("lockedDate" , Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" )) ));
250- if (rs .getTimestamp ("emptyDate" , Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" )) ) != null ) {
251- room .setEmptyDate (rs .getTimestamp ("emptyDate" , Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) )));
250+ room .setLockedDate (Date . from ( rs .getObject ("lockedDate" , Instant . class ) ));
251+ if (rs .getObject ("emptyDate" , Instant . class ) != null ) {
252+ room .setEmptyDate (Date . from ( rs .getObject ("emptyDate" , Instant . class )));
252253 }
253254 else {
254255 room .setEmptyDate (null );
@@ -398,7 +399,7 @@ public static void saveToDB(MUCRoom room) {
398399 con = DbConnectionManager .getConnection ();
399400 if (room .wasSavedToDB ()) {
400401 pstmt = con .prepareStatement (UPDATE_ROOM );
401- pstmt .setTimestamp (1 , new Timestamp ( room .getModificationDate ().getTime ()), Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) ));
402+ pstmt .setObject (1 , room .getModificationDate ().toInstant ( ));
402403 pstmt .setString (2 , room .getNaturalLanguageName ());
403404 pstmt .setString (3 , room .getDescription ());
404405 pstmt .setInt (4 , (room .canOccupantsChangeSubject () ? 1 : 0 ));
@@ -450,18 +451,18 @@ public static void saveToDB(MUCRoom room) {
450451 pstmt = con .prepareStatement (ADD_ROOM );
451452 pstmt .setLong (1 , XMPPServer .getInstance ().getMultiUserChatManager ().getMultiUserChatServiceID (room .getMUCService ().getServiceName ()));
452453 pstmt .setLong (2 , room .getID ());
453- pstmt .setTimestamp (3 , new Timestamp ( room .getCreationDate ().getTime ()), Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) ));
454- pstmt .setTimestamp (4 , new Timestamp ( room .getModificationDate ().getTime ()), Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) ));
454+ pstmt .setObject (3 , room .getCreationDate ().toInstant ( ));
455+ pstmt .setObject (4 , room .getModificationDate ().toInstant ( ));
455456 pstmt .setString (5 , room .getName ());
456457 pstmt .setString (6 , room .getNaturalLanguageName ());
457458 pstmt .setString (7 , room .getDescription ());
458- pstmt .setTimestamp (8 , new Timestamp ( room .getLockedDate ().getTime ()), Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) ));
459+ pstmt .setObject (8 , room .getLockedDate ().toInstant ( ));
459460 Date emptyDate = room .getEmptyDate ();
460461 if (emptyDate == null ) {
461- pstmt .setTimestamp (9 , null );
462+ pstmt .setObject (9 , null );
462463 }
463464 else {
464- pstmt .setTimestamp (9 , new Timestamp ( emptyDate .getTime ()), Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) ));
465+ pstmt .setObject (9 , emptyDate .toInstant ( ));
465466 }
466467 pstmt .setInt (10 , (room .canOccupantsChangeSubject () ? 1 : 0 ));
467468 pstmt .setInt (11 , room .getMaxUsers ());
@@ -731,7 +732,7 @@ private static Map<Long, MUCRoom> loadRooms(Long serviceID, Date cleanupDate, Mu
731732 {
732733 statement = connection .prepareStatement (RELOAD_ALL_ROOMS_WITH_RECENT_ACTIVITY );
733734 statement .setLong (1 , serviceID );
734- statement .setTimestamp (2 , new Timestamp ( cleanupDate .getTime ()), Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) ));
735+ statement .setObject (2 , cleanupDate .toInstant ( ));
735736 }
736737 else
737738 {
@@ -744,13 +745,13 @@ private static Map<Long, MUCRoom> loadRooms(Long serviceID, Date cleanupDate, Mu
744745 try {
745746 MUCRoom room = new MUCRoom (chatserver , resultSet .getString ("name" ));
746747 room .setID (resultSet .getLong ("roomID" ));
747- room .setCreationDate (resultSet .getTimestamp ("creationDate" , Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) )));
748- room .setModificationDate (resultSet .getTimestamp ("modificationDate" , Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) )));
748+ room .setCreationDate (Date . from ( resultSet .getObject ("creationDate" , Instant . class )));
749+ room .setModificationDate (Date . from ( resultSet .getObject ("modificationDate" , Instant . class )));
749750 room .setNaturalLanguageName (resultSet .getString ("naturalName" ));
750751 room .setDescription (resultSet .getString ("description" ));
751- room .setLockedDate (resultSet .getTimestamp ("lockedDate" , Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) )));
752- if (resultSet .getTimestamp ("emptyDate" , Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" )) ) != null ) {
753- room .setEmptyDate (resultSet .getTimestamp ("emptyDate" , Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) )));
752+ room .setLockedDate (Date . from ( resultSet .getObject ("lockedDate" , Instant . class )));
753+ if (resultSet .getObject ("emptyDate" , Instant . class ) != null ) {
754+ room .setEmptyDate (Date . from ( resultSet .getObject ("emptyDate" , Instant . class )));
754755 }
755756 else {
756757 room .setEmptyDate (null );
@@ -879,7 +880,7 @@ public static void loadHistory(@Nonnull final MUCRoom room, final int maxNumber)
879880 from = System .currentTimeMillis () - (BigInteger .valueOf (86400000 ).multiply (BigInteger .valueOf (reloadLimitDays ))).longValue ();
880881 }
881882
882- pstmt .setTimestamp (1 , new Timestamp ( from ), Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) ));
883+ pstmt .setObject (1 , Instant . ofEpochMilli ( from ));
883884 pstmt .setLong (2 , room .getID ());
884885 rs = pstmt .executeQuery ();
885886
@@ -899,11 +900,11 @@ public static void loadHistory(@Nonnull final MUCRoom room, final int maxNumber)
899900 while (rs .next ()) {
900901 String senderJID = rs .getString ("sender" );
901902 String nickname = rs .getString ("nickname" );
902- Date sentDate = rs .getTimestamp ("logTime" , Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" )) );
903+ Instant sentDate = rs .getObject ("logTime" , Instant . class );
903904 String subject = rs .getString ("subject" );
904905 String body = rs .getString ("body" );
905906 String stanza = rs .getString ("stanza" );
906- oldMessages .add (room .getRoomHistory ().parseHistoricMessage (senderJID , nickname , sentDate , subject , body , stanza ));
907+ oldMessages .add (room .getRoomHistory ().parseHistoricMessage (senderJID , nickname , Date . from ( sentDate ) , subject , body , stanza ));
907908 }
908909
909910 if (!oldMessages .isEmpty ()) {
@@ -942,7 +943,7 @@ private static void loadHistory(Long serviceID, Map<Long, MUCRoom> rooms) throws
942943 from = System .currentTimeMillis () - (BigInteger .valueOf (86400000 ).multiply (BigInteger .valueOf (reloadLimitDays ))).longValue ();
943944 }
944945 statement .setLong (1 , serviceID );
945- statement .setTimestamp (2 , new Timestamp ( from ), Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) ));
946+ statement .setObject (2 , Instant . ofEpochMilli ( from ));
946947 resultSet = statement .executeQuery ();
947948
948949 while (resultSet .next ()) {
@@ -954,11 +955,11 @@ private static void loadHistory(Long serviceID, Map<Long, MUCRoom> rooms) throws
954955 }
955956 String senderJID = resultSet .getString ("sender" );
956957 String nickname = resultSet .getString ("nickname" );
957- Date sentDate = resultSet .getTimestamp ("logTime" , Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" )) );
958+ Instant sentDate = resultSet .getObject ("logTime" , Instant . class );
958959 String subject = resultSet .getString ("subject" );
959960 String body = resultSet .getString ("body" );
960961 String stanza = resultSet .getString ("stanza" );
961- final Message message = room .getRoomHistory ().parseHistoricMessage (senderJID , nickname , sentDate , subject , body , stanza );
962+ final Message message = room .getRoomHistory ().parseHistoricMessage (senderJID , nickname , Date . from ( sentDate ) , subject , body , stanza );
962963 room .getRoomHistory ().addOldMessages (message );
963964 } catch (SQLException e ) {
964965 Log .warn ("A database exception prevented the history for one particular MUC room to be loaded from the database." , e );
@@ -1125,7 +1126,7 @@ public static void updateRoomLock(MUCRoom room) {
11251126 try {
11261127 con = DbConnectionManager .getConnection ();
11271128 pstmt = con .prepareStatement (UPDATE_LOCK );
1128- pstmt .setTimestamp (1 , new Timestamp ( room .getLockedDate ().getTime ()), Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) ));
1129+ pstmt .setObject (1 , room .getLockedDate ().toInstant ( ));
11291130 pstmt .setLong (2 , room .getID ());
11301131 pstmt .executeUpdate ();
11311132 }
@@ -1154,10 +1155,10 @@ public static void updateRoomEmptyDate(MUCRoom room) {
11541155 pstmt = con .prepareStatement (UPDATE_EMPTYDATE );
11551156 Date emptyDate = room .getEmptyDate ();
11561157 if (emptyDate == null ) {
1157- pstmt .setTimestamp (1 , null );
1158+ pstmt .setObject (1 , null );
11581159 }
11591160 else {
1160- pstmt .setTimestamp (1 , new Timestamp ( emptyDate .getTime ()), Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) ));
1161+ pstmt .setObject (1 , emptyDate .toInstant ( ));
11611162 }
11621163 pstmt .setLong (2 , room .getID ());
11631164 pstmt .executeUpdate ();
@@ -1428,7 +1429,7 @@ public static boolean saveConversationLogBatch(List<ConversationLogEntry> batch)
14281429 pstmt .setLong (2 , entry .getMessageID ());
14291430 pstmt .setString (3 , entry .getSender ().toString ());
14301431 pstmt .setString (4 , entry .getNickname ());
1431- pstmt .setTimestamp (5 , new Timestamp ( entry .getDate ().getTime ()), Calendar . getInstance ( TimeZone . getTimeZone ( "UTC" ) ));
1432+ pstmt .setObject (5 , entry .getDate ().toInstant ( ));
14321433 pstmt .setString (6 , entry .getSubject ());
14331434 pstmt .setString (7 , entry .getBody ());
14341435 pstmt .setString (8 , entry .getStanza ());
0 commit comments