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