Example usage for java.sql CallableStatement execute

List of usage examples for java.sql CallableStatement execute

Introduction

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

Prototype

boolean execute() throws SQLException;

Source Link

Document

Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement.

Usage

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSybase.CFAsteriskSybaseClusterTable.java

public long nextSecGroupIncludeIdGen(CFSecurityAuthorization Authorization, CFSecurityClusterPKey PKey) {
    final String S_ProcName = "nextSecGroupIncludeIdGen";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Not in a transaction");
    }//from   w w w  .j  a  va 2s  .com
    Connection cnx = schema.getCnx();
    long Id = PKey.getRequiredId();

    CallableStatement stmtSelectNextSecGroupIncludeIdGen = null;
    try {
        String sql = "{ call sp_next_secgroupincludeidgen( ?" + ", " + "?" + " ) }";
        stmtSelectNextSecGroupIncludeIdGen = cnx.prepareCall(sql);
        int argIdx = 1;
        stmtSelectNextSecGroupIncludeIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT);
        stmtSelectNextSecGroupIncludeIdGen.setLong(argIdx++, Id);
        stmtSelectNextSecGroupIncludeIdGen.execute();
        long nextId = stmtSelectNextSecGroupIncludeIdGen.getLong(1);
        return (nextId);
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (stmtSelectNextSecGroupIncludeIdGen != null) {
            try {
                stmtSelectNextSecGroupIncludeIdGen.close();
            } catch (SQLException e) {
            }
            stmtSelectNextSecGroupIncludeIdGen = null;
        }
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseClusterTable.java

public long nextSecGroupMemberIdGen(CFAstAuthorization Authorization, CFAstClusterPKey PKey) {
    final String S_ProcName = "nextSecGroupMemberIdGen";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Not in a transaction");
    }/*from   ww  w . j  av a2 s.co  m*/
    Connection cnx = schema.getCnx();
    long Id = PKey.getRequiredId();

    CallableStatement stmtSelectNextSecGroupMemberIdGen = null;
    try {
        String sql = "{ call sp_next_secgroupmemberidgen( ?" + ", " + "?" + " ) }";
        stmtSelectNextSecGroupMemberIdGen = cnx.prepareCall(sql);
        int argIdx = 1;
        stmtSelectNextSecGroupMemberIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT);
        stmtSelectNextSecGroupMemberIdGen.setLong(argIdx++, Id);
        stmtSelectNextSecGroupMemberIdGen.execute();
        long nextId = stmtSelectNextSecGroupMemberIdGen.getLong(1);
        return (nextId);
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (stmtSelectNextSecGroupMemberIdGen != null) {
            try {
                stmtSelectNextSecGroupMemberIdGen.close();
            } catch (SQLException e) {
            }
            stmtSelectNextSecGroupMemberIdGen = null;
        }
    }
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public Item addBid(final Bid bid) {
    Item obj = null;//from   ww w  .j  a v a  2 s  .  co  m

    Connection conn = null;
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_EDITBID (?,?,?,?)}");
        stmt.registerOutParameter(1, Types.INTEGER);
        stmt.setInt(2, bid.getItemUid());
        stmt.setInt(3, bid.getUserUid());
        stmt.setDouble(4, bid.getBidPrice());

        stmt.execute();
        stmt.close(); // close statement to prevent leak

        stmt = conn.prepareCall("{call SP_GETITEM (?)}");
        stmt.setInt(1, bid.getItemUid());

        rs = stmt.executeQuery();

        if (rs.next()) {
            ItemBuilder builder = Item.newBuilder().setUid(rs.getInt("UID"))
                    .setAuctionUid(rs.getInt("AUCTIONUID")).setItemNumber(rs.getString("ITEMNUMBER"))
                    .setName(rs.getString("NAME")).sertCurPrice(rs.getDouble("CURPRICE"))
                    .setWinner(rs.getString("WINNER")).setBidCount(rs.getInt("BIDCOUNT"))
                    .setWatchCount(rs.getInt("WATCHCOUNT"));

            obj = builder.build();
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("BID [method:{} result:{}]",
                new Object[] { "add", obj != null ? obj.toString() : "[error]" });
    }

    return obj;
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSybase.CFAsteriskSybaseClusterTable.java

public long nextConfigurationFileIdGen(CFSecurityAuthorization Authorization, CFSecurityClusterPKey PKey) {
    final String S_ProcName = "nextConfigurationFileIdGen";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Not in a transaction");
    }/*ww w  .  j a v  a  2  s  .co  m*/
    Connection cnx = schema.getCnx();
    long Id = PKey.getRequiredId();

    CallableStatement stmtSelectNextConfigurationFileIdGen = null;
    try {
        String sql = "{ call sp_next_configurationfileidgen( ?" + ", " + "?" + " ) }";
        stmtSelectNextConfigurationFileIdGen = cnx.prepareCall(sql);
        int argIdx = 1;
        stmtSelectNextConfigurationFileIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT);
        stmtSelectNextConfigurationFileIdGen.setLong(argIdx++, Id);
        stmtSelectNextConfigurationFileIdGen.execute();
        long nextId = stmtSelectNextConfigurationFileIdGen.getLong(1);
        return (nextId);
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (stmtSelectNextConfigurationFileIdGen != null) {
            try {
                stmtSelectNextConfigurationFileIdGen.close();
            } catch (SQLException e) {
            }
            stmtSelectNextConfigurationFileIdGen = null;
        }
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseClusterTable.java

public long nextSecGroupIncludeIdGen(CFAstAuthorization Authorization, CFAstClusterPKey PKey) {
    final String S_ProcName = "nextSecGroupIncludeIdGen";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Not in a transaction");
    }/*from   w  ww .  ja v a 2 s.  co m*/
    Connection cnx = schema.getCnx();
    long Id = PKey.getRequiredId();

    CallableStatement stmtSelectNextSecGroupIncludeIdGen = null;
    try {
        String sql = "{ call sp_next_secgroupincludeidgen( ?" + ", " + "?" + " ) }";
        stmtSelectNextSecGroupIncludeIdGen = cnx.prepareCall(sql);
        int argIdx = 1;
        stmtSelectNextSecGroupIncludeIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT);
        stmtSelectNextSecGroupIncludeIdGen.setLong(argIdx++, Id);
        stmtSelectNextSecGroupIncludeIdGen.execute();
        long nextId = stmtSelectNextSecGroupIncludeIdGen.getLong(1);
        return (nextId);
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (stmtSelectNextSecGroupIncludeIdGen != null) {
            try {
                stmtSelectNextSecGroupIncludeIdGen.close();
            } catch (SQLException e) {
            }
            stmtSelectNextSecGroupIncludeIdGen = null;
        }
    }
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public int addDevice(final Device device) {
    int uid = -1;

    Connection conn = null;//from w  w  w . j a  va  2  s .c om
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_REGISTERDEVICE (?,?,?,?)}");
        stmt.registerOutParameter(1, Types.INTEGER);
        stmt.setInt(2, device.getUserUid());
        stmt.setString(3, device.getDeviceId());
        stmt.setString(4, device.getDeviceType());
        stmt.execute();

        uid = stmt.getInt(1);
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("DEVICE [method:{} result:{}]", new Object[] { "edit", uid });
    }

    return uid;
}

From source file:com.mimp.hibernate.HiberNna.java

public ArrayList<Nna> ListaNnaSeguimiento(String clasificacion) {
    Session session = sessionFactory.getCurrentSession();
    final String clasif = clasificacion;
    final ArrayList<Nna> allNna = new ArrayList();
    final ArrayList<Nna> allNnaAux = new ArrayList();
    final ArrayList<Nna> allNnaFinal = new ArrayList();

    Work work = new Work() {
        @Override//from  w  w w  .  j a v a 2 s.  co m
        public void execute(Connection connection) throws SQLException {
            ExpedienteNna expnna;
            Nna tempnna;
            Designacion desig;

            EstudioCaso est;

            String hql = "{call HN_GET_NNA_SEG(?)}";
            CallableStatement statement = connection.prepareCall(hql);
            statement.registerOutParameter(1, OracleTypes.CURSOR);
            statement.execute();

            temp = (ResultSet) statement.getObject(1);

            while (temp.next()) {
                tempnna = new Nna();
                tempnna.setIdnna(temp.getLong(1));
                tempnna.setNombre(temp.getString(2));
                tempnna.setApellidoP(temp.getString(3));
                tempnna.setApellidoM(temp.getString(4));
                tempnna.setSexo(temp.getString(5));
                tempnna.setFechaNacimiento(temp.getDate(6));
                tempnna.setEdadAnhos(temp.getShort(7));
                tempnna.setEdadMeses(temp.getShort(8));
                tempnna.setActaNacimiento(temp.getShort(9));
                tempnna.setCondicionSalud(temp.getString(10));
                tempnna.setDepartamentoNacimiento(temp.getString(11));
                tempnna.setProvinciaNacimiento(temp.getString(12));
                tempnna.setDistritoNacimiento(temp.getString(13));
                tempnna.setPaisNacimiento(temp.getString(14));
                tempnna.setLugarNac(temp.getString(15));
                tempnna.setFechaResolAbandono(temp.getDate(16));
                tempnna.setFechaResolConsentida(temp.getDate(17));
                tempnna.setClasificacion(temp.getString(18));
                tempnna.setIncesto(temp.getShort(19));
                tempnna.setMental(temp.getShort(20));
                tempnna.setEpilepsia(temp.getShort(21));
                tempnna.setAbuso(temp.getShort(22));
                tempnna.setSifilis(temp.getShort(23));
                tempnna.setSeguiMedico(temp.getShort(24));
                tempnna.setOperacion(temp.getShort(25));
                tempnna.setHiperactivo(temp.getShort(26));
                tempnna.setEspecial(temp.getShort(27));
                tempnna.setEnfermo(temp.getShort(28));
                tempnna.setMayor(temp.getShort(29));
                tempnna.setAdolescente(temp.getShort(30));
                tempnna.setHermano(temp.getShort(31));
                tempnna.setNn(temp.getShort(32));
                tempnna.setObservaciones(temp.getString(33));
                tempnna.setNResolAband(temp.getString(34));
                tempnna.setNResolCons(temp.getString(35));
                try {
                    expnna = getExpNna(temp.getLong(1));
                    if (expnna.getIdexpedienteNna() != 0) {
                        Set<ExpedienteNna> listexp = new HashSet<ExpedienteNna>();
                        listexp.add(expnna);
                        tempnna.setExpedienteNnas(listexp);
                    }
                } catch (Exception e) {

                }
                allNnaAux.add(tempnna);
            }
            statement.close();
            temp.close();

            //AQUI DESIGNACIONES Y ESTUDIO DE CASOS EN CASO SEA PRIORITARIO
            for (Nna auxnna : allNnaAux) {
                Set<Designacion> listDesig = new HashSet<Designacion>();
                String hql2 = "{call HN_GET_DESIGNACIONES(?,?)}";
                CallableStatement statement2 = connection.prepareCall(hql2);
                statement2.setLong(1, auxnna.getIdnna());
                statement2.registerOutParameter(2, OracleTypes.CURSOR);
                statement2.execute();

                ResultSet rs2 = (ResultSet) statement2.getObject(2);
                while (rs2.next()) {
                    desig = new Designacion();
                    desig.setIddesignacion(rs2.getLong(1));
                    desig.setNDesignacion(rs2.getString(5));
                    desig.setPrioridad(rs2.getLong(6));
                    desig.setFechaPropuesta(rs2.getDate(7));
                    desig.setFechaConsejo(rs2.getDate(8));
                    desig.setAceptacionConsejo(rs2.getShort(9));
                    desig.setTipoPropuesta(rs2.getString(10));
                    desig.setObs(rs2.getString(11));
                    listDesig.add(desig);
                }
                auxnna.setDesignacions(listDesig);
                allNna.add(auxnna);
                statement2.close();
                rs2.close();
            }

            for (Nna auxnna : allNna) {
                if (auxnna.getClasificacion().equals("prioritario")) {
                    Set<EstudioCaso> listEst = new HashSet<EstudioCaso>();
                    String hql3 = "{call HN_GET_ESTUDIOS_CASO(?,?)}";
                    CallableStatement statement3 = connection.prepareCall(hql3);
                    statement3.setLong(1, auxnna.getIdnna());
                    statement3.registerOutParameter(2, OracleTypes.CURSOR);
                    statement3.execute();

                    ResultSet rs3 = (ResultSet) statement3.getObject(2);
                    while (rs3.next()) {
                        est = new EstudioCaso();
                        est.setIdestudioCaso(rs3.getLong(1));
                        est.setOrden(rs3.getString(4));
                        est.setFechaEstudio(rs3.getDate(5));
                        est.setFechaSolAdop(rs3.getDate(6));
                        est.setResultado(rs3.getString(7));
                        est.setPrioridad(rs3.getLong(8));
                        est.setNSolicitud(rs3.getLong(9));
                        listEst.add(est);
                    }
                    auxnna.setEstudioCasos(listEst);
                    statement3.close();
                    rs3.close();
                }
                allNnaFinal.add(auxnna);
            }

            //METODO BUBBLESORT PARA ORDENAR POR CODIGO
            if (clasif.equals("prioritario")) {
                Nna auxnna2;
                int n = allNnaFinal.size();
                for (int i = 0; i < n - 1; i++) {
                    for (int j = i; j < n - 1; j++) {
                        if (allNnaFinal.get(i).getExpedienteNnas().isEmpty()) {
                            if (!allNnaFinal.get(j + 1).getExpedienteNnas().isEmpty()) {
                                auxnna2 = allNnaFinal.get(i);
                                allNnaFinal.set(i, allNnaFinal.get(j + 1));
                                allNnaFinal.set(j + 1, auxnna2);
                            } else {
                                String apellidoPrev = "";
                                String apellidoNext = "";
                                try {
                                    apellidoPrev = allNnaFinal.get(i).getApellidoP();
                                    if (apellidoPrev == null) {
                                        apellidoPrev = "";
                                    }
                                } catch (Exception ex) {
                                    apellidoPrev = "";
                                }
                                try {
                                    apellidoNext = allNnaFinal.get(j + 1).getApellidoP();
                                    if (apellidoNext == null) {
                                        apellidoNext = "";
                                    }
                                } catch (Exception ex) {
                                    apellidoNext = "";
                                }
                                if (apellidoPrev.compareToIgnoreCase(apellidoNext) > 0) {
                                    auxnna2 = allNnaFinal.get(i);
                                    allNnaFinal.set(i, allNnaFinal.get(j + 1));
                                    allNnaFinal.set(j + 1, auxnna2);
                                }
                            }
                        } else {
                            Set<ExpedienteNna> listExp1 = allNnaFinal.get(i).getExpedienteNnas();
                            Set<ExpedienteNna> listExp2 = allNnaFinal.get(j + 1).getExpedienteNnas();
                            if (!listExp2.isEmpty()) {
                                for (ExpedienteNna exp1 : listExp1) {
                                    for (ExpedienteNna exp2 : listExp2) {
                                        String codant = exp1.getCodigoReferencia();
                                        String codpost = exp2.getCodigoReferencia();
                                        if (codant == null) {
                                            codant = "";
                                        }
                                        if (codpost == null) {
                                            codpost = "";
                                        }
                                        if (codant.compareToIgnoreCase(codpost) > 0) {
                                            auxnna2 = allNnaFinal.get(i);
                                            allNnaFinal.set(i, allNnaFinal.get(j + 1));
                                            allNnaFinal.set(j + 1, auxnna2);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    };
    session.doWork(work);

    return allNnaFinal;
}

From source file:com.mimp.hibernate.HiberNna.java

public ArrayList<Nna> ListaNnaPrioritarios(String clasificacion) {
    Session session = sessionFactory.getCurrentSession();
    final String clasif = clasificacion;
    final ArrayList<Nna> allNna = new ArrayList();
    final ArrayList<Nna> allNnaAux = new ArrayList();
    final ArrayList<Nna> allNnaFinal = new ArrayList();

    Work work = new Work() {
        @Override/*from  ww w.j a  v a  2s  .c o m*/
        public void execute(Connection connection) throws SQLException {
            ExpedienteNna expnna;
            Nna tempnna;
            Designacion desig;

            EstudioCaso est;

            String hql = "{call HN_GET_NNA_PRIO(?)}";
            CallableStatement statement = connection.prepareCall(hql);
            statement.registerOutParameter(1, OracleTypes.CURSOR);
            statement.execute();

            temp = (ResultSet) statement.getObject(1);

            while (temp.next()) {
                tempnna = new Nna();
                tempnna.setIdnna(temp.getLong(1));
                tempnna.setNombre(temp.getString(2));
                tempnna.setApellidoP(temp.getString(3));
                tempnna.setApellidoM(temp.getString(4));
                tempnna.setSexo(temp.getString(5));
                tempnna.setFechaNacimiento(temp.getDate(6));
                tempnna.setEdadAnhos(temp.getShort(7));
                tempnna.setEdadMeses(temp.getShort(8));
                tempnna.setActaNacimiento(temp.getShort(9));
                tempnna.setCondicionSalud(temp.getString(10));
                tempnna.setDepartamentoNacimiento(temp.getString(11));
                tempnna.setProvinciaNacimiento(temp.getString(12));
                tempnna.setDistritoNacimiento(temp.getString(13));
                tempnna.setPaisNacimiento(temp.getString(14));
                tempnna.setLugarNac(temp.getString(15));
                tempnna.setFechaResolAbandono(temp.getDate(16));
                tempnna.setFechaResolConsentida(temp.getDate(17));
                tempnna.setClasificacion(temp.getString(18));
                tempnna.setIncesto(temp.getShort(19));
                tempnna.setMental(temp.getShort(20));
                tempnna.setEpilepsia(temp.getShort(21));
                tempnna.setAbuso(temp.getShort(22));
                tempnna.setSifilis(temp.getShort(23));
                tempnna.setSeguiMedico(temp.getShort(24));
                tempnna.setOperacion(temp.getShort(25));
                tempnna.setHiperactivo(temp.getShort(26));
                tempnna.setEspecial(temp.getShort(27));
                tempnna.setEnfermo(temp.getShort(28));
                tempnna.setMayor(temp.getShort(29));
                tempnna.setAdolescente(temp.getShort(30));
                tempnna.setHermano(temp.getShort(31));
                tempnna.setNn(temp.getShort(32));
                tempnna.setObservaciones(temp.getString(33));
                tempnna.setNResolAband(temp.getString(34));
                tempnna.setNResolCons(temp.getString(35));
                try {
                    expnna = getExpNna(temp.getLong(1));
                    if (expnna.getIdexpedienteNna() != 0) {
                        Set<ExpedienteNna> listexp = new HashSet<ExpedienteNna>();
                        listexp.add(expnna);
                        tempnna.setExpedienteNnas(listexp);
                    }
                } catch (Exception e) {

                }
                allNnaAux.add(tempnna);
            }
            statement.close();
            temp.close();

            //AQUI DESIGNACIONES Y ESTUDIO DE CASOS EN CASO SEA PRIORITARIO
            for (Nna auxnna : allNnaAux) {
                Set<Designacion> listDesig = new HashSet<Designacion>();
                String hql2 = "{call HN_GET_DESIGNACIONES(?,?)}";
                CallableStatement statement2 = connection.prepareCall(hql2);
                statement2.setLong(1, auxnna.getIdnna());
                statement2.registerOutParameter(2, OracleTypes.CURSOR);
                statement2.execute();

                ResultSet rs2 = (ResultSet) statement2.getObject(2);
                while (rs2.next()) {
                    desig = new Designacion();
                    desig.setIddesignacion(rs2.getLong(1));
                    desig.setNDesignacion(rs2.getString(5));
                    desig.setPrioridad(rs2.getLong(6));
                    desig.setFechaPropuesta(rs2.getDate(7));
                    desig.setFechaConsejo(rs2.getDate(8));
                    desig.setAceptacionConsejo(rs2.getShort(9));
                    desig.setTipoPropuesta(rs2.getString(10));
                    desig.setObs(rs2.getString(11));
                    listDesig.add(desig);
                }
                auxnna.setDesignacions(listDesig);
                allNna.add(auxnna);
                statement2.close();
                rs2.close();
            }

            for (Nna auxnna : allNna) {
                if (auxnna.getClasificacion().equals("prioritario")) {
                    Set<EstudioCaso> listEst = new HashSet<EstudioCaso>();
                    String hql3 = "{call HN_GET_ESTUDIOS_CASO(?,?)}";
                    CallableStatement statement3 = connection.prepareCall(hql3);
                    statement3.setLong(1, auxnna.getIdnna());
                    statement3.registerOutParameter(2, OracleTypes.CURSOR);
                    statement3.execute();

                    ResultSet rs3 = (ResultSet) statement3.getObject(2);
                    while (rs3.next()) {
                        est = new EstudioCaso();
                        est.setIdestudioCaso(rs3.getLong(1));
                        est.setOrden(rs3.getString(4));
                        est.setFechaEstudio(rs3.getDate(5));
                        est.setFechaSolAdop(rs3.getDate(6));
                        est.setResultado(rs3.getString(7));
                        est.setPrioridad(rs3.getLong(8));
                        est.setNSolicitud(rs3.getLong(9));
                        listEst.add(est);
                    }
                    auxnna.setEstudioCasos(listEst);
                    statement3.close();
                    rs3.close();
                }
                allNnaFinal.add(auxnna);
            }

            //METODO BUBBLESORT PARA ORDENAR POR CODIGO
            if (clasif.equals("prioritario")) {
                Nna auxnna2;
                int n = allNnaFinal.size();
                for (int i = 0; i < n - 1; i++) {
                    for (int j = i; j < n - 1; j++) {
                        if (allNnaFinal.get(i).getExpedienteNnas().isEmpty()) {
                            if (!allNnaFinal.get(j + 1).getExpedienteNnas().isEmpty()) {
                                auxnna2 = allNnaFinal.get(i);
                                allNnaFinal.set(i, allNnaFinal.get(j + 1));
                                allNnaFinal.set(j + 1, auxnna2);
                            } else {
                                String apellidoPrev = "";
                                String apellidoNext = "";
                                try {
                                    apellidoPrev = allNnaFinal.get(i).getApellidoP();
                                    if (apellidoPrev == null) {
                                        apellidoPrev = "";
                                    }
                                } catch (Exception ex) {
                                    apellidoPrev = "";
                                }
                                try {
                                    apellidoNext = allNnaFinal.get(j + 1).getApellidoP();
                                    if (apellidoNext == null) {
                                        apellidoNext = "";
                                    }
                                } catch (Exception ex) {
                                    apellidoNext = "";
                                }

                                if (apellidoPrev.compareToIgnoreCase(apellidoNext) > 0) {
                                    auxnna2 = allNnaFinal.get(i);
                                    allNnaFinal.set(i, allNnaFinal.get(j + 1));
                                    allNnaFinal.set(j + 1, auxnna2);
                                }
                            }
                        } else {
                            Set<ExpedienteNna> listExp1 = allNnaFinal.get(i).getExpedienteNnas();
                            Set<ExpedienteNna> listExp2 = allNnaFinal.get(j + 1).getExpedienteNnas();
                            if (!listExp2.isEmpty()) {
                                for (ExpedienteNna exp1 : listExp1) {
                                    for (ExpedienteNna exp2 : listExp2) {
                                        String codant = exp1.getCodigoReferencia();
                                        String codpost = exp2.getCodigoReferencia();
                                        if (codant == null) {
                                            codant = "";
                                        }
                                        if (codpost == null) {
                                            codpost = "";
                                        }
                                        if (codant.compareToIgnoreCase(codpost) > 0) {
                                            auxnna2 = allNnaFinal.get(i);
                                            allNnaFinal.set(i, allNnaFinal.get(j + 1));
                                            allNnaFinal.set(j + 1, auxnna2);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    };
    session.doWork(work);

    return allNnaFinal;
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseClusterTable.java

public long nextConfigurationFileIdGen(CFAstAuthorization Authorization, CFAstClusterPKey PKey) {
    final String S_ProcName = "nextConfigurationFileIdGen";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Not in a transaction");
    }//from w  w  w.  j  a v  a2 s .  c  o  m
    Connection cnx = schema.getCnx();
    long Id = PKey.getRequiredId();

    CallableStatement stmtSelectNextConfigurationFileIdGen = null;
    try {
        String sql = "{ call sp_next_configurationfileidgen( ?" + ", " + "?" + " ) }";
        stmtSelectNextConfigurationFileIdGen = cnx.prepareCall(sql);
        int argIdx = 1;
        stmtSelectNextConfigurationFileIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT);
        stmtSelectNextConfigurationFileIdGen.setLong(argIdx++, Id);
        stmtSelectNextConfigurationFileIdGen.execute();
        long nextId = stmtSelectNextConfigurationFileIdGen.getLong(1);
        return (nextId);
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (stmtSelectNextConfigurationFileIdGen != null) {
            try {
                stmtSelectNextConfigurationFileIdGen.close();
            } catch (SQLException e) {
            }
            stmtSelectNextConfigurationFileIdGen = null;
        }
    }
}

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

/**
 * @see com.cws.esolutions.core.dao.interfaces.IWebMessagingDAO#getMessagesByAttribute(String)
 *///  www .ja  v a 2 s . c  om
public synchronized List<Object[]> getMessagesByAttribute(final String value) throws SQLException {
    final String methodName = IWebMessagingDAO.CNAME
            + "#getMessagesByAttribute(final String value) throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
    }

    Connection sqlConn = null;
    ResultSet resultSet = null;
    CallableStatement stmt = null;
    List<Object[]> responseData = null;

    try {
        sqlConn = dataSource.getConnection();

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

        sqlConn.setAutoCommit(true);
        StringBuilder sBuilder = new StringBuilder();

        if (StringUtils.split(value, " ").length >= 2) {
            for (String str : StringUtils.split(value, " ")) {
                if (DEBUG) {
                    DEBUGGER.debug("Value: {}", str);
                }

                sBuilder.append("+" + str);
                sBuilder.append(" ");
            }

            if (DEBUG) {
                DEBUGGER.debug("StringBuilder: {}", sBuilder);
            }
        } else {
            sBuilder.append("+" + value);
        }

        stmt = sqlConn.prepareCall("{CALL getMessagesByAttribute(?)}");
        stmt.setString(1, sBuilder.toString().trim());

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

        if (stmt.execute()) {
            resultSet = stmt.getResultSet();

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

            if (resultSet.next()) {
                resultSet.beforeFirst();
                responseData = new ArrayList<Object[]>();

                while (resultSet.next()) {
                    Object[] messageData = new Object[] { resultSet.getString(1), // svc_message_id
                            resultSet.getString(2), // svc_message_title
                            resultSet.getString(3), // svc_message_txt
                            resultSet.getString(4), // svc_message_author
                            resultSet.getTimestamp(5), // svc_message_submitdate
                            resultSet.getBoolean(6), // svc_message_active
                            resultSet.getBoolean(7), // svc_message_alert
                            resultSet.getBoolean(8), // svc_message_expires
                            resultSet.getTimestamp(9), // svc_message_expirydate
                            resultSet.getTimestamp(10), // svc_message_modifiedon
                            resultSet.getString(11) // svc_message_modifiedby
                    };

                    if (DEBUG) {
                        for (Object obj : messageData) {
                            DEBUGGER.debug("Value: {}", obj);
                        }
                    }

                    responseData.add(messageData);
                }

                if (DEBUG) {
                    for (Object[] str : responseData) {
                        for (Object obj : str) {
                            DEBUGGER.debug("Value: {}", obj);
                        }
                    }
                }
            }
        }
    } catch (SQLException sqx) {
        ERROR_RECORDER.error(sqx.getMessage(), sqx);

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

        if (stmt != null) {
            stmt.close();
        }

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

    return responseData;
}