filter page bugs resolved
[mir.git] / source / mir / storage / Database.java
index 5550c87..481efa5 100755 (executable)
@@ -35,7 +35,6 @@ import mir.entity.Entity;
 import mir.entity.EntityList;
 import mir.entity.StorableObjectEntity;
 import mir.log.LoggerWrapper;
-import mir.misc.StringUtil;
 import mir.storage.store.*;
 import mir.util.JDBCStringRoutines;
 import mir.util.StreamCopier;
@@ -56,23 +55,22 @@ import java.util.*;
 /**
  * Implements database access.
  *
- * @version $Id: Database.java,v 1.44.2.33 2005/08/21 17:09:21 zapata Exp $
+ * @version $Id: Database.java,v 1.44.2.34 2005/11/09 22:11:06 zapata Exp $
  * @author rk
  * @author Zapata
  *
  */
 public class Database {
-       private static int DEFAULT_LIMIT = 20;
-  private static Class GENERIC_ENTITY_CLASS = mir.entity.StorableObjectEntity.class;
+       private static final int DEFAULT_LIMIT = 20;
+  private static final Class GENERIC_ENTITY_CLASS = StorableObjectEntity.class;
   protected static final ObjectStore o_store = ObjectStore.getInstance();
-  private static final int _millisPerHour = 60 * 60 * 1000;
 
   protected LoggerWrapper logger;
 
   protected String mainTable;
   protected String primaryKeyField = "id";
 
-  protected List fieldNames;
+  private List fieldNames;
   private int[] fieldTypes;
   private Map fieldNameToType;
 
@@ -81,29 +79,26 @@ public class Database {
   //
   private Set binaryFields;
 
-  TimeZone timezone;
-  SimpleDateFormat internalDateFormat;
-  SimpleDateFormat userInputDateFormat;
+  private TimeZone timezone;
+  private SimpleDateFormat userInputDateFormat;
 
   public Database() throws DatabaseFailure {
     MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();
     logger = new LoggerWrapper("Database");
     timezone = TimeZone.getTimeZone(configuration.getString("Mir.DefaultTimezone"));
-    internalDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-    internalDateFormat.setTimeZone(timezone);
 
     userInputDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
     userInputDateFormat.setTimeZone(timezone);
 
     binaryFields = new HashSet();
 
-    String theAdaptorName = configuration.getString("Database.Adaptor");
+    String adapterName = configuration.getString("Database.Adaptor");
 
     try {
       entityClass = GENERIC_ENTITY_CLASS;
     }
     catch (Throwable e) {
-      logger.error("Error in Database() constructor with " + theAdaptorName + " -- " + e.getMessage());
+      logger.error("Error in Database() constructor with " + adapterName + " -- " + e.getMessage());
       throw new DatabaseFailure("Error in Database() constructor.", e);
     }
   }
@@ -246,20 +241,7 @@ public class Database {
 
             if (!aResultSet.wasNull()) {
               java.util.Date date = new java.util.Date(timestamp.getTime());
-
-              Calendar calendar = new GregorianCalendar();
-              calendar.setTime(date);
-              calendar.setTimeZone(timezone);
-              outValue = internalDateFormat.format(date);
-
-              int offset = calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET);
-              String tzOffset = StringUtil.zeroPaddingNumber(Math.abs(offset) / _millisPerHour, 2, 2);
-
-              if (offset<0)
-                outValue = outValue + "-";
-              else
-                outValue = outValue + "+";
-              outValue = outValue + tzOffset;
+              outValue = DatabaseHelper.convertDateToInternalRepresenation(date);
             }
 
             break;
@@ -268,7 +250,8 @@ public class Database {
             outValue = "<unsupported value>";
             logger.warn("Unsupported Datatype: at " + aFieldIndex + " (" + aType + ")");
         }
-      } catch (SQLException e) {
+      }
+      catch (SQLException e) {
         throw new DatabaseFailure("Could not get Value out of Resultset -- ",
           e);
       }
@@ -618,21 +601,17 @@ public class Database {
    * @param theEntity
    */
   public void update(Entity theEntity) throws DatabaseFailure {
-    Connection connection = null;
-
     invalidateStore();
 
     RecordUpdater generator = new RecordUpdater(getTableName(), theEntity.getId());
 
-    String field;
-
     // build sql statement
     for (int i = 0; i < getFieldNames().size(); i++) {
-      field = (String) getFieldNames().get(i);
+      String field = (String) getFieldNames().get(i);
 
       if (!(field.equals(primaryKeyField) ||
-            field.equals("webdb_create") ||
-            field.equals("webdb_lastchange") ||
+            "webdb_create".equals(field) ||
+            "webdb_lastchange".equals(field) ||
             binaryFields.contains(field))) {
 
         if (theEntity.hasFieldValue(field)) {
@@ -669,6 +648,7 @@ public class Database {
         }
       }
     }
+    Connection connection = null;
 
     try {
       connection = obtainConnection();