View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   //CabaWeb
3   //Copyright (C) 2004  Thomas Vogt <Thomas.Vogt@TVC-Software.com>
4   //
5   //This library is free software; you can redistribute it and/or
6   //modify it under the terms of the GNU Lesser General Public
7   //License as published by the Free Software Foundation; either
8   //version 2.1 of the License, or (at your option) any later version.
9   //
10  //This library is distributed in the hope that it will be useful,
11  //but WITHOUT ANY WARRANTY; without even the implied warranty of
12  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  //Lesser General Public License for more details.
14  //
15  //You should have received a copy of the GNU Lesser General Public
16  //License along with this library; if not, write to the Free Software
17  //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ////////////////////////////////////////////////////////////////////////////////
19  
20  package org.fhw.cabaweb.ojb;
21  
22  import java.util.ArrayList;
23  import java.util.Collection;
24  
25  import org.apache.ojb.broker.metadata.FieldHelper;
26  import org.apache.ojb.broker.query.Criteria;
27  import org.apache.ojb.broker.PersistenceBroker;
28  
29  import org.fhw.cabaweb.ojb.abstracts.AbstractUseCase;
30  import org.fhw.cabaweb.ojb.dataobjects.Projekte;
31  import org.fhw.cabaweb.ojb.dataobjects.Reportnamen;
32  
33  /***
34   * Abstrakte Klasse f&uuml;r die OJB Kapselung der Reportnamen
35   *
36   * @author  <a href="mailto:thomas.vogt@tvc-software.com">Thomas Vogt</a>
37   * @version Version 1.0 17.05.2004
38   */
39  public class UseCaseReportnamen extends AbstractUseCase
40  {
41      /*** Konstruktor
42       * 
43       * @param broker Instanz des Persistence Brokers
44       */
45      public UseCaseReportnamen(PersistenceBroker broker)
46      {
47          super(broker);
48      }
49  
50      /***
51        * @see org.fhw.cabaweb.ojb.abstracts.AbstractUseCase#erzeugen(java.lang.Object)
52        */
53      public final boolean erzeugen(Object arg)
54      {
55          Reportnamen newReportnamen = (Reportnamen) arg;
56          return anlegen(newReportnamen);
57      }
58  
59      /***
60        * @see org.fhw.cabaweb.ojb.abstracts.AbstractUseCase#editieren(java.lang.Object)
61        */
62      public final boolean editieren(Object arg)
63      {
64          boolean retval = true;
65          Reportnamen editReportnamenTemp = (Reportnamen) arg;
66          Reportnamen editReportnamen = null;
67  
68          Collection liste =  null;
69  
70          Criteria criteria = new Criteria();
71  
72          if (editReportnamenTemp.getReportnummer() != null)
73              criteria.addEqualTo("Reportnummer", editReportnamenTemp.getReportnummer());
74          if (editReportnamenTemp.getProjekte() != null && ((Projekte) editReportnamenTemp.getProjekte()).getProjektnummer() != null)
75              criteria.addEqualTo("Projektnummer", (editReportnamenTemp.getProjekte()).getProjektnummer());
76  
77          liste = sucheQBC(Reportnamen.class, criteria, null);
78          if(liste != null && liste.size() == 1)
79              editReportnamen = (Reportnamen) liste.iterator().next();
80  
81          // Editieren des existierenden Eintrags
82          editReportnamen.setBezeichnung(editReportnamenTemp.getBezeichnung());
83  
84          retval = beginTransaction();
85          if(retval != false)
86              retval = storeAndEndTransaction(editReportnamen);
87          
88          return retval;
89      }
90  
91      /***
92        * @see org.fhw.cabaweb.ojb.abstracts.AbstractUseCase#loeschen(java.lang.Object)
93        */
94      public final boolean loeschen(Object arg)
95      {
96          boolean retval = true;
97  
98          Reportnamen deleteReportnamen = (Reportnamen) arg;
99  
100         Collection liste =  null;
101         Reportnamen objekt =  null;
102 
103         Criteria criteria = new Criteria();
104 
105         if (deleteReportnamen.getReportnummer() != null)
106             criteria.addEqualTo("Reportnummer", deleteReportnamen.getReportnummer());
107         if (deleteReportnamen.getProjekte() != null && ((Projekte) deleteReportnamen.getProjekte()).getProjektnummer() != null)
108             criteria.addEqualTo("Projektnummer", (deleteReportnamen.getProjekte()).getProjektnummer());
109 
110         liste = sucheQBC(Reportnamen.class, criteria, null);
111         if(liste != null && liste.size() == 1)
112             objekt = (Reportnamen) liste.iterator().next();
113 
114         retval = beginTransaction();
115         if(retval != false)
116             retval = deleteAndEndTransaction(objekt);
117         
118         return retval;
119     }
120 
121     /***
122       * @see org.fhw.cabaweb.ojb.abstracts.AbstractUseCase#sucheObjekt(java.lang.Object)
123       */
124     public final Object sucheObjekt(Object arg)
125     {
126         Reportnamen suchReportnamen = (Reportnamen) arg;
127         Collection liste =  null;
128         Object rueckgabeWert =  null;
129 
130         Criteria criteria = new Criteria();
131 
132         if (suchReportnamen.getReportnummer() != null)
133             criteria.addEqualTo("Reportnummer", suchReportnamen.getReportnummer());
134         if (suchReportnamen.getProjekte() != null && ((Projekte) suchReportnamen.getProjekte()).getProjektnummer() != null)
135             criteria.addEqualTo("Projektnummer", (suchReportnamen.getProjekte()).getProjektnummer());
136 
137         liste = sucheQBC(Reportnamen.class, criteria, null);
138         if(liste != null && liste.size() == 1)
139             rueckgabeWert = (Reportnamen) liste.iterator().next();
140 
141         return rueckgabeWert;
142     }
143 
144     /***
145       * @see org.fhw.cabaweb.ojb.abstracts.AbstractUseCase#sucheObjekte(java.lang.Object)
146       */
147     public final Collection sucheObjekte(Object arg)
148     {
149         Reportnamen suchReportnamen = (Reportnamen) arg;
150         Collection rueckgabeWert =  null;
151         ArrayList orderBy = new ArrayList();
152 
153         Criteria criteria = new Criteria();
154 
155         if (suchReportnamen.getReportnummer() != null)
156             criteria.addEqualTo("Reportnummer", suchReportnamen.getReportnummer());
157         if (suchReportnamen.getProjekte() != null && ((Projekte) suchReportnamen.getProjekte()).getProjektnummer() != null)
158             criteria.addEqualTo("Projektnummer", (suchReportnamen.getProjekte()).getProjektnummer());
159         if (suchReportnamen.getBezeichnung() != null)
160             criteria.addLike("Bezeichnung", "%"+suchReportnamen.getBezeichnung()+"%");
161 
162         orderBy.add(0, new FieldHelper("Reportnummer", true));
163         orderBy.add(1, new FieldHelper("Projektnummer", true));
164 
165         rueckgabeWert = sucheQBC(Reportnamen.class, criteria, orderBy);
166 
167         return rueckgabeWert;
168     }
169 }