@@ -47,12 +47,11 @@ public final class TopicDAO implements ITopicDAO
4747 // Constants
4848 private static final String SQL_QUERY_NEW_PK = "SELECT max( id_topic ) FROM wiki_topic" ;
4949 private static final String SQL_QUERY_SELECT = "SELECT id_topic, namespace, page_name, page_view_role, page_edit_role, parent_page_name FROM wiki_topic WHERE id_topic = ?" ;
50- private static final String SQL_QUERY_INSERT = "INSERT INTO wiki_topic ( id_topic, namespace, page_name, page_view_role, page_edit_role, parent_page_name ) VALUES ( ?, ?, ?, ?, ?, ? ) " ;
50+ private static final String SQL_QUERY_INSERT = "INSERT INTO wiki_topic ( id_topic, namespace, page_name, page_view_role, page_edit_role, parent_page_name ) VALUES (?, ?, ?, ?, ?, ? ) " ;
5151 private static final String SQL_QUERY_DELETE = "DELETE FROM wiki_topic WHERE id_topic = ? " ;
5252 private static final String SQL_QUERY_UPDATE = "UPDATE wiki_topic SET id_topic = ?, namespace = ?, page_name = ?, page_view_role = ?, page_edit_role = ?, parent_page_name = ? WHERE id_topic = ?" ;
5353 private static final String SQL_QUERY_SELECTALL = "SELECT id_topic, namespace, page_name, page_view_role, page_edit_role, parent_page_name FROM wiki_topic" ;
5454 private static final String SQL_QUERY_SELECT_BY_NAME = "SELECT id_topic, namespace, page_name, page_view_role, page_edit_role, parent_page_name FROM wiki_topic WHERE page_name = ?" ;
55-
5655 /**
5756 * Generates a new primary key
5857 *
@@ -64,7 +63,7 @@ public int newPrimaryKey( Plugin plugin )
6463 {
6564 int nKey ;
6665
67- try ( DAOUtil daoUtil = new DAOUtil ( SQL_QUERY_NEW_PK , plugin ) )
66+ try ( DAOUtil daoUtil = new DAOUtil ( SQL_QUERY_NEW_PK , plugin ) )
6867 {
6968 daoUtil .executeQuery ( );
7069
@@ -81,7 +80,7 @@ public int newPrimaryKey( Plugin plugin )
8180 @ Override
8281 public void insert ( Topic topic , Plugin plugin )
8382 {
84- try ( DAOUtil daoUtil = new DAOUtil ( SQL_QUERY_INSERT , plugin ) )
83+ try ( DAOUtil daoUtil = new DAOUtil ( SQL_QUERY_INSERT , plugin ) )
8584 {
8685 topic .setIdTopic ( newPrimaryKey ( plugin ) );
8786
@@ -104,21 +103,14 @@ public Topic load( int nId, Plugin plugin )
104103 {
105104 Topic topic = null ;
106105
107- try ( DAOUtil daoUtil = new DAOUtil ( SQL_QUERY_SELECT , plugin ) )
106+ try ( DAOUtil daoUtil = new DAOUtil ( SQL_QUERY_SELECT , plugin ) )
108107 {
109108 daoUtil .setInt ( 1 , nId );
110109 daoUtil .executeQuery ( );
111110
112111 if ( daoUtil .next ( ) )
113112 {
114- topic = new Topic ( );
115-
116- topic .setIdTopic ( daoUtil .getInt ( 1 ) );
117- topic .setNamespace ( daoUtil .getInt ( 2 ) );
118- topic .setPageName ( daoUtil .getString ( 3 ) );
119- topic .setViewRole ( daoUtil .getString ( 4 ) );
120- topic .setEditRole ( daoUtil .getString ( 5 ) );
121- topic .setParentPageName ( daoUtil .getString ( 6 ) );
113+ topic = setTopicWithDaoUtil (daoUtil );
122114 }
123115 }
124116
@@ -131,7 +123,7 @@ public Topic load( int nId, Plugin plugin )
131123 @ Override
132124 public void delete ( int nTopicId , Plugin plugin )
133125 {
134- try ( DAOUtil daoUtil = new DAOUtil ( SQL_QUERY_DELETE , plugin ) )
126+ try ( DAOUtil daoUtil = new DAOUtil ( SQL_QUERY_DELETE , plugin ) )
135127 {
136128 daoUtil .setInt ( 1 , nTopicId );
137129 daoUtil .executeUpdate ( );
@@ -144,7 +136,7 @@ public void delete( int nTopicId, Plugin plugin )
144136 @ Override
145137 public void store ( Topic topic , Plugin plugin )
146138 {
147- try ( DAOUtil daoUtil = new DAOUtil ( SQL_QUERY_UPDATE , plugin ) )
139+ try ( DAOUtil daoUtil = new DAOUtil ( SQL_QUERY_UPDATE , plugin ) )
148140 {
149141 daoUtil .setInt ( 1 , topic .getIdTopic ( ) );
150142 daoUtil .setInt ( 2 , topic .getNamespace ( ) );
@@ -165,20 +157,13 @@ public void store( Topic topic, Plugin plugin )
165157 public Collection <Topic > selectTopicsList ( Plugin plugin )
166158 {
167159 Collection <Topic > topicList = new ArrayList <>( );
168- try ( DAOUtil daoUtil = new DAOUtil ( SQL_QUERY_SELECTALL , plugin ) )
160+ try ( DAOUtil daoUtil = new DAOUtil ( SQL_QUERY_SELECTALL , plugin ) )
169161 {
170162 daoUtil .executeQuery ( );
171163
172164 while ( daoUtil .next ( ) )
173165 {
174- Topic topic = new Topic ( );
175-
176- topic .setIdTopic ( daoUtil .getInt ( 1 ) );
177- topic .setNamespace ( daoUtil .getInt ( 2 ) );
178- topic .setPageName ( daoUtil .getString ( 3 ) );
179- topic .setViewRole ( daoUtil .getString ( 4 ) );
180- topic .setEditRole ( daoUtil .getString ( 5 ) );
181- topic .setParentPageName ( daoUtil .getString ( 6 ) );
166+ Topic topic = setTopicWithDaoUtil (daoUtil );
182167
183168 topicList .add ( topic );
184169 }
@@ -195,24 +180,30 @@ public Topic load( String strTopicName, Plugin plugin )
195180 {
196181 Topic topic = null ;
197182
198- try ( DAOUtil daoUtil = new DAOUtil ( SQL_QUERY_SELECT_BY_NAME , plugin ) )
183+ try ( DAOUtil daoUtil = new DAOUtil ( SQL_QUERY_SELECT_BY_NAME , plugin ) )
199184 {
200185 daoUtil .setString ( 1 , strTopicName );
201186 daoUtil .executeQuery ( );
202187
203188 if ( daoUtil .next ( ) )
204189 {
205- topic = new Topic ( );
206-
207- topic .setIdTopic ( daoUtil .getInt ( 1 ) );
208- topic .setNamespace ( daoUtil .getInt ( 2 ) );
209- topic .setPageName ( daoUtil .getString ( 3 ) );
210- topic .setViewRole ( daoUtil .getString ( 4 ) );
211- topic .setEditRole ( daoUtil .getString ( 5 ) );
212- topic .setParentPageName ( daoUtil .getString ( 6 ) );
190+ topic = setTopicWithDaoUtil (daoUtil );
213191 }
214192 }
215193
216194 return topic ;
217195 }
196+ /**
197+ * set the content of a topic version with doaUtil
198+ */
199+ public Topic setTopicWithDaoUtil (DAOUtil daoUtil ) {
200+ Topic topic = new Topic ( );
201+ topic .setIdTopic ( daoUtil .getInt ( 1 ) );
202+ topic .setNamespace ( daoUtil .getInt ( 2 ) );
203+ topic .setPageName ( daoUtil .getString ( 3 ) );
204+ topic .setViewRole ( daoUtil .getString ( 4 ) );
205+ topic .setEditRole ( daoUtil .getString ( 5 ) );
206+ topic .setParentPageName ( daoUtil .getString ( 6 ) );
207+ return topic ;
208+ }
218209}
0 commit comments