Skip to content

Commit 309c355

Browse files
authored
feat: add missing indexes to the oracle ddl script (#503)
## Add missing indexes to the oracle ddl script Every example for other databases (Postgres, Mssql, Mysql) contains indexes on `execution_time` and `last_heartbeat` while for Oracle DB they are missing. I also expanded `DbUtiils` method to allow splitting sql statements from an sql file. `jdbcRunner.execute(statement, NOOP)` can run only one statement at a time for Oracle Db. PS: two tests for oracle db are failing on master, is that expected? ## Reminders - [x] Added/ran automated tests - [x] Update README and/or examples - no need - [x] Ran `mvn spotless:apply` --- cc @kagkarlsson
1 parent 16f6908 commit 309c355

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/DbUtils.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,25 @@ public static void clearTables(DataSource dataSource) {
2323
}
2424

2525
public static Consumer<DataSource> runSqlResource(String resource) {
26+
return runSqlResource(resource, false);
27+
}
28+
29+
public static Consumer<DataSource> runSqlResource(String resource, boolean splitStatements) {
2630
return dataSource -> {
2731
final JdbcRunner jdbcRunner = new JdbcRunner(dataSource);
2832
try {
2933
final String statements =
3034
CharStreams.toString(
3135
new InputStreamReader(DbUtils.class.getResourceAsStream(resource)));
32-
jdbcRunner.execute(statements, NOOP);
36+
if (splitStatements) {
37+
for (String statement : statements.split(";")) {
38+
if (!statement.trim().isEmpty()) {
39+
jdbcRunner.execute(statement, NOOP);
40+
}
41+
}
42+
} else {
43+
jdbcRunner.execute(statements, NOOP);
44+
}
3345
} catch (IOException e) {
3446
throw new RuntimeException(e);
3547
}

db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/compatibility/Oracle11gCompatibilityTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static void initSchema() {
4444
pooledDatasource = new HikariDataSource(hikariConfig);
4545

4646
// init schema
47-
DbUtils.runSqlResource("/oracle_tables.sql").accept(pooledDatasource);
47+
DbUtils.runSqlResource("/oracle_tables.sql", true).accept(pooledDatasource);
4848
}
4949

5050
@BeforeEach

db-scheduler/src/test/resources/oracle_tables.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ create table scheduled_tasks
1212
last_heartbeat TIMESTAMP(6) WITH TIME ZONE,
1313
version NUMBER(19, 0),
1414
PRIMARY KEY (task_name, task_instance)
15-
)
15+
);
1616

17+
CREATE INDEX scheduled_tasks__execution_time__idx on scheduled_tasks(execution_time);
18+
CREATE INDEX scheduled_tasks__last_heartbeat__idx on scheduled_tasks(last_heartbeat);

0 commit comments

Comments
 (0)