db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1701885 - in /db/derby/code/trunk/java: optional/org/apache/derby/optional/api/SimpleJsonUtils.java optional/org/apache/derby/optional/json/SimpleJsonTool.java testing/org/apache/derbyTesting/functionTests/tests/lang/SimpleJsonTest.java
Date Wed, 09 Sep 2015 00:26:49 GMT
Author: rhillegas
Date: Wed Sep  9 00:26:49 2015
New Revision: 1701885

URL: http://svn.apache.org/r1701885
Log:
DERBY-6825: Add to the simpleJson tool a function which converts a JSONArray into a Clob;
commit derby-6825-05-aa-toClobFunction.diff.

Modified:
    db/derby/code/trunk/java/optional/org/apache/derby/optional/api/SimpleJsonUtils.java
    db/derby/code/trunk/java/optional/org/apache/derby/optional/json/SimpleJsonTool.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SimpleJsonTest.java

Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/api/SimpleJsonUtils.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/api/SimpleJsonUtils.java?rev=1701885&r1=1701884&r2=1701885&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/api/SimpleJsonUtils.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/api/SimpleJsonUtils.java Wed
Sep  9 00:26:49 2015
@@ -46,6 +46,7 @@ import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
 
+import org.apache.derby.iapi.types.HarmonySerialClob;
 import org.apache.derby.iapi.util.StringUtil;
 import org.apache.derby.optional.utils.ToolUtilities;
 
@@ -243,6 +244,14 @@ public abstract class SimpleJsonUtils
         return readArrayFromStream( inputStream, characterSetName );
     }
 
+    /**
+     * SQL FUNCTION to convert a JSONArray into a CLOB.
+     */
+    public static Clob arrayToClob( JSONArray array )
+    {
+        if ( array == null ) { return null; }
+        else { return new HarmonySerialClob( array.toJSONString() ); }
+    }
 
     /////////////////////////////////////////////////////////////////
     //

Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/json/SimpleJsonTool.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/json/SimpleJsonTool.java?rev=1701885&r1=1701884&r2=1701885&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/json/SimpleJsonTool.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/json/SimpleJsonTool.java Wed
Sep  9 00:26:49 2015
@@ -107,6 +107,14 @@ public	class   SimpleJsonTool  implement
             "language java parameter style java contains sql\n" +
             "external name 'org.apache.derby.optional.api.SimpleJsonUtils.readArrayFromURL'\n"
         ),
+
+        new FunctionDescriptor
+        (
+            "arrayToClob",
+            "create function arrayToClob( jsonDocument JSONArray ) returns clob\n" +
+            "language java parameter style java no sql\n" +
+            "external name 'org.apache.derby.optional.api.SimpleJsonUtils.arrayToClob'"
+        ),
     };
 
     ////////////////////////////////////////////////////////////////////////

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SimpleJsonTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SimpleJsonTest.java?rev=1701885&r1=1701884&r2=1701885&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SimpleJsonTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SimpleJsonTest.java
Wed Sep  9 00:26:49 2015
@@ -751,6 +751,39 @@ public class SimpleJsonTest extends Base
         goodStatement( conn, "drop function f_" + datatype );
     }
 
+    /**
+     * <p>
+     * Test the arrayToClob() function.
+     * </p>
+     */
+	public void testArrayToClob_006() throws Exception
+    {
+        Connection  conn = getConnection();
+
+        goodStatement( conn, "call syscs_util.syscs_register_tool( 'simpleJson', true )"
);
+        goodStatement( conn, "create table employee( fullName varchar( 100 ) )" );
+        goodStatement( conn, "create table docs( stringDoc varchar( 32672 ) )" );
+        goodStatement( conn, "insert into employee values ( 'Fred Flintstone' ), ( 'Barney
Rubble' )" );
+        goodStatement( conn, "insert into docs values( arrayToClob( toJSON( 'select * from
employee' ) ) )" );
+
+        assertResults
+            (
+             conn,
+             "select * from docs",
+             new String[][]
+             {
+                 {
+                     "[{\"FULLNAME\":\"Fred Flintstone\"},{\"FULLNAME\":\"Barney Rubble\"}]"
+                 }
+             },
+             true
+             );
+
+        goodStatement( conn, "drop table docs" );
+        goodStatement( conn, "drop table employee" );
+        goodStatement( conn, "call syscs_util.syscs_register_tool( 'simpleJson', false )"
);
+    }
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // FUNCTIONS



Mime
View raw message