tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adrianocrest...@apache.org
Subject svn commit: r568437 - in /incubator/tuscany/java/das/rdb/src: main/java/org/apache/tuscany/das/rdb/graphbuilder/schema/ test/java/org/apache/tuscany/das/rdb/test/ test/java/org/apache/tuscany/das/rdb/test/data/ test/java/org/apache/tuscany/das/rdb/test...
Date Wed, 22 Aug 2007 06:29:38 GMT
Author: adrianocrestani
Date: Tue Aug 21 23:29:37 2007
New Revision: 568437

URL: http://svn.apache.org/viewvc?rev=568437&view=rev
Log:
applying patch from JIRA-1463

Added:
    incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/LOBTests.java
    incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/DocumentsImagesData.java
    incubator/tuscany/java/das/rdb/src/test/resources/asciifile.txt
    incubator/tuscany/java/das/rdb/src/test/resources/moin-www.png   (with props)
Modified:
    incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/schema/ResultSetTypeMap.java
    incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DatabaseSetup.java
    incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllCommonTests.java

Modified: incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/schema/ResultSetTypeMap.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/schema/ResultSetTypeMap.java?rev=568437&r1=568436&r2=568437&view=diff
==============================================================================
--- incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/schema/ResultSetTypeMap.java
(original)
+++ incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/schema/ResultSetTypeMap.java
Tue Aug 21 23:29:37 2007
@@ -109,13 +109,13 @@
                 return helper.getType("commonj.sdo", "Date");
 
             case Types.CLOB:
-                return helper.getType("commonj.sdo", "Clob");
+                return helper.getType("commonj.sdo", "Object");
 
             case Types.BLOB:
                 return helper.getType("commonj.sdo", "Bytes");
 
             case Types.ARRAY:
-                return helper.getType("commonj.sdo", "Array");
+                return helper.getType("commonj.sdo", "Object");
 
             case Types.DISTINCT:
             case Types.STRUCT:

Added: incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/LOBTests.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/LOBTests.java?rev=568437&view=auto
==============================================================================
--- incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/LOBTests.java
(added)
+++ incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/LOBTests.java
Tue Aug 21 23:29:37 2007
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.das.rdb.test;
+
+import java.util.List;
+
+import org.apache.tuscany.das.rdb.Command;
+import org.apache.tuscany.das.rdb.DAS;
+import org.apache.tuscany.das.rdb.test.data.DocumentsImagesData;
+import org.apache.tuscany.das.rdb.test.framework.DasTest;
+
+import commonj.sdo.DataObject;
+
+public class LOBTests extends DasTest {
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        new DocumentsImagesData(getAutoConnection()).refresh();
+    }
+    
+    protected void tearDown() throws Exception {
+    	super.tearDown();
+    }
+    
+    public void testReadWriteBlob() throws Exception {
+    	DAS das = DAS.FACTORY.createDAS(getConnection());
+    	
+    	//Select image
+    	Command read = das.createCommand("SELECT PIC FROM DOCUMENTS_IMAGES WHERE id = 100");
+    	DataObject root = read.executeQuery();
+    	List result = root.getList("DOCUMENTS_IMAGES");
+    	assertEquals(1, result.size());
+    	byte[] imgArray = ((DataObject)result.get(0)).getBytes(0);
+    	assertEquals(150, imgArray.length);
+    	
+    	//insert same image
+    	Command insert = das.createCommand("INSERT INTO DOCUMENTS_IMAGES (ID, PIC) VALUES (?,?)");
+    	insert.setParameter(1, new Integer(101));
+    	insert.setParameter(2, imgArray);
+    	insert.execute();
+    	
+    	//Select again
+    	Command readNew = das.createCommand("SELECT PIC FROM DOCUMENTS_IMAGES WHERE id = 101");
+    	root = readNew.executeQuery();
+    	result = root.getList("DOCUMENTS_IMAGES");
+    	assertEquals(1, result.size());
+    	imgArray = ((DataObject)result.get(0)).getBytes(0);
+    	assertEquals(150, imgArray.length);
+    }
+    
+    public void testReadWriteClob() throws Exception {
+    	DAS das = DAS.FACTORY.createDAS(getConnection());
+    	
+    	//Select image
+    	Command read = das.createCommand("SELECT TEXT FROM DOCUMENTS_IMAGES WHERE id = 100");
+    	DataObject root = read.executeQuery();
+    	List result = root.getList("DOCUMENTS_IMAGES");
+    	assertEquals(1, result.size());
+    	Object txtObj = ((DataObject)result.get(0)).get(0);
+    	assertTrue(txtObj instanceof java.sql.Clob);
+    	java.sql.Clob txtClob = (java.sql.Clob)txtObj;
+    	assertEquals(19, txtClob.length());
+    	
+    	//insert same image
+    	Command insert = das.createCommand("INSERT INTO DOCUMENTS_IMAGES (ID, TEXT) VALUES (?,?)");
+    	insert.setParameter(1, new Integer(101));
+    	insert.setParameter(2, txtClob);
+    	insert.execute();
+    	
+    	//Select again
+    	Command readNew = das.createCommand("SELECT TEXT FROM DOCUMENTS_IMAGES WHERE id = 101");
+    	root = readNew.executeQuery();
+    	result = root.getList("DOCUMENTS_IMAGES");
+    	assertEquals(1, result.size());
+    	txtObj = ((DataObject)result.get(0)).get(0);    	
+    	assertTrue(txtObj instanceof java.sql.Clob);
+    	txtClob = (java.sql.Clob)txtObj;
+    	assertEquals(19, txtClob.length());
+    }    
+}

Added: incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/DocumentsImagesData.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/DocumentsImagesData.java?rev=568437&view=auto
==============================================================================
--- incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/DocumentsImagesData.java
(added)
+++ incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/DocumentsImagesData.java
Tue Aug 21 23:29:37 2007
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.das.rdb.test.data;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import javax.sql.rowset.serial.SerialBlob;
+
+import org.apache.tuscany.das.rdb.test.framework.TestDataWithExplicitColumns;
+
+public class DocumentsImagesData extends TestDataWithExplicitColumns {
+
+	public DocumentsImagesData(Connection connection) {
+		super(connection, null, null, null);
+	}
+	
+    public String getTableName() {
+        return "DOCUMENTS_IMAGES";
+    }
+
+    //Due to special processing, not using superclass methods.
+    protected void insertRows() throws SQLException {    	
+    	try{
+    		InputStream fileAsciiStream = this.getClass().getClassLoader().getResourceAsStream("asciifile.txt");
+			PreparedStatement ps = this.connection.prepareStatement("INSERT INTO DOCUMENTS_IMAGES
VALUES (?, ?, ?)");
+			ps.setInt(1, 100);
+			
+			// - set the value of the input parameter to the input stream
+			ps.setAsciiStream(2, fileAsciiStream, fileAsciiStream.available());
+			
+			//Blob
+			InputStream fileImgStream = this.getClass().getClassLoader().getResourceAsStream("moin-www.png");
		
+			byte[] imgBytes = new byte[fileImgStream.available()];
+			int i=0;
+			while(fileImgStream.available()>0){					
+				imgBytes[i] = (byte)fileImgStream.read();
+				i++;
+			}
+			SerialBlob serialBlob = new SerialBlob(imgBytes);
+			ps.setBlob(3, serialBlob);
+			ps.execute(); 
+			ps.close();
+    	}catch(IOException ioe){
+    		ioe.printStackTrace();
+    		throw new RuntimeException("Could not insert data for Blob/Clob..Please check resources!"+ioe.getMessage());
+    	}
+    }
+}

Modified: incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DatabaseSetup.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DatabaseSetup.java?rev=568437&r1=568436&r2=568437&view=diff
==============================================================================
--- incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DatabaseSetup.java
(original)
+++ incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DatabaseSetup.java
Tue Aug 21 23:29:37 2007
@@ -164,7 +164,10 @@
             "DROP TABLE DASTEST3.ORDERDETAILSDESC", "DROP TABLE DASTEST1.ORDERDETAILS",
             "DROP TABLE DASTEST1.EMPLOYEE",
             "DROP TABLE SINGER",
-            "DROP TABLE SONG"            
+            "DROP TABLE SONG",            
+            "DROP TABLE DASTEST1.EMPLOYEE",
+            "DROP TABLE DOCUMENTS_IMAGES"
+
         };
 
         for (int i = 0; i < statements.length; i++) {
@@ -272,6 +275,8 @@
             //JIRA-952 end
             s.execute(getCreateSinger());
             s.execute(getCreateSong());            
+            s.execute(getCreateDocumentsImages());
+
         } catch (SQLException e) {
             throw new RuntimeException(e);
         }
@@ -487,7 +492,8 @@
                 + " NOT NULL,"+ getStringColumn("DESCR", 20)+", PRIMARY KEY (ID))";
     }
     //JIRA-952 end
-    // /////////////////
+    // //////////////
+
     protected String getCreateSinger() {
     	return "CREATE TABLE SINGER ("+ getIntegerColumn("ID") + " NOT NULL, " +
     		getStringColumn("NAME", 20) +" )";
@@ -499,6 +505,19 @@
     		getIntegerColumn("SINGERID") + " )";
     }
     
+
+    protected String getCreateDocumentsImages() {
+    	return "CREATE TABLE DOCUMENTS_IMAGES (ID INT, TEXT CLOB(64K),PIC BLOB(16M))";
+    }
+    
+
+
+
+
+
+
+
+
     protected String getForeignKeyConstraint(String pkTable, String pkColumn, String foreignKey)
{
         StringBuffer buffer = new StringBuffer();
         buffer.append("CONSTRAINT FK1 FOREIGN KEY (");

Modified: incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllCommonTests.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllCommonTests.java?rev=568437&r1=568436&r2=568437&view=diff
==============================================================================
--- incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllCommonTests.java
(original)
+++ incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllCommonTests.java
Tue Aug 21 23:29:37 2007
@@ -39,6 +39,7 @@
 import org.apache.tuscany.das.rdb.test.ImpliedRelationshipTests;
 import org.apache.tuscany.das.rdb.test.KennelTests;
 import org.apache.tuscany.das.rdb.test.MissingPKTests;
+import org.apache.tuscany.das.rdb.test.LOBTests;
 import org.apache.tuscany.das.rdb.test.MultiSchemaTests;
 import org.apache.tuscany.das.rdb.test.OCCTests;
 import org.apache.tuscany.das.rdb.test.OneToOneRelationshipTests;
@@ -112,7 +113,9 @@
         suite.addTest(new TestSuite(MultiSchemaTests.class));
         suite.addTest(new TestSuite(MissingPKTests.class));
     
+
         suite.addTest(new TestSuite(DynamicResultDescriptorTests.class));
+        suite.addTest(new TestSuite(LOBTests.class));
         //$JUnit-END$
         return suite;
     }

Added: incubator/tuscany/java/das/rdb/src/test/resources/asciifile.txt
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/test/resources/asciifile.txt?rev=568437&view=auto
==============================================================================
--- incubator/tuscany/java/das/rdb/src/test/resources/asciifile.txt (added)
+++ incubator/tuscany/java/das/rdb/src/test/resources/asciifile.txt Tue Aug 21 23:29:37 2007
@@ -0,0 +1 @@
+this is a long file
\ No newline at end of file

Added: incubator/tuscany/java/das/rdb/src/test/resources/moin-www.png
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/test/resources/moin-www.png?rev=568437&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/tuscany/java/das/rdb/src/test/resources/moin-www.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message