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.quicklinks.business;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.util.sql.DAOUtil;
38
39
40
41
42
43
44 public class EntrySelectDAO implements IEntrySpecificDAO
45 {
46 private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = "SELECT title,target FROM quicklinks_entry_select WHERE id_entry = ? ";
47 private static final String SQL_QUERY_INSERT = " INSERT INTO quicklinks_entry_select ( id_entry,title,target ) VALUES ( ?, ?, ? )";
48 private static final String SQL_QUERY_DELETE = " DELETE FROM quicklinks_entry_select WHERE id_entry = ?";
49 private static final String SQL_QUERY_UPDATE = " UPDATE quicklinks_entry_select SET title = ?, target = ? WHERE id_entry = ?";
50
51
52
53
54
55
56
57
58 public IEntryef="../../../../../../fr/paris/lutece/plugins/quicklinks/business/IEntry.html#IEntry">IEntry load( IEntry entry, Plugin plugin )
59 {
60 EntrySelect entrySelect = null;
61
62 if ( entry == null )
63 {
64 return null;
65 }
66
67 if ( entry instanceof EntrySelect )
68 {
69 entrySelect = (EntrySelect) entry;
70 }
71 else
72 {
73 return null;
74 }
75
76 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, plugin ) )
77 {
78 daoUtil.setInt( 1, entrySelect.getId( ) );
79 daoUtil.executeQuery( );
80
81 if ( daoUtil.next( ) )
82 {
83 entrySelect.setTitle( daoUtil.getString( 1 ) );
84 entrySelect.setTarget( daoUtil.getString( 2 ) );
85 }
86
87 }
88
89 return entrySelect;
90 }
91
92
93
94
95
96
97
98 public void delete( int nEntryId, Plugin plugin )
99 {
100 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin ) )
101 {
102 daoUtil.setInt( 1, nEntryId );
103
104 daoUtil.executeUpdate( );
105 }
106 }
107
108
109
110
111
112
113
114
115 public IEntry="../../../../../../fr/paris/lutece/plugins/quicklinks/business/IEntry.html#IEntry">IEntry insert( IEntry entry, Plugin plugin )
116 {
117 EntrySelect entrySelect = null;
118
119 if ( entry == null )
120 {
121 return null;
122 }
123
124 if ( entry instanceof EntrySelect )
125 {
126 entrySelect = (EntrySelect) entry;
127 }
128 else
129 {
130 return null;
131 }
132
133 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin ) )
134 {
135 int nParam = 1;
136 daoUtil.setInt( nParam++, entrySelect.getId( ) );
137 daoUtil.setString( nParam++, entrySelect.getTitle( ) );
138 daoUtil.setString( nParam++, entrySelect.getTarget( ) );
139
140 daoUtil.executeUpdate( );
141 }
142
143 return entry;
144 }
145
146
147
148
149
150
151
152 public void store( IEntry entry, Plugin plugin )
153 {
154 EntrySelect entrySelect = null;
155
156 if ( entry == null )
157 {
158 return;
159 }
160
161 if ( entry instanceof EntrySelect )
162 {
163 entrySelect = (EntrySelect) entry;
164 }
165 else
166 {
167 return;
168 }
169
170 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin ) )
171 {
172
173 int nParam = 1;
174 daoUtil.setString( nParam++, entrySelect.getTitle( ) );
175 daoUtil.setString( nParam++, entrySelect.getTarget( ) );
176 daoUtil.setInt( nParam++, entrySelect.getId( ) );
177 daoUtil.executeUpdate( );
178 }
179 }
180 }