/** Inserts a new row in the carrito_compras table. */ public CarritoComprasPk insert(CarritoCompras dto) throws CarritoComprasDaoException { long t1 = System.currentTimeMillis(); // declare variables final boolean isConnSupplied = (userConn != null); Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try { // get the user-specified connection or get a connection from the ResourceManager conn = isConnSupplied ? userConn : ResourceManager.getConnection(); stmt = conn.prepareStatement(SQL_INSERT); int index = 1; stmt.setString(index++, dto.getIdCarrito()); stmt.setDouble(index++, dto.getTotal()); stmt.setDouble(index++, dto.getSubtotal()); stmt.setDouble(index++, dto.getImpuestos()); System.out.println("Executing " + SQL_INSERT + " with DTO: " + dto); int rows = stmt.executeUpdate(); long t2 = System.currentTimeMillis(); System.out.println(rows + " rows affected (" + (t2 - t1) + " ms)"); reset(dto); return dto.createPk(); } catch (Exception _e) { _e.printStackTrace(); throw new CarritoComprasDaoException("Exception: " + _e.getMessage(), _e); } finally { ResourceManager.close(stmt); if (!isConnSupplied) { ResourceManager.close(conn); } } }
/** Deletes a single row in the carrito_compras table. */ public void delete(CarritoComprasPk pk) throws CarritoComprasDaoException { long t1 = System.currentTimeMillis(); // declare variables final boolean isConnSupplied = (userConn != null); Connection conn = null; PreparedStatement stmt = null; try { // get the user-specified connection or get a connection from the ResourceManager conn = isConnSupplied ? userConn : ResourceManager.getConnection(); System.out.println("Executing " + SQL_DELETE + " with PK: " + pk); stmt = conn.prepareStatement(SQL_DELETE); stmt.setString(1, pk.getIdCarrito()); int rows = stmt.executeUpdate(); long t2 = System.currentTimeMillis(); System.out.println(rows + " rows affected (" + (t2 - t1) + " ms)"); } catch (Exception _e) { _e.printStackTrace(); throw new CarritoComprasDaoException("Exception: " + _e.getMessage(), _e); } finally { ResourceManager.close(stmt); if (!isConnSupplied) { ResourceManager.close(conn); } } }
@Override public List<MotInteInventario> findByInternamiento(Long codigo) throws MotInteInventarioDaoException { Connection conn = null; CallableStatement stmt = null; ResultSet rs = null; List<MotInteInventario> list = null; try { conn = ResourceManager.getConnection(); stmt = conn.prepareCall("{call SP_MOT_GET_INTEINVENTARIOBYINTERNAMIENTO;1(?)}"); stmt.setLong(1, codigo); boolean results = stmt.execute(); if (results) { list = new ArrayList<MotInteInventario>(); rs = stmt.getResultSet(); MotInteInventario inventario = null; while (rs.next()) { inventario = new MotInteInventario(); inventario.getInternamiento().setIntcodigoD(rs.getLong("INTCODIGO")); inventario.getInventarioTipo().setBitcodigoI(rs.getInt("BITCODIGO")); inventario.setBivcantidadI(rs.getInt("CANTIDAD")); inventario.setBivestadoC(rs.getString("ESTADO")); list.add(inventario); } } } catch (SQLException e) { throw new MotInteInventarioDaoException(e.getMessage(), e); } finally { ResourceManager.close(rs); ResourceManager.close(stmt); ResourceManager.close(conn); } return list; }
/** Inserts a new row in the project_phases table. */ public ProjectPhasesPk insert(ProjectPhases dto) throws ProjectPhasesDaoException { long t1 = System.currentTimeMillis(); // declare variables final boolean isConnSupplied = (userConn != null); Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try { // get the user-specified connection or get a connection from the ResourceManager conn = isConnSupplied ? userConn : ResourceManager.getConnection(); stmt = conn.prepareStatement(SQL_INSERT, Statement.RETURN_GENERATED_KEYS); int index = 1; stmt.setInt(index++, dto.getIdprojectPhases()); stmt.setString(index++, dto.getName()); stmt.setString(index++, dto.getDescription()); stmt.setDate( index++, dto.getStartDate() == null ? null : new java.sql.Date(dto.getStartDate().getTime())); stmt.setDate( index++, dto.getEndDate() == null ? null : new java.sql.Date(dto.getEndDate().getTime())); if (dto.isStatusNull()) { stmt.setNull(index++, java.sql.Types.INTEGER); } else { stmt.setInt(index++, dto.getStatus()); } if (dto.isProjectIdNull()) { stmt.setNull(index++, java.sql.Types.INTEGER); } else { stmt.setInt(index++, dto.getProjectId()); } System.out.println("Executing " + SQL_INSERT + " with DTO: " + dto); int rows = stmt.executeUpdate(); long t2 = System.currentTimeMillis(); System.out.println(rows + " rows affected (" + (t2 - t1) + " ms)"); // retrieve values from auto-increment columns rs = stmt.getGeneratedKeys(); if (rs != null && rs.next()) { dto.setIdprojectPhases(rs.getInt(1)); } reset(dto); return dto.createPk(); } catch (Exception _e) { _e.printStackTrace(); throw new ProjectPhasesDaoException("Exception: " + _e.getMessage(), _e); } finally { ResourceManager.close(stmt); if (!isConnSupplied) { ResourceManager.close(conn); } } }
@Override public List<MotEmpConductor> findByCriterio(String criterio, String texto, Long empcodigoD) throws MotEmpConductorDaoException { Connection conn = null; CallableStatement stmt = null; ResultSet rs = null; List<MotEmpConductor> list = new ArrayList<MotEmpConductor>(); try { conn = ResourceManager.getConnection(); stmt = conn.prepareCall("{call SP_MOT_GET_LISTADO_CONDUCTORPORRITERIO;1(?,?,?)}"); stmt.setString(1, criterio); stmt.setString(2, texto); stmt.setLong(3, empcodigoD); boolean results = stmt.execute(); if (results) { rs = stmt.getResultSet(); MotPersona persona = null; MotConductor conductor = null; MotEmpConductor empresaconductor = null; // ??? while (rs.next()) { persona = new MotPersona(); persona.setPernombresV(rs.getString("Nombres")); persona.setPerpaternoV(rs.getString("Paterno")); persona.setPermaternoV(rs.getString("Materno")); persona.setPerdniV(rs.getString("DNI")); conductor = new MotConductor(); conductor.setConcodigoD(rs.getLong("CONDCODIGO")); conductor.setPersona(persona); empresaconductor = new MotEmpConductor(); empresaconductor.setMotosasignadasI(rs.getInt("Motos Asignadas")); empresaconductor.setEcofechainicioF(rs.getString("Fecha Inicio")); empresaconductor.setEcofechaceseF(rs.getString("Fecha Cese")); empresaconductor.setConductor(conductor); list.add(empresaconductor); } } } catch (SQLException ex) { throw new MotEmpConductorDaoException(ex.getMessage()); } finally { ResourceManager.close(rs); ResourceManager.close(stmt); ResourceManager.close(conn); } return list; }
/** Updates a single row in the project_phases table. */ public void update(ProjectPhasesPk pk, ProjectPhases dto) throws ProjectPhasesDaoException { long t1 = System.currentTimeMillis(); // declare variables final boolean isConnSupplied = (userConn != null); Connection conn = null; PreparedStatement stmt = null; try { // get the user-specified connection or get a connection from the ResourceManager conn = isConnSupplied ? userConn : ResourceManager.getConnection(); System.out.println("Executing " + SQL_UPDATE + " with DTO: " + dto); stmt = conn.prepareStatement(SQL_UPDATE); int index = 1; stmt.setInt(index++, dto.getIdprojectPhases()); stmt.setString(index++, dto.getName()); stmt.setString(index++, dto.getDescription()); stmt.setDate( index++, dto.getStartDate() == null ? null : new java.sql.Date(dto.getStartDate().getTime())); stmt.setDate( index++, dto.getEndDate() == null ? null : new java.sql.Date(dto.getEndDate().getTime())); if (dto.isStatusNull()) { stmt.setNull(index++, java.sql.Types.INTEGER); } else { stmt.setInt(index++, dto.getStatus()); } if (dto.isProjectIdNull()) { stmt.setNull(index++, java.sql.Types.INTEGER); } else { stmt.setInt(index++, dto.getProjectId()); } stmt.setInt(8, pk.getIdprojectPhases()); int rows = stmt.executeUpdate(); reset(dto); long t2 = System.currentTimeMillis(); System.out.println(rows + " rows affected (" + (t2 - t1) + " ms)"); } catch (Exception _e) { _e.printStackTrace(); throw new ProjectPhasesDaoException("Exception: " + _e.getMessage(), _e); } finally { ResourceManager.close(stmt); if (!isConnSupplied) { ResourceManager.close(conn); } } }
@Override public void procesar(MotEmpConductor dto) throws MotEmpConductorDaoException { Connection conn = null; CallableStatement stmt = null; ResultSet rs = null; try { conn = ResourceManager.getConnection(); stmt = conn.prepareCall( "{call SP_MOT_INS_PERSONA_CONDUCTOR;1(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); stmt.registerOutParameter(1, Types.DECIMAL); stmt.setLong(1, dto.getConductor().getConcodigoD()); stmt.setLong(2, dto.getConductor().getPersona().getPercodigoD()); stmt.setString(3, dto.getConductor().getPersona().getPerdniV()); stmt.setString(4, dto.getConductor().getPersona().getPernombresV()); stmt.setString(5, dto.getConductor().getPersona().getPerpaternoV()); stmt.setString(6, dto.getConductor().getPersona().getPermaternoV()); stmt.setString(7, dto.getConductor().getPersona().getPernacimientoF()); stmt.setString(8, dto.getConductor().getPersona().getPerestadocivilC()); stmt.setString(9, dto.getConductor().getPersona().getPermovilclaV()); stmt.setString(10, dto.getConductor().getPersona().getPermovilmovV()); stmt.setString(11, dto.getConductor().getPersona().getPermovilnexV()); stmt.setString(12, dto.getConductor().getPersona().getPerteleffijoV()); stmt.setString(13, dto.getConductor().getPersona().getPeremailV()); stmt.setString(14, dto.getConductor().getPersona().getPerdomicilioV()); stmt.setString(15, dto.getConductor().getPersona().getPerubidistV()); stmt.setString(16, dto.getConductor().getPersona().getPerubdptoV()); stmt.setString(17, dto.getConductor().getPersona().getPerubprovV()); stmt.setString(18, dto.getConductor().getPersona().getPersexoC()); stmt.setLong(19, dto.getEmpresa().getEmpcodigoD()); stmt.setString(20, dto.getEcofechainicioF()); stmt.execute(); Long codigo = stmt.getLong(1); if (codigo != null) { dto.getConductor().setConcodigoD(codigo); } } catch (Exception ex) { logger.error("Exception: " + ex.getMessage(), ex); throw new MotEmpConductorDaoException("Exception: " + ex.getMessage(), ex); } finally { ResourceManager.close(rs); ResourceManager.close(stmt); ResourceManager.close(conn); } }
/** Returns all rows from the producto table that match the specified arbitrary SQL statement */ public Producto[] findByDynamicSelect(String sql, Object[] sqlParams) throws ProductoDaoException { // declare variables final boolean isConnSupplied = (userConn != null); Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try { // get the user-specified connection or get a connection from the ResourceManager conn = isConnSupplied ? userConn : ResourceManager.getConnection(); // construct the SQL statement final String SQL = sql; if (logger.isDebugEnabled()) { logger.debug("Executing " + SQL); } // prepare statement stmt = conn.prepareStatement(SQL); stmt.setMaxRows(maxRows); // bind parameters for (int i = 0; sqlParams != null && i < sqlParams.length; i++) { stmt.setObject(i + 1, sqlParams[i]); } rs = stmt.executeQuery(); // fetch the results return fetchMultiResults(rs); } catch (Exception _e) { logger.error("Exception: " + _e.getMessage(), _e); throw new ProductoDaoException("Exception: " + _e.getMessage(), _e); } finally { ResourceManager.close(rs); ResourceManager.close(stmt); if (!isConnSupplied) { ResourceManager.close(conn); } } }
@Override public void modificar(MotInteInventario inteInventario) throws MotInteInventarioDaoException { Connection conn = null; CallableStatement stmt = null; try { conn = ResourceManager.getConnection(); stmt = conn.prepareCall("{call SP_MOT_UPD_INTE_INVENTARIO;1(?,?,?,?)}"); stmt.setLong(1, inteInventario.getInternamiento().getIntcodigoD()); stmt.setInt(2, inteInventario.getInventarioTipo().getBitcodigoI()); stmt.setString(3, inteInventario.getBivestadoC()); stmt.setInt(4, inteInventario.getBivcantidadI()); stmt.execute(); } catch (SQLException e) { throw new MotInteInventarioDaoException(e.getMessage(), e); } finally { ResourceManager.close(stmt); ResourceManager.close(conn); } }
/** * Returns all rows from the carrito_compras table that match the specified arbitrary SQL * statement */ public CarritoCompras[] findByDynamicWhere(String sql, Object[] sqlParams) throws CarritoComprasDaoException { // declare variables final boolean isConnSupplied = (userConn != null); Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try { // get the user-specified connection or get a connection from the ResourceManager conn = isConnSupplied ? userConn : ResourceManager.getConnection(); // construct the SQL statement final String SQL = SQL_SELECT + " WHERE " + sql; System.out.println("Executing " + SQL); // prepare statement stmt = conn.prepareStatement(SQL); stmt.setMaxRows(maxRows); // bind parameters for (int i = 0; sqlParams != null && i < sqlParams.length; i++) { stmt.setObject(i + 1, sqlParams[i]); } rs = stmt.executeQuery(); // fetch the results return fetchMultiResults(rs); } catch (Exception _e) { _e.printStackTrace(); throw new CarritoComprasDaoException("Exception: " + _e.getMessage(), _e); } finally { ResourceManager.close(rs); ResourceManager.close(stmt); if (!isConnSupplied) { ResourceManager.close(conn); } } }
@Override public void insertar(MotInteInventario inteInventario) throws MotInteInventarioDaoException { Connection conn = null; CallableStatement stmt = null; try { conn = ResourceManager.getConnection(); stmt = conn.prepareCall("{call SP_MOT_INS_INTE_INVENTARIO;1(?,?,?,?,?)}"); stmt.registerOutParameter(1, Types.DECIMAL); stmt.setLong(2, inteInventario.getInternamiento().getIntcodigoD()); stmt.setInt(3, inteInventario.getInventarioTipo().getBitcodigoI()); stmt.setString(4, inteInventario.getBivestadoC()); stmt.setInt(5, inteInventario.getBivcantidadI()); stmt.execute(); Long codigo = stmt.getLong(1); if (codigo != null) { inteInventario.setBivcodigoD(codigo); } } catch (SQLException e) { throw new MotInteInventarioDaoException(e.getMessage(), e); } finally { ResourceManager.close(stmt); ResourceManager.close(conn); } }
/** Updates a single row in the producto table. */ public void update(ProductoPk pk, Producto dto) throws ProductoDaoException { long t1 = System.currentTimeMillis(); // declare variables final boolean isConnSupplied = (userConn != null); Connection conn = null; PreparedStatement stmt = null; try { // get the user-specified connection or get a connection from the ResourceManager conn = isConnSupplied ? userConn : ResourceManager.getConnection(); StringBuffer sql = new StringBuffer(); sql.append("UPDATE " + getTableName() + " SET "); boolean modified = false; if (dto.isIdProductoModified()) { if (modified) { sql.append(", "); } sql.append("ID_PRODUCTO=?"); modified = true; } if (dto.isNombreProductoModified()) { if (modified) { sql.append(", "); } sql.append("NOMBRE_PRODUCTO=?"); modified = true; } if (dto.isPrecioModified()) { if (modified) { sql.append(", "); } sql.append("PRECIO=?"); modified = true; } if (dto.isImagenModified()) { if (modified) { sql.append(", "); } sql.append("IMAGEN=?"); modified = true; } if (dto.isCantidadModified()) { if (modified) { sql.append(", "); } sql.append("CANTIDAD=?"); modified = true; } if (dto.isActivoModified()) { if (modified) { sql.append(", "); } sql.append("ACTIVO=?"); modified = true; } if (dto.isFechaCreacionModified()) { if (modified) { sql.append(", "); } sql.append("FECHA_CREACION=?"); modified = true; } if (dto.isUsuarioCreacionModified()) { if (modified) { sql.append(", "); } sql.append("USUARIO_CREACION=?"); modified = true; } if (dto.isFechaUltimaModificacionModified()) { if (modified) { sql.append(", "); } sql.append("FECHA_ULTIMA_MODIFICACION=?"); modified = true; } if (dto.isUsuarioUltimaModificacionModified()) { if (modified) { sql.append(", "); } sql.append("USUARIO_ULTIMA_MODIFICACION=?"); modified = true; } if (dto.isCategoriaIdCategoriaModified()) { if (modified) { sql.append(", "); } sql.append("CATEGORIA_ID_CATEGORIA=?"); modified = true; } if (dto.isCatalogoIdCatalogoModified()) { if (modified) { sql.append(", "); } sql.append("CATALOGO_ID_CATALOGO=?"); modified = true; } if (!modified) { // nothing to update return; } sql.append(" WHERE ID_PRODUCTO=?"); if (logger.isDebugEnabled()) { logger.debug("Executing " + sql.toString() + " with values: " + dto); } stmt = conn.prepareStatement(sql.toString()); int index = 1; if (dto.isIdProductoModified()) { stmt.setString(index++, dto.getIdProducto()); } if (dto.isNombreProductoModified()) { stmt.setString(index++, dto.getNombreProducto()); } if (dto.isPrecioModified()) { stmt.setDouble(index++, dto.getPrecio()); } if (dto.isImagenModified()) { super.setBlobColumn(stmt, index++, dto.getImagen()); } if (dto.isCantidadModified()) { if (dto.isCantidadNull()) { stmt.setNull(index++, java.sql.Types.FLOAT); } else { stmt.setFloat(index++, dto.getCantidad()); } } if (dto.isActivoModified()) { stmt.setShort(index++, dto.getActivo()); } if (dto.isFechaCreacionModified()) { stmt.setTimestamp( index++, dto.getFechaCreacion() == null ? null : new java.sql.Timestamp(dto.getFechaCreacion().getTime())); } if (dto.isUsuarioCreacionModified()) { stmt.setString(index++, dto.getUsuarioCreacion()); } if (dto.isFechaUltimaModificacionModified()) { stmt.setTimestamp( index++, dto.getFechaUltimaModificacion() == null ? null : new java.sql.Timestamp(dto.getFechaUltimaModificacion().getTime())); } if (dto.isUsuarioUltimaModificacionModified()) { stmt.setString(index++, dto.getUsuarioUltimaModificacion()); } if (dto.isCategoriaIdCategoriaModified()) { stmt.setInt(index++, dto.getCategoriaIdCategoria()); } if (dto.isCatalogoIdCatalogoModified()) { stmt.setInt(index++, dto.getCatalogoIdCatalogo()); } stmt.setString(index++, pk.getIdProducto()); int rows = stmt.executeUpdate(); reset(dto); long t2 = System.currentTimeMillis(); if (logger.isDebugEnabled()) { logger.debug(rows + " rows affected (" + (t2 - t1) + " ms)"); } } catch (Exception _e) { logger.error("Exception: " + _e.getMessage(), _e); throw new ProductoDaoException("Exception: " + _e.getMessage(), _e); } finally { ResourceManager.close(stmt); if (!isConnSupplied) { ResourceManager.close(conn); } } }