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.genericattributes.business;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.util.sql.DAOUtil;
38
39 import java.util.ArrayList;
40 import java.util.List;
41
42
43
44
45
46
47 public class EntryTypeDAO implements IEntryTypeDAO
48 {
49 private static final String SQL_QUERY_ORDER_BY = " order by display_order ASC ";
50 private static final String SQL_QUERY_SELECT_ALL = "SELECT id_type,title,is_group,is_comment,class_name,icon_name,is_mylutece_user,plugin,display_order,inactive"
51 + " FROM genatt_entry_type ";
52 private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = SQL_QUERY_SELECT_ALL + " WHERE id_type=?";
53 private static final String SQL_QUERY_SELECT = SQL_QUERY_SELECT_ALL + " WHERE plugin = ? " + SQL_QUERY_ORDER_BY;
54 private static final String SQL_QUERY_UPDATE = "UPDATE genatt_entry_type SET title = ?,is_group = ?,is_comment = ?,class_name = ?,icon_name = ?,is_mylutece_user = ?,plugin = ?,display_order = ?,inactive = ? WHERE id_type = ? ";
55
56
57
58
59 @Override
60 public EntryType load( int idKey, Plugin plugin )
61 {
62 EntryType entryType = null;
63 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, plugin ) )
64 {
65 daoUtil.setInt( 1, idKey );
66 daoUtil.executeQuery( );
67
68 if ( daoUtil.next( ) )
69 {
70 entryType = dataToObject( daoUtil );
71 }
72 }
73 return entryType;
74 }
75
76 @Override
77 public List<EntryType> selectAll( Plugin plugin )
78 {
79 List<EntryType> listEntryType = new ArrayList<>( );
80 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ALL + SQL_QUERY_ORDER_BY, plugin ) )
81 {
82 daoUtil.executeQuery( );
83
84 while ( daoUtil.next( ) )
85 {
86 EntryType entryType = dataToObject( daoUtil );
87 listEntryType.add( entryType );
88 }
89 }
90 return listEntryType;
91 }
92
93
94
95
96 @Override
97 public List<EntryType> select( String strPlugin, Plugin plugin )
98 {
99 List<EntryType> listEntryType = new ArrayList<>( );
100 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin ) )
101 {
102 daoUtil.setString( 1, strPlugin );
103 daoUtil.executeQuery( );
104
105 while ( daoUtil.next( ) )
106 {
107 EntryType entryType = dataToObject( daoUtil );
108 listEntryType.add( entryType );
109 }
110
111 }
112
113 return listEntryType;
114 }
115
116 private EntryType dataToObject( DAOUtil daoUtil )
117 {
118 int index = 0;
119 EntryTypericattributes/business/EntryType.html#EntryType">EntryType entryType = new EntryType( );
120 entryType.setIdType( daoUtil.getInt( ++index ) );
121 entryType.setTitle( daoUtil.getString( ++index ) );
122 entryType.setGroup( daoUtil.getBoolean( ++index ) );
123 entryType.setComment( daoUtil.getBoolean( ++index ) );
124 entryType.setBeanName( daoUtil.getString( ++index ) );
125 entryType.setIconName( daoUtil.getString( ++index ) );
126 entryType.setMyLuteceUser( daoUtil.getBoolean( ++index ) );
127 entryType.setPlugin( daoUtil.getString( ++index ) );
128 entryType.setOrder( daoUtil.getInt( ++index ) );
129 entryType.setInactive( daoUtil.getBoolean( ++index ) );
130
131 return entryType;
132 }
133
134 @Override
135 public void store( EntryType entryType, Plugin plugin )
136 {
137 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin ) )
138 {
139 int index = 0;
140 daoUtil.setString( ++index, entryType.getTitle( ) );
141 daoUtil.setBoolean( ++index, entryType.getGroup( ) );
142 daoUtil.setBoolean( ++index, entryType.getComment( ) );
143 daoUtil.setString( ++index, entryType.getBeanName( ) );
144 daoUtil.setString( ++index, entryType.getIconName( ) );
145 daoUtil.setBoolean( ++index, entryType.getMyLuteceUser( ) );
146 daoUtil.setString( ++index, entryType.getPlugin( ) );
147 daoUtil.setInt( ++index, entryType.getOrder( ) );
148 daoUtil.setBoolean( ++index, entryType.isInactive( ) );
149
150 daoUtil.setInt( ++index, entryType.getIdType( ) );
151
152 daoUtil.executeUpdate( );
153 }
154
155 }
156 }