1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.stock.modules.recommendation.business;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.util.sql.DAOUtil;
38
39 import java.util.ArrayList;
40 import java.util.List;
41
42
43
44
45
46 public final class RecommendationDAO
47 {
48
49
50 private static final String SQL_QUERY_INSERT = "INSERT INTO stock_recommendation ( username, id_product, score ) VALUES ( ?, ?, ? ) ";
51 private static final String SQL_QUERY_DELETE = "DELETE FROM stock_recommendation WHERE username = ? ";
52 private static final String SQL_QUERY_SELECTALL = "SELECT username, id_product, score FROM stock_recommendation WHERE username = ?";
53
54
55
56
57
58
59
60
61
62
63 public void insert( Recommendation recommendation, Plugin plugin )
64 {
65 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
66
67 daoUtil.setString( 1, recommendation.getUsername( ) );
68 daoUtil.setInt( 2, recommendation.getIdProduct( ) );
69 daoUtil.setDouble( 3, recommendation.getScore( ) );
70
71 daoUtil.executeUpdate( );
72 daoUtil.free( );
73 }
74
75
76
77
78
79
80
81
82
83
84 public void deleteByUser( String strUsername, Plugin plugin )
85 {
86 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
87 daoUtil.setString( 1, strUsername );
88 daoUtil.executeUpdate( );
89 daoUtil.free( );
90 }
91
92
93
94
95
96
97
98
99
100
101
102 public List<Recommendation> selectRecommendationsByUser( String strUsername, Plugin plugin )
103 {
104 List<Recommendation> recommendationList = new ArrayList<Recommendation>( );
105 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin );
106 daoUtil.setString( 1, strUsername );
107 daoUtil.executeQuery( );
108
109 while ( daoUtil.next( ) )
110 {
111 Recommendation recommendation = new Recommendation( );
112
113 recommendation.setUsername( daoUtil.getString( 1 ) );
114 recommendation.setIdProduct( daoUtil.getInt( 2 ) );
115 recommendation.setScore( daoUtil.getDouble( 3 ) );
116
117 recommendationList.add( recommendation );
118 }
119
120 daoUtil.free( );
121 return recommendationList;
122 }
123
124 }