View Javadoc
1   /*
2    * Copyright (c) 2002-2017, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.appcenter.modules.fastdeployapplication.business.task;
35  
36  import fr.paris.lutece.plugins.appcenter.modules.fastdeployapplication.service.AppCenterFastDeployApplicationPlugin;
37  import fr.paris.lutece.plugins.workflowcore.business.config.ITaskConfigDAO;
38  import fr.paris.lutece.portal.service.plugin.Plugin;
39  import fr.paris.lutece.portal.service.plugin.PluginService;
40  import fr.paris.lutece.util.sql.DAOUtil;
41  
42  
43  /**
44   *
45   * TaskRunDeploymentActionConfigDAO
46   *
47   */
48  public class TaskRunServerActionConfigDAO implements ITaskConfigDAO<TaskRunServerActionConfig>
49  {
50      private static final String SQL_QUERY_INSERT = "INSERT INTO task_run_server_action_cf(id_task,action_key)"
51              + "VALUES (?,?)";
52      private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = "SELECT id_task,action_key FROM task_run_server_action_cf  WHERE id_task=?";
53      private static final String SQL_QUERY_UPDATE = "UPDATE task_run_server_action_cf SET action_key = ? WHERE id_task = ? ";
54      private static final String SQL_QUERY_DELETE = "DELETE FROM task_run_server_action_cf WHERE id_task = ? ";
55  
56      /**
57       * Get the WorkflowUserGu plugin
58       * @return The WorkflowUserGu plugin
59       */
60      private Plugin getPlugin( )
61      {
62          return PluginService.getPlugin( AppCenterFastDeployApplicationPlugin.PLUGIN_NAME );
63      }
64  
65      /**
66       * {@inheritDoc}
67       */
68      @Override
69      public synchronized void insert( TaskRunServerActionConfig config )
70      {
71          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, getPlugin( ) );
72  
73          int nPos = 0;
74  
75          daoUtil.setInt( ++nPos, config.getIdTask( ) );
76          daoUtil.setString( ++nPos, config.getActionKey() );
77  
78          daoUtil.executeUpdate(  );
79          daoUtil.free(  );
80      }
81  
82      /**
83       * {@inheritDoc}
84       */
85      @Override
86      public void store( TaskRunServerActionConfig config )
87      {
88          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, getPlugin( ) );
89  
90          int nPos = 0;
91  
92          daoUtil.setString( ++nPos, config.getActionKey());
93          daoUtil.setInt( ++nPos, config.getIdTask(  ) );
94  
95          daoUtil.executeUpdate(  );
96          daoUtil.free(  );
97      }
98  
99      /**
100      * {@inheritDoc}
101      */
102     @Override
103     public TaskRunServerActionConfig load( int nIdTask )
104     {
105         TaskRunServerActionConfig config = null;
106         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, getPlugin( ) );
107 
108         daoUtil.setInt( 1, nIdTask );
109 
110         daoUtil.executeQuery(  );
111 
112         int nPos = 0;
113 
114         if ( daoUtil.next(  ) )
115         {
116             config = new TaskRunServerActionConfig( );
117             config.setIdTask( daoUtil.getInt( ++nPos ) );
118             config.setActionKey( daoUtil.getString( ++nPos ) );
119         }
120 
121         daoUtil.free(  );
122 
123         return config;
124     }
125 
126     /**
127      * {@inheritDoc}
128      */
129     @Override
130     public void delete( int nIdState )
131     {
132         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, getPlugin( ) );
133 
134         daoUtil.setInt( 1, nIdState );
135         daoUtil.executeUpdate(  );
136         daoUtil.free(  );
137     }
138 }