Entity / Database fix
[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.44.2.1 2003/05/22 19:45:06 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 SimpleList popupCache = null;
113   protected boolean hasPopupCache = false;
114   protected SimpleHash hashCache = null;
115   protected boolean hasTimestamp = true;
116   private String database_driver;
117   private String database_url;
118   private int defaultLimit;
119   protected DatabaseAdaptor theAdaptor;
120   private SimpleDateFormat _dateFormatterOut =
121     new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
122   private SimpleDateFormat _dateFormatterIn =
123     new SimpleDateFormat("yyyy-MM-dd HH:mm");
124   private Calendar _cal = new GregorianCalendar();
125
126   /**
127    * Kontruktor bekommt den Filenamen des Konfigurationsfiles ?bergeben.
128    * Aus diesem file werden <code>Database.Logfile</code>,
129    * <code>Database.Username</code>,<code>Database.Password</code>,
130    * <code>Database.Host</code> und <code>Database.Adaptor</code>
131    * ausgelesen und ein Broker f?r die Verbindugen zur Datenbank
132    * erzeugt.
133    *
134    * @param   String confFilename Dateiname der Konfigurationsdatei
135    */
136   public Database() throws StorageObjectFailure {
137     try {
138       configuration = MirPropertiesConfiguration.instance();
139     }
140     catch (PropertiesConfigExc e) {
141       throw new StorageObjectFailure(e);
142     }
143     logger = new LoggerWrapper("Database");
144
145     String theAdaptorName = configuration.getString("Database.Adaptor");
146     defaultLimit = Integer.parseInt(configuration.getString("Database.Limit"));
147
148     try {
149       theEntityClass = GENERIC_ENTITY_CLASS;
150       theAdaptor = (DatabaseAdaptor) Class.forName(theAdaptorName).newInstance();
151     }
152     catch (Throwable e) {
153       logger.error("Error in Database() constructor with " + theAdaptorName + " -- " + e.getMessage());
154       throw new StorageObjectFailure("Error in Database() constructor.", e);
155     }
156   }
157
158   /**
159    * Liefert die Entity-Klasse zur?ck, in der eine Datenbankzeile gewrappt
160    * wird. Wird die Entity-Klasse durch die erbende Klasse nicht ?berschrieben,
161    * wird eine mir.entity.GenericEntity erzeugt.
162    *
163    * @return Class-Objekt der Entity
164    */
165   public java.lang.Class getEntityClass() {
166     return theEntityClass;
167   }
168
169   /**
170    * Liefert die Standardbeschr?nkung von select-Statements zur?ck, also
171    * wieviel Datens?tze per Default selektiert werden.
172    *
173    * @return Standard-Anzahl der Datens?tze
174    */
175   public int getLimit() {
176     return defaultLimit;
177   }
178
179   /**
180    * Liefert den Namen des Primary-Keys zur?ck. Wird die Variable nicht von
181    * der erbenden Klasse ?berschrieben, so ist der Wert <code>PKEY</code>
182    * @return Name des Primary-Keys
183    */
184   public String getIdName() {
185     return thePKeyName;
186   }
187
188   /**
189    * Liefert den Namen der Tabelle, auf das sich das Datenbankobjekt bezieht.
190    *
191    * @return Name der Tabelle
192    */
193   public String getTableName() {
194     return theTable;
195   }
196
197   /*
198   *   Dient dazu vererbte Tabellen bei objectrelationalen DBMS
199   *   zu speichern, wenn die id einer Tabelle in der parenttabelle verwaltet
200   *   wird.
201   *   @return liefert theCoreTabel als String zurueck, wenn gesetzt, sonst
202   *    the Table
203    */
204   public String getCoreTable() {
205     if (theCoreTable != null) {
206       return theCoreTable;
207     }
208     else {
209       return theTable;
210     }
211   }
212
213   /**
214    * Liefert Feldtypen der Felder der Tabelle zurueck (s.a. java.sql.Types)
215    * @return int-Array mit den Typen der Felder
216    * @exception StorageObjectException
217    */
218   public int[] getTypes() throws StorageObjectFailure {
219     if (metadataTypes == null) {
220       get_meta_data();
221     }
222
223     return metadataTypes;
224   }
225
226   /**
227    * Liefert eine Liste der Labels der Tabellenfelder
228    * @return ArrayListe mit Labeln
229    * @exception StorageObjectException
230    */
231   public List getLabels() throws StorageObjectFailure {
232     if (metadataLabels == null) {
233       get_meta_data();
234     }
235
236     return metadataLabels;
237   }
238
239   /**
240    * Liefert eine Liste der Felder der Tabelle
241    * @return ArrayList mit Feldern
242    * @exception StorageObjectException
243    */
244   public List getFields() throws StorageObjectFailure {
245     if (metadataFields == null) {
246       get_meta_data();
247     }
248
249     return metadataFields;
250   }
251
252   /*
253   *   Gets value out of ResultSet according to type and converts to String
254   *   @param inValue  Wert aus ResultSet.
255   *   @param aType  Datenbanktyp.
256   *   @return liefert den Wert als String zurueck. Wenn keine Umwandlung moeglich
257   *           dann /unsupported value/
258    */
259   private String getValueAsString(ResultSet rs, int valueIndex, int aType)
260     throws StorageObjectFailure {
261     String outValue = null;
262
263     if (rs != null) {
264       try {
265         switch (aType) {
266           case java.sql.Types.BIT:
267             outValue = (rs.getBoolean(valueIndex) == true) ? "1" : "0";
268
269             break;
270
271           case java.sql.Types.INTEGER:
272           case java.sql.Types.SMALLINT:
273           case java.sql.Types.TINYINT:
274           case java.sql.Types.BIGINT:
275
276             int out = rs.getInt(valueIndex);
277
278             if (!rs.wasNull()) {
279               outValue = new Integer(out).toString();
280             }
281
282             break;
283
284           case java.sql.Types.NUMERIC:
285
286             /** @todo Numeric can be float or double depending upon
287              *  metadata.getScale() / especially with oracle */
288             long outl = rs.getLong(valueIndex);
289
290             if (!rs.wasNull()) {
291               outValue = new Long(outl).toString();
292             }
293
294             break;
295
296           case java.sql.Types.REAL:
297
298             float tempf = rs.getFloat(valueIndex);
299
300             if (!rs.wasNull()) {
301               tempf *= 10;
302               tempf += 0.5;
303
304               int tempf_int = (int) tempf;
305               tempf = (float) tempf_int;
306               tempf /= 10;
307               outValue = "" + tempf;
308               outValue = outValue.replace('.', ',');
309             }
310
311             break;
312
313           case java.sql.Types.DOUBLE:
314
315             double tempd = rs.getDouble(valueIndex);
316
317             if (!rs.wasNull()) {
318               tempd *= 10;
319               tempd += 0.5;
320
321               int tempd_int = (int) tempd;
322               tempd = (double) tempd_int;
323               tempd /= 10;
324               outValue = "" + tempd;
325               outValue = outValue.replace('.', ',');
326             }
327
328             break;
329
330           case java.sql.Types.CHAR:
331           case java.sql.Types.VARCHAR:
332           case java.sql.Types.LONGVARCHAR:
333             outValue = rs.getString(valueIndex);
334
335             break;
336
337           case java.sql.Types.LONGVARBINARY:
338             outValue = rs.getString(valueIndex);
339
340             break;
341
342           case java.sql.Types.TIMESTAMP:
343
344             // it's important to use Timestamp here as getting it
345             // as a string is undefined and is only there for debugging
346             // according to the API. we can make it a string through formatting.
347             // -mh
348             Timestamp timestamp = (rs.getTimestamp(valueIndex));
349
350             if (!rs.wasNull()) {
351               java.util.Date date = new java.util.Date(timestamp.getTime());
352               outValue = _dateFormatterOut.format(date);
353               _cal.setTime(date);
354
355               int offset =
356                   _cal.get(Calendar.ZONE_OFFSET) + _cal.get(Calendar.DST_OFFSET);
357               String tzOffset =
358                   StringUtil.zeroPaddingNumber(offset / _millisPerHour, 2, 2);
359               outValue = outValue + "+" + tzOffset;
360             }
361
362             break;
363
364           default:
365             outValue = "<unsupported value>";
366             logger.warn("Unsupported Datatype: at " + valueIndex + " (" + aType + ")");
367         }
368       } catch (SQLException e) {
369         throw new StorageObjectFailure("Could not get Value out of Resultset -- ",
370           e);
371       }
372     }
373
374     return outValue;
375   }
376
377   /*
378   *   select-Operator um einen Datensatz zu bekommen.
379   *   @param id Primaerschluessel des Datensatzes.
380   *   @return liefert EntityObject des gefundenen Datensatzes oder null.
381    */
382   public Entity selectById(String id) throws StorageObjectExc {
383     if ((id == null) || id.equals("")) {
384       throw new StorageObjectExc("Database.selectById: Missing id");
385     }
386
387     // ask object store for object
388     if (StoreUtil.implementsStorableObject(theEntityClass)) {
389       String uniqueId = id;
390
391       if (theEntityClass.equals(StorableObjectEntity.class)) {
392         uniqueId += ("@" + theTable);
393       }
394
395       StoreIdentifier search_sid = new StoreIdentifier(theEntityClass, uniqueId);
396       logger.debug("CACHE: (dbg) looking for sid " + search_sid.toString());
397
398       Entity hit = (Entity) o_store.use(search_sid);
399
400       if (hit != null) {
401         return hit;
402       }
403     }
404
405     Statement stmt = null;
406     Connection con = getPooledCon();
407     Entity returnEntity = null;
408
409     try {
410       ResultSet rs;
411
412       /** @todo better prepared statement */
413       String selectSql =
414         "select * from " + theTable + " where " + thePKeyName + "=" + id;
415       stmt = con.createStatement();
416       rs = executeSql(stmt, selectSql);
417
418       if (rs != null) {
419         if (evaluatedMetaData == false) {
420           evalMetaData(rs.getMetaData());
421         }
422
423         if (rs.next()) {
424           returnEntity = makeEntityFromResultSet(rs);
425         }
426         else {
427           logger.debug("No data for id: " + id + " in table " + theTable);
428         }
429
430         rs.close();
431       }
432       else {
433         logger.debug("No Data for Id " + id + " in Table " + theTable);
434       }
435     }
436     catch (SQLException sqe) {
437       throwSQLException(sqe, "selectById");
438       return null;
439     }
440     catch (NumberFormatException e) {
441       logger.error("ID is no number: " + id);
442     }
443     finally {
444       freeConnection(con, stmt);
445     }
446
447     return returnEntity;
448   }
449
450   /**
451    *   select-Operator um Datensaetze zu bekommen, die key = value erfuellen.
452    *   @param key  Datenbankfeld der Bedingung.
453    *   @param value  Wert die der key anehmen muss.
454    *   @return EntityList mit den gematchten Entities
455    */
456   public EntityList selectByFieldValue(String aField, String aValue) throws StorageObjectFailure {
457     return selectByFieldValue(aField, aValue, 0);
458   }
459
460   /**
461    *   select-Operator um Datensaetze zu bekommen, die key = value erfuellen.
462    *   @param key  Datenbankfeld der Bedingung.
463    *   @param value  Wert die der key anehmen muss.
464    *   @param offset  Gibt an ab welchem Datensatz angezeigt werden soll.
465    *   @return EntityList mit den gematchten Entities
466    */
467   public EntityList selectByFieldValue(String aField, String aValue, int offset) throws StorageObjectFailure {
468     return selectByWhereClause(aField + "=" + aValue, offset);
469   }
470
471   /**
472    * select-Operator liefert eine EntityListe mit den gematchten Datens?tzen zur?ck.
473    * Also offset wird der erste Datensatz genommen.
474    *
475    * @param wc where-Clause
476    * @return EntityList mit den gematchten Entities
477    * @exception StorageObjectException
478    */
479   public EntityList selectByWhereClause(String where) throws StorageObjectFailure {
480     return selectByWhereClause(where, 0);
481   }
482
483   /**
484    * select-Operator liefert eine EntityListe mit den gematchten Datens?tzen zur?ck.
485    * Als maximale Anzahl wird das Limit auf der Konfiguration genommen.
486    *
487    * @param wc where-Clause
488    * @param offset ab welchem Datensatz.
489    * @return EntityList mit den gematchten Entities
490    * @exception StorageObjectException
491    */
492   public EntityList selectByWhereClause(String whereClause, int offset) throws StorageObjectFailure {
493     return selectByWhereClause(whereClause, null, offset);
494   }
495
496   /**
497    * select-Operator liefert eine EntityListe mit den gematchten Datens?tzen zur?ck.
498    * Also offset wird der erste Datensatz genommen.
499    * Als maximale Anzahl wird das Limit auf der Konfiguration genommen.
500    *
501    * @param wc where-Clause
502    * @param ob orderBy-Clause
503    * @return EntityList mit den gematchten Entities
504    * @exception StorageObjectException
505    */
506   public EntityList selectByWhereClause(String where, String order) throws StorageObjectFailure {
507     return selectByWhereClause(where, order, 0);
508   }
509
510   /**
511    * select-Operator liefert eine EntityListe mit den gematchten Datens?tzen zur?ck.
512    * Als maximale Anzahl wird das Limit auf der Konfiguration genommen.
513    *
514    * @param wc where-Clause
515    * @param ob orderBy-Clause
516    * @param offset ab welchem Datensatz
517    * @return EntityList mit den gematchten Entities
518    * @exception StorageObjectException
519    */
520   public EntityList selectByWhereClause(String whereClause, String orderBy, int offset) throws StorageObjectFailure {
521     return selectByWhereClause(whereClause, orderBy, offset, defaultLimit);
522   }
523
524   /**
525    * select-Operator liefert eine EntityListe mit den gematchten Datens?tzen zur?ck.
526    * @param aWhereClause where-Clause
527    * @param anOrderByClause orderBy-Clause
528    * @param offset ab welchem Datensatz
529    * @param limit wieviele Datens?tze
530    * @return EntityList mit den gematchten Entities
531    * @exception StorageObjectException
532    */
533   public EntityList selectByWhereClause(String aWhereClause, String anOrderByClause,
534             int offset, int limit) throws StorageObjectFailure {
535
536     // check o_store for entitylist
537     if (StoreUtil.implementsStorableObject(theEntityClass)) {
538       StoreIdentifier search_sid =
539           new StoreIdentifier(
540             theEntityClass, StoreContainerType.STOC_TYPE_ENTITYLIST,
541             StoreUtil.getEntityListUniqueIdentifierFor(theTable, aWhereClause, anOrderByClause, offset, limit));
542       EntityList hit = (EntityList) o_store.use(search_sid);
543
544       if (hit != null) {
545         logger.debug("CACHE (hit): " + search_sid.toString());
546
547         return hit;
548       }
549     }
550
551     // local
552     EntityList theReturnList = null;
553     Connection con = null;
554     Statement stmt = null;
555     ResultSet rs;
556     int offsetCount = 0;
557     int count = 0;
558
559     // build sql-statement
560
561     /** @todo count sql string should only be assembled if we really count
562      *  see below at the end of method //rk */
563     if ((aWhereClause != null) && (aWhereClause.trim().length() == 0)) {
564       aWhereClause = null;
565     }
566
567     StringBuffer countSql =
568       new StringBuffer("select count(*) from ").append(theTable);
569     StringBuffer selectSql =
570       new StringBuffer("select * from ").append(theTable);
571
572     if (aWhereClause != null) {
573       selectSql.append(" where ").append(aWhereClause);
574       countSql.append(" where ").append(aWhereClause);
575     }
576
577     if ((anOrderByClause != null) && !(anOrderByClause.trim().length() == 0)) {
578       selectSql.append(" order by ").append(anOrderByClause);
579     }
580
581     if (theAdaptor.hasLimit()) {
582       if ((limit > -1) && (offset > -1)) {
583         selectSql.append(" LIMIT ").append(limit).append(" OFFSET ").append(offset);
584       }
585     }
586
587     // execute sql
588     try {
589       con = getPooledCon();
590       stmt = con.createStatement();
591
592       // selecting...
593       rs = executeSql(stmt, selectSql.toString());
594
595       if (rs != null) {
596         if (!evaluatedMetaData) {
597           evalMetaData(rs.getMetaData());
598         }
599
600         theReturnList = new EntityList();
601
602         Entity theResultEntity;
603
604         while (rs.next()) {
605           theResultEntity = makeEntityFromResultSet(rs);
606           theReturnList.add(theResultEntity);
607           offsetCount++;
608         }
609
610         rs.close();
611       }
612
613       // making entitylist infos
614       if (!(theAdaptor.hasLimit())) {
615         count = offsetCount;
616       }
617
618       if (theReturnList != null) {
619         // now we decide if we have to know an overall count...
620         count = offsetCount;
621
622         if ((limit > -1) && (offset > -1)) {
623           if (offsetCount == limit) {
624             /** @todo counting should be deffered to entitylist
625              *  getSize() should be used */
626             rs = executeSql(stmt, countSql.toString());
627
628             if (rs != null) {
629               if (rs.next()) {
630                 count = rs.getInt(1);
631               }
632
633               rs.close();
634             }
635             else {
636               logger.error("Could not count: " + countSql);
637             }
638           }
639         }
640
641         theReturnList.setCount(count);
642         theReturnList.setOffset(offset);
643         theReturnList.setWhere(aWhereClause);
644         theReturnList.setOrder(anOrderByClause);
645         theReturnList.setStorage(this);
646         theReturnList.setLimit(limit);
647
648         if (offset >= limit) {
649           theReturnList.setPrevBatch(offset - limit);
650         }
651
652         if ((offset + offsetCount) < count) {
653           theReturnList.setNextBatch(offset + limit);
654         }
655
656         if (StoreUtil.implementsStorableObject(theEntityClass)) {
657           StoreIdentifier sid = theReturnList.getStoreIdentifier();
658           logger.debug("CACHE (add): " + sid.toString());
659           o_store.add(sid);
660         }
661       }
662     }
663     catch (SQLException sqe) {
664       throwSQLException(sqe, "selectByWhereClause");
665     }
666     finally {
667       try {
668         if (con != null) {
669           freeConnection(con, stmt);
670         }
671       } catch (Throwable t) {
672       }
673     }
674
675     return theReturnList;
676   }
677
678   /**
679    *  Bastelt aus einer Zeile der Datenbank ein EntityObjekt.
680    *
681    *  @param rs Das ResultSetObjekt.
682    *  @return Entity Die Entity.
683    */
684   private Entity makeEntityFromResultSet(ResultSet rs)
685     throws StorageObjectFailure {
686     /** @todo OS: get Pkey from ResultSet and consult ObjectStore */
687     Map theResultHash = new HashMap();
688     String theResult = null;
689     int theType;
690     Entity returnEntity = null;
691
692     try {
693       int size = metadataFields.size();
694
695       for (int i = 0; i < size; i++) {
696         // alle durchlaufen bis nix mehr da
697         theType = metadataTypes[i];
698
699         if (theType == java.sql.Types.LONGVARBINARY) {
700           InputStreamReader is =
701             (InputStreamReader) rs.getCharacterStream(i + 1);
702
703           if (is != null) {
704             char[] data = new char[32768];
705             StringBuffer theResultString = new StringBuffer();
706             int len;
707
708             while ((len = is.read(data)) > 0) {
709               theResultString.append(data, 0, len);
710             }
711
712             is.close();
713             theResult = theResultString.toString();
714           } else {
715             theResult = null;
716           }
717         } else {
718           theResult = getValueAsString(rs, (i + 1), theType);
719         }
720
721         if (theResult != null) {
722           theResultHash.put(metadataFields.get(i), theResult);
723         }
724       }
725
726       if (theEntityClass != null) {
727         returnEntity = (Entity) theEntityClass.newInstance();
728         returnEntity.setStorage(this);
729         returnEntity.setValues(theResultHash);
730
731         if (returnEntity instanceof StorableObject) {
732           logger.debug("CACHE: ( in) " + returnEntity.getId() + " :" + theTable);
733           o_store.add(((StorableObject) returnEntity).getStoreIdentifier());
734         }
735       } else {
736         throwStorageObjectException("Internal Error: theEntityClass not set!");
737       }
738     }
739     catch (IllegalAccessException e) {
740       throwStorageObjectException("No access! -- " + e.getMessage());
741     }
742     catch (IOException e) {
743       throwStorageObjectException("IOException! -- " + e.getMessage());
744     }
745     catch (InstantiationException e) {
746       throwStorageObjectException("No Instatiation! -- " + e.getMessage());
747     }
748     catch (SQLException sqe) {
749       throwSQLException(sqe, "makeEntityFromResultSet");
750
751       return null;
752     }
753
754     return returnEntity;
755   }
756
757   /**
758    * Inserts an entity into the database.
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           }
799           else {
800             if ((streamedInput != null) && streamedInput.contains(aField)) {
801               aValue = "?";
802             } else {
803               if (theEntity.hasValueForField(aField)) {
804                 aValue =
805                   "'" +
806                   JDBCStringRoutines.escapeStringLiteral((String) theEntity.getValue(
807                       aField)) + "'";
808               }
809             }
810           }
811
812           // wenn Wert gegeben, dann einbauen
813           if (aValue != null) {
814             if (firstField == false) {
815               f.append(",");
816               v.append(",");
817             }
818             else {
819               firstField = false;
820             }
821
822             f.append(aField);
823             v.append(aValue);
824           }
825         }
826       }
827        // end for
828
829       // insert into db
830       StringBuffer sqlBuf =
831         new StringBuffer("insert into ").append(theTable).append("(").append(f)
832                                         .append(") values (").append(v).append(")");
833       String sql = sqlBuf.toString();
834
835       logger.debug("INSERT: " + sql);
836       con = getPooledCon();
837       con.setAutoCommit(false);
838       pstmt = con.prepareStatement(sql);
839
840       if (streamedInput != null) {
841         for (int i = 0; i < streamedInput.size(); i++) {
842           String inputString =
843             (String) theEntity.getValue((String) streamedInput.get(i));
844           pstmt.setBytes(i + 1, inputString.getBytes());
845         }
846       }
847
848       int ret = pstmt.executeUpdate();
849
850       if (ret == 0) {
851         //insert failed
852         return null;
853       }
854
855       pstmt = con.prepareStatement(theAdaptor.getLastInsertSQL(this));
856
857       ResultSet rs = pstmt.executeQuery();
858       rs.next();
859       returnId = rs.getString(1);
860       theEntity.setId(returnId);
861     }
862     catch (SQLException sqe) {
863       throwSQLException(sqe, "insert");
864     }
865     finally {
866       try {
867         con.setAutoCommit(true);
868       }
869       catch (Exception e) {
870       }
871
872       freeConnection(con, pstmt);
873     }
874
875     /** @todo store entity in o_store */
876     return returnId;
877   }
878
879   /**
880    * Updates an entity in the database
881    *
882    * @param theEntity
883    */
884   public void update(Entity theEntity) throws StorageObjectFailure {
885     Connection con = null;
886     PreparedStatement pstmt = null;
887
888     /** @todo this is stupid: why do we prepare statement, when we
889      *  throw it away afterwards. should be regular statement
890      *  update/insert could better be one routine called save()
891      *  that chooses to either insert or update depending if we
892      *  have a primary key in the entity. i don't know if we
893      *  still need the streamed input fields. // rk  */
894     /** @todo extension: check if Entity did change, otherwise we don't need
895      *  the roundtrip to the database */
896     /** invalidating corresponding entitylists in o_store*/
897     if (StoreUtil.implementsStorableObject(theEntityClass)) {
898       StoreContainerType stoc_type =
899         StoreContainerType.valueOf(theEntityClass,
900           StoreContainerType.STOC_TYPE_ENTITYLIST);
901       o_store.invalidate(stoc_type);
902     }
903
904     List streamedInput = theEntity.streamedInput();
905     String id = theEntity.getId();
906     String aField;
907     StringBuffer fv = new StringBuffer();
908     boolean firstField = true;
909
910     //cache
911     invalidatePopupCache();
912
913     // build sql statement
914     for (int i = 0; i < getFields().size(); i++) {
915       aField = (String) metadataFields.get(i);
916
917       // only normal cases
918       if (  !(aField.equals(thePKeyName) ||
919             aField.equals("webdb_create") ||
920             aField.equals("webdb_lastchange") ||
921             ((streamedInput != null) && streamedInput.contains(aField)))) {
922         if (theEntity.hasValueForField(aField)) {
923           if (firstField == false) {
924             fv.append(", ");
925           }
926           else {
927             firstField = false;
928           }
929
930           fv.append(aField).append("='").append(JDBCStringRoutines.escapeStringLiteral((String) theEntity.getValue(aField))).append("'");
931
932           //              fv.append(aField).append("='").append(StringUtil.quote((String)theEntity.getValue(aField))).append("'");
933         }
934       }
935     }
936
937     StringBuffer sql =
938       new StringBuffer("update ").append(theTable).append(" set ").append(fv);
939
940     // exceptions
941     if (metadataFields.contains("webdb_lastchange")) {
942       sql.append(",webdb_lastchange=NOW()");
943     }
944
945     // special case: the webdb_create requires the field in yyyy-mm-dd HH:mm
946     // format so anything extra will be ignored. -mh
947     if (metadataFields.contains("webdb_create") &&
948         theEntity.hasValueForField("webdb_create")) {
949       // minimum of 10 (yyyy-mm-dd)...
950       if (theEntity.getValue("webdb_create").length() >= 10) {
951         String dateString = theEntity.getValue("webdb_create");
952
953         // if only 10, then add 00:00 so it doesn't throw a ParseException
954         if (dateString.length() == 10) {
955           dateString = dateString + " 00:00";
956         }
957
958         // TimeStamp stuff
959         try {
960           java.util.Date d = _dateFormatterIn.parse(dateString);
961           Timestamp tStamp = new Timestamp(d.getTime());
962           sql.append(",webdb_create='" + tStamp.toString() + "'");
963         } catch (ParseException e) {
964           throw new StorageObjectFailure(e);
965         }
966       }
967     }
968
969     if (streamedInput != null) {
970       for (int i = 0; i < streamedInput.size(); i++) {
971         sql.append(",").append(streamedInput.get(i)).append("=?");
972       }
973     }
974
975     sql.append(" where id=").append(id);
976     logger.debug("UPDATE: " + sql);
977
978     try {
979       con = getPooledCon();
980       con.setAutoCommit(false);
981       pstmt = con.prepareStatement(sql.toString());
982
983       if (streamedInput != null) {
984         for (int i = 0; i < streamedInput.size(); i++) {
985           String inputString =
986             theEntity.getValue((String) streamedInput.get(i));
987           pstmt.setBytes(i + 1, inputString.getBytes());
988         }
989       }
990
991       pstmt.executeUpdate();
992     }
993     catch (SQLException sqe) {
994       throwSQLException(sqe, "update");
995     }
996     finally {
997       try {
998         con.setAutoCommit(true);
999       }
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     Connection connection = null;
1238     Statement statement = null;
1239
1240     try {
1241       connection = getPooledCon();
1242       statement = connection.createStatement();
1243       ResultSet result;
1244
1245       result = statement.executeQuery(sql);
1246
1247       logger.debug((System.currentTimeMillis() - startTime) + "ms. for: " + sql);
1248       return result;
1249     }
1250     catch (Throwable e) {
1251       logger.error(e.getMessage() +"\n" + (System.currentTimeMillis() - startTime) + "ms. for: " + sql);
1252       throw new StorageObjectFailure(e);
1253     }
1254     finally {
1255       if (connection!=null) {
1256         freeConnection(connection, statement);
1257       }
1258     }
1259   }
1260 */
1261   private Map processRow(ResultSet aResultSet) throws StorageObjectFailure, StorageObjectExc {
1262     try {
1263       Map result = new HashMap();
1264       ResultSetMetaData metaData = aResultSet.getMetaData();
1265       int nrColumns = metaData.getColumnCount();
1266       for (int i=0; i<nrColumns; i++) {
1267         result.put(metaData.getColumnName(i+1), getValueAsString(aResultSet, i+1, metaData.getColumnType(i+1)));
1268       }
1269
1270       return result;
1271     }
1272     catch (Throwable e) {
1273       throw new StorageObjectFailure(e);
1274     }
1275   }
1276
1277   public List executeFreeSql(String sql, int aLimit) throws StorageObjectFailure, StorageObjectExc {
1278     Connection connection = null;
1279     Statement statement = null;
1280     try {
1281       List result = new Vector();
1282       connection = getPooledCon();
1283       statement = connection.createStatement();
1284       ResultSet resultset = executeSql(statement, sql);
1285       try {
1286         while (resultset.next() && result.size() < aLimit) {
1287           result.add(processRow(resultset));
1288         }
1289       }
1290       finally {
1291         resultset.close();
1292       }
1293
1294       return result;
1295     }
1296     catch (Throwable e) {
1297       throw new StorageObjectFailure(e);
1298     }
1299     finally {
1300       if (connection!=null) {
1301         freeConnection(connection, statement);
1302       }
1303     }
1304   };
1305
1306   public Map executeFreeSingleRowSql(String anSqlStatement) throws StorageObjectFailure, StorageObjectExc {
1307     try {
1308       List resultList = executeFreeSql(anSqlStatement, 1);
1309       try {
1310         if (resultList.size()>0)
1311           return (Map) resultList.get(0);
1312         else
1313           return null;
1314       }
1315       finally {
1316       }
1317     }
1318     catch (Throwable t) {
1319       throw new StorageObjectFailure(t);
1320     }
1321   };
1322
1323   public String executeFreeSingleValueSql(String sql) throws StorageObjectFailure, StorageObjectExc {
1324     Map row = executeFreeSingleRowSql(sql);
1325
1326     if (row==null)
1327       return null;
1328
1329     Iterator i = row.values().iterator();
1330     if (i.hasNext())
1331       return (String) i.next();
1332     else
1333       return null;
1334   };
1335
1336   /**
1337    * returns the number of rows in the table
1338    */
1339   public int getSize(String where) throws SQLException, StorageObjectFailure {
1340     long startTime = System.currentTimeMillis();
1341     String sql = "SELECT Count(*) FROM " + theTable;
1342
1343     if ((where != null) && (where.length() != 0)) {
1344       sql = sql + " where " + where;
1345     }
1346
1347     Connection con = null;
1348     Statement stmt = null;
1349     int result = 0;
1350
1351     try {
1352       con = getPooledCon();
1353       stmt = con.createStatement();
1354
1355       ResultSet rs = executeSql(stmt, sql);
1356
1357       while (rs.next()) {
1358         result = rs.getInt(1);
1359       }
1360     }
1361     catch (SQLException e) {
1362       logger.error("Database.getSize: " + e.getMessage());
1363     }
1364     finally {
1365       freeConnection(con, stmt);
1366     }
1367
1368     //theLog.printInfo(theTable + " has "+ result +" rows where " + where);
1369     logger.debug((System.currentTimeMillis() - startTime) + "ms. for: " + sql);
1370
1371     return result;
1372   }
1373
1374   public int executeUpdate(Statement stmt, String sql)
1375     throws StorageObjectFailure, SQLException {
1376     int rs;
1377     long startTime = System.currentTimeMillis();
1378
1379     try {
1380       rs = stmt.executeUpdate(sql);
1381
1382       logger.debug((System.currentTimeMillis() - startTime) + "ms. for: " + sql);
1383     }
1384     catch (SQLException e) {
1385       logger.error("Failed: " + (System.currentTimeMillis() - startTime) + "ms. for: " + sql);
1386       throw e;
1387     }
1388
1389     return rs;
1390   }
1391
1392   public int executeUpdate(String sql)
1393     throws StorageObjectFailure, SQLException {
1394     int result = -1;
1395     long startTime = System.currentTimeMillis();
1396     Connection con = null;
1397     PreparedStatement pstmt = null;
1398
1399     try {
1400       con = getPooledCon();
1401       pstmt = con.prepareStatement(sql);
1402       result = pstmt.executeUpdate();
1403     }
1404     catch (Throwable e) {
1405       logger.error("Database.executeUpdate(" + sql + "): " + e.getMessage());
1406       throw new StorageObjectFailure("Database.executeUpdate(" + sql + "): " + e.getMessage(), e);
1407     }
1408     finally {
1409       freeConnection(con, pstmt);
1410     }
1411
1412     logger.debug((System.currentTimeMillis() - startTime) + "ms. for: " + sql);
1413     return result;
1414   }
1415
1416   /**
1417    * Wertet ResultSetMetaData aus und setzt interne Daten entsprechend
1418    * @param md ResultSetMetaData
1419    * @exception StorageObjectException
1420    */
1421   private void evalMetaData(ResultSetMetaData md) throws StorageObjectFailure {
1422     this.evaluatedMetaData = true;
1423     this.metadataFields = new ArrayList();
1424     this.metadataLabels = new ArrayList();
1425     this.metadataNotNullFields = new ArrayList();
1426
1427     try {
1428       int numFields = md.getColumnCount();
1429       this.metadataTypes = new int[numFields];
1430
1431       String aField;
1432       int aType;
1433
1434       for (int i = 1; i <= numFields; i++) {
1435         aField = md.getColumnName(i);
1436         metadataFields.add(aField);
1437         metadataLabels.add(md.getColumnLabel(i));
1438         aType = md.getColumnType(i);
1439         metadataTypes[i - 1] = aType;
1440
1441         if (aField.equals(thePKeyName)) {
1442           thePKeyType = aType;
1443           thePKeyIndex = i;
1444         }
1445
1446         if (md.isNullable(i) == ResultSetMetaData.columnNullable) {
1447           metadataNotNullFields.add(aField);
1448         }
1449       }
1450     }
1451     catch (SQLException e) {
1452       throwSQLException(e, "evalMetaData");
1453     }
1454   }
1455
1456   /**
1457    *  Wertet die Metadaten eines Resultsets fuer eine Tabelle aus,
1458    *  um die alle Columns und Typen einer Tabelle zu ermitteln.
1459    */
1460   private void get_meta_data() throws StorageObjectFailure {
1461     Connection con = null;
1462     PreparedStatement pstmt = null;
1463     String sql = "select * from " + theTable + " where 0=1";
1464
1465     try {
1466       con = getPooledCon();
1467       pstmt = con.prepareStatement(sql);
1468
1469       logger.debug("METADATA: " + sql);
1470       ResultSet rs = pstmt.executeQuery();
1471       evalMetaData(rs.getMetaData());
1472       rs.close();
1473     }
1474     catch (SQLException e) {
1475       throwSQLException(e, "get_meta_data");
1476     }
1477     finally {
1478       freeConnection(con, pstmt);
1479     }
1480   }
1481
1482   public Connection getPooledCon() throws StorageObjectFailure {
1483     Connection con = null;
1484
1485     try {
1486       con = SQLManager.getInstance().requestConnection();
1487     }
1488     catch (SQLException e) {
1489       logger.error("could not connect to the database " + e.getMessage());
1490
1491       throw new StorageObjectFailure("Could not connect to the database", e);
1492     }
1493
1494     return con;
1495   }
1496
1497   public void freeConnection(Connection con, Statement stmt)
1498     throws StorageObjectFailure {
1499     SQLManager.closeStatement(stmt);
1500     SQLManager.getInstance().returnConnection(con);
1501   }
1502
1503   /**
1504    * Wertet SQLException aus und wirft dannach eine StorageObjectException
1505    * @param sqe SQLException
1506    * @param wo Funktonsname, in der die SQLException geworfen wurde
1507    * @exception StorageObjectException
1508    */
1509   protected void throwSQLException(SQLException sqe, String aFunction) throws StorageObjectFailure {
1510     String state = "";
1511     String message = "";
1512     int vendor = 0;
1513
1514     if (sqe != null) {
1515       state = sqe.getSQLState();
1516       message = sqe.getMessage();
1517       vendor = sqe.getErrorCode();
1518     }
1519
1520     String information =
1521         "SQL Error: " +
1522         "state= " + state +
1523         ", vendor= " + vendor +
1524         ", message=" + message +
1525         ", function= " + aFunction;
1526
1527     logger.error(information);
1528
1529     throw new StorageObjectFailure(information, sqe);
1530   }
1531
1532   protected void _throwStorageObjectException(Exception e, String aFunction)
1533     throws StorageObjectFailure {
1534
1535     if (e != null) {
1536       logger.error(e.getMessage() + aFunction);
1537       throw new StorageObjectFailure(aFunction, e);
1538     }
1539   }
1540
1541   /**
1542    * Loggt Fehlermeldung mit dem Parameter Message und wirft dannach
1543    * eine StorageObjectException
1544    * @param message Nachricht mit dem Fehler
1545    * @exception StorageObjectException
1546    */
1547   void throwStorageObjectException(String aMessage) throws StorageObjectFailure {
1548     logger.error(aMessage);
1549     throw new StorageObjectFailure(aMessage, null);
1550   }
1551 }