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.workflow.modules.elasticsearch.business;
35
36 import fr.paris.lutece.plugins.workflow.modules.elasticsearch.service.WorkflowElasticSearchPlugin;
37 import fr.paris.lutece.plugins.workflowcore.business.config.ITaskConfigDAO;
38 import fr.paris.lutece.util.sql.DAOUtil;
39
40
41
42
43 public class TaskElasticSearchConfigDAO implements ITaskConfigDAO<TaskElasticSearchConfig>
44 {
45
46 private static final String SQL_QUERY_INSERT = "INSERT INTO workflow_task_elasticsearch (id, `index`, bean_name) VALUES( ? , ? , ? )";
47 private static final String SQL_QUERY_DELETE = "DELETE FROM workflow_task_elasticsearch WHERE id = ?";
48 private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = "SELECT id, `index`, bean_name FROM workflow_task_elasticsearch WHERE id = ? ";
49 private static final String SQL_QUERY_UPDATE = "UPDATE workflow_task_elasticsearch SET `index` = ? , bean_name = ? WHERE id = ?";
50
51
52
53
54 @Override
55 public void delete( int nId )
56 {
57 DAOUtil dao = new DAOUtil( SQL_QUERY_DELETE, WorkflowElasticSearchPlugin.getPlugin( ) );
58 dao.setInt( 1, nId );
59 dao.executeUpdate( );
60 dao.free( );
61 }
62
63
64
65
66 @Override
67 public synchronized void insert( TaskElasticSearchConfig config )
68 {
69 DAOUtil dao = new DAOUtil( SQL_QUERY_INSERT, WorkflowElasticSearchPlugin.getPlugin( ) );
70
71 int nPos = 1;
72 dao.setInt( nPos++, config.getId( ) );
73 dao.setString( nPos++, config.getIndex( ) );
74 dao.setString( nPos++, config.getBeanName( ) );
75
76 dao.executeUpdate( );
77 dao.free( );
78 }
79
80
81
82
83 @Override
84 public TaskElasticSearchConfig load( int nId )
85 {
86 int nPos = 1;
87 TaskElasticSearchConfig config = null;
88 DAOUtil dao = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, WorkflowElasticSearchPlugin.getPlugin( ) );
89 dao.setInt( nPos, nId );
90 dao.executeQuery( );
91 if ( dao.next( ) )
92 {
93 config = new TaskElasticSearchConfig( );
94 config.setId( dao.getInt( nPos++ ) );
95 config.setIndex( dao.getString( nPos++ ) );
96 config.setBeanName( dao.getString( nPos ) );
97 }
98 dao.free( );
99 return config;
100 }
101
102
103
104
105 @Override
106 public void store( TaskElasticSearchConfig config )
107 {
108 int nPos = 1;
109 DAOUtil dao = new DAOUtil( SQL_QUERY_UPDATE, WorkflowElasticSearchPlugin.getPlugin( ) );
110 dao.setString( nPos++, config.getIndex( ) );
111 dao.setString( nPos++, config.getBeanName( ) );
112 dao.setInt( nPos, config.getId( ) );
113 dao.executeUpdate( );
114 dao.free( );
115 }
116
117 }