Olá,
Tenho uma duvida como pegar erro quando vai fazer o READER do chunck pois queria pegar o erro se houver uma mudança de campo ou nome da tabela.
Já fiz o seguinte pois alterei o nome da tabela para dar o erro e tentar pegar o erro e gravar no banco de dados e continuar a rodar outro job que está na sequencia :
<step id="step1">
<tasklet>
<chunk reader="multiResourceReader" writer="flatFileItemWriter" commit-interval="1" skip-policy="sampleSkipPolicy" skip-limit="1">
<skippable-exception-classes>
<include class="org.springframework.batch.item.file.FlatFileParseException" />
<include class="java.lang.IllegalArgumentException" />
<include class="org.springframework.jdbc.BadSqlGrammarException"/>
<include class="org.springframework.batch.item.ItemStreamException"/>
<include class="java.sql.SQLSyntaxErrorException"/>
<include class="org.springframework.jdbc.UncategorizedSQLException"/>
<include class="org.xml.sax.SAXParseException"/>
<include class="java.sql.SQLException"/>
</skippable-exception-classes>
</chunk>
<listeners>
<listener ref="sampleSkipListener" />
<listener ref="sampleStepExecutionListener" />
</listeners>
public class SampleSkipException extends RuntimeException{
}
@Component
@Named("sampleSkipListener")
public class SampleSkipListener extends BaseElement implements SkipListener {
public void onSkipInProcess(Object item, Throwable t) {
System.out.println("na Rotina DomainSkipListener --> onSkipInProcess");
if(t instanceof SampleSkipException){
SampleSkipException domainSkipException=(SampleSkipException)t;
System.out.println("item.toString() = "+item.toString() +" "+"t.getClass().toString() =" + t.getClass().toString() + " "+"domainSkipException ="+domainSkipException);
}
}
public void onSkipInRead(Throwable t) {
System.out.println("na Rotina DomainSkipListener --> onSkipInRead");
if(t instanceof SampleSkipException){
SampleSkipException domainSkipException=(SampleSkipException)t;
System.out.println("READ =" + " "+"t.getClass().toString() =" + t.getClass().toString() + " "+"domainSkipException ="+domainSkipException);
}
}
public void onSkipInWrite(Object item, Throwable t) {
System.out.println("na Rotina DomainSkipListener --> onSkipInWrite");
if(t instanceof SampleSkipException){
SampleSkipException domainSkipException=(SampleSkipException)t;
System.out.println("WRITE =" + " "+"t.getClass().toString() =" + t.getClass().toString() + " "+"domainSkipException ="+domainSkipException);
}
}
private SkipItems createSkipElement(String type, String item, String msg, SampleSkipException domainSkipException){
System.out.println("na Rotina DomainSkipListener --> SkipItems");
SkipItems skipElement=new SkipItems();
skipElement.setType(type);
skipElement.setItem(item);
skipElement.setMsg(msg);
skipElement.setJobExecutionId(getJobExecutionId());
skipElement.setStepExecutionId(getStepExecutionId());
return skipElement;
}
}
@Component
@Named("sampleSkipPolicy")
public class SampleSkipPolicy implements SkipPolicy{
public boolean shouldSkip(Throwable t, int skipCount) throws SkipLimitExceededException {
// TODO Auto-generated method stub
return SampleSkipException.class.isAssignableFrom(t.getClass());
}
}
@Component
@Named("sampleStepExecutionListener")
public class SampleStepExecutionListener implements StepExecutionListener {
public void beforeStep(StepExecution stepExecution){
Long jobExecutionId =stepExecution.getJobExecutionId();
String jobName=stepExecution.getJobExecution().getJobInstance().getJobName();
stepExecution.getExecutionContext().put("jobExecutionId", jobExecutionId);
stepExecution.getExecutionContext().put("stepExecutionId", stepExecution.getId());
stepExecution.getExecutionContext().put("jobName", jobName);
}
public ExitStatus afterStep(StepExecution stepExecution){
return null;
}
}
Ainda me da o erro :
INFO [28/07/2014 14:55:20] [Main Thread] - Executing step: [step1]
ERROR [28/07/2014 14:55:20] [Main Thread] - Encountered an error executing the step
org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:137)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:93)
at org.springframework.batch.core.step.item.ChunkMonitor.open(ChunkMonitor.java:105)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:93)
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:301)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:192)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:282)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:121)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:349)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574)
Caused by: org.springframework.jdbc.BadSqlGrammarException: Executing query; bad SQL grammar [select ar.num_artigo_st ,ar.des_artigo from artigo_st1 ar]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00942: a tabela ou view não existe
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:233)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.batch.item.database.JdbcCursorItemReader.openCursor(JdbcCursorItemReader.java:130)
at org.springframework.batch.item.database.AbstractCursorItemReader.doOpen(AbstractCursorItemReader.java:401)
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:134)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:93)
at org.springframework.batch.core.step.item.ChunkMonitor.open(ChunkMonitor.java:105)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:93)
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:301)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:192)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48)
... 3 more
Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: a tabela ou view não existe
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:863)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1153)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1275)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3576)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3620)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491)
at org.springframework.batch.item.database.JdbcCursorItemReader.openCursor(JdbcCursorItemReader.java:125)
... 19 more
ERROR [28/07/2014 14:55:21] [Main Thread] - Encountered an error saving batch meta data. This job is now in an unknown state and should not be restarted.
org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [UPDATE BATCH_STEP_EXECUTION set START_TIME = ?, END_TIME = ?, STATUS = ?, COMMIT_COUNT = ?, READ_COUNT = ?, FILTER_COUNT = ?, WRITE_COUNT = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = ?, READ_SKIP_COUNT = ?, PROCESS_SKIP_COUNT = ?, WRITE_SKIP_COUNT = ?, ROLLBACK_COUNT = ?, LAST_UPDATED = ? where STEP_EXECUTION_ID = ? and VERSION = ?]; SQL state [72000]; error code [12899]; ORA-12899: valor muito grande para a coluna "ORASPRING"."BATCH_STEP_EXECUTION"."EXIT_MESSAGE" (real: 2501, máximo: 2500)
; nested exception is java.sql.SQLException: ORA-12899: valor muito grande para a coluna "ORASPRING"."BATCH_STEP_EXECUTION"."EXIT_MESSAGE" (real: 2501, máximo: 2500)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:602)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:811)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:867)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:871)
at org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.updateStepExecution(JdbcStepExecutionDao.java:172)
at org.springframework.batch.core.repository.support.SimpleJobRepository.update(SimpleJobRepository.java:171)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy55.update(Unknown Source)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:244)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:349)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574)
Caused by: java.sql.SQLException: ORA-12899: valor muito grande para a coluna "ORASPRING"."BATCH_STEP_EXECUTION"."EXIT_MESSAGE" (real: 2501, máximo: 2500)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1010)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1315)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3576)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3657)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:817)
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:1)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:586)
... 29 more