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