简体   繁体   中英

Share HSQLDB across all Spring Batch Steps

I have a Spring Batch application with an HSQLDB. I notice the db was drop and reinit after each step in my Job but I want it persisten across all the step of the job.

Here my datasource configuration:

<jdbc:initialize-database data-source="dataSource">
    <jdbc:script location="classpath:rubrica.sql" />
    <jdbc:script location="org/springframework/batch/core/schema-drop-hsqldb.sql" />
    <jdbc:script location="org/springframework/batch/core/schema-hsqldb.sql" />
</jdbc:initialize-database>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
    <property name="driverClassName" value="org.hsqldb.jdbc.JDBCDriver" />
    <property name="url" value="jdbc:hsqldb:file:C:\Users\U390902\Documents\workspace-sts-3.8.4.RELEASE\ixpg0-statsloader\src\main\resources\input\TestDataBase;user=sa;password=sa" />
</bean>

Basically I have this logic steps structure

<job>
<step 1> Read a flat file and write it in the HSQL DB </step 1>
<step 2> Read a CSV file and join it with the HSQL DB</step 1>
</job>

But analyzing the logs I see that the db is reinit using the provided sql scripts. This is the log:

INSERT INTO EMPLOYEE VALUES('123456','PIPPO','PLUTO')
COMMIT
/*C4*/SET SCHEMA PUBLIC
DISCONNECT
/*C5*/SET SCHEMA PUBLIC
DROP TABLE EMPLOYEE IF EXISTS
CREATE TABLE EMPLOYEE ( ID VARCHAR(6), FIRSTNAME VARCHAR(100), LASTNAME VARCHAR(100) ) 

My goal is to share the db across all steps.

Thanks to all, if any write me a comment.

The problem in this case is that I reinit the Application Context in the next step so the Db was reinitialized.

Using the interface ApplicationContextAware solve the problem.

If you need more details write me a comment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM