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.blog.business;
35
36 import fr.paris.lutece.plugins.blog.utils.BlogUtils;
37 import fr.paris.lutece.portal.service.plugin.Plugin;
38 import fr.paris.lutece.util.sql.DAOUtil;
39
40 import java.sql.Statement;
41 import java.util.ArrayList;
42 import java.util.List;
43
44
45
46
47 public final class IndexerActionDAO implements IIndexerActionDAO
48 {
49
50 private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = "SELECT id_action,id_blog,id_task" + " FROM blog_indexer_action WHERE id_action = ?";
51 private static final String SQL_QUERY_INSERT = "INSERT INTO blog_indexer_action( id_blog,id_task) VALUES(?,?)";
52 private static final String SQL_QUERY_DELETE = "DELETE FROM blog_indexer_action WHERE id_action = ? ";
53 private static final String SQL_QUERY_SELECT = "SELECT id_action,id_blog,id_task" + " FROM blog_indexer_action ";
54 private static final String SQL_FILTER_ID_TASK = " id_task = ? ";
55 private static final String SQL_FILTER_ID_BLOG = " id_blog = ? ";
56
57
58
59
60 @Override
61 public synchronized void insert( IndexerAction indexerAction, Plugin plugin )
62 {
63 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, Statement.RETURN_GENERATED_KEYS, plugin ) )
64 {
65 daoUtil.setInt( 1, indexerAction.getIdBlog( ) );
66 daoUtil.setInt( 2, indexerAction.getIdTask( ) );
67
68 daoUtil.executeUpdate( );
69 if ( daoUtil.nextGeneratedKey( ) )
70 {
71 indexerAction.setIdAction( daoUtil.getGeneratedKeyInt( 1 ) );
72 }
73 }
74 }
75
76
77
78
79 @Override
80 public IndexerAction load( int nId, Plugin plugin )
81 {
82 IndexerAction indexerAction = null;
83
84 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, plugin ) )
85 {
86 daoUtil.setInt( 1, nId );
87 daoUtil.executeQuery( );
88
89 if ( daoUtil.next( ) )
90 {
91 indexerAction = new IndexerAction( );
92 indexerAction.setIdAction( daoUtil.getInt( 1 ) );
93 indexerAction.setIdBlog( daoUtil.getInt( 2 ) );
94 indexerAction.setIdTask( daoUtil.getInt( 3 ) );
95 }
96 }
97
98 return indexerAction;
99 }
100
101
102
103
104 @Override
105 public void delete( int nId, Plugin plugin )
106 {
107 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin ) )
108 {
109 daoUtil.setInt( 1, nId );
110 daoUtil.executeUpdate( );
111 }
112 }
113
114
115
116
117 @Override
118 public List<IndexerAction> selectList( IndexerActionFilter filter, Plugin plugin )
119 {
120 List<IndexerAction> indexerActionList = new ArrayList<>( );
121 IndexerAction indexerAction = null;
122 List<String> listStrFilter = new ArrayList<>( );
123
124 if ( filter.containsIdTask( ) )
125 {
126 listStrFilter.add( SQL_FILTER_ID_TASK );
127 }
128
129 if ( filter.containsIdBlog( ) )
130 {
131 listStrFilter.add( SQL_FILTER_ID_BLOG );
132 }
133
134 String strSQL = BlogUtils.buildRequetteWithFilter( SQL_QUERY_SELECT, listStrFilter, null );
135
136 try ( DAOUtil daoUtil = new DAOUtil( strSQL, plugin ) )
137 {
138
139 int nIndex = 1;
140
141 if ( filter.containsIdTask( ) )
142 {
143 daoUtil.setInt( nIndex, filter.getIdTask( ) );
144 nIndex++;
145 }
146
147 if ( filter.containsIdBlog( ) )
148 {
149 daoUtil.setInt( nIndex, filter.getIdBlog( ) );
150 }
151
152 daoUtil.executeQuery( );
153
154 while ( daoUtil.next( ) )
155 {
156 indexerAction = new IndexerAction( );
157 indexerAction.setIdAction( daoUtil.getInt( 1 ) );
158 indexerAction.setIdBlog( daoUtil.getInt( 2 ) );
159 indexerAction.setIdTask( daoUtil.getInt( 3 ) );
160
161 indexerActionList.add( indexerAction );
162 }
163
164 }
165
166 return indexerActionList;
167 }
168 }