Update of /var/cvs/src/org/mmbase/storage/implementation/database
In directory james.mmbase.org:/tmp/cvs-serv1046
Modified Files:
DatabaseStorageManager.java
Log Message:
made recognition of binary stored fields a bit more robust. I encounterd a db
where the reported columnt type of string fields was LONGVARBINARY, which
broken evernything horribly
See also:
http://cvs.mmbase.org/viewcvs/src/org/mmbase/storage/implementation/database
Index: DatabaseStorageManager.java
===================================================================
RCS file:
/var/cvs/src/org/mmbase/storage/implementation/database/DatabaseStorageManager.java,v
retrieving revision 1.194
retrieving revision 1.195
diff -u -b -r1.194 -r1.195
--- DatabaseStorageManager.java 22 Jul 2008 05:29:19 -0000 1.194
+++ DatabaseStorageManager.java 25 Jul 2008 11:16:34 -0000 1.195
@@ -32,7 +32,7 @@
*
* @author Pierre van Rooden
* @since MMBase-1.7
- * @version $Id: DatabaseStorageManager.java,v 1.194 2008/07/22 05:29:19
michiel Exp $
+ * @version $Id: DatabaseStorageManager.java,v 1.195 2008/07/25 11:16:34
michiel Exp $
*/
public class DatabaseStorageManager implements StorageManager {
@@ -382,6 +382,23 @@
}
/**
+ * Sometimes (legacy) string were stored in binary fields. They must be
dealt with seperately.
+ *
+ * @since MMBase-1.9
+ */
+ protected boolean isBinaryColumnType(int st) {
+ switch(st) {
+ case Types.CLOB:
+ case Types.BLOB:
+ case Types.LONGVARBINARY:
+ case Types.VARBINARY:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
* Retrieve a text for a specified object field.
* The default method uses [EMAIL PROTECTED] ResultSet#getString(int)} to
obtain text.
* Override this method if you want to optimize retrieving large texts,
@@ -395,7 +412,8 @@
*/
protected Object getStringValue(ResultSet result, int index, CoreField
field, boolean mayShorten) throws StorageException, SQLException {
String untrimmedResult = null;
- if (field != null && (field.getStorageType() == Types.CLOB ||
field.getStorageType() == Types.BLOB ||
factory.hasOption(Attributes.FORCE_ENCODE_TEXT))) {
+ // would be equals to field.getStorageType()
+ if (isBinaryColumnType(result.getMetaData().getColumnType(index)) ||
factory.hasOption(Attributes.FORCE_ENCODE_TEXT)) {
InputStream inStream = result.getBinaryStream(index);
if (result.wasNull()) {
return null;
@@ -536,7 +554,7 @@
* @throws StorageException when data is incompatible or the function is
not supported
*/
protected boolean shorten(CoreField field) {
- return field.getType() == Field.TYPE_BINARY;
+ return field != null && field.getType() == Field.TYPE_BINARY;
}
/**
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs