| 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.ILocalCardChapterDAO; |
| 37 | |
import fr.paris.lutece.plugins.dila.business.fichelocale.dto.LocalCardChapterDTO; |
| 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 LocalCardChapterDAO implements ILocalCardChapterDAO, Serializable |
| 51 | |
{ |
| 52 | |
|
| 53 | |
private static final long serialVersionUID = 1871080044687399057L; |
| 54 | |
private static final String SQL_QUERY_NEW_PK = "SELECT max(id) FROM dila_local_card_chapter"; |
| 55 | |
private static final String SQL_QUERY_INSERT = " INSERT INTO dila_local_card_chapter " |
| 56 | |
+ "( id, title, content, position, local_card_id ) VALUES ( ?, ? ,?, ?, ?)"; |
| 57 | |
private static final String SQL_QUERY_DELETE_BY_CARD_ID = " DELETE FROM dila_local_card_chapter " |
| 58 | |
+ "WHERE local_card_id = ?"; |
| 59 | |
private static final String SQL_QUERY_FIND_BY_CARD_ID = " SELECT id, title, content, position from dila_local_card_chapter WHERE local_card_id = ? ORDER BY id ASC"; |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
private Long newPrimaryKey( ) |
| 66 | |
{ |
| 67 | 0 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, PluginService.getPlugin( DilaPlugin.PLUGIN_NAME ) ); |
| 68 | 0 | daoUtil.executeQuery( ); |
| 69 | |
|
| 70 | 0 | Long nKey = 1L; |
| 71 | |
|
| 72 | 0 | if ( daoUtil.next( ) ) |
| 73 | |
{ |
| 74 | 0 | nKey = daoUtil.getLong( 1 ) + 1L; |
| 75 | |
} |
| 76 | |
|
| 77 | 0 | daoUtil.free( ); |
| 78 | |
|
| 79 | 0 | return nKey; |
| 80 | |
} |
| 81 | |
|
| 82 | |
@Override |
| 83 | |
public void create( LocalCardChapterDTO chapter ) |
| 84 | |
{ |
| 85 | 0 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, PluginService.getPlugin( DilaPlugin.PLUGIN_NAME ) ); |
| 86 | |
|
| 87 | 0 | chapter.setLocalCardChapterId( newPrimaryKey( ) ); |
| 88 | |
|
| 89 | 0 | daoUtil.setLong( 1, chapter.getLocalCardChapterId( ) ); |
| 90 | 0 | daoUtil.setString( 2, chapter.getTitle( ) ); |
| 91 | 0 | daoUtil.setString( 3, chapter.getContent( ) ); |
| 92 | 0 | daoUtil.setInt( 4, chapter.getPosition( ) ); |
| 93 | 0 | daoUtil.setLong( 5, chapter.getLocalCard( ).getId( ) ); |
| 94 | |
|
| 95 | 0 | daoUtil.executeUpdate( ); |
| 96 | 0 | daoUtil.free( ); |
| 97 | 0 | } |
| 98 | |
|
| 99 | |
@Override |
| 100 | |
public void deleteByCardId( Long ficheId ) |
| 101 | |
{ |
| 102 | 0 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_BY_CARD_ID, PluginService.getPlugin( DilaPlugin.PLUGIN_NAME ) ); |
| 103 | |
|
| 104 | 0 | daoUtil.setLong( 1, ficheId ); |
| 105 | |
|
| 106 | 0 | daoUtil.executeUpdate( ); |
| 107 | 0 | daoUtil.free( ); |
| 108 | 0 | } |
| 109 | |
|
| 110 | |
@Override |
| 111 | |
public List<LocalCardChapterDTO> findByCardId( Long cardId ) |
| 112 | |
{ |
| 113 | 0 | List<LocalCardChapterDTO> results = new ArrayList<LocalCardChapterDTO>( ); |
| 114 | 0 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_CARD_ID, PluginService.getPlugin( DilaPlugin.PLUGIN_NAME ) ); |
| 115 | |
|
| 116 | 0 | daoUtil.setLong( 1, cardId ); |
| 117 | 0 | daoUtil.executeQuery( ); |
| 118 | |
|
| 119 | 0 | while ( daoUtil.next( ) ) |
| 120 | |
{ |
| 121 | 0 | LocalCardChapterDTO chapter = new LocalCardChapterDTO( ); |
| 122 | |
|
| 123 | 0 | chapter.setLocalCardChapterId( daoUtil.getLong( 1 ) ); |
| 124 | 0 | chapter.setTitle( daoUtil.getString( 2 ) ); |
| 125 | 0 | chapter.setContent( daoUtil.getString( 3 ) ); |
| 126 | 0 | chapter.setPosition( daoUtil.getInt( 4 ) ); |
| 127 | |
|
| 128 | 0 | results.add( chapter ); |
| 129 | 0 | } |
| 130 | |
|
| 131 | 0 | daoUtil.free( ); |
| 132 | |
|
| 133 | 0 | return results; |
| 134 | |
} |
| 135 | |
} |