public void update(ExecutionContext executionContext) throws ItemStreamException { executionContext.putLong("POSITION", index); }
/** * Get the restart data. * * @param executionContext the batch context. * * @see org.springframework.batch.item.ItemStream#update(ExecutionContext) */ @Override public void update(ExecutionContext executionContext) { super.update(executionContext); if (saveState) { Assert.notNull(executionContext, "ExecutionContext must not be null"); executionContext.putLong(getExecutionContextKey(RESTART_DATA_NAME), getPosition()); executionContext.putLong(getExecutionContextKey(WRITE_STATISTICS_NAME), currentRecordCount); if (!unclosedHeaderCallbackElements.isEmpty()) { executionContext.put(getExecutionContextKey(UNCLOSED_HEADER_CALLBACK_ELEMENTS_NAME), unclosedHeaderCallbackElements); } } }
/** * @see ItemStream#update(ExecutionContext) */ @Override public void update(ExecutionContext executionContext) { super.update(executionContext); if (state == null) { throw new ItemStreamException("ItemStream not open or already closed."); } Assert.notNull(executionContext, "ExecutionContext must not be null"); if (saveState) { try { executionContext.putLong(getExecutionContextKey(RESTART_DATA_NAME), state.position()); } catch (IOException e) { throw new ItemStreamException("ItemStream does not return current position properly", e); } executionContext.putLong(getExecutionContextKey(WRITTEN_STATISTICS_NAME), state.linesWritten); } }
@Override public void update(ExecutionContext executionContext) throws ItemStreamException { super.update(executionContext); executionContext.putLong(getExecutionContextKey("POSITION"), index); }
context.putLong(key, splitSize);
@Test public void testInvalidCast() { context.putLong("1", 1); try { context.getDouble("1"); fail(); } catch (ClassCastException ex) { // expected } }
@Transactional @Test public void testUpdateStepContext() { ExecutionContext ctx = new ExecutionContext(Collections.<String, Object> singletonMap("key", "value")); stepExecution.setExecutionContext(ctx); contextDao.saveExecutionContext(stepExecution); ctx.putLong("longKey", 7); contextDao.updateExecutionContext(stepExecution); ExecutionContext retrieved = contextDao.getExecutionContext(stepExecution); assertEquals(ctx, retrieved); assertEquals(7, retrieved.getLong("longKey")); }
@Transactional @Test public void testUpdateContext() { ExecutionContext ctx = new ExecutionContext(Collections .<String, Object> singletonMap("key", "value")); jobExecution.setExecutionContext(ctx); contextDao.saveExecutionContext(jobExecution); ctx.putLong("longKey", 7); contextDao.updateExecutionContext(jobExecution); ExecutionContext retrieved = contextDao.getExecutionContext(jobExecution); assertEquals(ctx, retrieved); assertEquals(7, retrieved.getLong("longKey")); }
@Test public void testGetNamedLongJobParameters() throws Exception { stepExecution.getExecutionContext().putLong("foo",11L); extractor.setKeys(new String[] {"foo(long)", "bar"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=11}", jobParameters.toString()); }
@Test public void testSerialization() { TestSerializable s = new TestSerializable(); s.value = 7; context.putString("1", "testString1"); context.putString("2", "testString2"); context.putLong("3", 3); context.putDouble("4", 4.4); context.put("5", s); context.putInt("6", 6); byte[] serialized = SerializationUtils.serialize(context); ExecutionContext deserialized = (ExecutionContext) SerializationUtils.deserialize(serialized); assertEquals(context, deserialized); assertEquals(7, ((TestSerializable) deserialized.get("5")).value); }
@Test public void testNormalUsage() { context.putString("1", "testString1"); context.putString("2", "testString2"); context.putLong("3", 3); context.putDouble("4", 4.4); context.putInt("5", 5); assertEquals("testString1", context.getString("1")); assertEquals("testString2", context.getString("2")); assertEquals("defaultString", context.getString("55", "defaultString")); assertEquals(4.4, context.getDouble("4"), 0); assertEquals(5.5, context.getDouble("55", 5.5), 0); assertEquals(3, context.getLong("3")); assertEquals(5, context.getLong("55", 5)); assertEquals(5, context.getInt("5")); assertEquals(6, context.getInt("55", 6)); }
@Override public void beforeStep(StepExecution stepExecution) { //使用环境容器自定义变量 stepExecution.getExecutionContext().putLong("id", 100L); }
/** * STEP参数保存 * * @param exitStatus */ public void saveStepParameter(String key, long Value) { this.getExecutionContext().putLong(key, Value); }
protected void processBeforeStep(Map<String, String> stateMap, StepExecution execution) { Map<String, Object> executionContext = context.getContext(execution.getJobExecution()); if (executionContext.containsKey(IMPORT_INITIALIZATION_STATUS)) { return; } String lastTimestamp = stateMap.get(HBASE_LAST_TIMESTAMP); executionContext.put(HBASE_CURRENT_TIMESTAMP, System.currentTimeMillis()); executionContext.put(IMPORT_INITIALIZATION_STATUS, true); if (!StringUtils.isBlank(lastTimestamp)) { execution.getJobExecution().getExecutionContext().putLong(HBASE_LAST_TIMESTAMP, Long.parseLong(lastTimestamp)); } }
/** * STEP参数保存 * * @param exitStatus */ public void saveStepParameter(String key, long Value) { this.stepExecution.getJobExecution().getExecutionContext().putLong(key, Value); }
/** * STEP参数保存 * * @param exitStatus */ public void saveStepParameter(String key, long Value) { this.stepExecution.getJobExecution().getExecutionContext().putLong(key, Value); }
/** * STEP参数保存 * * @param exitStatus */ public void saveStepParameter(String key, long Value) { this.stepExecution.getJobExecution().getExecutionContext().putLong(key, Value); }
/** * Get the restart data. * * @param executionContext the batch context. * * @see org.springframework.batch.item.ItemStream#update(ExecutionContext) */ @Override public void update(ExecutionContext executionContext) { super.update(executionContext); if (saveState) { Assert.notNull(executionContext, "ExecutionContext must not be null"); executionContext.putLong(getExecutionContextKey(RESTART_DATA_NAME), getPosition()); executionContext.putLong(getExecutionContextKey(WRITE_STATISTICS_NAME), currentRecordCount); if (!unclosedHeaderCallbackElements.isEmpty()) { executionContext.put(getExecutionContextKey(UNCLOSED_HEADER_CALLBACK_ELEMENTS_NAME), unclosedHeaderCallbackElements); } } }
/** * @see ItemStream#update(ExecutionContext) */ @Override public void update(ExecutionContext executionContext) { super.update(executionContext); if (state == null) { throw new ItemStreamException("ItemStream not open or already closed."); } Assert.notNull(executionContext, "ExecutionContext must not be null"); if (saveState) { try { executionContext.putLong(getExecutionContextKey(RESTART_DATA_NAME), state.position()); } catch (IOException e) { throw new ItemStreamException("ItemStream does not return current position properly", e); } executionContext.putLong(getExecutionContextKey(WRITTEN_STATISTICS_NAME), state.linesWritten); } }
context.putLong(key, splitSize);