1 /* 2 * Copyright (c) 2002-2022, City of Paris 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright notice 10 * and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright notice 13 * and the following disclaimer in the documentation and/or other materials 14 * provided with the distribution. 15 * 16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 * 32 * License 1.0 33 */ 34 35 36 package fr.paris.lutece.plugins.termofservice.business; 37 38 import fr.paris.lutece.portal.service.plugin.Plugin; 39 import fr.paris.lutece.portal.service.plugin.PluginService; 40 import fr.paris.lutece.portal.service.spring.SpringContextService; 41 import fr.paris.lutece.util.ReferenceList; 42 43 44 import java.util.List; 45 import java.util.Optional; 46 47 /** 48 * This class provides instances management methods (create, find, ...) for Entry objects 49 */ 50 public final class EntryHome 51 { 52 // Static variable pointed at the DAO instance 53 private static IEntryDAO _dao = SpringContextService.getBean( "termofservice.entryDAO" ); 54 private static Plugin _plugin = PluginService.getPlugin( "termofservice" ); 55 56 /** 57 * Private constructor - this class need not be instantiated 58 */ 59 private EntryHome( ) 60 { 61 } 62 63 /** 64 * Create an instance of the entry class 65 * @param entry The instance of the Entry which contains the informations to store 66 * @return The instance of entry which has been created with its primary key. 67 */ 68 public static Entryf="../../../../../../fr/paris/lutece/plugins/termofservice/business/Entry.html#Entry">Entry create( Entry entry ) 69 { 70 _dao.insert( entry, _plugin ); 71 72 return entry; 73 } 74 75 /** 76 * Update of the entry which is specified in parameter 77 * @param entry The instance of the Entry which contains the data to store 78 * @return The instance of the entry which has been updated 79 */ 80 public static Entryf="../../../../../../fr/paris/lutece/plugins/termofservice/business/Entry.html#Entry">Entry update( Entry entry ) 81 { 82 _dao.store( entry, _plugin ); 83 84 return entry; 85 } 86 87 /** 88 * Remove the entry whose identifier is specified in parameter 89 * @param nKey The entry Id 90 */ 91 public static void remove( int nKey ) 92 { 93 _dao.delete( nKey, _plugin ); 94 } 95 96 /** 97 * Returns an instance of a entry whose identifier is specified in parameter 98 * @param nKey The entry primary key 99 * @return an instance of Entry 100 */ 101 public static Optional<Entry> findByPrimaryKey( int nKey ) 102 { 103 return _dao.load( nKey, _plugin ); 104 } 105 106 /** 107 * Returns an instance of a entry whose identifier is specified in parameter 108 * @param nKey The entry primary key 109 * @return an instance of Entry 110 */ 111 public static Optional<Entry> findByLastVersion( ) 112 { 113 return _dao.loadLastVersion( _plugin ); 114 } 115 116 /** 117 * Load the data of all the entry objects and returns them as a list 118 * @return the list which contains the data of all the entry objects 119 */ 120 public static List<Entry> getEntrysList( ) 121 { 122 return _dao.selectEntrysList( _plugin ); 123 } 124 125 /** 126 * Load the id of all the entry objects and returns them as a list 127 * @return the list which contains the id of all the entry objects 128 */ 129 public static List<Integer> getIdEntrysList( ) 130 { 131 return _dao.selectIdEntrysList( _plugin ); 132 } 133 134 /** 135 * Load the data of all the entry objects and returns them as a referenceList 136 * @return the referenceList which contains the data of all the entry objects 137 */ 138 public static ReferenceList getEntrysReferenceList( ) 139 { 140 return _dao.selectEntrysReferenceList( _plugin ); 141 } 142 143 144 /** 145 * Load the data of all the avant objects and returns them as a list 146 * @param listIds liste of ids 147 * @return the list which contains the data of all the avant objects 148 */ 149 public static List<Entry> getEntrysListByIds( List<Integer> listIds ) 150 { 151 return _dao.selectEntrysListByIds( _plugin, listIds ); 152 } 153 154 } 155