Skip to content

Commit

Permalink
feat: bootstrap TaskRepository #1626
Browse files Browse the repository at this point in the history
  • Loading branch information
bamthomas committed Jan 15, 2025
1 parent fddc692 commit f676863
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 0 deletions.
5 changes: 5 additions & 0 deletions datashare-db/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<groupId>org.icij.datashare</groupId>
<artifactId>datashare-api</artifactId>
</dependency>
<dependency>
<groupId>org.icij.datashare</groupId>
<artifactId>datashare-tasks</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.icij.extract</groupId>
<artifactId>extract-lib</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.icij.datashare.db;

import org.icij.datashare.asynctasks.Task;
import org.icij.datashare.asynctasks.TaskRepository;
import org.jooq.SQLDialect;

import javax.sql.DataSource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class JooqTaskRepository implements TaskRepository {
private final DataSource connectionProvider;
private final SQLDialect dialect;

JooqTaskRepository(final DataSource connectionProvider, final SQLDialect dialect) {
this.connectionProvider = connectionProvider;
this.dialect = dialect;
}

@Override
public int size() {
return 0;
}

@Override
public boolean isEmpty() {
return false;
}

@Override
public boolean containsKey(Object o) {
return false;
}

@Override
public boolean containsValue(Object o) {
return false;
}

@Override
public Task<?> get(Object o) {
return null;
}

@Override
public Task<?> put(String s, Task<?> task) {
return null;
}

@Override
public Task<?> remove(Object o) {
return null;
}

@Override
public void putAll(Map<? extends String, ? extends Task<?>> map) {

}

@Override
public void clear() {

}

@Override
public Set<String> keySet() {
return Set.of();
}

@Override
public Collection<Task<?>> values() {
return List.of();
}

@Override
public Set<Entry<String, Task<?>>> entrySet() {
return Set.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public JooqApiKeyRepository createApiKeyRepository() {
return new JooqApiKeyRepository(dataSource, RepositoryFactoryImpl.guessSqlDialectFrom(dataSourceUrl));
}

public JooqTaskRepository createTaskRepository() {
return new JooqTaskRepository(dataSource, RepositoryFactoryImpl.guessSqlDialectFrom(dataSourceUrl));
}

private static DataSource createDatasource(final String jdbcUrl) {
return new RepositoryFactoryImpl(new PropertiesProvider(new HashMap<>() {{
put("dataSourceUrl", ofNullable(jdbcUrl).orElse("jdbc:sqlite:file:memorydb.db?mode=memory&cache=shared"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.icij.datashare.db;

import org.icij.datashare.asynctasks.Task;
import org.icij.datashare.test.DatashareTimeRule;
import org.icij.datashare.user.User;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Collection;
import java.util.Map;

import static java.util.Arrays.asList;
import static org.fest.assertions.Assertions.assertThat;

@RunWith(Parameterized.class)
public class JooqTaskRepositoryTest {
@Rule
public DatashareTimeRule time = new DatashareTimeRule("2021-06-30T12:13:14Z");
@Rule
public DbSetupRule dbRule;
private final JooqTaskRepository repository;

@Ignore
@Test
public void test_get_put() {
Task<Object> foo = new Task<>("foo", User.local(), Map.of());
repository.put("foo", foo);
assertThat(repository.get("foo")).isNotSameAs(foo); // not same instance
assertThat(repository.get("foo")).isEqualTo(foo); // but equals as defined by Task
}

@Parameterized.Parameters
public static Collection<Object[]> dataSources() {
return asList(new Object[][]{
{new DbSetupRule("jdbc:sqlite:file:memorydb.db?mode=memory&cache=shared")},
{new DbSetupRule("jdbc:postgresql://postgres/dstest?user=dstest&password=test")}
});
}



public JooqTaskRepositoryTest(DbSetupRule rule) {
dbRule = rule;
repository = rule.createTaskRepository();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.icij.datashare.asynctasks;

import java.util.Map;

public interface TaskRepository extends Map<String, Task<?>> {
}

0 comments on commit f676863

Please sign in to comment.