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  import org.fhw.cabaweb.ojb.abstracts.AbstractUseCase;
29  import org.fhw.cabaweb.ojb.dataobjects.Sprachen;
30  
31  /***
32   * Abstrakte Klasse f&uuml;r die OJB Kapselung der Datenbankoperationen
33   *
34   * @author  <a href="mailto:thomas.vogt@tvc-software.com">Thomas Vogt</a>
35   * @version Version 1.0 12.04.2004
36   */
37  public class UseCaseSprachen extends AbstractUseCase
38  {
39      /*** Konstruktor
40       * 
41       * @param broker Instanz des Persistence Brokers
42       */
43      public UseCaseSprachen(PersistenceBroker broker)
44      {
45          super(broker);
46      }
47  
48      /***
49        * @see org.fhw.cabaweb.ojb.abstracts.AbstractUseCase#erzeugen(java.lang.Object)
50        */
51      public final boolean erzeugen(Object arg)
52      {
53          Sprachen newSprache = (Sprachen) arg;
54          return anlegen(newSprache);
55      }
56  
57      /***
58        * @see org.fhw.cabaweb.ojb.abstracts.AbstractUseCase#editieren(java.lang.Object)
59        */
60      public final boolean editieren(Object arg)
61      {
62          boolean retval = true;
63          Sprachen editSpracheTemp = (Sprachen) arg;
64          Sprachen editSprache = null;
65  
66          retval = beginTransaction();
67  
68          editSprache = (Sprachen) sucheQBE(editSpracheTemp);
69  
70          // Editieren des existierenden Eintrags
71          editSprache.setSprachname(editSpracheTemp.getSprachname());
72          editSprache.setAnzeigen(editSpracheTemp.getAnzeigen());
73  
74          if(retval != false)
75              retval = storeAndEndTransaction(editSprache);
76          
77          return retval;
78      }
79  
80      /***
81        * @see org.fhw.cabaweb.ojb.abstracts.AbstractUseCase#loeschen(java.lang.Object)
82        */
83      public final boolean loeschen(Object arg)
84      {
85          boolean retval = true;
86  
87          Sprachen deleteSprache = (Sprachen) arg;
88  
89          retval = beginTransaction();
90  
91          deleteSprache = (Sprachen) sucheQBE(deleteSprache);
92  
93          if(retval != false)
94              retval = deleteAndEndTransaction(deleteSprache);
95          
96          return retval;
97      }
98  
99      /***
100       * @see org.fhw.cabaweb.ojb.abstracts.AbstractUseCase#sucheObjekt(java.lang.Object)
101       */
102 	public final Object sucheObjekt(Object arg)
103 	{
104         Sprachen suchSprache = (Sprachen) arg;
105         Object rueckgabeWert =  null;
106 
107         suchSprache = (Sprachen) sucheQBE(suchSprache);
108 
109         rueckgabeWert = suchSprache;
110 
111         return rueckgabeWert;
112 	}
113 
114     /***
115       * @see org.fhw.cabaweb.ojb.abstracts.AbstractUseCase#sucheObjekte(java.lang.Object)
116       */
117 	public final Collection sucheObjekte(Object arg)
118 	{
119         Sprachen suchSprache = (Sprachen) arg;
120         Collection rueckgabeWert =  null;
121         ArrayList orderBy = new ArrayList();
122 
123         Criteria criteria = new Criteria();
124 
125         if (suchSprache.getSprachnummer() != null)
126             criteria.addEqualTo("Sprachnummer", suchSprache.getSprachnummer());
127         if (suchSprache.getSprachname() != null)
128             criteria.addLike("Sprachname", "%"+suchSprache.getSprachname()+"%");
129         if (suchSprache.getAnzeigen() != null)
130             criteria.addEqualTo("Anzeigen", suchSprache.getAnzeigen());
131 
132         orderBy.add(0, new FieldHelper("Sprachnummer", true));
133         
134         rueckgabeWert = sucheQBC(Sprachen.class, criteria, orderBy);
135 
136         return rueckgabeWert;
137 	}
138 }