30
30
import org .silverpeas .components .forums .model .Message ;
31
31
import org .silverpeas .components .forums .model .MessagePK ;
32
32
import org .silverpeas .components .forums .model .Moderator ;
33
- import org .silverpeas .core .exception .SilverpeasRuntimeException ;
34
33
import org .silverpeas .core .persistence .jdbc .DBUtil ;
35
34
import org .silverpeas .core .util .DateUtil ;
36
35
import org .silverpeas .core .util .StringUtil ;
51
50
import java .util .List ;
52
51
import java .util .stream .Collectors ;
53
52
53
+ import static org .silverpeas .core .SilverpeasExceptionMessages .failureOnGetting ;
54
+
54
55
/**
55
56
* Class managing database accesses for forums.
56
57
*/
@@ -159,7 +160,7 @@ private ForumsDAO() {
159
160
*/
160
161
public static Collection <ForumDetail > selectByForumPKs (Connection con ,
161
162
Collection <ForumPK > forumPKs ) throws SQLException {
162
- List <ForumDetail > forumDetails = new ArrayList <ForumDetail >(forumPKs .size ());
163
+ List <ForumDetail > forumDetails = new ArrayList <>(forumPKs .size ());
163
164
for (ForumPK forumPK : forumPKs ) {
164
165
forumDetails .add (getForumDetail (con , forumPK ));
165
166
}
@@ -174,7 +175,7 @@ public static Collection<ForumDetail> selectByForumPKs(Connection con,
174
175
*/
175
176
public static Collection <Forum > getForumsByKeys (Connection con , Collection <ForumPK > forumPKs )
176
177
throws SQLException {
177
- ArrayList <Forum > forums = new ArrayList <Forum >();
178
+ ArrayList <Forum > forums = new ArrayList <>();
178
179
Iterator <ForumPK > iterator = forumPKs .iterator ();
179
180
ForumPK forumPK ;
180
181
Forum forum ;
@@ -220,7 +221,7 @@ public static Collection<Message> getThreadsByKeys(Connection con,
220
221
*/
221
222
private static Collection <Message > getMessagesByKeys (Connection con ,
222
223
Collection <MessagePK > messagePKs , boolean onlyThreads ) throws SQLException {
223
- ArrayList <Message > messages = new ArrayList <Message >();
224
+ ArrayList <Message > messages = new ArrayList <>();
224
225
for (MessagePK messagePK : messagePKs ) {
225
226
Message message = (onlyThreads ? getThread (con , messagePK ) : getMessage (con , messagePK ));
226
227
if (message != null ) {
@@ -251,7 +252,7 @@ private static Collection<Message> getMessagesByKeys(Connection con,
251
252
public static List <Forum > getForumsList (Connection con , ForumPK forumPK ) throws SQLException {
252
253
253
254
254
- List <Forum > forums = new ArrayList <Forum >();
255
+ List <Forum > forums = new ArrayList <>();
255
256
PreparedStatement selectStmt = null ;
256
257
ResultSet rs = null ;
257
258
try {
@@ -277,7 +278,7 @@ public static List<String> getForumsIds(Connection con, ForumPK forumPK)
277
278
throws SQLException {
278
279
279
280
280
- ArrayList <String > forumsIds = new ArrayList <String >();
281
+ ArrayList <String > forumsIds = new ArrayList <>();
281
282
PreparedStatement selectStmt = null ;
282
283
ResultSet rs = null ;
283
284
try {
@@ -329,7 +330,7 @@ public static List<Forum> getForumsListByCategory(Connection con, ForumPK forumP
329
330
public static List <String > getForumSonsIds (Connection con , ForumPK forumPK ) throws SQLException {
330
331
331
332
332
- List <String > forumIds = new ArrayList <String >();
333
+ List <String > forumIds = new ArrayList <>();
333
334
PreparedStatement selectStmt = null ;
334
335
ResultSet rs = null ;
335
336
try {
@@ -487,9 +488,7 @@ public static String getForumCreatorId(Connection con, int forumId) throws SQLEx
487
488
if (rs .next ()) {
488
489
return rs .getString (FORUM_COLUMN_FORUM_CREATOR );
489
490
} else {
490
- throw new ForumsRuntimeException ("ForumsDAO.getForumCreatorId()" ,
491
- SilverpeasRuntimeException .ERROR , "root.EX_CANT_LOAD_ENTITY_ATTRIBUTES" ,
492
- "ForumId = " + forumId + " not found in database !" );
491
+ throw new ForumsRuntimeException (failureOnGetting ("forum" , forumId ));
493
492
}
494
493
} finally {
495
494
DBUtil .close (rs , stmt );
@@ -645,7 +644,9 @@ public static void updateForum(Connection con, ForumPK forumPK, String forumName
645
644
public static void deleteForum (Connection con , ForumPK forumPK ) throws SQLException {
646
645
String sForumId = forumPK .getId ();
647
646
int forumId = Integer .parseInt (sForumId );
648
- PreparedStatement deleteStmt1 = null , deleteStmt2 = null , deleteStmt3 = null ;
647
+ PreparedStatement deleteStmt1 = null ;
648
+ PreparedStatement deleteStmt2 = null ;
649
+ PreparedStatement deleteStmt3 = null ;
649
650
try {
650
651
deleteStmt1 = con .prepareStatement (QUERY_DELETE_FORUM_RIGHTS );
651
652
deleteStmt1 .setString (1 , sForumId );
@@ -715,7 +716,7 @@ public static List<Message> getMessagesList(Connection con, ForumPK forumPK)
715
716
throws SQLException {
716
717
717
718
718
- ArrayList <Message > messages = new ArrayList <Message >();
719
+ ArrayList <Message > messages = new ArrayList <>();
719
720
PreparedStatement selectStmt = null ;
720
721
ResultSet rs = null ;
721
722
try {
@@ -752,7 +753,7 @@ public static List<String> getMessagesIds(Connection con, ForumPK forumPK, int m
752
753
QUERY_GET_MESSAGES_IDS_BY_FORUM );
753
754
754
755
755
- ArrayList <String > messagesIds = new ArrayList <String >();
756
+ ArrayList <String > messagesIds = new ArrayList <>();
756
757
PreparedStatement selectStmt = null ;
757
758
ResultSet rs = null ;
758
759
try {
@@ -874,7 +875,7 @@ public static int getAuthorNbMessages(Connection con, String userId, String stat
874
875
public static int getNbResponses (Connection con , int forumId , int messageId , String status ) {
875
876
PreparedStatement prepStmt = null ;
876
877
ResultSet rs = null ;
877
- ArrayList <Integer > nextMessageIds = new ArrayList <Integer >();
878
+ ArrayList <Integer > nextMessageIds = new ArrayList <>();
878
879
try {
879
880
prepStmt = con .prepareStatement (QUERY_GET_NB_RESPONSES );
880
881
prepStmt .setInt (1 , forumId );
@@ -893,7 +894,7 @@ public static int getNbResponses(Connection con, int forumId, int messageId, Str
893
894
int nb = nextMessageIds .size ();
894
895
int nextMessageId ;
895
896
for (int i = 0 , n = nextMessageIds .size (); i < n ; i ++) {
896
- nextMessageId = (( Integer ) nextMessageIds .get (i )). intValue ( );
897
+ nextMessageId = (Integer ) nextMessageIds .get (i );
897
898
nb += getNbResponses (con , forumId , nextMessageId , status );
898
899
}
899
900
return nb ;
@@ -945,7 +946,7 @@ public static Message getLastMessage(Connection con, ForumPK forumPK, String sta
945
946
*/
946
947
public static List <Message > getLastThreads (Connection con , ForumPK [] forumPKs , int count )
947
948
throws SQLException {
948
- ArrayList <Message > messages = new ArrayList <Message >();
949
+ ArrayList <Message > messages = new ArrayList <>();
949
950
if (forumPKs .length > 0 ) {
950
951
StringBuilder selectQuery = new StringBuilder (
951
952
"SELECT " + MESSAGE_COLUMN_MESSAGE_ID + " FROM " + MESSAGE_TABLE + " WHERE " +
@@ -960,7 +961,7 @@ public static List<Message> getLastThreads(Connection con, ForumPK[] forumPKs, i
960
961
selectQuery .append (") ORDER BY " ).append (MESSAGE_COLUMN_MESSAGE_DATE ).append (" DESC" );
961
962
962
963
963
- ArrayList <String > messageIds = new ArrayList <String >(count );
964
+ ArrayList <String > messageIds = new ArrayList <>(count );
964
965
int messagesCount = 0 ;
965
966
PreparedStatement selectStmt = null ;
966
967
ResultSet rs = null ;
@@ -978,7 +979,7 @@ public static List<Message> getLastThreads(Connection con, ForumPK[] forumPKs, i
978
979
979
980
String componentName = forumPKs [0 ].getComponentName ();
980
981
for (int i = 0 ; i < messagesCount ; i ++) {
981
- MessagePK messagePK = new MessagePK (componentName , ( String ) messageIds .get (i ));
982
+ MessagePK messagePK = new MessagePK (componentName , messageIds .get (i ));
982
983
messages .add (getMessage (con , messagePK ));
983
984
}
984
985
}
@@ -995,7 +996,7 @@ public static List<Message> getLastThreads(Connection con, ForumPK[] forumPKs, i
995
996
*/
996
997
public static Collection <Message > getNotAnsweredLastThreads (Connection con , ForumPK [] forumPKs ,
997
998
int count ) throws SQLException {
998
- ArrayList <Message > messages = new ArrayList <Message >();
999
+ ArrayList <Message > messages = new ArrayList <>();
999
1000
if (forumPKs .length > 0 ) {
1000
1001
StringBuilder selectQuery = new StringBuilder (
1001
1002
"SELECT " + MESSAGE_COLUMN_MESSAGE_ID + ", " + MESSAGE_COLUMN_FORUM_ID + " FROM " +
@@ -1010,7 +1011,7 @@ public static Collection<Message> getNotAnsweredLastThreads(Connection con, Foru
1010
1011
selectQuery .append (") ORDER BY " + MESSAGE_COLUMN_MESSAGE_DATE + " DESC" );
1011
1012
1012
1013
1013
- ArrayList <String > messageIds = new ArrayList <String >(count );
1014
+ ArrayList <String > messageIds = new ArrayList <>(count );
1014
1015
int messageId ;
1015
1016
int forumId ;
1016
1017
int messagesCount = 0 ;
@@ -1066,7 +1067,7 @@ public static Collection<Message> getNotAnsweredLastThreads(Connection con, Foru
1066
1067
*/
1067
1068
public static Collection <String > getLastMessageRSS (Connection con , String instanceId )
1068
1069
throws SQLException {
1069
- Collection <String > messageIds = new ArrayList <String >();
1070
+ Collection <String > messageIds = new ArrayList <>();
1070
1071
Collection <Integer > forumIds = getAllForumsByInstanceId (con , instanceId );
1071
1072
Iterator <Integer > it = forumIds .iterator ();
1072
1073
while (it .hasNext ()) {
@@ -1086,7 +1087,7 @@ private static Collection<Integer> getAllForumsByInstanceId(Connection con, Stri
1086
1087
throws SQLException {
1087
1088
1088
1089
1089
- Collection <Integer > forumIds = new ArrayList <Integer >();
1090
+ Collection <Integer > forumIds = new ArrayList <>();
1090
1091
PreparedStatement selectStmt = null ;
1091
1092
ResultSet rs = null ;
1092
1093
try {
@@ -1117,7 +1118,7 @@ private static Collection<String> getAllMessageByForum(Connection con, int forum
1117
1118
throws SQLException {
1118
1119
1119
1120
1120
- Collection <String > messageIds = new ArrayList <String >();
1121
+ Collection <String > messageIds = new ArrayList <>();
1121
1122
PreparedStatement selectStmt = null ;
1122
1123
ResultSet rs = null ;
1123
1124
try {
@@ -1616,9 +1617,7 @@ public static ForumDetail getForumDetail(Connection con, ForumPK forumPK) throws
1616
1617
if (rs .next ()) {
1617
1618
return resultSet2ForumDetail (rs , forumPK );
1618
1619
} else {
1619
- throw new ForumsRuntimeException ("ForumsDAO.getForumDetail()" ,
1620
- SilverpeasRuntimeException .ERROR , "root.EX_CANT_LOAD_ENTITY_ATTRIBUTES" ,
1621
- "ForumId = " + forumPK .getId () + " not found in database !" );
1620
+ throw new ForumsRuntimeException (failureOnGetting ("forum" , forumPK .getId ()));
1622
1621
}
1623
1622
} finally {
1624
1623
DBUtil .close (rs , stmt );
0 commit comments