Entity now freemarker compliant, freemarker lib update, deprecation of HTMLTemplatePr...
[mir.git] / source / mir / storage / Database.java
index 9fc15d0..f6de097 100755 (executable)
@@ -7,8 +7,7 @@ import  java.sql.*;
 import  java.lang.*;
 import  java.io.*;
 import  java.util.*;
-import  freemarker.template.SimpleList;
-import  freemarker.template.SimpleHash;
+import  freemarker.template.*;
 import  com.javaexchange.dbConnectionBroker.*;
 import  mir.storage.StorageObject;
 import  mir.entity.*;
@@ -564,7 +563,6 @@ public class Database implements StorageObject {
     //cache
     invalidatePopupCache();
     try {
-      HashMap theEntityValues = theEntity.getValues();
       ArrayList streamedInput = theEntity.streamedInput();
       StringBuffer f = new StringBuffer();
       StringBuffer v = new StringBuffer();
@@ -584,8 +582,8 @@ public class Database implements StorageObject {
               aValue = "?";
             }
             else {
-              if (theEntityValues.containsKey(aField)) {
-                aValue = "'" + StringUtil.quote((String)theEntityValues.get(aField))
+              if (theEntity.hasValueForField(aField)) {
+                aValue = "'" + StringUtil.quote((String)theEntity.getValue(aField))
                     + "'";
               }
             }
@@ -613,7 +611,7 @@ public class Database implements StorageObject {
       pstmt = con.prepareStatement(sql);
       if (streamedInput != null) {
         for (int i = 0; i < streamedInput.size(); i++) {
-          String inputString = (String)theEntityValues.get(streamedInput.get(i));
+          String inputString = (String)theEntity.getValue((String)streamedInput.get(i));
           pstmt.setBytes(i + 1, inputString.getBytes());
         }
       }
@@ -650,7 +648,6 @@ public class Database implements StorageObject {
     Connection con = null;
     PreparedStatement pstmt = null;
     ArrayList streamedInput = theEntity.streamedInput();
-    HashMap theEntityValues = theEntity.getValues();
     String id = theEntity.getId();
     String aField;
     StringBuffer fv = new StringBuffer();
@@ -663,14 +660,14 @@ public class Database implements StorageObject {
       // only normal cases
       if (!(aField.equals(thePKeyName) || aField.equals("webdb_create") ||
           aField.equals("webdb_lastchange") || (streamedInput != null && streamedInput.contains(aField)))) {
-        if (theEntityValues.containsKey(aField)) {
+        if (theEntity.hasValueForField(aField)) {
           if (firstField == false) {
             fv.append(", ");
           }
           else {
             firstField = false;
           }
-          fv.append(aField).append("='").append(StringUtil.quote((String)theEntityValues.get(aField))).append("'");
+          fv.append(aField).append("='").append(StringUtil.quote((String)theEntity.getValue(aField))).append("'");
         }
       }
     }
@@ -693,7 +690,7 @@ public class Database implements StorageObject {
       pstmt = con.prepareStatement(sql.toString());
       if (streamedInput != null) {
         for (int i = 0; i < streamedInput.size(); i++) {
-          String inputString = (String)theEntityValues.get(streamedInput.get(i));
+          String inputString = theEntity.getValue((String)streamedInput.get(i));
           pstmt.setBytes(i + 1, inputString.getBytes());
         }
       }
@@ -1103,14 +1100,24 @@ public class Database implements StorageObject {
         sqe.toString());
   }
 
+  protected void _throwStorageObjectException (Exception e, String wo) throws StorageObjectException {
+    if (e != null) {
+        theLog.printError(e.toString()+ wo);
+        throw  new StorageObjectException(wo + e.toString());
+    } else {
+        theLog.printError(wo);
+        throw  new StorageObjectException(wo);
+    }
+        
+  }
+
   /**
    * Loggt Fehlermeldung mit dem Parameter Message und wirft dannach eine StorageObjectException
    * @param message Nachricht mit dem Fehler
    * @exception StorageObjectException
    */
   void throwStorageObjectException (String message) throws StorageObjectException {
-    theLog.printError(message);
-    throw  new StorageObjectException(message);
+    _throwStorageObjectException(null, message);
   }
 }