*** empty log message ***
[mir.git] / source / mir / storage / Database.java
1 /*
2  * Copyright (C) 2001, 2002 The Mir-coders group
3  *
4  * This file is part of Mir.
5  *
6  * Mir is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Mir is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Mir; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * In addition, as a special exception, The Mir-coders gives permission to link
21  * the code of this program with  any library licensed under the Apache Software License,
22  * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
23  * (or with modified versions of the above that use the same license as the above),
24  * and distribute linked combinations including the two.  You must obey the
25  * GNU General Public License in all respects for all of the code used other than
26  * the above mentioned libraries.  If you modify this file, you may extend this
27  * exception to your version of the file, but you are not obligated to do so.
28  * If you do not wish to do so, delete this exception statement from your version.
29  */
30 package mir.storage;
31
32 import java.io.IOException;
33 import java.io.InputStreamReader;
34 import java.sql.Connection;
35 import java.sql.PreparedStatement;
36 import java.sql.ResultSet;
37 import java.sql.ResultSetMetaData;
38 import java.sql.SQLException;
39 import java.sql.Statement;
40 import java.sql.Timestamp;
41 import java.text.ParseException;
42 import java.text.SimpleDateFormat;
43 import java.util.ArrayList;
44 import java.util.Calendar;
45 import java.util.GregorianCalendar;
46 import java.util.HashMap;
47 import java.util.Iterator;
48 import java.util.List;
49 import java.util.Map;
50 import java.util.TimeZone;
51 import java.util.Vector;
52
53 import mir.config.MirPropertiesConfiguration;
54 import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
55 import mir.entity.Entity;
56 import mir.entity.EntityList;
57 import mir.entity.StorableObjectEntity;
58 import mir.log.LoggerWrapper;
59 import mir.misc.StringUtil;
60 import mir.storage.store.ObjectStore;
61 import mir.storage.store.StorableObject;
62 import mir.storage.store.StoreContainerType;
63 import mir.storage.store.StoreIdentifier;
64 import mir.storage.store.StoreUtil;
65 import mir.util.JDBCStringRoutines;
66
67 import com.codestudio.util.SQLManager;
68
69
70 /**
71  * Diese Klasse implementiert die Zugriffsschicht auf die Datenbank.
72  * Alle Projektspezifischen Datenbankklassen erben von dieser Klasse.
73  * In den Unterklassen wird im Minimalfall nur die Tabelle angegeben.
74  * Im Konfigurationsfile findet sich eine Verweis auf den verwendeten
75  * Treiber, Host, User und Passwort, ueber den der Zugriff auf die
76  * Datenbank erfolgt.
77  *
78  * @version $Id: Database.java,v 1.44.2.15 2003/11/26 19:21:05 rk Exp $
79  * @author rk
80  *
81  */
82 public class Database implements StorageObject {
83   private static Class GENERIC_ENTITY_CLASS = mir.entity.StorableObjectEntity.class;
84   private static Class STORABLE_OBJECT_ENTITY_CLASS = mir.entity.StorableObjectEntity.class;
85
86
87   private static Map POPUP_EMPTYLINE = new HashMap();
88   protected static final ObjectStore o_store = ObjectStore.getInstance();
89   private static final int _millisPerHour = 60 * 60 * 1000;
90   private static final int _millisPerMinute = 60 * 1000;
91
92   static {
93     // always same object saves a little space
94     POPUP_EMPTYLINE.put("key", "");
95     POPUP_EMPTYLINE.put("value", "--");
96   }
97
98   protected LoggerWrapper logger;
99   protected MirPropertiesConfiguration configuration;
100   protected String theTable;
101   protected String theCoreTable = null;
102   protected String thePKeyName = "id";
103   protected int thePKeyType;
104   protected int thePKeyIndex;
105   protected boolean evaluatedMetaData = false;
106   protected ArrayList metadataFields;
107   protected ArrayList metadataLabels;
108   protected ArrayList metadataNotNullFields;
109   protected int[] metadataTypes;
110   protected Class theEntityClass;
111   protected List popupCache = null;
112   protected boolean hasPopupCache = false;
113   protected Map hashCache = null;
114   protected boolean hasTimestamp = true;
115   private String database_driver;
116   private String database_url;
117   private int defaultLimit;
118
119   TimeZone timezone;
120   SimpleDateFormat internalDateFormat;
121   SimpleDateFormat userInputDateFormat;
122 /*
123   private SimpleDateFormat _dateFormatterOut;
124   private SimpleDateFormat _dateFormatterIn;
125   _dateFormatterOut = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
126   _dateFormatterIn = new SimpleDateFormat("yyyy-MM-dd HH:mm");
127 */
128
129   /**
130    * Kontruktor bekommt den Filenamen des Konfigurationsfiles ?bergeben.
131    * Aus diesem file werden <code>Database.Logfile</code>,
132    * <code>Database.Username</code>,<code>Database.Password</code>,
133    * <code>Database.Host</code> und <code>Database.Adaptor</code>
134    * ausgelesen und ein Broker f?r die Verbindugen zur Datenbank
135    * erzeugt.
136    *
137    * @param   String confFilename Dateiname der Konfigurationsdatei
138    */
139   public Database() throws StorageObjectFailure {
140     try {
141       configuration = MirPropertiesConfiguration.instance();
142     }
143     catch (PropertiesConfigExc e) {
144       throw new StorageObjectFailure(e);
145     }
146     logger = new LoggerWrapper("Database");
147     timezone = TimeZone.getTimeZone(configuration.getString("Mir.DefaultTimezone"));
148     internalDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
149     internalDateFormat.setTimeZone(timezone);
150
151     userInputDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
152     userInputDateFormat.setTimeZone(timezone);
153
154
155     String theAdaptorName = configuration.getString("Database.Adaptor");
156     defaultLimit = Integer.parseInt(configuration.getString("Database.Limit"));
157
158     try {
159       theEntityClass = GENERIC_ENTITY_CLASS;
160     }
161     catch (Throwable e) {
162       logger.error("Error in Database() constructor with " + theAdaptorName + " -- " + e.getMessage());
163       throw new StorageObjectFailure("Error in Database() constructor.", e);
164     }
165   }
166
167   /**
168    * Liefert die Entity-Klasse zur?ck, in der eine Datenbankzeile gewrappt
169    * wird. Wird die Entity-Klasse durch die erbende Klasse nicht ?berschrieben,
170    * wird eine mir.entity.GenericEntity erzeugt.
171    *
172    * @return Class-Objekt der Entity
173    */
174   public java.lang.Class getEntityClass() {
175     return theEntityClass;
176   }
177
178   /**
179    * Liefert die Standardbeschr?nkung von select-Statements zur?ck, also
180    * wieviel Datens?tze per Default selektiert werden.
181    *
182    * @return Standard-Anzahl der Datens?tze
183    */
184   public int getLimit() {
185     return defaultLimit;
186   }
187
188   /**
189    * Liefert den Namen des Primary-Keys zur?ck. Wird die Variable nicht von
190    * der erbenden Klasse ?berschrieben, so ist der Wert <code>PKEY</code>
191    * @return Name des Primary-Keys
192    */
193   public String getIdName() {
194     return thePKeyName;
195   }
196
197   /**
198    * Liefert den Namen der Tabelle, auf das sich das Datenbankobjekt bezieht.
199    *
200    * @return Name der Tabelle
201    */
202   public String getTableName() {
203     return theTable;
204   }
205
206   /*
207   *   Dient dazu vererbte Tabellen bei objectrelationalen DBMS
208   *   zu speichern, wenn die id einer Tabelle in der parenttabelle verwaltet
209   *   wird.
210   *   @return liefert theCoreTabel als String zurueck, wenn gesetzt, sonst
211   *    the Table
212    */
213   public String getCoreTable() {
214     if (theCoreTable != null) {
215       return theCoreTable;
216     }
217     else {
218       return theTable;
219     }
220   }
221
222   /**
223    * Liefert Feldtypen der Felder der Tabelle zurueck (s.a. java.sql.Types)
224    * @return int-Array mit den Typen der Felder
225    * @exception StorageObjectException
226    */
227   public int[] getTypes() throws StorageObjectFailure {
228     if (metadataTypes == null) {
229       get_meta_data();
230     }
231
232     return metadataTypes;
233   }
234
235   /**
236    * Liefert eine Liste der Labels der Tabellenfelder
237    * @return ArrayListe mit Labeln
238    * @exception StorageObjectException
239    */
240   public List getLabels() throws StorageObjectFailure {
241     if (metadataLabels == null) {
242       get_meta_data();
243     }
244
245     return metadataLabels;
246   }
247
248   /**
249    * Liefert eine Liste der Felder der Tabelle
250    * @return ArrayList mit Feldern
251    * @exception StorageObjectException
252    */
253   public List getFields() throws StorageObjectFailure {
254     if (metadataFields == null) {
255       get_meta_data();
256     }
257
258     return metadataFields;
259   }
260
261   /**
262    *   Gets value out of ResultSet according to type and converts to String
263    *   @param rs  ResultSet.
264    *   @param aType  a type from java.sql.Types.*
265    *   @param index  index in ResultSet
266    *   @return returns the value as String. If no conversion is possible
267    *                             /unsupported value/ is returned
268    */
269   private String getValueAsString(ResultSet rs, int valueIndex, int aType)
270     throws StorageObjectFailure {
271     String outValue = null;
272
273     if (rs != null) {
274       try {
275         switch (aType) {
276           case java.sql.Types.BIT:
277             outValue = (rs.getBoolean(valueIndex) == true) ? "1" : "0";
278
279             break;
280
281           case java.sql.Types.INTEGER:
282           case java.sql.Types.SMALLINT:
283           case java.sql.Types.TINYINT:
284           case java.sql.Types.BIGINT:
285
286             int out = rs.getInt(valueIndex);
287
288             if (!rs.wasNull()) {
289               outValue = new Integer(out).toString();
290             }
291
292             break;
293
294           case java.sql.Types.NUMERIC:
295
296             /** @todo Numeric can be float or double depending upon
297              *  metadata.getScale() / especially with oracle */
298             long outl = rs.getLong(valueIndex);
299
300             if (!rs.wasNull()) {
301               outValue = new Long(outl).toString();
302             }
303
304             break;
305
306           case java.sql.Types.REAL:
307
308             float tempf = rs.getFloat(valueIndex);
309
310             if (!rs.wasNull()) {
311               tempf *= 10;
312               tempf += 0.5;
313
314               int tempf_int = (int) tempf;
315               tempf = (float) tempf_int;
316               tempf /= 10;
317               outValue = "" + tempf;
318               outValue = outValue.replace('.', ',');
319             }
320
321             break;
322
323           case java.sql.Types.DOUBLE:
324
325             double tempd = rs.getDouble(valueIndex);
326
327             if (!rs.wasNull()) {
328               tempd *= 10;
329               tempd += 0.5;
330
331               int tempd_int = (int) tempd;
332               tempd = (double) tempd_int;
333               tempd /= 10;
334               outValue = "" + tempd;
335               outValue = outValue.replace('.', ',');
336             }
337
338             break;
339
340           case java.sql.Types.CHAR:
341           case java.sql.Types.VARCHAR:
342           case java.sql.Types.LONGVARCHAR:
343             outValue = rs.getString(valueIndex);
344
345             break;
346
347           case java.sql.Types.LONGVARBINARY:
348             outValue = rs.getString(valueIndex);
349
350             break;
351
352           case java.sql.Types.TIMESTAMP:
353
354             // it's important to use Timestamp here as getting it
355             // as a string is undefined and is only there for debugging
356             // according to the API. we can make it a string through formatting.
357             // -mh
358             Timestamp timestamp = (rs.getTimestamp(valueIndex));
359
360             if (!rs.wasNull()) {
361               java.util.Date date = new java.util.Date(timestamp.getTime());
362
363               Calendar calendar = new GregorianCalendar();
364               calendar.setTime(date);
365               calendar.setTimeZone(timezone);
366               outValue = internalDateFormat.format(date);
367
368               int offset = calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET);
369               String tzOffset = StringUtil.zeroPaddingNumber(Math.abs(offset) / _millisPerHour, 2, 2);
370
371               if (offset<0)
372                 outValue = outValue + "-";
373               else
374                 outValue = outValue + "+";
375               outValue = outValue + tzOffset;
376             }
377
378             break;
379
380           default:
381             outValue = "<unsupported value>";
382             logger.warn("Unsupported Datatype: at " + valueIndex + " (" + aType + ")");
383         }
384       } catch (SQLException e) {
385         throw new StorageObjectFailure("Could not get Value out of Resultset -- ",
386           e);
387       }
388     }
389
390     return outValue;
391   }
392
393   /**
394    *   select-Operator um einen Datensatz zu bekommen.
395    *   @param id Primaerschluessel des Datensatzes.
396    *   @return liefert EntityObject des gefundenen Datensatzes oder null.
397    */
398   public Entity selectById(String id) throws StorageObjectExc {
399     if ((id == null) || id.equals("")) {
400       throw new StorageObjectExc("Database.selectById: Missing id");
401     }
402
403     // ask object store for object
404     if (StoreUtil.implementsStorableObject(theEntityClass)) {
405       String uniqueId = id;
406
407       if (theEntityClass.equals(StorableObjectEntity.class)) {
408         uniqueId += ("@" + theTable);
409       }
410
411       StoreIdentifier search_sid = new StoreIdentifier(theEntityClass, uniqueId);
412       logger.debug("CACHE: (dbg) looking for sid " + search_sid.toString());
413
414       Entity hit = (Entity) o_store.use(search_sid);
415
416       if (hit != null) {
417         return hit;
418       }
419     }
420
421     Statement stmt = null;
422     Connection con = getPooledCon();
423     Entity returnEntity = null;
424
425     try {
426       ResultSet rs;
427
428       /** @todo better prepared statement */
429       String selectSql =
430         "select * from " + theTable + " where " + thePKeyName + "=" + id;
431       stmt = con.createStatement();
432       rs = executeSql(stmt, selectSql);
433
434       if (rs != null) {
435         if (evaluatedMetaData == false) {
436           evalMetaData(rs.getMetaData());
437         }
438
439         if (rs.next()) {
440           returnEntity = makeEntityFromResultSet(rs);
441         }
442         else {
443           logger.debug("No data for id: " + id + " in table " + theTable);
444         }
445
446         rs.close();
447       }
448       else {
449         logger.debug("No Data for Id " + id + " in Table " + theTable);
450       }
451     }
452     catch (SQLException sqe) {
453       throwSQLException(sqe, "selectById");
454       return null;
455     }
456     catch (NumberFormatException e) {
457       logger.error("ID is no number: " + id);
458     }
459     finally {
460       freeConnection(con, stmt);
461     }
462
463     return returnEntity;
464   }
465
466   /**
467    * This method makes it possible to make selects across multiple tables
468    * 
469    * @param mainTablePrefix prefix for the mainTable
470    * @param extraTables a vector of tables for relational select
471    * @param aWhereClause whereClause
472    * @return EntityList of selected Objects
473    * @throws StorageObjectFailure
474    */
475
476   public EntityList selectByWhereClauseWithExtraTables(String mainTablePrefix, 
477                                                 List extraTables, String aWhereClause )
478    throws StorageObjectFailure {
479         return selectByWhereClause( mainTablePrefix, extraTables, aWhereClause, "", 0, defaultLimit);
480   }
481
482   /**
483    *   select-Operator um Datensaetze zu bekommen, die key = value erfuellen.
484    *   @param key  Datenbankfeld der Bedingung.
485    *   @param value  Wert die der key anehmen muss.
486    *   @return EntityList mit den gematchten Entities
487    */
488   public EntityList selectByFieldValue(String aField, String aValue) throws StorageObjectFailure {
489     return selectByFieldValue(aField, aValue, 0);
490   }
491
492   /**
493    *   select-Operator um Datensaetze zu bekommen, die key = value erfuellen.
494    *   @param key  Datenbankfeld der Bedingung.
495    *   @param value  Wert die der key anehmen muss.
496    *   @param offset  Gibt an ab welchem Datensatz angezeigt werden soll.
497    *   @return EntityList mit den gematchten Entities
498    */
499   public EntityList selectByFieldValue(String aField, String aValue, int offset) throws StorageObjectFailure {
500     return selectByWhereClause(aField + "=" + aValue, offset);
501   }
502
503   /**
504    * select-Operator liefert eine EntityListe mit den gematchten Datens?tzen zur?ck.
505    * Also offset wird der erste Datensatz genommen.
506    *
507    * @param wc where-Clause
508    * @return EntityList mit den gematchten Entities
509    * @exception StorageObjectException
510    */
511   public EntityList selectByWhereClause(String where) throws StorageObjectFailure {
512     return selectByWhereClause(where, 0);
513   }
514
515   /**
516    * select-Operator liefert eine EntityListe mit den gematchten Datens?tzen zur?ck.
517    * Als maximale Anzahl wird das Limit auf der Konfiguration genommen.
518    *
519    * @param wc where-Clause
520    * @param offset ab welchem Datensatz.
521    * @return EntityList mit den gematchten Entities
522    * @exception StorageObjectException
523    */
524   public EntityList selectByWhereClause(String whereClause, int offset) throws StorageObjectFailure {
525     return selectByWhereClause(whereClause, null, offset);
526   }
527
528   /**
529    * select-Operator liefert eine EntityListe mit den gematchten Datens?tzen zur?ck.
530    * Also offset wird der erste Datensatz genommen.
531    * Als maximale Anzahl wird das Limit auf der Konfiguration genommen.
532    *
533    * @param wc where-Clause
534    * @param ob orderBy-Clause
535    * @return EntityList mit den gematchten Entities
536    * @exception StorageObjectException
537    */
538   public EntityList selectByWhereClause(String where, String order) throws StorageObjectFailure {
539     return selectByWhereClause(where, order, 0);
540   }
541
542   public EntityList selectByWhereClause(String mainTablePrefix, List extraTables, String where, String order) throws StorageObjectFailure {
543     return selectByWhereClause(mainTablePrefix, extraTables, where, order, 0, defaultLimit);
544   }
545
546   /**
547    * select-Operator liefert eine EntityListe mit den gematchten Datens?tzen zur?ck.
548    * Als maximale Anzahl wird das Limit auf der Konfiguration genommen.
549    *
550    * @param wc where-Clause
551    * @param ob orderBy-Clause
552    * @param offset ab welchem Datensatz
553    * @return EntityList mit den gematchten Entities
554    * @exception StorageObjectException
555    */
556   public EntityList selectByWhereClause(String whereClause, String orderBy, int offset) throws StorageObjectFailure {
557     return selectByWhereClause(whereClause, orderBy, offset, defaultLimit);
558   }
559
560   /**
561    * select-Operator returns EntityList with matching rows in Database.
562    * @param aWhereClause where-Clause
563    * @param anOrderByClause orderBy-Clause
564    * @param offset ab welchem Datensatz
565    * @param limit wieviele Datens?tze
566    * @return EntityList mit den gematchten Entities
567    * @exception StorageObjectException
568    */
569   public EntityList selectByWhereClause(String aWhereClause, String anOrderByClause,
570             int offset, int limit) throws StorageObjectFailure {
571     return selectByWhereClause("", null, aWhereClause, anOrderByClause, offset, limit);              
572   }
573
574
575   /**
576    * select-Operator returns EntityList with matching rows in Database.
577    * @param aWhereClause where-Clause
578    * @param anOrderByClause orderBy-Clause
579    * @param offset ab welchem Datensatz
580    * @param limit wieviele Datens?tze
581    * @return EntityList mit den gematchten Entities
582    * @exception StorageObjectException
583    */
584   public EntityList selectByWhereClause(String mainTablePrefix, List extraTables,
585       String aWhereClause, String anOrderByClause,
586                         int offset, int limit) throws StorageObjectFailure {
587     
588     // make extraTables null, if single empty String in it
589     if (extraTables != null && ((String)extraTables.get(0)).trim().equals(""))
590       {
591         logger.debug("+++ made extraTables to null!");
592         extraTables=null;
593       }
594     
595       String useTable = theTable;
596           String selectStar = "*";
597           if (mainTablePrefix!=null && mainTablePrefix.trim().length()>0) {
598             useTable+=" "+mainTablePrefix;
599             selectStar=mainTablePrefix.trim() + ".*";
600           }
601     
602     // check o_store for entitylist
603     // only if no relational select
604     if (extraTables==null) {
605       if (StoreUtil.implementsStorableObject(theEntityClass)) {
606         StoreIdentifier search_sid =
607             new StoreIdentifier(
608               theEntityClass, StoreContainerType.STOC_TYPE_ENTITYLIST,
609               StoreUtil.getEntityListUniqueIdentifierFor(useTable, aWhereClause, anOrderByClause, offset, limit));
610         EntityList hit = (EntityList) o_store.use(search_sid);
611   
612         if (hit != null) {
613           logger.debug("CACHE (hit): " + search_sid.toString());
614   
615           return hit;
616         }
617       }
618     }
619
620     // local
621     EntityList theReturnList = null;
622     Connection con = null;
623     Statement stmt = null;
624     ResultSet rs;
625     int offsetCount = 0;
626     int count = 0;
627
628     // build sql-statement
629
630     if ((aWhereClause != null) && (aWhereClause.trim().length() == 0)) {
631       aWhereClause = null;
632     }
633
634     StringBuffer countSql =
635       new StringBuffer("select count(*) from ").append(useTable);
636     StringBuffer selectSql =
637       new StringBuffer("select "+selectStar+" from ").append(useTable);
638  
639     // append extratables, if necessary
640     if (extraTables!=null) {
641       for (int i=0;i < extraTables.size();i++) {
642         if (!extraTables.get(i).equals("")) {        
643           countSql.append( ", " + extraTables.get(i));
644           selectSql.append( ", " + extraTables.get(i));
645         }
646       }
647     }
648     
649     if (aWhereClause != null) {
650       selectSql.append(" where ").append(aWhereClause);
651       countSql.append(" where ").append(aWhereClause);
652     }
653
654     if ((anOrderByClause != null) && !(anOrderByClause.trim().length() == 0)) {
655       selectSql.append(" order by ").append(anOrderByClause);
656     }
657
658     if ((limit > -1) && (offset > -1)) {
659       selectSql.append(" LIMIT ").append(limit).append(" OFFSET ").append(offset);
660     }
661
662     // execute sql
663     try {
664       con = getPooledCon();
665       stmt = con.createStatement();
666
667       // selecting...
668       rs = executeSql(stmt, selectSql.toString());
669
670       if (rs != null) {
671         if (!evaluatedMetaData) {
672           evalMetaData(rs.getMetaData());
673         }
674
675         theReturnList = new EntityList();
676         Entity theResultEntity;
677         while (rs.next()) {
678           theResultEntity = makeEntityFromResultSet(rs);
679           theReturnList.add(theResultEntity);
680           offsetCount++;
681         }
682         rs.close();
683       }
684
685       // making entitylist infos
686       count = offsetCount;
687
688       if (theReturnList != null) {
689         // now we decide if we have to know an overall count...
690         count = offsetCount;
691
692         if ((limit > -1) && (offset > -1)) {
693           if (offsetCount == limit) {
694             rs = executeSql(stmt, countSql.toString());
695
696             if (rs != null) {
697               if (rs.next()) {
698                 count = rs.getInt(1);
699               }
700
701               rs.close();
702             }
703             else {
704               logger.error("Could not count: " + countSql);
705             }
706           }
707         }
708
709         theReturnList.setCount(count);
710         theReturnList.setOffset(offset);
711         theReturnList.setWhere(aWhereClause);
712         theReturnList.setOrder(anOrderByClause);
713         theReturnList.setStorage(this);
714         theReturnList.setLimit(limit);
715
716         if (offset >= limit) {
717           theReturnList.setPrevBatch(offset - limit);
718         }
719
720         if ((offset + offsetCount) < count) {
721           theReturnList.setNextBatch(offset + limit);
722         }
723
724         if (extraTables==null && StoreUtil.implementsStorableObject(theEntityClass)) {
725           StoreIdentifier sid = theReturnList.getStoreIdentifier();
726           logger.debug("CACHE (add): " + sid.toString());
727           o_store.add(sid);
728         }
729       }
730     }
731     catch (SQLException sqe) {
732       throwSQLException(sqe, "selectByWhereClause");
733     }
734     finally {
735       try {
736         if (con != null) {
737           freeConnection(con, stmt);
738         }
739       } catch (Throwable t) {
740       }
741     }
742
743     return theReturnList;
744   }
745
746   /**
747    *  Bastelt aus einer Zeile der Datenbank ein EntityObjekt.
748    *
749    *  @param rs Das ResultSetObjekt.
750    *  @return Entity Die Entity.
751    */
752   private Entity makeEntityFromResultSet(ResultSet rs)
753     throws StorageObjectFailure {
754     /** @todo OS: get Pkey from ResultSet and consult ObjectStore */
755     Map theResultHash = new HashMap();
756     String theResult = null;
757     int theType;
758     Entity returnEntity = null;
759
760     try {
761       int size = metadataFields.size();
762
763       for (int i = 0; i < size; i++) {
764         // alle durchlaufen bis nix mehr da
765         theType = metadataTypes[i];
766
767         if (theType == java.sql.Types.LONGVARBINARY) {
768           InputStreamReader is =
769             (InputStreamReader) rs.getCharacterStream(i + 1);
770
771           if (is != null) {
772             char[] data = new char[32768];
773             StringBuffer theResultString = new StringBuffer();
774             int len;
775
776             while ((len = is.read(data)) > 0) {
777               theResultString.append(data, 0, len);
778             }
779
780             is.close();
781             theResult = theResultString.toString();
782           } else {
783             theResult = null;
784           }
785         } else {
786           theResult = getValueAsString(rs, (i + 1), theType);
787         }
788
789         if (theResult != null) {
790           theResultHash.put(metadataFields.get(i), theResult);
791         }
792       }
793
794       if (theEntityClass != null) {
795         returnEntity = (Entity) theEntityClass.newInstance();
796         returnEntity.setStorage(this);
797         returnEntity.setValues(theResultHash);
798
799         if (returnEntity instanceof StorableObject) {
800           logger.debug("CACHE: ( in) " + returnEntity.getId() + " :" + theTable);
801           o_store.add(((StorableObject) returnEntity).getStoreIdentifier());
802         }
803       } else {
804         throwStorageObjectException("Internal Error: theEntityClass not set!");
805       }
806     }
807     catch (IllegalAccessException e) {
808       throwStorageObjectException("No access! -- " + e.getMessage());
809     }
810     catch (IOException e) {
811       throwStorageObjectException("IOException! -- " + e.getMessage());
812     }
813     catch (InstantiationException e) {
814       throwStorageObjectException("No Instatiation! -- " + e.getMessage());
815     }
816     catch (SQLException sqe) {
817       throwSQLException(sqe, "makeEntityFromResultSet");
818
819       return null;
820     }
821
822     return returnEntity;
823   }
824
825   /**
826    * Inserts an entity into the database.
827    *
828    * @param theEntity
829    * @return der Wert des Primary-keys der eingef?gten Entity
830    */
831   public String insert(Entity theEntity) throws StorageObjectFailure {
832     //cache
833     invalidatePopupCache();
834
835     // invalidating all EntityLists corresponding with theEntityClass
836     if (StoreUtil.implementsStorableObject(theEntityClass)) {
837       StoreContainerType stoc_type =
838         StoreContainerType.valueOf(theEntityClass,
839           StoreContainerType.STOC_TYPE_ENTITYLIST);
840       o_store.invalidate(stoc_type);
841     }
842
843     String returnId = null;
844     Connection con = null;
845     PreparedStatement pstmt = null;
846
847     try {
848       List streamedInput = theEntity.streamedInput();
849       StringBuffer f = new StringBuffer();
850       StringBuffer v = new StringBuffer();
851       String aField;
852       String aValue;
853       boolean firstField = true;
854
855       // make sql-string
856       for (int i = 0; i < getFields().size(); i++) {
857         aField = (String) getFields().get(i);
858
859         if (!aField.equals(thePKeyName)) {
860           aValue = null;
861
862           // exceptions
863           if (!theEntity.hasValueForField(aField) && (
864               aField.equals("webdb_create") ||
865               aField.equals("webdb_lastchange"))) {
866             aValue = "NOW()";
867           }
868           else {
869             if ((streamedInput != null) && streamedInput.contains(aField)) {
870               aValue = "?";
871             }
872             else {
873               if (theEntity.hasValueForField(aField)) {
874                 aValue =
875                   "'" +
876                    JDBCStringRoutines.escapeStringLiteral((String) theEntity.getValue(aField)) + "'";
877               }
878             }
879           }
880
881           // wenn Wert gegeben, dann einbauen
882           if (aValue != null) {
883             if (firstField == false) {
884               f.append(",");
885               v.append(",");
886             }
887             else {
888               firstField = false;
889             }
890
891             f.append(aField);
892             v.append(aValue);
893           }
894         }
895       }
896        // end for
897
898       // insert into db
899       StringBuffer sqlBuf =
900         new StringBuffer("insert into ").append(theTable).append("(").append(f)
901                                         .append(") values (").append(v).append(")");
902       String sql = sqlBuf.toString();
903
904       logger.debug("INSERT: " + sql);
905       con = getPooledCon();
906       con.setAutoCommit(false);
907       pstmt = con.prepareStatement(sql);
908
909       if (streamedInput != null) {
910         for (int i = 0; i < streamedInput.size(); i++) {
911           String inputString =
912             (String) theEntity.getValue((String) streamedInput.get(i));
913           pstmt.setBytes(i + 1, inputString.getBytes());
914         }
915       }
916
917       int ret = pstmt.executeUpdate();
918
919       if (ret == 0) {
920         //insert failed
921         return null;
922       }
923
924       pstmt = con.prepareStatement("select currval('" + getCoreTable() + "_id_seq')");
925
926       ResultSet rs = pstmt.executeQuery();
927       rs.next();
928       returnId = rs.getString(1);
929       theEntity.setId(returnId);
930     }
931     catch (SQLException sqe) {
932       throwSQLException(sqe, "insert");
933     }
934     finally {
935       try {
936         con.setAutoCommit(true);
937       }
938       catch (Exception e) {
939       }
940
941       freeConnection(con, pstmt);
942     }
943
944     /** @todo store entity in o_store */
945     return returnId;
946   }
947
948   /**
949    * Updates an entity in the database
950    *
951    * @param theEntity
952    */
953   public void update(Entity theEntity) throws StorageObjectFailure {
954     Connection con = null;
955     PreparedStatement pstmt = null;
956
957     /** @todo this is stupid: why do we prepare statement, when we
958      *  throw it away afterwards. should be regular statement
959      *  update/insert could better be one routine called save()
960      *  that chooses to either insert or update depending if we
961      *  have a primary key in the entity. i don't know if we
962      *  still need the streamed input fields. // rk  */
963     /** @todo extension: check if Entity did change, otherwise we don't need
964      *  the roundtrip to the database */
965     /** invalidating corresponding entitylists in o_store*/
966     if (StoreUtil.implementsStorableObject(theEntityClass)) {
967       StoreContainerType stoc_type =
968         StoreContainerType.valueOf(theEntityClass,
969           StoreContainerType.STOC_TYPE_ENTITYLIST);
970       o_store.invalidate(stoc_type);
971     }
972
973     List streamedInput = theEntity.streamedInput();
974     String id = theEntity.getId();
975     String aField;
976     StringBuffer fv = new StringBuffer();
977     boolean firstField = true;
978
979     //cache
980     invalidatePopupCache();
981
982     // build sql statement
983     for (int i = 0; i < getFields().size(); i++) {
984       aField = (String) metadataFields.get(i);
985
986       // only normal cases
987       if (  !(aField.equals(thePKeyName) ||
988             aField.equals("webdb_create") ||
989             aField.equals("webdb_lastchange") ||
990             ((streamedInput != null) && streamedInput.contains(aField)))) {
991         if (theEntity.hasValueForField(aField)) {
992           if (firstField == false) {
993             fv.append(", ");
994           }
995           else {
996             firstField = false;
997           }
998
999           fv.append(aField).append("='").append(JDBCStringRoutines.escapeStringLiteral((String) theEntity.getValue(aField))).append("'");
1000
1001           //              fv.append(aField).append("='").append(StringUtil.quote((String)theEntity.getValue(aField))).append("'");
1002         }
1003       }
1004     }
1005
1006     StringBuffer sql =
1007       new StringBuffer("update ").append(theTable).append(" set ").append(fv);
1008
1009     // exceptions
1010     if (metadataFields.contains("webdb_lastchange")) {
1011       sql.append(",webdb_lastchange=NOW()");
1012     }
1013
1014     // special case: the webdb_create requires the field in yyyy-mm-dd HH:mm
1015     // format so anything extra will be ignored. -mh
1016     if (metadataFields.contains("webdb_create") &&
1017         theEntity.hasValueForField("webdb_create")) {
1018       // minimum of 10 (yyyy-mm-dd)...
1019       if (theEntity.getValue("webdb_create").length() >= 10) {
1020         String dateString = theEntity.getValue("webdb_create");
1021
1022         // if only 10, then add 00:00 so it doesn't throw a ParseException
1023         if (dateString.length() == 10) {
1024           dateString = dateString + " 00:00";
1025         }
1026
1027         // TimeStamp stuff
1028         try {
1029           java.util.Date d = userInputDateFormat.parse(dateString);
1030 //          Timestamp tStamp = new Timestamp(d.getTime());
1031           sql.append(",webdb_create='" + JDBCStringRoutines.formatDate(d) + "'");
1032         }
1033         catch (ParseException e) {
1034           throw new StorageObjectFailure(e);
1035         }
1036       }
1037     }
1038
1039     if (streamedInput != null) {
1040       for (int i = 0; i < streamedInput.size(); i++) {
1041         sql.append(",").append(streamedInput.get(i)).append("=?");
1042       }
1043     }
1044
1045     sql.append(" where id=").append(id);
1046     logger.debug("UPDATE: " + sql);
1047
1048     try {
1049       con = getPooledCon();
1050       con.setAutoCommit(false);
1051       pstmt = con.prepareStatement(sql.toString());
1052
1053       if (streamedInput != null) {
1054         for (int i = 0; i < streamedInput.size(); i++) {
1055           String inputString =
1056             theEntity.getValue((String) streamedInput.get(i));
1057           pstmt.setBytes(i + 1, inputString.getBytes());
1058         }
1059       }
1060
1061       pstmt.executeUpdate();
1062     }
1063     catch (SQLException sqe) {
1064       throwSQLException(sqe, "update");
1065     }
1066     finally {
1067       try {
1068         con.setAutoCommit(true);
1069       }
1070       catch (Exception e) {
1071         ;
1072       }
1073
1074       freeConnection(con, pstmt);
1075     }
1076   }
1077
1078   /*
1079   *   delete-Operator
1080   *   @param id des zu loeschenden Datensatzes
1081   *   @return boolean liefert true zurueck, wenn loeschen erfolgreich war.
1082    */
1083   public boolean delete(String id) throws StorageObjectFailure {
1084     invalidatePopupCache();
1085
1086     // ostore send notification
1087     if (StoreUtil.implementsStorableObject(theEntityClass)) {
1088       String uniqueId = id;
1089
1090       if (theEntityClass.equals(StorableObjectEntity.class)) {
1091         uniqueId += ("@" + theTable);
1092       }
1093
1094       logger.debug("CACHE: (del) " + id);
1095
1096       StoreIdentifier search_sid =
1097         new StoreIdentifier(theEntityClass,
1098           StoreContainerType.STOC_TYPE_ENTITY, uniqueId);
1099       o_store.invalidate(search_sid);
1100     }
1101
1102     /** @todo could be prepared Statement */
1103     Statement stmt = null;
1104     Connection con = null;
1105     int res = 0;
1106     String sql =
1107       "delete from " + theTable + " where " + thePKeyName + "='" + id + "'";
1108
1109     //theLog.printInfo("DELETE " + sql);
1110     try {
1111       con = getPooledCon();
1112       stmt = con.createStatement();
1113       res = stmt.executeUpdate(sql);
1114     } catch (SQLException sqe) {
1115       throwSQLException(sqe, "delete");
1116     } finally {
1117       freeConnection(con, stmt);
1118     }
1119
1120     return (res > 0) ? true : false;
1121   }
1122
1123   /**
1124    * Deletes entities based on a where clause
1125    *
1126    * @param aWhereClause
1127    * @return
1128    * @throws StorageObjectFailure
1129    */
1130   public int deleteByWhereClause(String aWhereClause) throws StorageObjectFailure {
1131     invalidatePopupCache();
1132     if (StoreUtil.implementsStorableObject(theEntityClass)) {
1133       StoreContainerType stoc_type = StoreContainerType.valueOf(theEntityClass, StoreContainerType.STOC_TYPE_ENTITYLIST);
1134       o_store.invalidate(stoc_type);
1135     }
1136
1137     Statement stmt = null;
1138     Connection con = null;
1139     int res = 0;
1140     String sql =
1141       "delete from " + theTable + " where " + aWhereClause;
1142
1143     //theLog.printInfo("DELETE " + sql);
1144     try {
1145       con = getPooledCon();
1146       stmt = con.createStatement();
1147       res = stmt.executeUpdate(sql);
1148     }
1149     catch (SQLException sqe) {
1150       throwSQLException(sqe, "delete");
1151     }
1152     finally {
1153       freeConnection(con, stmt);
1154     }
1155
1156     return res;
1157   }
1158
1159   /* noch nicht implementiert.
1160   * @return immer false
1161    */
1162   public boolean delete(EntityList theEntityList) {
1163     invalidatePopupCache();
1164
1165     return false;
1166   }
1167
1168   /* invalidates the popupCache
1169    */
1170   protected void invalidatePopupCache() {
1171     /** @todo  invalidates toooo much */
1172     popupCache = null;
1173     hashCache = null;
1174   }
1175
1176   /**
1177    * Diese Methode fuehrt den Sqlstring <i>sql</i> aus und timed im Logfile.
1178    * @param stmt Statemnt
1179    * @param sql Sql-String
1180    * @return ResultSet
1181    * @exception StorageObjectException
1182    */
1183   public ResultSet executeSql(Statement stmt, String sql)
1184                             throws StorageObjectFailure, SQLException {
1185     ResultSet rs;
1186     long startTime = System.currentTimeMillis();
1187
1188     try {
1189       rs = stmt.executeQuery(sql);
1190
1191       logger.debug((System.currentTimeMillis() - startTime) + "ms. for: " + sql);
1192     }
1193     catch (SQLException e) {
1194       logger.error(e.getMessage() +"\n" + (System.currentTimeMillis() - startTime) + "ms. for: " + sql);
1195       throw e;
1196     }
1197
1198     return rs;
1199   }
1200 /*
1201   public ResultSet executeSql(String sql) throws StorageObjectFailure, SQLException {
1202     long startTime = System.currentTimeMillis();
1203     Connection connection = null;
1204     Statement statement = null;
1205
1206     try {
1207       connection = getPooledCon();
1208       statement = connection.createStatement();
1209       ResultSet result;
1210
1211       result = statement.executeQuery(sql);
1212
1213       logger.debug((System.currentTimeMillis() - startTime) + "ms. for: " + sql);
1214       return result;
1215     }
1216     catch (Throwable e) {
1217       logger.error(e.getMessage() +"\n" + (System.currentTimeMillis() - startTime) + "ms. for: " + sql);
1218       throw new StorageObjectFailure(e);
1219     }
1220     finally {
1221       if (connection!=null) {
1222         freeConnection(connection, statement);
1223       }
1224     }
1225   }
1226 */
1227   private Map processRow(ResultSet aResultSet) throws StorageObjectFailure, StorageObjectExc {
1228     try {
1229       Map result = new HashMap();
1230       ResultSetMetaData metaData = aResultSet.getMetaData();
1231       int nrColumns = metaData.getColumnCount();
1232       for (int i=0; i<nrColumns; i++) {
1233         result.put(metaData.getColumnName(i+1), getValueAsString(aResultSet, i+1, metaData.getColumnType(i+1)));
1234       }
1235
1236       return result;
1237     }
1238     catch (Throwable e) {
1239       throw new StorageObjectFailure(e);
1240     }
1241   }
1242
1243   public List executeFreeSql(String sql, int aLimit) throws StorageObjectFailure, StorageObjectExc {
1244     Connection connection = null;
1245     Statement statement = null;
1246     try {
1247       List result = new Vector();
1248       connection = getPooledCon();
1249       statement = connection.createStatement();
1250       ResultSet resultset = executeSql(statement, sql);
1251       try {
1252         while (resultset.next() && result.size() < aLimit) {
1253           result.add(processRow(resultset));
1254         }
1255       }
1256       finally {
1257         resultset.close();
1258       }
1259
1260       return result;
1261     }
1262     catch (Throwable e) {
1263       throw new StorageObjectFailure(e);
1264     }
1265     finally {
1266       if (connection!=null) {
1267         freeConnection(connection, statement);
1268       }
1269     }
1270   };
1271
1272   public Map executeFreeSingleRowSql(String anSqlStatement) throws StorageObjectFailure, StorageObjectExc {
1273     try {
1274       List resultList = executeFreeSql(anSqlStatement, 1);
1275       try {
1276         if (resultList.size()>0)
1277           return (Map) resultList.get(0);
1278         else
1279           return null;
1280       }
1281       finally {
1282       }
1283     }
1284     catch (Throwable t) {
1285       throw new StorageObjectFailure(t);
1286     }
1287   };
1288
1289   public String executeFreeSingleValueSql(String sql) throws StorageObjectFailure, StorageObjectExc {
1290     Map row = executeFreeSingleRowSql(sql);
1291
1292     if (row==null)
1293       return null;
1294
1295     Iterator i = row.values().iterator();
1296     if (i.hasNext())
1297       return (String) i.next();
1298     else
1299       return null;
1300   };
1301
1302   public int getSize(String where) throws SQLException, StorageObjectFailure {
1303     return getSize("", null, where);
1304   }
1305   /**
1306    * returns the number of rows in the table
1307    */
1308   public int getSize(String mainTablePrefix, List extraTables, String where) throws SQLException, StorageObjectFailure {
1309     
1310     long startTime = System.currentTimeMillis();
1311     
1312     String useTable = theTable;
1313     if (mainTablePrefix!=null && mainTablePrefix.trim().length()>0) {
1314           useTable+=" "+mainTablePrefix;
1315     }
1316     StringBuffer countSql =
1317       new StringBuffer("select count(*) from ").append(useTable);
1318         // append extratables, if necessary
1319       if (extraTables!=null) {
1320         for (int i=0;i < extraTables.size();i++) {
1321           if (!extraTables.get(i).equals("")) {        
1322             countSql.append( ", " + extraTables.get(i));
1323           }
1324         }
1325       }
1326
1327     if ((where != null) && (where.length() != 0)) {
1328       countSql.append( " where " + where);
1329     }
1330
1331     Connection con = null;
1332     Statement stmt = null;
1333     int result = 0;
1334
1335     try {
1336       con = getPooledCon();
1337       stmt = con.createStatement();
1338
1339       ResultSet rs = executeSql(stmt, countSql.toString());
1340
1341       while (rs.next()) {
1342         result = rs.getInt(1);
1343       }
1344     }
1345     catch (SQLException e) {
1346       logger.error("Database.getSize: " + e.getMessage());
1347     }
1348     finally {
1349       freeConnection(con, stmt);
1350     }
1351     logger.debug((System.currentTimeMillis() - startTime) + "ms. for: " + countSql);
1352
1353     return result;
1354   }
1355
1356   public int executeUpdate(Statement stmt, String sql)
1357     throws StorageObjectFailure, SQLException {
1358     int rs;
1359     long startTime = System.currentTimeMillis();
1360
1361     try {
1362       rs = stmt.executeUpdate(sql);
1363
1364       logger.debug((System.currentTimeMillis() - startTime) + "ms. for: " + sql);
1365     }
1366     catch (SQLException e) {
1367       logger.error("Failed: " + (System.currentTimeMillis() - startTime) + "ms. for: " + sql);
1368       throw e;
1369     }
1370
1371     return rs;
1372   }
1373
1374   public int executeUpdate(String sql)
1375     throws StorageObjectFailure, SQLException {
1376     int result = -1;
1377     long startTime = System.currentTimeMillis();
1378     Connection con = null;
1379     PreparedStatement pstmt = null;
1380
1381     try {
1382       con = getPooledCon();
1383       pstmt = con.prepareStatement(sql);
1384       result = pstmt.executeUpdate();
1385     }
1386     catch (Throwable e) {
1387       logger.error("Database.executeUpdate(" + sql + "): " + e.getMessage());
1388       throw new StorageObjectFailure("Database.executeUpdate(" + sql + "): " + e.getMessage(), e);
1389     }
1390     finally {
1391       freeConnection(con, pstmt);
1392     }
1393
1394     logger.debug((System.currentTimeMillis() - startTime) + "ms. for: " + sql);
1395     return result;
1396   }
1397
1398   /**
1399    * Wertet ResultSetMetaData aus und setzt interne Daten entsprechend
1400    * @param md ResultSetMetaData
1401    * @exception StorageObjectException
1402    */
1403   private void evalMetaData(ResultSetMetaData md) throws StorageObjectFailure {
1404     this.evaluatedMetaData = true;
1405     this.metadataFields = new ArrayList();
1406     this.metadataLabels = new ArrayList();
1407     this.metadataNotNullFields = new ArrayList();
1408
1409     try {
1410       int numFields = md.getColumnCount();
1411       this.metadataTypes = new int[numFields];
1412
1413       String aField;
1414       int aType;
1415
1416       for (int i = 1; i <= numFields; i++) {
1417         aField = md.getColumnName(i);
1418         metadataFields.add(aField);
1419         metadataLabels.add(md.getColumnLabel(i));
1420         aType = md.getColumnType(i);
1421         metadataTypes[i - 1] = aType;
1422
1423         if (aField.equals(thePKeyName)) {
1424           thePKeyType = aType;
1425           thePKeyIndex = i;
1426         }
1427
1428         if (md.isNullable(i) == ResultSetMetaData.columnNullable) {
1429           metadataNotNullFields.add(aField);
1430         }
1431       }
1432     }
1433     catch (SQLException e) {
1434       throwSQLException(e, "evalMetaData");
1435     }
1436   }
1437
1438   /**
1439    *  Wertet die Metadaten eines Resultsets fuer eine Tabelle aus,
1440    *  um die alle Columns und Typen einer Tabelle zu ermitteln.
1441    */
1442   private void get_meta_data() throws StorageObjectFailure {
1443     Connection con = null;
1444     PreparedStatement pstmt = null;
1445     String sql = "select * from " + theTable + " where 0=1";
1446
1447     try {
1448       con = getPooledCon();
1449       pstmt = con.prepareStatement(sql);
1450
1451       logger.debug("METADATA: " + sql);
1452       ResultSet rs = pstmt.executeQuery();
1453       evalMetaData(rs.getMetaData());
1454       rs.close();
1455     }
1456     catch (SQLException e) {
1457       throwSQLException(e, "get_meta_data");
1458     }
1459     finally {
1460       freeConnection(con, pstmt);
1461     }
1462   }
1463
1464   public Connection getPooledCon() throws StorageObjectFailure {
1465     Connection con = null;
1466
1467     try {
1468       con = SQLManager.getInstance().requestConnection();
1469     }
1470     catch (SQLException e) {
1471       logger.error("could not connect to the database " + e.getMessage());
1472
1473       throw new StorageObjectFailure("Could not connect to the database", e);
1474     }
1475
1476     return con;
1477   }
1478
1479   public void freeConnection(Connection con, Statement stmt)
1480     throws StorageObjectFailure {
1481     SQLManager.closeStatement(stmt);
1482     SQLManager.getInstance().returnConnection(con);
1483   }
1484
1485   /**
1486    * Wertet SQLException aus und wirft dannach eine StorageObjectException
1487    * @param sqe SQLException
1488    * @param wo Funktonsname, in der die SQLException geworfen wurde
1489    * @exception StorageObjectException
1490    */
1491   protected void throwSQLException(SQLException sqe, String aFunction) throws StorageObjectFailure {
1492     String state = "";
1493     String message = "";
1494     int vendor = 0;
1495
1496     if (sqe != null) {
1497       state = sqe.getSQLState();
1498       message = sqe.getMessage();
1499       vendor = sqe.getErrorCode();
1500     }
1501
1502     String information =
1503         "SQL Error: " +
1504         "state= " + state +
1505         ", vendor= " + vendor +
1506         ", message=" + message +
1507         ", function= " + aFunction;
1508
1509     logger.error(information);
1510
1511     throw new StorageObjectFailure(information, sqe);
1512   }
1513
1514   protected void _throwStorageObjectException(Exception e, String aFunction)
1515     throws StorageObjectFailure {
1516
1517     if (e != null) {
1518       logger.error(e.getMessage() + aFunction);
1519       throw new StorageObjectFailure(aFunction, e);
1520     }
1521   }
1522
1523   /**
1524    * Loggt Fehlermeldung mit dem Parameter Message und wirft dannach
1525    * eine StorageObjectException
1526    * @param message Nachricht mit dem Fehler
1527    * @exception StorageObjectException
1528    */
1529   void throwStorageObjectException(String aMessage) throws StorageObjectFailure {
1530     logger.error(aMessage);
1531     throw new StorageObjectFailure(aMessage, null);
1532   }
1533 }