1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.sensorframework.dao.file; |
5 | |
6 | import java.util.ArrayList; |
7 | import java.util.Collection; |
8 | import java.util.Collections; |
9 | import java.util.List; |
10 | |
11 | import de.uka.ipd.sdq.sensorframework.dao.file.entities.ExperimentImpl; |
12 | import de.uka.ipd.sdq.sensorframework.entities.Experiment; |
13 | import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory; |
14 | import de.uka.ipd.sdq.sensorframework.entities.dao.IExperimentDAO; |
15 | |
16 | /** |
17 | * @author Ihssane El-Oudghiri |
18 | * @author Steffen Becker |
19 | * |
20 | * Data Access Object (DAO) for persistence of Experiment Objects. |
21 | * |
22 | */ |
23 | public class FileExperimentDAO extends AbstractFileDAO<Experiment> implements IExperimentDAO { |
24 | |
25 | public FileExperimentDAO(IDAOFactory factory, IDGenerator idGen) { |
26 | super(factory,idGen,FileDAOFactory.EXP_FILE_NAME_PREFIX); |
27 | } |
28 | |
29 | public Experiment addExperiment(String p_experimentname) { |
30 | ExperimentImpl exp = new ExperimentImpl(factory); |
31 | exp.setExperimentID(idGen.getNextExperimentID()); |
32 | exp.setExperimentName(p_experimentname); |
33 | |
34 | this.putEntity(exp); |
35 | |
36 | return exp; |
37 | } |
38 | |
39 | /**{@inheritDoc}*/ |
40 | public Collection<Experiment> findByExperimentName(String searchKey) { |
41 | List<Experiment> result = new ArrayList<Experiment>(); |
42 | for (Experiment exp : getAllEntities()) |
43 | if (exp.getExperimentName().equals(searchKey)) |
44 | result.add(exp); |
45 | |
46 | return Collections.unmodifiableCollection(result); |
47 | } |
48 | |
49 | public Collection<Experiment> getExperiments() { |
50 | return this.getAllEntities(); |
51 | } |
52 | |
53 | public void removeExperiment(Experiment experiment, boolean doCascade) { |
54 | this.removeEntity(experiment, doCascade); |
55 | } |
56 | } |