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.parisvideo.business;
35
36 import java.sql.Timestamp;
37 import java.util.ArrayList;
38 import java.util.Collection;
39
40 import fr.paris.lutece.portal.service.plugin.Plugin;
41 import fr.paris.lutece.util.sql.DAOUtil;
42
43
44
45
46
47 public class ParisVideoDAO implements IParisVideoDAO
48 {
49
50 private static final String SQL_QUERY_NEWPK = "SELECT max( id_account ) FROM parisvideo_account ";
51 private static final String SQL_QUERY_SELECTALL = "SELECT id_account, name, login, password FROM parisvideo_account";
52 private static final String SQL_QUERY_INSERT = "INSERT INTO parisvideo_account ( id_account , name, login, password, date_update ) VALUES ( ?, ?, ?, ?, ? ) ";
53 private static final String SQL_QUERY_DELETEALL = "DELETE FROM parisvideo_account";
54
55
56
57
58
59
60 private int newPrimaryKey( Plugin plugin )
61 {
62 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEWPK, plugin );
63 daoUtil.executeQuery( );
64
65 int nKey;
66
67 if ( !daoUtil.next( ) )
68 {
69
70 nKey = 1;
71 }
72
73 nKey = daoUtil.getInt( 1 ) + 1;
74
75 daoUtil.free( );
76
77 return nKey;
78 }
79
80
81
82
83
84
85
86 public void insert( ParisVideoAccount parisVideoAccount, Plugin plugin )
87 {
88 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
89 int id = newPrimaryKey( plugin );
90 parisVideoAccount.setId( id );
91 daoUtil.setInt( 1, parisVideoAccount.getId( ) );
92 daoUtil.setString( 2, parisVideoAccount.getName( ) );
93 daoUtil.setString( 3, parisVideoAccount.getLogin( ) );
94 daoUtil.setString( 4, parisVideoAccount.getPassword( ) );
95 daoUtil.setTimestamp( 5, new Timestamp( new java.util.Date( ).getTime( ) ) );
96 daoUtil.executeUpdate( );
97 daoUtil.free( );
98 }
99
100
101
102
103
104
105
106 public Collection<ParisVideoAccount> selectAll( Plugin plugin )
107 {
108 Collection<ParisVideoAccount> parisVideoAccountList = new ArrayList<ParisVideoAccount>( );
109 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin );
110 daoUtil.executeQuery( );
111
112 while ( daoUtil.next( ) )
113 {
114 ParisVideoAccount parisVideoAccount = new ParisVideoAccount( );
115 parisVideoAccount.setId( daoUtil.getInt( 1 ) );
116 parisVideoAccount.setName( daoUtil.getString( 2 ) );
117 parisVideoAccount.setLogin( daoUtil.getString( 3 ) );
118 parisVideoAccount.setPassword( daoUtil.getString( 4 ) );
119
120 parisVideoAccountList.add( parisVideoAccount );
121 }
122
123 daoUtil.free( );
124
125 return parisVideoAccountList;
126 }
127
128 public void deleteAll(Plugin plugin)
129 {
130 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETEALL, plugin );
131 daoUtil.executeUpdate( );
132 daoUtil.free( );
133 }
134 }