Java Code Examples for java.sql.CallableStatement.setArray()

The following are Jave code examples for showing how to use setArray() of the java.sql.CallableStatement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: jaffa-framework   File: JDBCSecurityPlugin.java   Source Code and License Vote up 5 votes
protected void executeStoredProcedure(final Connection pooledConnection, final String userid) throws java.sql.SQLException {
    CallableStatement cs = null;

    final String localId = (String) ContextManagerFactory.instance().getProperty(LOCAL_ID);
    Object[] roles = getUserRoles(userid).toArray();
    ARRAY newArray = null;

    Connection connection = null;
    try {
        // Extract the actual oracle connection
        connection = pooledConnection.unwrap(oracle.jdbc.OracleConnection.class);
        if (!(connection instanceof oracle.jdbc.OracleConnection)) {
        	throw new Exception(String.format("Not an Oracle Connection : %s",connection.getClass().getName()));
        }

        cs = connection.prepareCall(CALL_JAFFA_SEC_SET_USERID);
        cs.setString(1,userid);

        newArray = ((oracle.jdbc.OracleConnection)connection).createARRAY(ROLE,roles);
        cs.setArray(2,newArray);
        cs.setString(3,localId);

        if (log.isDebugEnabled()) {
            // Log the call to the stored procedure
            debugStatement(userid, localId, roles, newArray);
        }

        if(log.isDebugEnabled()) log.debug("Calling the Stored Procedure to Set the Context");
        cs.execute();
        connection.commit();
    }
    catch (Exception exception) {
    	final String message = String.format(String.format(SET_THE_CONTEXT_ERROR_MESSAGE,exception.getMessage()));
        log.error(message, exception);
        if (connection != null)
        	connection.rollback();
        throw new UOWSecurityException(message, exception);
    }
    finally {
        roles = null;
        if (newArray != null)
            newArray.free();
        if (cs != null) {
            cs.clearParameters();
            cs.close();
            cs = null;
        }
    }
}