| 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.fichelocale.dao.impl; |
| 35 | |
|
| 36 | |
import fr.paris.lutece.plugins.dila.business.fichelocale.dao.ILocalFolderLinkDAO; |
| 37 | |
import fr.paris.lutece.plugins.dila.business.fichelocale.dto.LocalFolderLinkDTO; |
| 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 | 0 | public class LocalFolderLinkDAO implements ILocalFolderLinkDAO, Serializable |
| 51 | |
{ |
| 52 | |
|
| 53 | |
private static final long serialVersionUID = 3635002841395718887L; |
| 54 | |
private static final String SQL_QUERY_NEW_PK = "SELECT max(id) FROM dila_local_folder_link"; |
| 55 | |
private static final String SQL_QUERY_INSERT = " INSERT INTO dila_local_folder_link " |
| 56 | |
+ "( id, title, position, card_id, local_folder_id ) VALUES ( ?, ? ,?, ?, ?)"; |
| 57 | |
private static final String SQL_QUERY_DELETE_BY_FOLDER_ID = " DELETE FROM dila_local_folder_link " |
| 58 | |
+ "WHERE local_folder_id = ?"; |
| 59 | |
private static final String SQL_QUERY_SELECT_BY_FOLDER_ID = " SELECT title, position, card_id FROM dila_local_folder_link " |
| 60 | |
+ "WHERE local_folder_id = ? ORDER BY position"; |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
private Long newPrimaryKey( ) |
| 67 | |
{ |
| 68 | 0 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, PluginService.getPlugin( DilaPlugin.PLUGIN_NAME ) ); |
| 69 | 0 | daoUtil.executeQuery( ); |
| 70 | |
|
| 71 | 0 | Long nKey = 1L; |
| 72 | |
|
| 73 | 0 | if ( daoUtil.next( ) ) |
| 74 | |
{ |
| 75 | |
|
| 76 | 0 | nKey = daoUtil.getLong( 1 ) + 1L; |
| 77 | |
} |
| 78 | |
|
| 79 | 0 | daoUtil.free( ); |
| 80 | |
|
| 81 | 0 | return nKey; |
| 82 | |
} |
| 83 | |
|
| 84 | |
@Override |
| 85 | |
public void insert( LocalFolderLinkDTO link ) |
| 86 | |
{ |
| 87 | 0 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, PluginService.getPlugin( DilaPlugin.PLUGIN_NAME ) ); |
| 88 | |
|
| 89 | 0 | link.setId( newPrimaryKey( ) ); |
| 90 | |
|
| 91 | 0 | daoUtil.setLong( 1, link.getId( ) ); |
| 92 | 0 | daoUtil.setString( 2, link.getTitle( ) ); |
| 93 | 0 | daoUtil.setInt( 3, link.getPosition( ) ); |
| 94 | 0 | daoUtil.setString( 4, link.getCardId( ) ); |
| 95 | 0 | daoUtil.setLong( 5, link.getLocalFolderId( ) ); |
| 96 | |
|
| 97 | 0 | daoUtil.executeUpdate( ); |
| 98 | 0 | daoUtil.free( ); |
| 99 | 0 | } |
| 100 | |
|
| 101 | |
@Override |
| 102 | |
public void deleteByFolderId( Long localFolderId ) |
| 103 | |
{ |
| 104 | 0 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_BY_FOLDER_ID, PluginService.getPlugin( DilaPlugin.PLUGIN_NAME ) ); |
| 105 | 0 | daoUtil.setLong( 1, localFolderId ); |
| 106 | 0 | daoUtil.executeUpdate( ); |
| 107 | 0 | daoUtil.free( ); |
| 108 | 0 | } |
| 109 | |
|
| 110 | |
@Override |
| 111 | |
public List<LocalFolderLinkDTO> findByFolderId( Long id ) |
| 112 | |
{ |
| 113 | 0 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_FOLDER_ID, PluginService.getPlugin( DilaPlugin.PLUGIN_NAME ) ); |
| 114 | |
|
| 115 | 0 | daoUtil.setLong( 1, id ); |
| 116 | 0 | daoUtil.executeQuery( ); |
| 117 | |
|
| 118 | 0 | List<LocalFolderLinkDTO> result = new ArrayList<LocalFolderLinkDTO>( ); |
| 119 | |
|
| 120 | 0 | while ( daoUtil.next( ) ) |
| 121 | |
{ |
| 122 | 0 | LocalFolderLinkDTO link = new LocalFolderLinkDTO( ); |
| 123 | |
|
| 124 | 0 | link.setTitle( daoUtil.getString( 1 ) ); |
| 125 | 0 | link.setPosition( daoUtil.getInt( 2 ) ); |
| 126 | 0 | link.setCardId( daoUtil.getString( 3 ) ); |
| 127 | |
|
| 128 | 0 | result.add( link ); |
| 129 | 0 | } |
| 130 | |
|
| 131 | 0 | daoUtil.free( ); |
| 132 | |
|
| 133 | 0 | return result; |
| 134 | |
} |
| 135 | |
} |