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.dila.business.stylesheet.dao.impl;
35
36 import fr.paris.lutece.plugins.dila.business.stylesheet.dao.IContentTypeDAO;
37 import fr.paris.lutece.plugins.dila.business.stylesheet.dto.ContentType;
38 import fr.paris.lutece.plugins.dila.service.DilaPlugin;
39 import fr.paris.lutece.portal.service.plugin.PluginService;
40 import fr.paris.lutece.util.sql.DAOUtil;
41
42 import java.io.Serializable;
43 import java.util.ArrayList;
44 import java.util.List;
45
46
47
48
49
50 public class ContentTypeDAO implements IContentTypeDAO, Serializable
51 {
52
53 private static final long serialVersionUID = -5939477738412898729L;
54
55
56 private static final String SQL_QUERY_SELECT_ALL_CONTENT_TYPE = "SELECT id, label FROM dila_content_type ORDER BY id ASC";
57 private static final String SQL_QUERY_SELECT = "SELECT id, label FROM dila_content_type WHERE id = ?";
58 private static final String SQL_QUERY_SELECT_CONTENT_TYPE_WITHOUT_ASSOCIATED_STYLESHEET = "SELECT id, label FROM dila_content_type WHERE id NOT IN (SELECT content_type_id FROM dila_stylesheet WHERE id_stylesheet <> ? ) ORDER BY id ASC";
59
60 @Override
61 public List<ContentType> getContentTypes( )
62 {
63 List<ContentType> result = new ArrayList<ContentType>( );
64
65 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ALL_CONTENT_TYPE,
66 PluginService.getPlugin( DilaPlugin.PLUGIN_NAME ) );
67
68 daoUtil.executeQuery( );
69
70 while ( daoUtil.next( ) )
71 {
72 ContentType contentType = new ContentType( );
73 contentType.setId( daoUtil.getInt( 1 ) );
74 contentType.setLabel( daoUtil.getString( 2 ) );
75
76 result.add( contentType );
77 }
78
79 daoUtil.free( );
80
81 return result;
82 }
83
84 @Override
85 public ContentType findByPrimaryKey( Integer nIdTypeContenu )
86 {
87 ContentType contentType = null;
88 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, PluginService.getPlugin( DilaPlugin.PLUGIN_NAME ) );
89 daoUtil.setInt( 1, nIdTypeContenu );
90
91 daoUtil.executeQuery( );
92
93 if ( daoUtil.next( ) )
94 {
95 contentType = new ContentType( );
96 contentType.setId( daoUtil.getInt( 1 ) );
97 contentType.setLabel( daoUtil.getString( 2 ) );
98 }
99
100 daoUtil.free( );
101
102 return contentType;
103 }
104
105 @Override
106 public List<ContentType> getContentTypesWithoutAssociatedStyleSheet( Integer nIdStylesheet )
107 {
108 List<ContentType> result = new ArrayList<ContentType>( );
109
110 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_CONTENT_TYPE_WITHOUT_ASSOCIATED_STYLESHEET,
111 PluginService.getPlugin( DilaPlugin.PLUGIN_NAME ) );
112 daoUtil.setInt( 1, nIdStylesheet );
113
114 daoUtil.executeQuery( );
115
116 while ( daoUtil.next( ) )
117 {
118 ContentType typeContenu = new ContentType( );
119 typeContenu.setId( daoUtil.getInt( 1 ) );
120 typeContenu.setLabel( daoUtil.getString( 2 ) );
121
122 result.add( typeContenu );
123 }
124
125 daoUtil.free( );
126
127 return result;
128 }
129 }