Example usage for java.sql CallableStatement setBoolean

List of usage examples for java.sql CallableStatement setBoolean

Introduction

In this page you can find the example usage for java.sql CallableStatement setBoolean.

Prototype

void setBoolean(String parameterName, boolean x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java boolean value.

Usage

From source file:de.whs.poodle.repositories.ExerciseWorksheetRepository.java

public void moveChapter(int chapterId, boolean up) {
    jdbc.update(con -> {/*w  w w .  j a  v  a  2 s. c o m*/
        CallableStatement cs = con.prepareCall("{ CALL move_chapter(?,?) }");
        cs.setInt(1, chapterId);
        cs.setBoolean(2, up);
        return cs;
    });
}

From source file:de.whs.poodle.repositories.ExerciseWorksheetRepository.java

public void moveExercise(int chapterId, int exerciseId, boolean up) {
    jdbc.update(con -> {//ww  w.ja  v a2 s. co  m
        CallableStatement cs = con.prepareCall("{ CALL move_exercise_in_worksheet(?,?,?) }");
        cs.setInt(1, chapterId);
        cs.setInt(2, exerciseId);
        cs.setBoolean(3, up);
        return cs;
    });
}

From source file:de.whs.poodle.repositories.CourseRepository.java

public void edit(Course course) {
    try {//from  w  w  w. j  a  va  2 s.  co m
        jdbc.update(con -> {
            CallableStatement cs = con.prepareCall("{ CALL update_course(?,?,?,?,?,?) }");
            cs.setInt(1, course.getId());
            cs.setString(2, course.getName());
            cs.setBoolean(3, course.getVisible());
            if (course.getPassword().trim().isEmpty())
                cs.setNull(4, Types.VARCHAR);
            else
                cs.setString(4, course.getPassword());

            Array otherInstructors = con.createArrayOf("int4", course.getOtherInstructorsIds().toArray());
            cs.setArray(5, otherInstructors);
            Array linkedCourses = con.createArrayOf("int4", course.getLinkedCoursesIds().toArray());
            cs.setArray(6, linkedCourses);
            return cs;
        });
    } catch (DuplicateKeyException e) {
        throw new BadRequestException();
    }
}

From source file:es.emergya.bbdd.dao.RoutingHome.java

/**
 * Devuelve la lista de ids de la ruta desde vertice_origen a
 * vertice_destino/* w  w w.  j a  va 2s .  c om*/
 * 
 * @param origin
 * @param goal
 * @return
 */
@Transactional(readOnly = true, rollbackFor = Throwable.class)
private List<Long> getSimpleGid(final Long origin, final Long goal) {
    final List<Long> lista = new ArrayList<Long>();
    try {
        Session currentSession = getSession();
        CallableStatement consulta = currentSession.connection().prepareCall("{call shortest_path(?,?,?,?,?)}");
        consulta.setString(1, "SELECT id, " + source + "::int4, " + target + "::int4, " + "ST_length2d("
                + the_geom + ")::float8 as cost FROM " + table);
        consulta.setLong(2, origin);
        consulta.setLong(3, goal);
        consulta.setBoolean(4, false);
        consulta.setBoolean(5, false);
        log.trace(consulta);
        ResultSet resultado = consulta.executeQuery();

        while (resultado.next())
            lista.add(resultado.getLong("edge_id"));
    } catch (Exception e) {
        log.error("No se pudo calcular la ruta", e);
    }

    return lista;
}

From source file:com.cws.esolutions.core.dao.impl.WebMessagingDAOImpl.java

/**
 * @see com.cws.esolutions.core.dao.interfaces.IWebMessagingDAO#updateMessage(String, List)
 *///from  w  ww .j  a  v  a  2s . com
public synchronized boolean updateMessage(final String messageId, final List<Object> messageList)
        throws SQLException {
    final String methodName = IWebMessagingDAO.CNAME
            + "#updateMessage(final String messageId, final List<Object> messageList) throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("messageId: {}", messageId);
        DEBUGGER.debug("messageList: {}", messageList);
    }

    Connection sqlConn = null;
    boolean isComplete = false;
    CallableStatement stmt = null;

    try {
        sqlConn = dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);
        stmt = sqlConn.prepareCall("{CALL updateServiceMessage(?, ?, ?, ?, ?, ?, ?, ?)}");
        stmt.setString(1, messageId); // messageId
        stmt.setString(2, (String) messageList.get(0)); // messageTitle
        stmt.setString(3, (String) messageList.get(1)); // messageText
        stmt.setBoolean(4, (Boolean) messageList.get(2)); // active
        stmt.setBoolean(5, (Boolean) messageList.get(3)); // alert
        stmt.setBoolean(6, (Boolean) messageList.get(4)); // expiry
        stmt.setLong(7, (messageList.get(5) == null) ? 0 : (Long) messageList.get(5)); // expiry date
        stmt.setString(8, (String) messageList.get(6)); // modifyAuthor

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        isComplete = (!(stmt.execute()));

        if (DEBUG) {
            DEBUGGER.debug("isComplete: {}", isComplete);
        }
    } catch (SQLException sqx) {
        ERROR_RECORDER.error(sqx.getMessage(), sqx);

        throw new SQLException(sqx.getMessage(), sqx);
    } finally {
        if (stmt != null) {
            stmt.close();
        }

        if ((sqlConn != null) && (!(sqlConn.isClosed()))) {
            sqlConn.close();
        }
    }

    return isComplete;
}

From source file:es.emergya.bbdd.dao.RoutingHome.java

/**
 * Devuelve la lista de ids de la ruta desde vertice_origen a
 * vertice_destino.//ww w  .j a v a  2 s  .  c  o m
 * 
 * Utiliza la funcion shooting_star
 * 
 * @param origin
 * @param goal
 * @return
 */
@Transactional(readOnly = true, rollbackFor = Throwable.class)
private List<Long> shortest_path_shooting_star(final Long origin, final Long goal) {
    final List<Long> lista = new ArrayList<Long>();
    try {
        Session currentSession = getSession();
        CallableStatement consulta = currentSession.connection()
                .prepareCall("{call shortest_path_shooting_star(?,?,?,?,?)}");

        consulta.setString(1,
                "SELECT " + id + "::integer as id, " + source + "::integer as source, " + target
                        + "::integer as target, " + cost + " as cost," + reverse_cost + " as reverse_cost, "
                        + "ST_X(ST_StartPoint(" + the_geom + ")) as x1," + "ST_Y(ST_StartPoint(" + the_geom
                        + ")) as y1," + "ST_X(ST_EndPoint(" + the_geom + ")) as x2," + "ST_Y(ST_EndPoint("
                        + the_geom + ")) as y2," + rule + " as rule, " + to_cost + " as to_cost FROM " + table
        // + " order by " + id
        );
        consulta.setInt(2, origin.intValue());
        consulta.setInt(3, goal.intValue());
        consulta.setBoolean(4, true);
        consulta.setBoolean(5, true);
        log.trace(consulta);
        ResultSet resultado = consulta.executeQuery();

        while (resultado.next())
            lista.add(resultado.getLong("edge_id"));

    } catch (Exception e) {
        log.error("No se pudo calcular la ruta", e);
    }

    return lista;
}

From source file:com.cws.esolutions.core.dao.impl.WebMessagingDAOImpl.java

/**
 * @see com.cws.esolutions.core.dao.interfaces.IWebMessagingDAO#insertMessage(List)
 *///from   w ww. j  a  v  a 2  s. com
public synchronized boolean insertMessage(final List<Object> messageList) throws SQLException {
    final String methodName = IWebMessagingDAO.CNAME
            + "#insertMessage(final List<Object> messageList) throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("messageList: {}", messageList);
    }

    Connection sqlConn = null;
    CallableStatement stmt = null;
    boolean isComplete = false;

    try {
        sqlConn = dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);
        stmt = sqlConn.prepareCall("{CALL submitSvcMessage(?, ?, ?, ?, ?, ?, ?, ?)}");
        stmt.setString(1, (String) messageList.get(0)); // message id
        stmt.setString(2, (String) messageList.get(1)); // message title
        stmt.setString(3, (String) messageList.get(2)); // message text
        stmt.setString(4, (String) messageList.get(3)); // author email
        stmt.setBoolean(5, (Boolean) messageList.get(4)); // is active
        stmt.setBoolean(6, (Boolean) messageList.get(5)); // is alert
        stmt.setBoolean(7, (Boolean) messageList.get(6)); // does expire
        stmt.setLong(8, (messageList.get(7) == null) ? 0 : (Long) messageList.get(7)); // expiry date

        isComplete = (!(stmt.execute()));

        if (DEBUG) {
            DEBUGGER.debug("isComplete: {}", isComplete);
        }
    } catch (SQLException sqx) {
        ERROR_RECORDER.error(sqx.getMessage(), sqx);

        throw new SQLException(sqx.getMessage(), sqx);
    } finally {
        if (stmt != null) {
            stmt.close();
        }

        if ((sqlConn != null) && (!(sqlConn.isClosed()))) {
            sqlConn.close();
        }
    }

    return isComplete;
}

From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java

/**
 * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyUserSuspension(java.lang.String, boolean)
 *//*from w w  w  .ja v  a2s. co m*/
public synchronized boolean modifyUserSuspension(final String userId, final boolean isSuspended)
        throws UserManagementException {
    final String methodName = SQLUserManager.CNAME
            + "#modifyUserSuspension(final String userId, final boolean isSuspended) throws UserManagementException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", userId);
        DEBUGGER.debug("Value: {}", isSuspended);
    }

    Connection sqlConn = null;
    boolean isComplete = false;
    CallableStatement stmt = null;

    try {
        sqlConn = SQLUserManager.dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);

        stmt = sqlConn.prepareCall("{ CALL modifyUserSuspension(?, ?) }");
        stmt.setString(1, userId);
        stmt.setBoolean(2, isSuspended);

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        int x = stmt.executeUpdate();

        if (DEBUG) {
            DEBUGGER.debug("Update: {}", x);
        }

        if (x == 1) {
            isComplete = true;
        }
    } catch (SQLException sqx) {
        throw new UserManagementException(sqx.getMessage(), sqx);
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }

            if (!(sqlConn == null) && (!(sqlConn.isClosed()))) {
                sqlConn.close();
            }
        } catch (SQLException sqx) {
            throw new UserManagementException(sqx.getMessage(), sqx);
        }
    }

    return isComplete;
}

From source file:it.greenvulcano.gvesb.datahandling.dbo.DBOCallSP.java

private void setBoolean(CallableStatement cs, boolean b) throws SQLException {
    if (useName) {
        cs.setBoolean(currName, b);
    } else {/*from   w  w w. j ava2s .  c om*/
        cs.setBoolean(colIdx, b);
    }
}

From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java

/**
 * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyOlrLock(java.lang.String, boolean)
 *//*from   www  .ja  v  a  2s. c o m*/
public synchronized boolean modifyOlrLock(final String userId, final boolean isLocked)
        throws UserManagementException {
    final String methodName = SQLUserManager.CNAME
            + "#modifyOlrLock(final String userId, final boolean value) throws UserManagementException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", userId);
        DEBUGGER.debug("Value: {}", isLocked);
    }

    Connection sqlConn = null;
    boolean isComplete = false;
    CallableStatement stmt = null;

    try {
        sqlConn = SQLUserManager.dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);

        // first make sure the existing password is proper
        // then make sure the new password doesnt match the existing password
        stmt = sqlConn.prepareCall("{ CALL updateOlrLock(?, ?,}");
        stmt.setString(1, userId);
        stmt.setBoolean(2, isLocked);

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (stmt.executeUpdate() == 1) {
            isComplete = true;
        }
    } catch (SQLException sqx) {
        throw new UserManagementException(sqx.getMessage(), sqx);
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }

            if (!(sqlConn == null) && (!(sqlConn.isClosed()))) {
                sqlConn.close();
            }
        } catch (SQLException sqx) {
            throw new UserManagementException(sqx.getMessage(), sqx);
        }
    }

    return isComplete;
}