Index: src/test/java/org/geotools/data/db2/DB2LobTest.java
===================================================================
--- src/test/java/org/geotools/data/db2/DB2LobTest.java	(revision 0)
+++ src/test/java/org/geotools/data/db2/DB2LobTest.java	(revision 0)
@@ -0,0 +1,13 @@
+package org.geotools.data.db2;
+
+import org.geotools.jdbc.JDBCLobTest;
+import org.geotools.jdbc.JDBCLobTestSetup;
+
+public class DB2LobTest extends JDBCLobTest {
+
+    @Override
+    protected JDBCLobTestSetup createTestSetup() {
+        return new DB2LobTestSetup();
+    }
+
+}

Property changes on: src/test/java/org/geotools/data/db2/DB2LobTest.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Id URL
Added: svn:eol-style
   + native

Index: src/test/java/org/geotools/data/db2/DB2LobTestSetup.java
===================================================================
--- src/test/java/org/geotools/data/db2/DB2LobTestSetup.java	(revision 0)
+++ src/test/java/org/geotools/data/db2/DB2LobTestSetup.java	(revision 0)
@@ -0,0 +1,42 @@
+package org.geotools.data.db2;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import org.geotools.jdbc.JDBCLobTestSetup;
+
+public class DB2LobTestSetup extends JDBCLobTestSetup {
+
+    protected DB2LobTestSetup() {
+        super(new DB2TestSetup());
+    }
+
+    @Override
+    protected void createLobTable() throws Exception {
+        
+        Connection con = getDataSource().getConnection();
+        con.prepareStatement("create table "+DB2TestUtil.SCHEMA_QUOTED+
+                        ".\"testlob\" (\"fid\" int not null , \"blob_field\" BLOB(32) , \"clob_field\" CLOB(32), PRIMARY KEY(\"fid\"))").execute();
+        
+        PreparedStatement ps =con.prepareStatement( "INSERT INTO "+DB2TestUtil.SCHEMA_QUOTED+".\"testlob\" (\"fid\",\"blob_field\",\"clob_field\")  VALUES (?,?,?)");
+        ps.setInt(1,0);
+        ps.setBytes(2, new byte[] {1,2,3,4,5});
+        ps.setString(3, "small clob");
+        ps.execute();
+        ps.close();
+        con.close();               
+    }
+
+    @Override
+    protected void dropLobTable() throws Exception {
+        Connection con = getDataSource().getConnection();
+        try {
+                DB2TestUtil.dropTable(DB2TestUtil.SCHEMA, "testlob", con);
+        } catch (SQLException e) {              
+        }
+        
+        con.close();
+    }
+
+}

Property changes on: src/test/java/org/geotools/data/db2/DB2LobTestSetup.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Id URL
Added: svn:eol-style
   + native

Index: src/main/java/org/geotools/data/db2/DB2BlobConverterFactory.java
===================================================================
--- src/main/java/org/geotools/data/db2/DB2BlobConverterFactory.java	(revision 0)
+++ src/main/java/org/geotools/data/db2/DB2BlobConverterFactory.java	(revision 0)
@@ -0,0 +1,83 @@
+/*
+ *    GeoTools - The Open Source Java GIS Toolkit
+ *    http://geotools.org
+ *
+ *    (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License as published by the Free Software Foundation;
+ *    version 2.1 of the License.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ */
+
+package org.geotools.data.db2;
+
+import java.lang.reflect.Method;
+
+import org.geotools.factory.Hints;
+import org.geotools.util.Converter;
+import org.geotools.util.ConverterFactory;
+
+public class DB2BlobConverterFactory implements ConverterFactory {
+	
+	DB2BlobConverter converter = new DB2BlobConverter();
+	static final Class<?> DB2_BLOB;
+	static final Method DB2_GET_BYTES;
+	static final Method DB2_LENGTH;
+	
+	static {
+	    Class<?> db2BlobClass = null;
+	    try {
+	        db2BlobClass = Class.forName("com.ibm.db2.jcc.DB2Blob");
+	    } catch (ClassNotFoundException e) {
+	        // db2jcc*.jar not on the path
+	    }
+	    if (db2BlobClass == null) {
+	        DB2_BLOB = null;
+	        DB2_GET_BYTES = null;
+	        DB2_LENGTH = null;
+	    } else {
+	        try {
+	            DB2_BLOB = db2BlobClass;
+	            DB2_LENGTH = DB2_BLOB.getMethod("length");
+	            DB2_GET_BYTES = DB2_BLOB.getMethod("getBytes", long.class, int.class);
+	        } catch(Exception e) {
+	            throw new RuntimeException("Could not initialize the db2 blob converter", e);
+	        }
+	    }
+	}
+
+	public Converter createConverter(Class<?> source, Class<?> target,
+			Hints hints) {
+	    // if the jdbc driver is not in the classpath don't bother trying to convert
+	    if(DB2_BLOB == null)
+	        return null;
+	    
+		// can only convert towards byte[]
+		if (!(byte[].class.equals(target)))
+			return null;
+
+		// can only deal with db2 specific blob classes
+		if (!DB2_BLOB.isAssignableFrom(source))
+			return null;
+		
+		// converter is thread safe, so cache and return just one
+		return converter;
+	}
+	
+	class DB2BlobConverter implements Converter {
+
+		public <T> T convert(Object source, Class<T> target) throws Exception {
+		    int length = ((Long) DB2_LENGTH.invoke(source)).intValue();
+		    return (T) DB2_GET_BYTES.invoke(source, 1l, length);
+		}
+
+	}
+
+	
+}

Property changes on: src/main/java/org/geotools/data/db2/DB2BlobConverterFactory.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Id URL
Added: svn:eol-style
   + native

Index: src/main/java/org/geotools/data/db2/DB2ClobConverterFactory.java
===================================================================
--- src/main/java/org/geotools/data/db2/DB2ClobConverterFactory.java	(revision 0)
+++ src/main/java/org/geotools/data/db2/DB2ClobConverterFactory.java	(revision 0)
@@ -0,0 +1,84 @@
+/*
+ *    GeoTools - The Open Source Java GIS Toolkit
+ *    http://geotools.org
+ *
+ *    (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License as published by the Free Software Foundation;
+ *    version 2.1 of the License.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ */
+
+package org.geotools.data.db2;
+
+import java.lang.reflect.Method;
+
+import org.geotools.factory.Hints;
+import org.geotools.util.Converter;
+import org.geotools.util.ConverterFactory;
+
+public class DB2ClobConverterFactory implements ConverterFactory {
+	
+	DB2ClobConverter converter = new DB2ClobConverter();
+	static final Class<?> DB2_CLOB;
+	static final Method DB2_GET_SUBSTRING;
+	static final Method DB2_LENGTH;
+	
+	static {
+	    Class<?> db2ClobClass = null;
+	    try {
+	        db2ClobClass = Class.forName("com.ibm.db2.jcc.DB2Clob");
+	    } catch (ClassNotFoundException e) {
+	        // db2jcc.jar not on the path
+	    }
+	    if (db2ClobClass == null) {
+	        DB2_CLOB = null;
+	        DB2_GET_SUBSTRING = null;
+	        DB2_LENGTH = null;
+	    } else {
+	        try {
+	            DB2_CLOB = db2ClobClass;
+	            DB2_LENGTH = DB2_CLOB.getMethod("length");
+	            DB2_GET_SUBSTRING = DB2_CLOB.getMethod("getSubString", long.class, int.class );
+	        } catch(Exception e) {
+	            throw new RuntimeException("Could not initialize the db2 clob converter", e);
+	        }
+	    }
+	}
+
+	public Converter createConverter(Class<?> source, Class<?> target,
+			Hints hints) {
+	    // if the jdbc driver is not in the classpath don't bother trying to convert
+	    if(DB2_CLOB == null)
+	        return null;
+	    
+		// can only convert towards String
+		if (!(String.class.equals(target)))
+			return null;
+
+		// can only deal with db2 specific blob classes
+		if (!DB2_CLOB.isAssignableFrom(source))
+			return null;
+		
+		// converter is thread safe, so cache and return just one
+		return converter;
+	}
+	
+	class DB2ClobConverter implements Converter {
+
+		public <T> T convert(Object source, Class<T> target) throws Exception {
+		    int length = ((Long) DB2_LENGTH.invoke(source)).intValue();
+		    return (T) DB2_GET_SUBSTRING.invoke(source, 1l, length);		    
+		    
+		}
+
+	}
+
+	
+}

Property changes on: src/main/java/org/geotools/data/db2/DB2ClobConverterFactory.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Id URL
Added: svn:eol-style
   + native

Index: src/main/resources/META-INF/services/org.geotools.util.ConverterFactory
===================================================================
--- src/main/resources/META-INF/services/org.geotools.util.ConverterFactory	(revision 0)
+++ src/main/resources/META-INF/services/org.geotools.util.ConverterFactory	(revision 0)
@@ -0,0 +1,2 @@
+org.geotools.data.db2.DB2BlobConverterFactory
+org.geotools.data.db2.DB2ClobConverterFactory
\ No newline at end of file
