Preliminary support for BLOBs in DAL
authorAntonio Moreno <antonio.moreno@openbravo.com>
Thu, 04 Jun 2009 18:04:44 +0200
changeset 3972 03036acb18fe
parent 3971 69fae109edc5
child 3973 b1db7b37413a
Preliminary support for BLOBs in DAL
src/org/openbravo/base/model/Property.java
src/org/openbravo/base/model/Reference.java
src/org/openbravo/dal/core/DalMappingGenerator.java
src/org/openbravo/dal/xml/XMLTypeConverter.java
--- a/src/org/openbravo/base/model/Property.java	Fri Jun 05 15:26:05 2009 +0200
+++ b/src/org/openbravo/base/model/Property.java	Thu Jun 04 18:04:44 2009 +0200
@@ -506,7 +506,11 @@
     if (isCompositeId) {
       typeName = getEntity().getClassName() + ".Id";
     } else if (isPrimitive()) {
-      typeName = getPrimitiveType().getName();
+      if (getPrimitiveType().isArray()) {
+        typeName = getPrimitiveType().getComponentType().getName() + "[]";
+      } else {
+        typeName = getPrimitiveType().getName();
+      }
     } else if (getTargetEntity() == null) {
       log.warn("ERROR NO REFERENCETYPE " + getEntity().getName() + "." + getColumnName());
       return "java.lang.Object";
@@ -576,6 +580,9 @@
     if ("double".equals(typeName)) {
       return Double.class;
     }
+    if ("byte[]".equals(typeName)) {
+      return byte[].class;
+    }
     Check.fail("Type " + typeName + " not supported as object type");
     // never gets here
     return null;
--- a/src/org/openbravo/base/model/Reference.java	Fri Jun 05 15:26:05 2009 +0200
+++ b/src/org/openbravo/base/model/Reference.java	Thu Jun 04 18:04:44 2009 +0200
@@ -66,8 +66,7 @@
     primitiveTypes.put("17", String.class);
     primitiveTypes.put("20", Boolean.class);
     primitiveTypes.put("22", Float.class);
-    primitiveTypes.put("23", Object.class); // Binary/Blob Data
-    // is not used
+    primitiveTypes.put("23", byte[].class); // Binary/Blob Data
     primitiveTypes.put("24", Timestamp.class);
     primitiveTypes.put("26", Object.class); // RowID is not used
     primitiveTypes.put("27", Object.class); // Color is not used
--- a/src/org/openbravo/dal/core/DalMappingGenerator.java	Fri Jun 05 15:26:05 2009 +0200
+++ b/src/org/openbravo/dal/core/DalMappingGenerator.java	Thu Jun 04 18:04:44 2009 +0200
@@ -89,7 +89,7 @@
       log.debug(result);
     }
 
-    if (false) {
+    if (true) {
       try {
         final File f = new File("/tmp/hibernate.hbm.xml");
         if (f.exists()) {
@@ -166,7 +166,12 @@
     final StringBuffer sb = new StringBuffer();
     sb.append(TAB2 + "<property name=\"" + p.getName() + "\"");
     sb.append(getAccessorAttribute());
-    String type = p.getPrimitiveType().getName();
+    String type;
+    if (p.getPrimitiveType().isArray()) {
+      type = p.getPrimitiveType().getComponentType().getName() + "[]";
+    } else {
+      type = p.getPrimitiveType().getName();
+    }
     if (p.isBoolean()) {
       type = OBYesNoType.class.getName(); // "yes_no";
     }
--- a/src/org/openbravo/dal/xml/XMLTypeConverter.java	Fri Jun 05 15:26:05 2009 +0200
+++ b/src/org/openbravo/dal/xml/XMLTypeConverter.java	Thu Jun 04 18:04:44 2009 +0200
@@ -24,6 +24,7 @@
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
+import org.apache.axis.encoding.Base64;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.provider.OBProvider;
 import org.openbravo.base.provider.OBSingleton;
@@ -103,6 +104,9 @@
     if (o instanceof Boolean) {
       return toXML((Boolean) o);
     }
+    if (o instanceof byte[]) {
+      return Base64.encode((byte[]) o);
+    }
     return o.toString();
     // throw new OBException("Type " + o.getClass().getName() +
     // " not supported");
@@ -149,6 +153,9 @@
       if (Float.class == targetClass) {
         return (T) new Float(xml);
       }
+      if (byte[].class == targetClass) {
+        return (T) Base64.decode(xml);
+      }
     } catch (final Exception e) {
       throw new EntityXMLException("Value " + xml + " can not be parsed to an instance of class "
           + targetClass.getName());