Search in sources :

Example 1 with HarmonySerialClob

use of org.apache.derby.iapi.types.HarmonySerialClob in project derby by apache.

the class ParameterMappingTest method clobInOut.

public static void clobInOut(Clob[] c) throws SQLException {
    String value = getClobValue(c[0]);
    char[] inValue = value.toCharArray();
    char[] outValue = reverse(inValue);
    c[0] = new HarmonySerialClob(new String(outValue));
}
Also used : HarmonySerialClob(org.apache.derby.iapi.types.HarmonySerialClob)

Example 2 with HarmonySerialClob

use of org.apache.derby.iapi.types.HarmonySerialClob in project derby by apache.

the class ParameterMappingTest method pmap.

public static void pmap(Clob in, Clob[] inout, Clob[] out) throws SQLException {
    inout[0] = new HarmonySerialClob(in.getSubString(1L, (int) in.length()) + inout[0].getSubString(1L, (int) inout[0].length()));
    out[0] = new HarmonySerialClob("abc");
}
Also used : HarmonySerialClob(org.apache.derby.iapi.types.HarmonySerialClob)

Example 3 with HarmonySerialClob

use of org.apache.derby.iapi.types.HarmonySerialClob in project derby by apache.

the class ParameterMappingTest method testClobMapping.

/**
 * Verify correct mapping of clobs.
 */
public void testClobMapping() throws Exception {
    Connection conn = getConnection();
    PreparedStatement ps;
    CallableStatement cs;
    Clob outVal;
    // 
    // Clob input parameter
    // 
    ps = chattyPrepare(conn, "create procedure clobIn\n" + "( in c clob, out result varchar( 100 ) )\n" + "language java\n" + "parameter style java\n" + "no sql\n" + "external name '" + getClass().getName() + ".clobIn'\n");
    ps.execute();
    ps.close();
    cs = chattyPrepareCall(conn, "call clobIn( cast( 'def' as clob ), ? )");
    cs.registerOutParameter(1, Types.VARCHAR);
    cs.execute();
    assertEquals("def", cs.getString(1));
    cs.close();
    cs = chattyPrepareCall(conn, "call clobIn( ?, ? )");
    cs.setClob(1, new HarmonySerialClob("ghi"));
    cs.registerOutParameter(2, Types.VARCHAR);
    cs.execute();
    assertEquals("ghi", cs.getString(2));
    cs.close();
    // 
    // Clob output parameter
    // 
    ps = chattyPrepare(conn, "create procedure clobOut\n" + "( out c clob )\n" + "language java\n" + "parameter style java\n" + "no sql\n" + "external name '" + getClass().getName() + ".clobOut'\n");
    ps.execute();
    ps.close();
    cs = chattyPrepareCall(conn, "call clobOut( ? )");
    cs.registerOutParameter(1, Types.CLOB);
    cs.execute();
    outVal = cs.getClob(1);
    assertEquals("abc", outVal.getSubString(1L, (int) outVal.length()));
    cs.close();
    // 
    // Clob inout parameter
    // 
    ps = chattyPrepare(conn, "create procedure clobInOut\n" + "( inout c clob )\n" + "language java\n" + "parameter style java\n" + "no sql\n" + "external name '" + getClass().getName() + ".clobInOut'\n");
    ps.execute();
    ps.close();
    cs = chattyPrepareCall(conn, "call clobInOut( ? )");
    cs.setClob(1, new HarmonySerialClob("ghi"));
    cs.registerOutParameter(1, Types.CLOB);
    cs.execute();
    outVal = cs.getClob(1);
    assertEquals("ihg", outVal.getSubString(1L, (int) outVal.length()));
    Clob inValue = makeBigClob();
    cs.setClob(1, inValue);
    cs.execute();
    Clob outValue = cs.getClob(1);
    compareClobs(inValue, outValue);
    cs.close();
}
Also used : CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Clob(java.sql.Clob) HarmonySerialClob(org.apache.derby.iapi.types.HarmonySerialClob) HarmonySerialClob(org.apache.derby.iapi.types.HarmonySerialClob)

Aggregations

HarmonySerialClob (org.apache.derby.iapi.types.HarmonySerialClob)3 CallableStatement (java.sql.CallableStatement)1 Clob (java.sql.Clob)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1