incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r1089597 - in /incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc: AbstractJdbcMultiFieldMapping.java JdbcMoneyValueMapper.java
Date Wed, 06 Apr 2011 19:37:00 GMT
Author: kevin
Date: Wed Apr  6 19:37:00 2011
New Revision: 1089597

URL: http://svn.apache.org/viewvc?rev=1089597&view=rev
Log:
Cleaned up AbstractJdbcMultiFieldMapping and JdbcMoneyValueMapper.

Modified:
    incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/AbstractJdbcMultiFieldMapping.java
    incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcMoneyValueMapper.java

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/AbstractJdbcMultiFieldMapping.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/AbstractJdbcMultiFieldMapping.java?rev=1089597&r1=1089596&r2=1089597&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/AbstractJdbcMultiFieldMapping.java
(original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/AbstractJdbcMultiFieldMapping.java
Wed Apr  6 19:37:00 2011
@@ -7,14 +7,38 @@ import org.apache.isis.core.metamodel.sp
 import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
 import org.apache.isis.runtimes.dflt.objectstores.sql.DatabaseConnector;
 import org.apache.isis.runtimes.dflt.objectstores.sql.Results;
+import org.apache.isis.runtimes.dflt.objectstores.sql.Sql;
 import org.apache.isis.runtimes.dflt.runtime.context.IsisContext;
 
 public abstract class AbstractJdbcMultiFieldMapping extends AbstractJdbcFieldMapping {
     private final int columnCount;
+    private final String[] types;
+    private final String[] columnNames;
 
-    public AbstractJdbcMultiFieldMapping(ObjectAssociation field, int columnCount) {
+    /**
+     * 
+     * @param field
+     *            the field object association.
+     * @param columnCount
+     *            the number of columns required to store this field. See the abstract methods
,
+     *            {@link AbstractJdbcFieldMapping#preparedStatementObject(int i, ObjectAdapter
fieldValue)},
+     *            {@link AbstractJdbcFieldMapping#getObjectFromResults(Results results)},
+     * @param types
+     *            the list of SQL data types, 1 per columnCount, to represent the value type.
+     */
+    public AbstractJdbcMultiFieldMapping(ObjectAssociation field, int columnCount, String...
types) {
         super(field);
         this.columnCount = columnCount;
+
+        this.types = new String[columnCount];
+        for (int i = 0; i < types.length; i++) {
+            this.types[i] = types[i];
+        }
+
+        String fieldName = field.getId();
+        columnNames = new String[columnCount];
+        columnNames[0] = Sql.sqlFieldName(fieldName + "1");
+        columnNames[1] = Sql.sqlFieldName(fieldName + "2");
     }
 
     @Override
@@ -37,10 +61,10 @@ public abstract class AbstractJdbcMultiF
         }
     }
 
-
     @Override
     public void appendInsertValues(DatabaseConnector connector, StringBuffer sql, ObjectAdapter
object) {
         ObjectAdapter fieldValue = field.get(object);
+        Object o = (fieldValue == null) ? null : fieldValue.getObject();
 
         for (int i = 0; i < columnCount; i++) {
             if (fieldValue == null) {
@@ -50,12 +74,12 @@ public abstract class AbstractJdbcMultiF
                 if (i < columnCount - 1) {
                     sql.append(", ");
                 }
-                connector.addToQueryValues(preparedStatementObject(i, fieldValue));
+
+                connector.addToQueryValues(preparedStatementObject(i, o));
             }
         }
     }
 
-
     @Override
     public void appendUpdateValues(DatabaseConnector connector, StringBuffer sql, ObjectAdapter
object) {
         for (int i = 0; i < columnCount; i++) {
@@ -74,6 +98,7 @@ public abstract class AbstractJdbcMultiF
         String condition) {
 
         ObjectAdapter fieldValue = field.get(object);
+        Object o = (fieldValue == null) ? null : fieldValue.getObject();
 
         for (int i = 0; i < columnCount; i++) {
             sql.append(columnName(i) + condition + "?");
@@ -81,7 +106,7 @@ public abstract class AbstractJdbcMultiF
                 sql.append(", ");
             }
 
-            connector.addToQueryValues(preparedStatementObject(i, fieldValue));
+            connector.addToQueryValues(o);
         }
     }
 
@@ -101,7 +126,6 @@ public abstract class AbstractJdbcMultiF
         ((OneToOneAssociation) field).initAssociation(object, restoredValue);
     }
 
-
     @Override
     public ObjectAdapter setFromDBColumn(Results results, final String encodedValue, String
columnName,
         final ObjectAssociation field) {
@@ -114,8 +138,6 @@ public abstract class AbstractJdbcMultiF
 
     }
 
-
-
     @Override
     public void debugData(DebugBuilder debug) {
         for (int i = 0; i < columnCount; i++) {
@@ -133,11 +155,32 @@ public abstract class AbstractJdbcMultiF
         throw new ApplicationException("Should never be called");
     }
 
-    protected abstract String columnName(int i);
-
-    protected abstract String columnType(int i);
+    protected String columnType(int index) {
+        return types[index];
+    }
 
-    protected abstract Object preparedStatementObject(int i, ObjectAdapter fieldValue);
+    protected String columnName(int index) {
+        return columnNames[index];
+    }
 
+    /**
+     * Return an object suitable for passing to the SQL prepared statement constructor, to
handle field "index". Will be
+     * called "columnCount" times.
+     * 
+     * @param index
+     *            0 based index
+     * @param fieldObject
+     *            the value type currently being
+     * @return a JDBC-compatible object.
+     */
+    protected abstract Object preparedStatementObject(int index, Object o);
+
+    /**
+     * Return an applib object represented by the results set.
+     * 
+     * @param results
+     *            the current record row from the underlying table
+     * @return a fully initialised value object.
+     */
     protected abstract Object getObjectFromResults(Results results);
 }

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcMoneyValueMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcMoneyValueMapper.java?rev=1089597&r1=1089596&r2=1089597&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcMoneyValueMapper.java
(original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcMoneyValueMapper.java
Wed Apr  6 19:37:00 2011
@@ -21,10 +21,8 @@ package org.apache.isis.runtimes.dflt.ob
 
 import org.apache.isis.applib.PersistFailedException;
 import org.apache.isis.applib.value.Money;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
 import org.apache.isis.runtimes.dflt.objectstores.sql.Results;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Sql;
 import org.apache.isis.runtimes.dflt.objectstores.sql.mapping.FieldMapping;
 import org.apache.isis.runtimes.dflt.objectstores.sql.mapping.FieldMappingFactory;
 
@@ -35,7 +33,7 @@ import org.apache.isis.runtimes.dflt.obj
  */
 public class JdbcMoneyValueMapper extends AbstractJdbcMultiFieldMapping {
 
-	public static class Factory implements FieldMappingFactory {
+    public static class Factory implements FieldMappingFactory {
         private final String type1;
         private final String type2;
 
@@ -45,31 +43,18 @@ public class JdbcMoneyValueMapper extend
         }
 
         @Override
-		public FieldMapping createFieldMapping(final ObjectAssociation field) {
+        public FieldMapping createFieldMapping(final ObjectAssociation field) {
             return new JdbcMoneyValueMapper(field, type1, type2);
-		}
-	}
-
-    private final String[] types = new String[2];
-    private final String[] columnNames = new String[2];
-
+        }
+    }
 
     public JdbcMoneyValueMapper(ObjectAssociation field, String type1, String type2) {
-        super(field, 2);
-        this.types[0] = type1;
-        this.types[1] = type2;
-
-        String fieldName = field.getId();
-        columnNames[0] = Sql.sqlFieldName(fieldName + "1");
-        columnNames[1] = Sql.sqlFieldName(fieldName + "2");
+        super(field, 2, type1, type2);
     }
 
     @Override
-    protected Object preparedStatementObject(int index, ObjectAdapter value){
-        if (value == null) return null;
-        
-        Object o = value.getObject();
-        
+    protected Object preparedStatementObject(int index, Object o) {
+
         if (o instanceof Money) {
             if (index == 0) {
                 return ((Money) o).doubleValue();
@@ -81,18 +66,6 @@ public class JdbcMoneyValueMapper extend
                 + " for MoneyValueMapper");
         }
     }
-	
-
-    @Override
-    protected String columnType(int index) {
-        return types[index];
-	}
-
-    @Override
-    protected String columnName(int index) {
-        return columnNames[index];
-    }
-
 
     @Override
     protected Object getObjectFromResults(Results results) {
@@ -104,8 +77,4 @@ public class JdbcMoneyValueMapper extend
         return moneyObject;
     }
 
-
-
-
-
 }



Mime
View raw message