changeset 271:8aad9d098b08

Integrated Patch of issue57 to get some Memoryusage-improvements geo-backend/trunk@248 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 20 Oct 2009 09:57:52 +0000
parents 1fe93e3c80c0
children 05912f0304ac
files geo-backend/ChangeLog geo-backend/src/main/java/de/intevation/gnv/geobackend/base/DefaultResult.java geo-backend/src/main/java/de/intevation/gnv/geobackend/base/DefaultResultDescriptor.java geo-backend/src/main/java/de/intevation/gnv/geobackend/base/Result.java geo-backend/src/main/java/de/intevation/gnv/geobackend/base/ResultDescriptor.java geo-backend/src/main/java/de/intevation/gnv/geobackend/base/query/QueryExecutorBase.java
diffstat 6 files changed, 110 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/geo-backend/ChangeLog	Mon Oct 19 10:27:24 2009 +0000
+++ b/geo-backend/ChangeLog	Tue Oct 20 09:57:52 2009 +0000
@@ -1,3 +1,12 @@
+2009-10-20  Tim Englich  <tim.englich@intevation.de>
+
+	* src/main/java/de/intevation/gnv/geobackend/base/query/QueryExecutorBase.java (QueryExecutorBase),
+	  src/main/java/de/intevation/gnv/geobackend/base/ResultDescriptor.java (getColumnClassName),
+	  src/main/java/de/intevation/gnv/geobackend/base/Result.java, 
+	  src/main/java/de/intevation/gnv/geobackend/base/DefaultResultDescriptor.java (serialVersionUID), 
+	  src/main/java/de/intevation/gnv/geobackend/base/DefaultResult.java (getDate):
+	  Integrated Patch of issue57 to get some Memoryusage-improvements  
+
 2009-10-19	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/gnv/geobackend/base/DefaultResult.java:
--- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/base/DefaultResult.java	Mon Oct 19 10:27:24 2009 +0000
+++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/base/DefaultResult.java	Tue Oct 20 09:57:52 2009 +0000
@@ -16,7 +16,6 @@
  *
  */
 public class DefaultResult 
-extends      HashMap<String, Object>
 implements   Result 
 {
     /**
@@ -28,6 +27,8 @@
     /**
      * HashMap which stores the Columnvalues identified by the unique Columnname
      */
+
+     private Object [] values;
     
     /**
      * The ResultDescriptor which describes the ColumnValues
@@ -38,15 +39,19 @@
      * Constructor
      */
     public DefaultResult(ResultDescriptor resultDescriptor) {
-        super();
         this.resultDescriptor = resultDescriptor;
+        values = new Object[resultDescriptor.getColumnCount()];
     }
 
     /**
      * @see de.intevation.gnv.geobackend.base.Result#getDate(java.lang.String)
      */
     public Date getDate(String columnName) {
-        Object o = get(columnName);
+        return getDate(resultDescriptor.getColumnIndex(columnName));
+    }
+
+    public Date getDate(int column) {
+        Object o = values[column];
         Date d = null;
         if(o instanceof Date){
             d = (Date)o;
@@ -60,23 +65,34 @@
      * @see de.intevation.gnv.geobackend.base.Result#getDouble(java.lang.String)
      */
     public Double getDouble(String columnName) {
-        return (Double)get(columnName);
+        return getDouble(resultDescriptor.getColumnIndex(columnName));
+    }
+
+    public Double getDouble(int column) {
+        return (Double)values[column];
     }
 
     /**
      * @see de.intevation.gnv.geobackend.base.Result#getFloat(java.lang.String)
      */
     public Float getFloat(String columnName) {
-        return (Float)get(columnName);
+        return getFloat(resultDescriptor.getColumnIndex(columnName));
+    }
+
+    public Float getFloat(int column) {
+        return (Float)values[column];
     }
 
     /**
      * @see de.intevation.gnv.geobackend.base.Result#getInteger(java.lang.String)
      */
     public Integer getInteger(String columnName) {
-        return (Integer)get(columnName);
+        return getInteger(resultDescriptor.getColumnIndex(columnName));
     }
 
+    public Integer getInteger(int column) {
+        return (Integer)values[column];
+    }
     /**
      * @see de.intevation.gnv.geobackend.base.Result#getResultDescriptor()
      */
@@ -88,7 +104,13 @@
      * @see de.intevation.gnv.geobackend.base.Result#getString(java.lang.String)
      */
     public String getString(String columnName) {
-        Object o = get(columnName);
+        return getString(resultDescriptor.getColumnIndex(columnName));
+    }
+
+    public String getString(int column) {
+
+        Object o = values[column];
+
         if (o instanceof Date){
             return DateUtils.getPatternedDateAmer((Date)o);
         }
@@ -98,21 +120,25 @@
             return DateUtils.getPatternedDateAmer(d);
         }
 
-        return o != null ? o.toString() : "";
+        return o != null ? o.toString() : null;
     }
 
     /**
      * @see de.intevation.gnv.geobackend.base.Result#addColumnValue(java.lang.String, java.lang.Object)
      */
-    public void addColumnValue(String columnName, Object value) {
-        put(columnName, value);
+    public void addColumnValue(int column, Object value) {
+        values[column] = value;
     }
 
     /**
      * @see de.intevation.gnv.geobackend.base.Result#getObject(java.lang.String)
      */
     public Object getObject(String columnName) {
-        return get(columnName);
+        return getObject(resultDescriptor.getColumnIndex(columnName));
+    }
+
+    public Object getObject(int column) {
+        return values[column];
     }
 
 }
--- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/base/DefaultResultDescriptor.java	Mon Oct 19 10:27:24 2009 +0000
+++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/base/DefaultResultDescriptor.java	Tue Oct 20 09:57:52 2009 +0000
@@ -4,7 +4,9 @@
 package de.intevation.gnv.geobackend.base;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * This Class is the DefaultImplementation of the
@@ -29,7 +31,10 @@
      */
     private List<String> columnClassNames = new ArrayList<String>();
     
-    
+    /**
+     * 
+     */
+    private Map<String, Integer> columnIndexLookup = new HashMap<String, Integer>();
     
     /**
      * Constructor
@@ -65,6 +70,35 @@
     public void addColumn(String name, String className) {
         this.columnClassNames.add(className);
         this.columnNames.add(name);
+        this.columnIndexLookup.put(name,this.columnNames.size()-1);
     }
 
-}
\ No newline at end of file
+    /**
+     * @see de.intevation.gnv.geobackend.base.ResultDescriptor#getColumnIndices(java.lang.String[])
+     */
+    public int [] getColumnIndices(String [] columnNames) {
+        if (columnNames == null) {
+            return null;
+        }
+
+        int [] indices = new int[columnNames.length];
+
+        for (int i = 0; i < indices.length; ++i) {
+            indices[i] = this.getColumnIndex(columnNames[i]);
+        }
+
+        return indices;
+    }
+
+    /**
+     * @see de.intevation.gnv.geobackend.base.ResultDescriptor#getColumnIndex(java.lang.String)
+     */
+    public int getColumnIndex(String columnName) {
+        
+        Integer value = this.columnIndexLookup.get(columnName);
+        if (value != null){
+            return value.intValue();
+        }
+        return -1;
+    }
+}
--- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/base/Result.java	Mon Oct 19 10:27:24 2009 +0000
+++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/base/Result.java	Tue Oct 20 09:57:52 2009 +0000
@@ -28,6 +28,9 @@
      * @return the Columnvalue as a String
      */
     public String getString(String columnName);
+
+
+    public String getString(int column);
     
     /**
      * Returns the Columnvalue as a Date
@@ -35,6 +38,8 @@
      * @return the Columnvalue as a Date
      */
     public Date getDate(String columnName);
+
+    public Date getDate(int column);
     
     /**
      * Returns the Columnvalue as a Integer
@@ -43,12 +48,16 @@
      */
     public Integer getInteger(String columnName);
 
+    public Integer getInteger(int column);
+
     /**
      * Returns the Columnvalue as a Float
      * @param columnName the Name of the column
      * @return the Columnvalue as a Float
      */
     public Float getFloat(String columnName);
+
+    public Float getFloat(int column);
     
     /**
      * Returns the Columnvalue as a Double
@@ -56,6 +65,8 @@
      * @return the Columnvalue as a Double
      */
     public Double getDouble(String columnName);
+
+    public Double getDouble(int column);
     
     /**
      * Returns the Columnvalue as a Object
@@ -63,11 +74,13 @@
      * @return the Columnvalue as a Object
      */
     public Object getObject(String columnName);
+
+    public Object getObject(int column);
     
     /**
      * Adds an new Coumnvalue to the Result.
      * @param columnName the Name of the Column
      * @param value the Value of the Column
      */
-    public void addColumnValue(String columnName, Object value);
+    public void addColumnValue(int column, Object value);
 }
--- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/base/ResultDescriptor.java	Mon Oct 19 10:27:24 2009 +0000
+++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/base/ResultDescriptor.java	Tue Oct 20 09:57:52 2009 +0000
@@ -38,4 +38,8 @@
      * @param className the Name of the Class (e.g. Double, Integer
      */
     public void addColumn(String name, String className);
+
+    public int [] getColumnIndices(String [] columnNames);
+
+    public int getColumnIndex(String columnName);
 }
--- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/base/query/QueryExecutorBase.java	Mon Oct 19 10:27:24 2009 +0000
+++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/base/query/QueryExecutorBase.java	Tue Oct 20 09:57:52 2009 +0000
@@ -55,20 +55,21 @@
         
         ResultDescriptor resultDescriptor = null;
         int columns = -1;
+
         List<String> columnNames = null;
+
         while (resultSet.next()){
             if (resultDescriptor == null){
                 resultDescriptor = new DefaultResultDescriptor();
                 ResultSetMetaData rsmd = resultSet.getMetaData();
                 columns = rsmd.getColumnCount();
-                columnNames = new ArrayList<String>(columns);
+
                 for (int i = 1; i <= columns; i++){
                     resultDescriptor.addColumn(rsmd.getColumnName(i), rsmd.getColumnClassName(i));
-                    columnNames.add(rsmd.getColumnName(i));
                 }
             }
             
-            Result result = convertResult(resultSet, resultDescriptor,columnNames);
+            Result result = convertResult(resultSet, resultDescriptor);
             
             returnValue.add(result);
         }
@@ -79,17 +80,16 @@
      * This Method converts one Singel ResultSetEntry into an Result-Object
      * @param resultSet the ResultSet where the Entry should be took from.
      * @param resultDescriptor the ResultsetDescriptor which describes the Entry
-     * @param columnNames the Name of the Columns which Values should be fetched.
      * @return an new Result-Objects containing the Values of the ResultSet-Entry
      * @throws SQLException
      */
-    private Result convertResult(ResultSet resultSet,
-            ResultDescriptor resultDescriptor, List<String> columnNames)
-            throws SQLException {
+    private Result convertResult(ResultSet resultSet, ResultDescriptor resultDescriptor)
+    throws SQLException {
+
         Result result = new DefaultResult(resultDescriptor);
-        for (int i = 0; i < columnNames.size(); i++){
-            String columnName = columnNames.get(i);
-            result.addColumnValue(columnName, resultSet.getObject(columnName));
+
+        for (int i = 0, N = resultDescriptor.getColumnCount(); i < N; i++) {
+            result.addColumnValue(i, resultSet.getObject(i+1));
         }
         return result;
     }

http://dive4elements.wald.intevation.org