Skip to content

Commit

Permalink
Issue #72 add test withSqlFile to wildfly-jberet-samples/purgeJdbcRep…
Browse files Browse the repository at this point in the history
…ository2.
  • Loading branch information
chengfang committed May 6, 2016
1 parent f02aa54 commit f699eae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public JdbcRepository(final DataSource dataSource, final Properties configProper
this.dataSource = dataSource;
dbUrl = null;
String sqlFile = DEFAULT_SQL_FILE;
final InputStream sqlResource = getClassLoader().getResourceAsStream(sqlFile);
final InputStream sqlResource = getClassLoader(false).getResourceAsStream(sqlFile);
try {
if (sqlResource == null) {
throw BatchMessages.MESSAGES.failToLoadSqlProperties(null, sqlFile);
Expand Down Expand Up @@ -213,7 +213,7 @@ private void createTables(final Properties configProperties) {
if (sqlFile == null || sqlFile.isEmpty()) {
sqlFile = DEFAULT_SQL_FILE;
}
final InputStream sqlResource = getClassLoader().getResourceAsStream(sqlFile);
final InputStream sqlResource = getClassLoader(false).getResourceAsStream(sqlFile);
try {
if (sqlResource == null) {
throw BatchMessages.MESSAGES.failToLoadSqlProperties(null, sqlFile);
Expand Down Expand Up @@ -258,7 +258,7 @@ private void createTables(final Properties configProperties) {
rs = countPartitionExecutionStatement.executeQuery();
} catch (final SQLException e) {
final String ddlFile = getDDLLocation(databaseProductName);
ddlResource = getClassLoader().getResourceAsStream(ddlFile);
ddlResource = getClassLoader(false).getResourceAsStream(ddlFile);
if (ddlResource == null) {
throw BatchMessages.MESSAGES.failToLoadDDL(ddlFile);
}
Expand Down Expand Up @@ -921,7 +921,7 @@ public void executeStatements(final String statements, final String statementsRe
if (statements == null) {
InputStream statementsResource = null;
try {
statementsResource = getClassLoader().getResourceAsStream(statementsResourcePath);
statementsResource = getClassLoader(true).getResourceAsStream(statementsResourcePath);
if (statementsResource != null) {
statementList = new ArrayList<String>();
} else {
Expand Down Expand Up @@ -1054,16 +1054,18 @@ private String getDDLLocation(final String databaseProductName) {
return ddlFile;
}

private static ClassLoader getClassLoader() {
private static ClassLoader getClassLoader(final boolean isContextClassLoader) {
if (WildFlySecurityManager.isChecking()) {
return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
@Override
public ClassLoader run() {
return JdbcRepository.class.getClassLoader();
return isContextClassLoader ? Thread.currentThread().getContextClassLoader() :
JdbcRepository.class.getClassLoader();
}
});
}
return JdbcRepository.class.getClassLoader();
return isContextClassLoader ? Thread.currentThread().getContextClassLoader() :
JdbcRepository.class.getClassLoader();
}

private static Timestamp createTimestamp(final Date date) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ delete from STEP_EXECUTION where JOBEXECUTIONID in
where JOB_EXECUTION.JOBINSTANCEID = JOB_INSTANCE.JOBINSTANCEID and JOB_INSTANCE.JOBNAME = 'prepurge2');


delete from JOB_EXECUTION where JOBEXECUTIONID in
(select JOBEXECUTIONID from JOB_EXECUTION, JOB_INSTANCE
where JOB_EXECUTION.JOBINSTANCEID = JOB_INSTANCE.JOBINSTANCEID and JOB_INSTANCE.JOBNAME = 'prepurge2')
delete from JOB_EXECUTION where JOBINSTANCEID in
(select DISTINCT JOBINSTANCEID from JOB_INSTANCE where JOBNAME = 'prepurge2')
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ public void withSql() throws Exception {
// assertEquals(null, prepurgeJobExecution);
}

@Test
public void withSqlFile() throws Exception {
final long prepurgeExecutionId = prepurge();
JobExecutionEntity prepurgeJobExecution = batchClient.getJobExecution(prepurgeExecutionId);
assertEquals(BatchStatus.COMPLETED, prepurgeJobExecution.getBatchStatus());

final String sqlFile = "purgeJdbcRepository2.sql";
final Properties jobParams = new Properties();
jobParams.setProperty("sqlFile", sqlFile);
startJobCheckStatus(jobName, jobParams, 3000, BatchStatus.COMPLETED);
}

private long prepurge() throws Exception {
final JobExecutionEntity jobExecutionEntity = batchClient.startJob(prepurge2JobName, null);
Thread.sleep(1000);
Expand Down

0 comments on commit f699eae

Please sign in to comment.