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.portal.business.portalcomponent;
35
36 import fr.paris.lutece.portal.business.stylesheet.StyleSheet;
37 import fr.paris.lutece.util.sql.DAOUtil;
38
39
40
41
42 public final class PortalComponentDAO implements IPortalComponentDAO
43 {
44
45 private static final String SQL_QUERY_SELECT = " SELECT name FROM core_portal_component WHERE id_portal_component = ?";
46 private static final String SQL_QUERY_INSERT = " INSERT INTO core_portal_component ( id_portal_component, name ) VALUES ( ?, ? )";
47 private static final String SQL_QUERY_DELETE = " DELETE FROM core_portal_component WHERE id_portal_component = ?";
48 private static final String SQL_QUERY_UPDATE = " UPDATE core_portal_component SET id_portal_component = ?, name = ? " + " WHERE id_portal_component = ?";
49 private static final String SQL_QUERY_SELECTXSL = " SELECT a.id_stylesheet , a.description , a.file_name, a.source "
50 + " FROM core_stylesheet a, core_portal_component b, core_style_mode_stylesheet c, core_style d "
51 + " WHERE a.id_stylesheet = c.id_stylesheet AND d.id_style = c.id_style "
52 + " AND b.id_portal_component = d.id_portal_component AND d.id_portal_component = ? " + " AND c.id_mode = ? ";
53
54
55
56
57
58
59
60 public synchronized void insert( PortalComponent portalComponent )
61 {
62 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT ) )
63 {
64
65 daoUtil.setInt( 1, portalComponent.getId( ) );
66 daoUtil.setString( 2, portalComponent.getName( ) );
67
68 daoUtil.executeUpdate( );
69 }
70 }
71
72
73
74
75 public PortalComponent load( int nPortalComponentId )
76 {
77 PortalComponent portalComponent = null;
78 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
79 {
80 daoUtil.setInt( 1, nPortalComponentId );
81
82 daoUtil.executeQuery( );
83
84 if ( daoUtil.next( ) )
85 {
86 portalComponent = new PortalComponent( );
87
88 portalComponent.setId( nPortalComponentId );
89 portalComponent.setName( daoUtil.getString( 1 ) );
90 }
91
92 }
93
94 return portalComponent;
95 }
96
97
98
99
100 public void delete( int nPortalComponentId )
101 {
102 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
103 {
104 daoUtil.setInt( 1, nPortalComponentId );
105
106 daoUtil.executeUpdate( );
107 }
108 }
109
110
111
112
113 public void store( PortalComponent portalComponent )
114 {
115 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE ) )
116 {
117
118 daoUtil.setInt( 1, portalComponent.getId( ) );
119 daoUtil.setString( 2, portalComponent.getName( ) );
120 daoUtil.setInt( 3, portalComponent.getId( ) );
121
122 daoUtil.executeUpdate( );
123 }
124 }
125
126
127
128
129 public StyleSheet selectXslFile( int nPortalComponentId, int nIdMode )
130 {
131 StyleSheets/stylesheet/StyleSheet.html#StyleSheet">StyleSheet stylesheet = new StyleSheet( );
132 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTXSL ) )
133 {
134
135 daoUtil.setInt( 1, nPortalComponentId );
136 daoUtil.setInt( 2, nIdMode );
137
138 daoUtil.executeQuery( );
139
140 if ( daoUtil.next( ) )
141 {
142 stylesheet.setId( daoUtil.getInt( 1 ) );
143 stylesheet.setDescription( daoUtil.getString( 2 ) );
144 stylesheet.setFile( daoUtil.getString( 3 ) );
145 stylesheet.setSource( daoUtil.getBytes( 4 ) );
146 }
147
148 }
149
150 return stylesheet;
151 }
152 }