首页 \ 问答 \ 在Spring Batch chunk-tasklet中生成多个项目(Produce several items in Spring Batch chunk-tasklet)

在Spring Batch chunk-tasklet中生成多个项目(Produce several items in Spring Batch chunk-tasklet)

我是SpringBatch的新手。 我正在使用读取器/写入器/处理器配置<chunk> tasklet。 我想为每个读取项生成写入器执行的零个或多个命令项。

AFAIK的ProcessorItem接口只允许我为每个读取项生成一个项或null。 当然我可以制作List但我想要一个更清洁的方法。

也许我没有使用正确的工具,而且对于不是一对一的读者/制片人与作家/消费者而言还有另外一件事......但我不知道。

有人能引导我朝着正确的方向前进吗?

谢谢!


I'm new to SpringBatch. I'm configuring a <chunk> tasklet with reader/writer/processors. I want to produce -for each read item- zero or more command-items that the writer executes.

AFAIK the ProcessorItem interface only let me produce one item for each read item or null. Of course I can produce List but I would like a cleaner approach.

Maybe I'm not using the right tool and there's another thing for not one-to-one-related readers/producers vs. writer/consumers... but I don't know.

Can someone lead me in the right direction?

Thanks!


原文:https://stackoverflow.com/questions/9412505
更新时间:2023-06-09 11:06

最满意答案

在创建表时,您不会创建任何自动递增主键(id)的内容。 您应该使用serialbigserial为您创建幕后序列。

同样,当您创建数据库时,它不会自动将您连接到它,因此在创建之后您需要使用\c连接到新数据库。 可能发生的是您在模板或默认数据库中创建表,因此重复键,关系存在错误..

CREATE DATABASE movie_info;
\c movie_info

CREATE TABLE movie_attributes
(
id serial PRIMARY KEY,
Title varchar(255),
Duration integer,
IMDB_Rating integer,
Release_Date integer
);

CREATE TABLE cinema_info
(
id serial PRIMARY KEY,
Title varchar(255),
Theatre_Number integer UNIQUE,
Showtime varchar(255)
);

应该解决当前的问题。

对于多个主键,您在DDL中将id指定为主键,然后尝试重新添加。 因此多个键(即使它们是相同的键..)

另一种选择是在insert语句中指定id。


when creating your tables, you are not creating anything that auto increments your primary keys (id). You should use either serial or bigserial which create sequences behind the scenes for you..

also when you create the database, it doesn't automatically connect you to it, so after creating you need to connect to the new DB using \c. What is probably happening is that you are creating the tables in your template or default database, hence the duplicate keys, relation exists errors..

CREATE DATABASE movie_info;
\c movie_info

CREATE TABLE movie_attributes
(
id serial PRIMARY KEY,
Title varchar(255),
Duration integer,
IMDB_Rating integer,
Release_Date integer
);

CREATE TABLE cinema_info
(
id serial PRIMARY KEY,
Title varchar(255),
Theatre_Number integer UNIQUE,
Showtime varchar(255)
);

should fix the current issue.

as for the multiple primary keys, you specify id as primary key in the DDL, then are trying to re-add. Hence the multiple keys (even though they are the same key..)

another option would be to specify the ids, on your insert statements.

相关问答

更多
  • Postgres在很多方面比mysql 好 。 您可以阅读这些关于从MySQL迁移rails应用程序到postgres的文章。 尽管mysql比postgres 更受欢迎 ,但是由于这些原因, instagram正在使用 postgres。 我觉得postgres比mysql更成熟,更健壮。 而mysql更简单易用。 在Rails中将MySQL迁移到PostgreSQL«mindlev 将Rails应用程序数据从MySQL转换到PostgreSQL 对于数据迁移,一个方便的小脚本: Rake任务,用于传输R ...
  • 在创建表时,您不会创建任何自动递增主键(id)的内容。 您应该使用serial或bigserial为您创建幕后序列。 同样,当您创建数据库时,它不会自动将您连接到它,因此在创建之后您需要使用\c连接到新数据库。 可能发生的是您在模板或默认数据库中创建表,因此重复键,关系存在错误.. CREATE DATABASE movie_info; \c movie_info CREATE TABLE movie_attributes ( id serial PRIMARY KEY, Title varchar(25 ...
  • 通常对于这种情况,我有一个单独的临时表没有PK约束,我使用COPY填充(假设数据的格式是有意义的COPY )。 然后我会做类似的事情: insert into table select a.* from staging a where not exists (select 1 from table where a.id = b.id) 这种方法与原始设计相差无几。 但是,我并不完全理解你问题的这一部分,这与你的问题似乎没有任何关系: ...
  • 一般来说,事前测试不是一个好主意,因为它要求您显式锁定表以防止其他客户端在测试和插入之间更改或插入数据。 显式锁定对并发性有害。 通过失败的插入自动递增的序列通常不是问题。 只是不要假设插入数据库的值是连续的。 数据库和obj-c是两个完全不同的东西。 让数据库检查问题,更容易向模式添加适当的约束,然后检查客户端程序中的所有内容。 默认是回滚到事务的开始。 但您可以使用保存点控制它并回滚到保存点。 但是,CTE是查询的一部分,并且当部分查询失败时,查询总是完全回滚。 但是,您可以通过将CTE拆分为创建临时表 ...
  • 使用这个PostgreSQL扩展: SELECT DISTINCT ON (location.id) thing.* FROM location JOIN thing ON thing.location_id = location_id WHERE type = 1 ORDER BY location.id ASC, price ASC 这将只为每个location.id选择第一行。 由于您的行按照location.id然后按price排序,因此这将是价格最低的 ...
  • 这种行为的原因是你启动pgsql的方式,因为你发出命令从命令行启动postgres它在后台运行并报告标准输出。 更改命令: pg_ctl -D /usr/local/var/postgres start 至: pg_ctl -D /usr/local/var/postgres start > /dev/null 而且您将不再看到这些错误消息。 或者如果你想看到它们但不希望它们污染你的python输出。 pg_ctl -D /usr/local/var/postgres -l /some/log/path ...
  • 由于数据库结构未知,因此很难确切地知道发生了什么。 但在sqlfiddle中尝试此查询显示以下内容: create table books ( id serial, title varchar ); PREPARE booksplan AS INSERT INTO books (title) SELECT $1 WHERE NOT EXISTS (SELECT * FROM books WHERE title = $1); >> ERROR: inconsistent types de ...
  • 首先 - “Imager”是一个非常Alpha阶段的实验,我还没有在本地安装或非Linux主机环境中测试它。 在您的Stackoverflow帖子中,您获得的“需要身份验证”弹出窗口与连接到数据库无关 - 它与您本地Web服务器上的权限有关(请尝试检查Apache日志)。 我发现设置新PGsql数据库的最简单方法是使用PhpPgadmin的GUI。 您也可以尝试手动填写数据库连接详细信息( https://github.com/Openpoint/Imager/blob/master/user_mod/se ...
  • 这是由不同的排序整理引起的。 尝试使用collate select * , dense_rank() over ( order by col collate sql_latin1_general_cp437_bin ) as drnk from ( select '#2 Mayfair Terrace' as col union all select '#2 MYSTIC COURT' as col ) Z; 回报 +--------------------+------+ | ...
  • 是否更好地利用数据库服务器功能,或者它没有用于此目的 它正是出于这个目的。 只是处理错误,否则你做了太多的工作。 如果检查相关行的存在性,则只需复制工作,因为PostgreSQL也会这样做。 如果您不想关心插入行的顺序,可以将约束声明为deferrable initially deferred 。 在这种情况下,所有相关的行必须在提交事务时存在,而不是在运行每个语句时。 这是一个简短的例子: http : //sqlfiddle.com/#!12 / 33de1 / 1 在这种情况下,您需要在提交时处理错误 ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)