You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by Jacques Le Roux <ja...@les7arts.com> on 2021/03/08 10:29:46 UTC

Re: Remove ByteWrapper class

Hi,

I created https://issues.apache.org/jira/browse/OFBIZ-12194 for that

Le 07/03/2021 à 18:32, Jacques Le Roux a écrit :
> Here is a comment from David in 2007 in the ByteWrapper class
>
>  * @deprecated
>  * NOTE DEJ20071022: deprecating this because we want to save the byte[] directly instead of inside a serialized
>  * object, which makes it hard for other apps to use the data, and causes problems if this object is ever updated
>
> Here is another comment where it's used, in GenericEntity.getBytes()
>
>         if (value instanceof byte[]) {
>             return (byte[]) value;
>         }
>         if (value instanceof org.apache.ofbiz.entity.util.ByteWrapper) {
>             // NOTE DEJ20071022: the use of ByteWrapper is not recommended and is deprecated, only old data should be stored that way
>             Debug.logWarning("Found a ByteWrapper object in the database for field [" + this.getEntityName() + "." + name + "]; converting to byte[] 
> and returning, but note that you need to update your database to unwrap these objects for future compatibility", module);
>             org.apache.ofbiz.entity.util.ByteWrapper wrapper = (org.apache.ofbiz.entity.util.ByteWrapper) value;
>             return wrapper.getBytes();
>         }
>
> Here is another related comment (in SqlJdbcUtil.deserializeField())
>
>         // NOTE DEJ20071022: the following code is to convert the byte[] back into an object; if that fails
>         //just return the byte[]; this was for the ByteWrapper thing which is now deprecated, so this may
>         //be removed in the near future to enhance performance
>
> Where there is also this code commented out
>
>         //alt 1: binaryInput = rs.getBinaryStream(ind);
>         //alt 2: Blob blobLocator = rs.getBlob(ind);
>         //if (blobLocator != null) {
>         //    binaryInput = blobLocator.getBinaryStream();
>         //}
>
> deserializeField() is only used (twice) in SqlJdbcUtil.getValue() and here are the concerned types (11 & 12):
>
>         fieldTypeMap.put("java.lang.Object", 11);
>         fieldTypeMap.put("Object", 11);
>
>         fieldTypeMap.put("java.sql.Blob", 12);
>         fieldTypeMap.put("Blob", 12);
>         fieldTypeMap.put("byte[]", 12);
>         fieldTypeMap.put("java.nio.ByteBuffer", 12);
>         fieldTypeMap.put("java.nio.HeapByteBuffer", 12);
>
> And I think we can clean this 2 cases from the ByteWrapper class . So it was 10 years ago, opinions before I open a Jira ?


Re: Remove ByteWrapper class

Posted by Jacques Le Roux <ja...@les7arts.com>.
Done

Le 08/03/2021 à 11:29, Jacques Le Roux a écrit :
> Hi,
>
> I created https://issues.apache.org/jira/browse/OFBIZ-12194 for that
>
> Le 07/03/2021 à 18:32, Jacques Le Roux a écrit :
>> Here is a comment from David in 2007 in the ByteWrapper class
>>
>>  * @deprecated
>>  * NOTE DEJ20071022: deprecating this because we want to save the byte[] directly instead of inside a serialized
>>  * object, which makes it hard for other apps to use the data, and causes problems if this object is ever updated
>>
>> Here is another comment where it's used, in GenericEntity.getBytes()
>>
>>         if (value instanceof byte[]) {
>>             return (byte[]) value;
>>         }
>>         if (value instanceof org.apache.ofbiz.entity.util.ByteWrapper) {
>>             // NOTE DEJ20071022: the use of ByteWrapper is not recommended and is deprecated, only old data should be stored that way
>>             Debug.logWarning("Found a ByteWrapper object in the database for field [" + this.getEntityName() + "." + name + "]; converting to 
>> byte[] and returning, but note that you need to update your database to unwrap these objects for future compatibility", module);
>>             org.apache.ofbiz.entity.util.ByteWrapper wrapper = (org.apache.ofbiz.entity.util.ByteWrapper) value;
>>             return wrapper.getBytes();
>>         }
>>
>> Here is another related comment (in SqlJdbcUtil.deserializeField())
>>
>>         // NOTE DEJ20071022: the following code is to convert the byte[] back into an object; if that fails
>>         //just return the byte[]; this was for the ByteWrapper thing which is now deprecated, so this may
>>         //be removed in the near future to enhance performance
>>
>> Where there is also this code commented out
>>
>>         //alt 1: binaryInput = rs.getBinaryStream(ind);
>>         //alt 2: Blob blobLocator = rs.getBlob(ind);
>>         //if (blobLocator != null) {
>>         //    binaryInput = blobLocator.getBinaryStream();
>>         //}
>>
>> deserializeField() is only used (twice) in SqlJdbcUtil.getValue() and here are the concerned types (11 & 12):
>>
>>         fieldTypeMap.put("java.lang.Object", 11);
>>         fieldTypeMap.put("Object", 11);
>>
>>         fieldTypeMap.put("java.sql.Blob", 12);
>>         fieldTypeMap.put("Blob", 12);
>>         fieldTypeMap.put("byte[]", 12);
>>         fieldTypeMap.put("java.nio.ByteBuffer", 12);
>>         fieldTypeMap.put("java.nio.HeapByteBuffer", 12);
>>
>> And I think we can clean this 2 cases from the ByteWrapper class . So it was 10 years ago, opinions before I open a Jira ?
>