Skip to content

Commit

Permalink
Add sqlite data stores for migration
Browse files Browse the repository at this point in the history
  • Loading branch information
paytoncain committed Apr 30, 2024
1 parent 9587530 commit 38bf1d4
Show file tree
Hide file tree
Showing 24 changed files with 870 additions and 0 deletions.
88 changes: 88 additions & 0 deletions pace-datastore/pace-sqlite-datastore/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.github.ci-cmg</groupId>
<artifactId>pace-datastore</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>

<artifactId>pace-sqlite-datastore</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>io.github.ci-cmg</groupId>
<artifactId>pace-common-datastore</artifactId>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.45.3.0</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.16.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.90</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.90</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package edu.colorado.cires.pace.datastore.sqlite;

import edu.colorado.cires.pace.data.object.DetectionType;
import java.nio.file.Path;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

public class DetectionTypeSQLiteDatastore extends SQLiteDatastore<DetectionType> {

protected DetectionTypeSQLiteDatastore(Path sqliteFile) {
super(sqliteFile, "DETECTION_TYPES");
}

@Override
protected Stream<DetectionType> resultSetToStream(ResultSet resultSet) throws SQLException {
List<DetectionType> detectionTypes = new ArrayList<>(0);

while (resultSet.next()) {
detectionTypes.add(DetectionType.builder()
.source(resultSet.getString("SOURCE"))
.scienceName(resultSet.getString("SCIENCE_NAME"))
.build());
}

return detectionTypes.stream();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package edu.colorado.cires.pace.datastore.sqlite;

import edu.colorado.cires.pace.data.object.FileType;
import java.nio.file.Path;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

public class FileTypeSQLiteDatastore extends SQLiteDatastore<FileType> {

protected FileTypeSQLiteDatastore(Path sqliteFile) {
super(sqliteFile, "FILE_TYPES");
}

@Override
protected Stream<FileType> resultSetToStream(ResultSet resultSet) throws SQLException {
List<FileType> fileTypes = new ArrayList<>(0);

while (resultSet.next()) {
fileTypes.add(FileType.builder()
.type(resultSet.getString("TYPE"))
.build());
}

return fileTypes.stream();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package edu.colorado.cires.pace.datastore.sqlite;

import edu.colorado.cires.pace.data.object.FileType;
import edu.colorado.cires.pace.data.object.Instrument;
import edu.colorado.cires.pace.datastore.Datastore;
import edu.colorado.cires.pace.datastore.DatastoreException;
import java.nio.file.Path;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class InstrumentSQLiteDatastore extends SQLiteDatastore<Instrument> {

private final Datastore<FileType> fileTypeDatastore;

protected InstrumentSQLiteDatastore(Path sqliteFile, Datastore<FileType> fileTypeDatastore) {
super(sqliteFile, "INSTRUMENTS");
this.fileTypeDatastore = fileTypeDatastore;
}

@Override
protected Stream<Instrument> resultSetToStream(ResultSet resultSet) throws SQLException {
List<Instrument> instruments = new ArrayList<>(0);

while (resultSet.next()) {
instruments.add(Instrument.builder()
.name(resultSet.getString("Name"))
.fileTypes(Arrays.stream(resultSet.getString("FILE_TYPES").split(","))
.map(ft -> {
try {
return fileTypeDatastore.findByUniqueField(ft).orElseThrow(
() -> new DatastoreException(String.format(
"file type %s not found", ft
), null)
);
} catch (DatastoreException e) {
throw new RuntimeException(e);
}
})
.toList())
.build());
}

return instruments.stream();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package edu.colorado.cires.pace.datastore.sqlite;

import edu.colorado.cires.pace.data.object.Organization;
import java.nio.file.Path;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Stream;

public class OrganizationsSQLiteDatastore extends SQLiteDatastore<Organization> {

protected OrganizationsSQLiteDatastore(Path sqliteFile) {
super(sqliteFile, "ORGANIZATIONS");
}

@Override
protected Stream<Organization> resultSetToStream(ResultSet resultSet) throws SQLException {
List<Organization> organizations = new ArrayList<>(0);

while (resultSet.next()) {
organizations.add(Organization.builder()
.name(resultSet.getString("NAME"))
.street(resultSet.getString("STREET"))
.city(resultSet.getString("CITY"))
.state(resultSet.getString("STATE"))
.zip(resultSet.getString("ZIP"))
.country(resultSet.getString("COUNTRY"))
.email(resultSet.getString("EMAIL"))
.phone(resultSet.getString("PHONE"))
.uuid(UUID.fromString(resultSet.getString("UUID")))
.build());
}

return organizations.stream();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package edu.colorado.cires.pace.datastore.sqlite;

import edu.colorado.cires.pace.data.object.Person;
import java.nio.file.Path;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Stream;

public class PersonSQLiteDatastore extends SQLiteDatastore<Person> {

protected PersonSQLiteDatastore(Path sqliteFile) {
super(sqliteFile, "PEOPLE");
}

@Override
protected Stream<Person> resultSetToStream(ResultSet resultSet) throws SQLException {
List<Person> people = new ArrayList<>(0);

while (resultSet.next()) {
people.add(Person.builder()
.name(resultSet.getString("NAME"))
.street(resultSet.getString("STREET"))
.city(resultSet.getString("CITY"))
.state(resultSet.getString("STATE"))
.zip(resultSet.getString("ZIP"))
.country(resultSet.getString("COUNTRY"))
.email(resultSet.getString("EMAIL"))
.phone(resultSet.getString("PHONE"))
.uuid(UUID.fromString(resultSet.getString("UUID")))
.orcid(resultSet.getString("ORCID"))
.organization(resultSet.getString("ORGANIZATION"))
.position(resultSet.getString("POSITION"))
.build());
}

return people.stream();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package edu.colorado.cires.pace.datastore.sqlite;

import edu.colorado.cires.pace.data.object.Platform;
import java.nio.file.Path;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

public class PlatformSQLiteDatastore extends SQLiteDatastore<Platform> {

protected PlatformSQLiteDatastore(Path sqliteFile) {
super(sqliteFile, "PLATFORMS");
}

@Override
protected Stream<Platform> resultSetToStream(ResultSet resultSet) throws SQLException {
List<Platform> platforms = new ArrayList<>(0);

while (resultSet.next()) {
platforms.add(Platform.builder()
.name(resultSet.getString("NAME"))
.build());
}

return platforms.stream();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package edu.colorado.cires.pace.datastore.sqlite;

import edu.colorado.cires.pace.data.object.Project;
import java.nio.file.Path;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

public class ProjectSQLiteDatastore extends SQLiteDatastore<Project> {

protected ProjectSQLiteDatastore(Path sqliteFile) {
super(sqliteFile, "PROJECTS");
}

@Override
protected Stream<Project> resultSetToStream(ResultSet resultSet) throws SQLException {
List<Project> projects = new ArrayList<>(0);

while (resultSet.next()) {
projects.add(Project.builder()
.name(resultSet.getString("NAME"))
.build());
}

return projects.stream();
}
}
Loading

0 comments on commit 38bf1d4

Please sign in to comment.