/** Inserts a new row in the producto table. */ public ProductoPk insert(Producto dto) throws ProductoDaoException { 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(); StringBuffer sql = new StringBuffer(); StringBuffer values = new StringBuffer(); sql.append("INSERT INTO " + getTableName() + " ("); int modifiedCount = 0; if (dto.isIdProductoModified()) { if (modifiedCount > 0) { sql.append(", "); values.append(", "); } sql.append("ID_PRODUCTO"); values.append("?"); modifiedCount++; } if (dto.isNombreProductoModified()) { if (modifiedCount > 0) { sql.append(", "); values.append(", "); } sql.append("NOMBRE_PRODUCTO"); values.append("?"); modifiedCount++; } if (dto.isPrecioModified()) { if (modifiedCount > 0) { sql.append(", "); values.append(", "); } sql.append("PRECIO"); values.append("?"); modifiedCount++; } if (dto.isImagenModified()) { if (modifiedCount > 0) { sql.append(", "); values.append(", "); } sql.append("IMAGEN"); values.append("?"); modifiedCount++; } if (dto.isCantidadModified()) { if (modifiedCount > 0) { sql.append(", "); values.append(", "); } sql.append("CANTIDAD"); values.append("?"); modifiedCount++; } if (dto.isActivoModified()) { if (modifiedCount > 0) { sql.append(", "); values.append(", "); } sql.append("ACTIVO"); values.append("?"); modifiedCount++; } if (dto.isFechaCreacionModified()) { if (modifiedCount > 0) { sql.append(", "); values.append(", "); } sql.append("FECHA_CREACION"); values.append("?"); modifiedCount++; } if (dto.isUsuarioCreacionModified()) { if (modifiedCount > 0) { sql.append(", "); values.append(", "); } sql.append("USUARIO_CREACION"); values.append("?"); modifiedCount++; } if (dto.isFechaUltimaModificacionModified()) { if (modifiedCount > 0) { sql.append(", "); values.append(", "); } sql.append("FECHA_ULTIMA_MODIFICACION"); values.append("?"); modifiedCount++; } if (dto.isUsuarioUltimaModificacionModified()) { if (modifiedCount > 0) { sql.append(", "); values.append(", "); } sql.append("USUARIO_ULTIMA_MODIFICACION"); values.append("?"); modifiedCount++; } if (dto.isCategoriaIdCategoriaModified()) { if (modifiedCount > 0) { sql.append(", "); values.append(", "); } sql.append("CATEGORIA_ID_CATEGORIA"); values.append("?"); modifiedCount++; } if (dto.isCatalogoIdCatalogoModified()) { if (modifiedCount > 0) { sql.append(", "); values.append(", "); } sql.append("CATALOGO_ID_CATALOGO"); values.append("?"); modifiedCount++; } if (modifiedCount == 0) { // nothing to insert throw new IllegalStateException("Nothing to insert"); } sql.append(") VALUES ("); sql.append(values); sql.append(")"); 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()); } if (logger.isDebugEnabled()) { logger.debug("Executing " + sql.toString() + " with values: " + dto); } int rows = stmt.executeUpdate(); long t2 = System.currentTimeMillis(); if (logger.isDebugEnabled()) { logger.debug(rows + " rows affected (" + (t2 - t1) + " ms)"); } reset(dto); return dto.createPk(); } 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); } } }