ワークマンのバックパックのカッパ代用品を探してみた
ワークマンのバックパックを買ってみた
登山用にワークマンのバックパックを買ってみた。
日帰りキャンプには十分な容量で、使い勝手も非常に良い。
ただし、レビューで言われている通りメイン収納のファスナーが緩い。
心配性の方は、ダブルファスナーの紐をカラビナでつないでロックしている模様。
5000円以内という値段を考えれば、非常にコスパの良い商品かなと思います。
バックパック用のカッパがほしい…!!
山の天気は変わりやすい。
やはり登山をしているとぱらぱらと雨に降られるものですよね。
まだ土砂降りまであったことはありませんが、安いカッパがあったらほしい!
う~ん、ネットで検索しても1000円以上しそう…
代用品ないかね
ネットでカバン用カッパの代用品を探していると、
どうやらダイソーの自転車カゴ用カッパがいいらしい!!
ダイソーの自転車カバーがジャストじゃん!!
ジャストじゃん!!やったぜ!
terasoluna-batch Spring Batchのメタデータスキーマについて
事象
チュートリアルの通りterasoluna-batchを実行したところ、下記エラーが発生した。
おそらくJobRepositoryの接続先をデフォルト値のH2 DatabaseからPostgresへ変更したことが原因。
[2022/06/28 23:22:59] [main] [o.s.b.c.l.s.CommandLineJobRunner] [ERROR] Job Terminated in error: Could not obtain sequence value; nested exception is org.postgresql.util.PSQLException: ERROR: リレーション"batch_job_seq"は存在しません 位置: 16 org.springframework.dao.DataAccessResourceFailureException: Could not obtain sequence value; nested exception is org.postgresql.util.PSQLException: ERROR: リレーション"batch_job_seq"は存在しません 位置: 16 at org.springframework.jdbc.support.incrementer.AbstractSequenceMaxValueIncrementer.getNextKey(AbstractSequenceMaxValueIncrementer.java:79) at org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer.nextLongValue(AbstractDataFieldMaxValueIncrementer.java:128) at org.springframework.batch.core.jsr.JsrJobParametersConverter.getJobParameters(JsrJobParametersConverter.java:105) at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:321) at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:582) Caused by: org.postgresql.util.PSQLException: ERROR: リレーション"batch_job_seq"は存在しません 位置: 16 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2674) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2364) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:354) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:484) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:404) at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:325) at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:311) at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:287) at org.postgresql.jdbc.PgStatement.executeQuery(PgStatement.java:239) at org.apache.commons.dbcp2.DelegatingStatement.executeQuery(DelegatingStatement.java:329) at org.apache.commons.dbcp2.DelegatingStatement.executeQuery(DelegatingStatement.java:329) at org.springframework.jdbc.support.incrementer.AbstractSequenceMaxValueIncrementer.getNextKey(AbstractSequenceMaxValueIncrementer.java:70) ... 4 common frames omitted
参考にしたサイト
原因
Spring Batchでは、バッチの実行状況などのメタデータをストアするJobRepositoryというものがある。
今回はこのJobRepositoryで使われるシーケンスが存在しなかったため、エラーが発生したらしい。
GithubからJobRepositoryのDDLを取得・実行してエラーが発生
DBごとのDDLは下記から取得可能した。
「launch-context.xml」に下記設定を追加してバッチを実行。
※実際には対応するプロパティファイルに記載。
<jdbc:initialize-database data-source="adminDataSource" enabled="true" ignore-failures="ALL"> <jdbc:script location="classpath:org/springframework/batch/core/schema-postgresql.sql" /> </jdbc:initialize-database>
すると、テーブルのカラムが不足している旨のエラーが発生。
[2022/06/29 23:28:58] [main] [o.s.b.c.l.s.CommandLineJobRunner] [ERROR] Job Terminated in error: PreparedStatementCallback; bad SQL grammar [INSERT into BATCH_JOB_EXECUTION(JOB_EXECUTION_ID, JOB_INSTANCE_ID, START_TIME, END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, VERSION, CREATE_TIME, LAST_UPDATED, JOB_CONFIGURATION_LOCATION) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; nested exception is org.postgresql.util.PSQLException: ERROR: リレーション"batch_job_execution"の列"job_configuration_location"は存在しません 位置: 159 org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT into BATCH_JOB_EXECUTION(JOB_EXECUTION_ID, JOB_INSTANCE_ID, START_TIME, END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, VERSION, CREATE_TIME, LAST_UPDATED, JOB_CONFIGURATION_LOCATION) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; nested exception is org.postgresql.util.PSQLException: ERROR: リレーション"batch_job_execution"の列"job_configuration_location"は存在しません 位置: 159 at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79) at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1541) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:667) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:960) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:1015) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:1020) at org.springframework.batch.core.repository.dao.JdbcJobExecutionDao.saveJobExecution(JdbcJobExecutionDao.java:160) at org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:158) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.batch.core.repository.support.AbstractJobRepositoryFactoryBean$1.invoke(AbstractJobRepositoryFactoryBean.java:181) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) at jdk.proxy2/jdk.proxy2.$Proxy12.createJobExecution(Unknown Source) at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:137) at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:378) at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:582) Caused by: org.postgresql.util.PSQLException: ERROR: リレーション"batch_job_execution"の列"job_configuration_location"は存在しません 位置: 159 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2674) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2364) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:354) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:484) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:404) at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:162) at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:130) at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:136) at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:136) at org.springframework.jdbc.core.JdbcTemplate.lambda$update$2(JdbcTemplate.java:965) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:651) ... 23 common frames omitted
Spring Batchのバージョン差分でテーブルカラムに差分あり
Spring Batchのバージョンによって、テーブルのカラムが増えることがある模様。
DDL取得時は、Spring Batchのバージョンに注意すること。
最新のDDLでテーブル生成後、バッチを正常に実行することが出来た。
まとめ
- Spring Batchの実行には、バッチのメタデータを蓄積するテーブルが必要になる。
- Spring Batchには、バッチ起動時にクエリを実行する仕組みがある。
- Spring Batchのバージョン差分によって、テーブルカラムに差分がある
terasoluna-batchを動かしてみた
前置き
Javaバッチを作りたいが、どのアーキテクトを採用すればいいんだ・・・とりあえずSpringかな?
ということで、チュートリアルが整備されたterasoluna-batchを動かしてみることにする。
TERASOLUNAとは、NTTデータがオープンソースとして提供しているフレームワークであり、 Spring Frameworkをベースに作られている。
参考にしたサイト
前提条件
作業内容
チュートリアルに従い、プロジェクトの作成から動作確認までを行う。 本記事では、データベース類の設定は行わない。
プロジェクトの作成
プロジェクト作成のディレクトリへ移動した後、mvnコマンドを実行する。
プロジェクトの設定を行う。
「BUILD SUCCESS」が表示されていれば完了。
プロジェクトのインポート
下記からEclipse 2022をダウンロード。
mavenでダウンロードしたプロジェクトをインポート。
既存のmavenプロジェクトを選択。
pom.xmlを選択して、完了ボタンを押下。
インポート完了。
プロジェクトの動作確認
実行構成を開く。
Javaアプリケーションの新規構成を開く。
プロジェクトとメイン・クラスを選択する。 プロジェクトはデフォルトで設定されている「terasoluna-batch-tutorial」でOK。
メイン・クラスは「CommandLineJobRunner」を選択。 コマンドからジョブ起動時に使うクラスの模様。
実行するジョブの情報を記載したxmlとジョブ名を引数に指定する。 今回はチュートリアルの通り、job01を指定。
コンソール上にCOMPLETEDが表示されればOK。
PostgreSQLのインストール
前置き
terasoluna-batchのDBとして使うため、PostgreSQLをインストールする。 バージョンはPostgreSQL 14.3。
作業内容
本記事では、インストーラ取得から起動までを行う。
インストーラ取得
下記URLより、インストーラを取得する。
https://www.postgresql.org/download/
インストール
インストールを行う。
インストール先の指定。
DBイメージの保存先を指定。
pgAdmin操作時などに求められるパスワードの設定。 必須項目のようです。
インストール設定の最終確認です。
Nextを押下するとインストールが開始します。
私の環境では10分ほどでインストール完了です。 おんぼろなのであまり参考にはなりませんが。
インストール完了です。
起動
WindowsのメニューからpgAdminを起動しましょう。 PostgreSQLをGUIで操作できるツールです。
初回は少し時間がかかる模様。
起動時にパスワードを求められます。 インストール時に決めたパスワードを入力しましょう。
サーバ接続時もパスワードを求められます。
起動してサーバ接続までできました。