1
1
package com .louay .projects .model .dao .impl ;
2
2
3
+ import com .louay .projects .model .chains .communications .group .GroupImgPost ;
3
4
import com .louay .projects .model .chains .communications .group .GroupTextPost ;
4
5
import com .louay .projects .model .chains .communications .group .GroupPicture ;
5
6
import com .louay .projects .model .chains .groups .GroupsDetail ;
@@ -75,6 +76,30 @@ public Long insertGroupTextPost(GroupTextPost post) {
75
76
return post .getIdPost ();
76
77
}
77
78
79
+ @ Override
80
+ public Long insertGroupImgPost (GroupImgPost post ) {
81
+ try {
82
+ ConnectionWrapper wrapper = this .pool .getConnection ();
83
+ PreparedStatement insert = wrapper .getConnection ().prepareStatement ("INSERT INTO `group_img_post`(`idGroup`, " +
84
+ "`username`, `img`, `fileName`, `dateUpload`) VALUES (?, ?, ?, ?, ?);" , Statement .RETURN_GENERATED_KEYS );
85
+ insert .setString (1 , post .getIdGroup ());
86
+ insert .setString (2 , post .getUsername ());
87
+ insert .setBlob (3 , post .getImage ());
88
+ insert .setString (4 , post .getFileName ());
89
+ insert .setTimestamp (5 , post .getDateUpload ());
90
+ insert .executeUpdate ();
91
+
92
+ ResultSet resultSet = insert .getGeneratedKeys ();
93
+ if (resultSet .next ()) {
94
+ post .setIdPost (resultSet .getLong (1 ));
95
+ }
96
+ this .pool .release (wrapper );
97
+ } catch (SQLException e ) {
98
+ System .out .println (e .getMessage ());
99
+ }
100
+ return post .getIdPost ();
101
+ }
102
+
78
103
@ Override
79
104
public int insertGroupPicture (GroupPicture picture ) {
80
105
int result = 0 ;
@@ -151,6 +176,19 @@ public int updateGroupTextPostByIdComment(GroupTextPost post) {
151
176
return result ;
152
177
}
153
178
179
+ @ Override
180
+ public int updateGroupImgPostByIdComment (GroupImgPost post ) {
181
+ int result = 0 ;
182
+ try {
183
+ result = this .pool .updateQuery ("UPDATE `group_img_post` SET `idGroup` = ?, `username` = ?, " +
184
+ "`img` = ?, `fileName` = ?, `dateUpload` = ? WHERE `idPost` = ?;" , post .getIdGroup (), post .getUsername (),
185
+ post .getImage (), post .getFileName (), post .getDateUpload (), post .getIdPost ());
186
+ } catch (SQLException e ) {
187
+ System .out .println (e .getMessage ());
188
+ }
189
+ return result ;
190
+ }
191
+
154
192
@ Override
155
193
public int updateGroupPictureByIdGroup (GroupPicture picture ) {
156
194
int result = 0 ;
@@ -265,7 +303,7 @@ public void buildGroupTextPostContainer(ResultSet resultSet, Collection<GroupTex
265
303
@ Override
266
304
public Collection <GroupTextPost > findGroupTextPostByIdPost (GroupTextPost post ) {
267
305
@ SuppressWarnings (value = "unchecked" )
268
- Collection <GroupTextPost > container = (Collection <GroupTextPost >) ac .getBean ("groupCommentContainer " );
306
+ Collection <GroupTextPost > container = (Collection <GroupTextPost >) ac .getBean ("groupTextPostContainer " );
269
307
try {
270
308
ResultSet resultSet = this .pool .selectResult ("SELECT * FROM `group_post` WHERE `idPost` = ? " +
271
309
"ORDER BY `group_post`.`postDate` DESC;" , post .getIdPost ());
@@ -279,7 +317,7 @@ public Collection<GroupTextPost> findGroupTextPostByIdPost(GroupTextPost post) {
279
317
@ Override
280
318
public Collection <GroupTextPost > findGroupTextPostByIdGroup (GroupTextPost post ) {
281
319
@ SuppressWarnings (value = "unchecked" )
282
- Collection <GroupTextPost > container = (Collection <GroupTextPost >) ac .getBean ("groupCommentContainer " );
320
+ Collection <GroupTextPost > container = (Collection <GroupTextPost >) ac .getBean ("groupTextPostContainer " );
283
321
try {
284
322
ResultSet resultSet = this .pool .selectResult ("SELECT * FROM `group_post` WHERE `idGroupe` = ? " +
285
323
"ORDER BY `group_post`.`postDate` DESC;" , post .getIdGroup ());
@@ -293,7 +331,7 @@ public Collection<GroupTextPost> findGroupTextPostByIdGroup(GroupTextPost post)
293
331
@ Override
294
332
public Collection <GroupTextPost > findGroupTextPostByUsername (GroupTextPost post ) {
295
333
@ SuppressWarnings (value = "unchecked" )
296
- Collection <GroupTextPost > container = (Collection <GroupTextPost >) ac .getBean ("groupCommentContainer " );
334
+ Collection <GroupTextPost > container = (Collection <GroupTextPost >) ac .getBean ("groupTextPostContainer " );
297
335
try {
298
336
ResultSet resultSet = this .pool .selectResult ("SELECT * FROM `group_post` WHERE `username` = ? " +
299
337
"ORDER BY `group_post`.`postDate` DESC;" , post .getUsername ());
@@ -307,7 +345,7 @@ public Collection<GroupTextPost> findGroupTextPostByUsername(GroupTextPost post)
307
345
@ Override
308
346
public Collection <GroupTextPost > findGroupTextPostByUsernameAndIdGroup (GroupTextPost post ) {
309
347
@ SuppressWarnings (value = "unchecked" )
310
- Collection <GroupTextPost > container = (Collection <GroupTextPost >) ac .getBean ("groupCommentContainer " );
348
+ Collection <GroupTextPost > container = (Collection <GroupTextPost >) ac .getBean ("groupTextPostContainer " );
311
349
try {
312
350
ResultSet resultSet = this .pool .selectResult ("SELECT * FROM `group_post` WHERE `username` = ? " +
313
351
"AND `idGroupe` = ? ORDER BY `group_post`.`postDate` DESC;" , post .getUsername (),
@@ -319,6 +357,45 @@ public Collection<GroupTextPost> findGroupTextPostByUsernameAndIdGroup(GroupText
319
357
return container ;
320
358
}
321
359
360
+ private GroupImgPost buildGroupImgPost (ResultSet resultSet ) {
361
+ GroupImgPost post = ac .getBean (GroupImgPost .class );
362
+ try {
363
+ post .setIdPost (resultSet .getLong (1 ));
364
+ post .setIdGroup (resultSet .getString (2 ));
365
+ post .setUsername (resultSet .getString (3 ));
366
+ post .setImage (resultSet .getBlob (4 ));
367
+ post .setFileName (resultSet .getString (5 ));
368
+ post .setDateUpload (resultSet .getTimestamp (6 ));
369
+ } catch (SQLException e ) {
370
+ System .out .println (e .getMessage ());
371
+ }
372
+ return post ;
373
+ }
374
+
375
+ public void buildGroupImgPostContainer (ResultSet resultSet , Collection <GroupImgPost > container ) {
376
+ try {
377
+ while (resultSet .next ()) {
378
+ container .add (buildGroupImgPost (resultSet ));
379
+ }
380
+ } catch (SQLException e ) {
381
+ System .out .println (e .getMessage ());
382
+ }
383
+ }
384
+
385
+ @ Override
386
+ public Collection <GroupImgPost > findGroupImgPostByUsername (GroupImgPost post ) {
387
+ @ SuppressWarnings (value = "unchecked" )
388
+ Collection <GroupImgPost > container = (Collection <GroupImgPost >) ac .getBean ("groupImgPostContainer" );
389
+ try {
390
+ ResultSet resultSet = this .pool .selectResult ("SELECT * FROM `group_img_post` WHERE `username` = ? " +
391
+ "ORDER BY `group_img_post`.`dateUpload` DESC;" , post .getUsername ());
392
+ buildGroupImgPostContainer (resultSet , container );
393
+ } catch (SQLException e ) {
394
+ System .out .println (e .getMessage ());
395
+ }
396
+ return container ;
397
+ }
398
+
322
399
private GroupInvite buildGroupInvite (ResultSet resultSet ) {
323
400
GroupInvite invite = ac .getBean (GroupInvite .class );
324
401
try {
@@ -536,6 +613,16 @@ public int deleteGroupTextPostByIdPost(GroupTextPost post) {
536
613
return result ;
537
614
}
538
615
616
+ @ Override
617
+ public int deleteGroupImgPostByIdPost (GroupImgPost post ) {
618
+ int result = 0 ;
619
+ try {
620
+ result = this .pool .updateQuery ("DELETE FROM `group_img_post` WHERE `idPost` = ?;" , post .getIdPost ());
621
+ } catch (SQLException e ) {
622
+ System .out .println (e .getMessage ());
623
+ }
624
+ return result ; }
625
+
539
626
@ Override
540
627
public int deleteGroupInviteByIdGroupAndUsername (GroupInvite invite ) {
541
628
int result = 0 ;
0 commit comments