コード例 #1
0
 /**
  * Funcion con la cual obtengo todos los municipios teniendo en cuenta el id de la ciudad
  *
  * @param idCiudad
  * @return
  */
 public ArrayList<Par_MunicipioTO> obtieneMunicipiosXId(String idCiudad) {
   String sql = "";
   ArrayList<Par_MunicipioTO> rta = null;
   Connection con = null;
   try {
     con = super.getConnection(this.objDataSession);
     sql = "select mpio_id, mpio_nombre ";
     sql += "from spar_municipio ";
     sql += "where ciu_id = ? ";
     sql += "and mpio_estado = 'A' ";
     PreparedStatement ps = con.prepareCall(sql);
     ps.setString(1, idCiudad);
     ResultSet rs = ps.executeQuery();
     while (rs.next()) {
       if (rta == null) {
         rta = new ArrayList<Par_MunicipioTO>();
       }
       Par_MunicipioTO aux = new Par_MunicipioTO();
       aux.setMpio_Id(rs.getLong("mpio_id"));
       aux.setMpio_Nombre(rs.getString("mpio_nombre"));
       rta.add(aux);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return rta;
 }
コード例 #2
0
 /**
  * Eliminar un registro.
  *
  * @param inTproc Object - Objeto procesado
  * @throws PersistenciaException - capa de persistencia
  * @return Object - identificador de objeto
  */
 public Object delete(Object par_municipio) throws PersistenciaException {
   PreparedStatement stmt = null;
   Connection connection = null;
   StringBuffer sqlString = new StringBuffer();
   Par_MunicipioTO par_municipioTO = (Par_MunicipioTO) par_municipio;
   sqlString.append(" DELETE FROM SPAR_MUNICIPIO");
   sqlString.append(" WHERE MPIO_ID=?");
   try {
     synchronized (this) {
       connection = super.getConnection(this.objDataSession);
       stmt = connection.prepareStatement(sqlString.toString());
       int i = 1;
       setLong(stmt, (Long) par_municipioTO.getAttribute(Par_MunicipioTO.MPIO_ID), i++);
       stmt.executeUpdate();
     }
     return "Ok";
   } catch (SQLException ex) {
     System.err.println("error Par_MunicipioDAO.delete: " + ex.toString());
     throw new PersistenciaException(ex.getMessage(), ex);
   } finally {
     try {
       super.cerrarConexiones(connection, stmt, null, this.objDataSession);
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   }
 }
コード例 #3
0
 /**
  * Retorna una colecci�n Par_MunicipioTO
  *
  * @param parameters Hashtable - parametros para la consulta
  * @throws PersistenciaException - capa de persistencia
  * @return Collection - resultado Par_Municipio
  */
 public java.util.Collection<Object> getPar_Municipio(Hashtable<String, Object> parameters)
     throws PersistenciaException {
   PreparedStatement stm = null;
   ResultSet rs = null;
   Connection connection = null;
   Collection<Object> result = new ArrayList<Object>();
   Par_MunicipioTO par_municipioTO = new Par_MunicipioTO();
   Par_MunicipioTO par_municipioCollTO = null;
   StringBuffer sqlString = new StringBuffer();
   int posicion = 1;
   try {
     sqlString.append(" SELECT mpio_id ");
     sqlString.append("       ,mpio_nombre ");
     sqlString.append("       ,mpio_comentarios ");
     sqlString.append("       ,ciu_id ");
     sqlString.append("       ,mpio_estado ");
     sqlString.append("       ,mpio_eligezona ");
     sqlString.append("       ,mpio_default ");
     sqlString.append(" FROM spar_municipio ");
     sqlString.append(" WHERE 1=1 ");
     adicionarCondiciones(sqlString, par_municipioTO, parameters);
     connection = super.getConnection(this.objDataSession);
     stm = connection.prepareStatement(sqlString.toString());
     rs = stm.executeQuery();
     while (rs.next()) {
       par_municipioCollTO = new Par_MunicipioTO();
       par_municipioCollTO.setPosicion(posicion++);
       poblarTO(rs, par_municipioCollTO);
       result.add(par_municipioCollTO);
     }
   } catch (SQLException e) {
     e.printStackTrace();
     throw new PersistenciaException("Error en getPar_MunicipioDAO.getPar_Municipio: ", e);
   } finally {
     super.cerrarConexiones(connection, stm, rs, this.objDataSession);
   }
   return result;
 }
コード例 #4
0
 /**
  * Actualizar un registro.
  *
  * @param inTproc Object - Objeto procesado.
  * @throws PersistenciaException - capa de persistencia.
  * @return Object - identificador de objeto
  */
 public Object update(Object par_municipio) throws PersistenciaException {
   PreparedStatement stmt = null;
   Connection connection = null;
   StringBuffer sqlString = new StringBuffer();
   Par_MunicipioTO par_municipioTO = (Par_MunicipioTO) par_municipio;
   sqlString.append(" UPDATE SPAR_MUNICIPIO ");
   sqlString.append(" SET MPIO_NOMBRE = ? ");
   sqlString.append("     ,MPIO_COMENTARIOS = ? ");
   sqlString.append("     ,CIU_ID = ? ");
   sqlString.append("     ,MPIO_ESTADO = ? ");
   sqlString.append("     ,MPIO_ELIGEZONA = ? ");
   sqlString.append("     ,MPIO_DEFAULT = ? ");
   sqlString.append(" WHERE MPIO_ID = ? ");
   try {
     synchronized (this) {
       connection = super.getConnection(this.objDataSession);
       stmt = connection.prepareStatement(sqlString.toString());
       int i = 1;
       setString(stmt, (String) par_municipioTO.getAttribute(Par_MunicipioTO.MPIO_NOMBRE), i++);
       setString(
           stmt, (String) par_municipioTO.getAttribute(Par_MunicipioTO.MPIO_COMENTARIOS), i++);
       setLong(stmt, (Long) par_municipioTO.getAttribute(Par_MunicipioTO.CIU_ID), i++);
       setString(stmt, (String) par_municipioTO.getAttribute(Par_MunicipioTO.MPIO_ESTADO), i++);
       setString(stmt, (String) par_municipioTO.getAttribute(Par_MunicipioTO.MPIO_ELIGEZONA), i++);
       setString(stmt, (String) par_municipioTO.getAttribute(Par_MunicipioTO.MPIO_DEFAULT), i++);
       // clausula where
       setLong(stmt, (Long) par_municipioTO.getAttribute(Par_MunicipioTO.MPIO_ID), i++);
       stmt.executeUpdate();
     }
     return "Ok";
   } catch (SQLException ex) {
     System.err.println("error Par_MunicipioDAO.update: " + ex.toString());
     throw new PersistenciaException(ex.getMessage(), ex);
   } finally {
     try {
       cerrarConexiones(connection, stmt, null, this.objDataSession);
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   }
 }
コード例 #5
0
 /**
  * Inserta un registro.
  *
  * @param inTproc Object - Objeto procesado
  * @throws PersistenciaException - capa de persistencia
  * @return Object - identificador de objeto
  */
 public Object insert(Object par_municipio) throws PersistenciaException {
   PreparedStatement stmt = null;
   Connection connection = null;
   StringBuffer sqlString = new StringBuffer();
   Par_MunicipioTO par_municipioTO = (Par_MunicipioTO) par_municipio;
   int i = 0;
   Long sequence = new Long(0);
   sqlString.append(" INSERT INTO SPAR_MUNICIPIO ");
   sqlString.append("    (mpio_id ");
   sqlString.append("    ,mpio_nombre ");
   sqlString.append("    ,mpio_comentarios ");
   sqlString.append("    ,ciu_id ");
   sqlString.append("    ,mpio_estado ");
   sqlString.append("    ,mpio_eligezona ");
   sqlString.append("    ,mpio_default ");
   sqlString.append(" )VALUES (?,?,?,?,?,?,?) ");
   try {
     synchronized (this) {
       connection = super.getConnection(this.objDataSession);
       sequence = getNextSequential("SPAR_MUNICIPIO", "MPIO_ID", connection);
       par_municipioTO.setAttribute(Par_MunicipioTO.MPIO_ID, sequence);
       stmt = connection.prepareStatement(sqlString.toString());
       i = 1;
       setLong(stmt, (Long) par_municipioTO.getAttribute(Par_MunicipioTO.MPIO_ID), i++);
       setString(stmt, (String) par_municipioTO.getAttribute(Par_MunicipioTO.MPIO_NOMBRE), i++);
       setString(
           stmt, (String) par_municipioTO.getAttribute(Par_MunicipioTO.MPIO_COMENTARIOS), i++);
       setLong(stmt, (Long) par_municipioTO.getAttribute(Par_MunicipioTO.CIU_ID), i++);
       if (par_municipioTO.getAttribute(Par_MunicipioTO.MPIO_ESTADO) == null
           || ""
               .equalsIgnoreCase("" + par_municipioTO.getAttribute(Par_MunicipioTO.MPIO_ESTADO))) {
         par_municipioTO.setAttribute(Par_MunicipioTO.MPIO_ESTADO, "A");
       }
       setString(stmt, (String) par_municipioTO.getAttribute(Par_MunicipioTO.MPIO_ESTADO), i++);
       setString(stmt, (String) par_municipioTO.getAttribute(Par_MunicipioTO.MPIO_ELIGEZONA), i++);
       setString(stmt, (String) par_municipioTO.getAttribute(Par_MunicipioTO.MPIO_DEFAULT), i++);
       stmt.executeUpdate();
     }
     return "Ok";
   } catch (SQLException ex) {
     System.err.println("error Par_MunicipioDAO.insert: " + ex.toString());
     throw new PersistenciaException(ex.getMessage(), ex);
   } finally {
     try {
       super.cerrarConexiones(connection, stmt, null, this.objDataSession);
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   }
 }