Example usage for org.springframework.jdbc.object SqlFunction SqlFunction

List of usage examples for org.springframework.jdbc.object SqlFunction SqlFunction

Introduction

In this page you can find the example usage for org.springframework.jdbc.object SqlFunction SqlFunction.

Prototype

public SqlFunction(DataSource ds, String sql, int[] types) 

Source Link

Document

Create a new SqlFunction object with SQL and parameters.

Usage

From source file:org.springframework.jdbc.object.SqlFunctionTests.java

public void testFunctionMixed() throws SQLException {
    ctrlResultSetMetaData = MockControl.createControl(ResultSetMetaData.class);
    mockResultSetMetaData = (ResultSetMetaData) ctrlResultSetMetaData.getMock();
    mockResultSetMetaData.getColumnCount();
    ctrlResultSetMetaData.setReturnValue(1);

    mockResultSet.getMetaData();/*from   w  ww .  ja v  a 2  s.c  o  m*/
    ctrlResultSet.setReturnValue(mockResultSetMetaData, 1);
    mockResultSet.next();
    ctrlResultSet.setReturnValue(true);
    mockResultSet.getObject(1);
    ctrlResultSet.setReturnValue(new Integer(14));
    mockResultSet.next();
    ctrlResultSet.setReturnValue(false);
    mockResultSet.close();
    ctrlResultSet.setVoidCallable();

    mockPreparedStatement.setObject(1, new Integer(1), Types.INTEGER);
    ctrlPreparedStatement.setVoidCallable();
    mockPreparedStatement.setString(2, "rod");
    ctrlPreparedStatement.setVoidCallable();
    mockPreparedStatement.executeQuery();
    ctrlPreparedStatement.setReturnValue(mockResultSet);
    if (debugEnabled) {
        mockPreparedStatement.getWarnings();
        ctrlPreparedStatement.setReturnValue(null);
    }
    mockPreparedStatement.close();
    ctrlPreparedStatement.setVoidCallable();

    mockConnection.prepareStatement(FUNCTION_MIXED);
    ctrlConnection.setReturnValue(mockPreparedStatement);

    replay();

    SqlFunction function = new SqlFunction(mockDataSource, FUNCTION_MIXED,
            new int[] { Types.INTEGER, Types.VARCHAR });
    function.compile();

    int count = function.run(new Object[] { new Integer(1), "rod" });
    assertTrue("Function returned value 14", count == 14);
}