コード例 #1
0
  /** Deletes a single row in the producto table. */
  public void delete(ProductoPk pk) 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();

      if (logger.isDebugEnabled()) {
        logger.debug("Executing " + SQL_DELETE + " with PK: " + pk);
      }

      stmt = conn.prepareStatement(SQL_DELETE);
      stmt.setString(1, pk.getIdProducto());
      int rows = stmt.executeUpdate();
      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);
      }
    }
  }
コード例 #2
0
 /** Returns the rows from the producto table that matches the specified primary-key value. */
 public Producto findByPrimaryKey(ProductoPk pk) throws ProductoDaoException {
   return findByPrimaryKey(pk.getIdProducto());
 }
コード例 #3
0
  /** 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);
      }
    }
  }