Skip to content

Commit 050940f

Browse files
authored
JDBC bindings (#5)
1 parent 7298095 commit 050940f

13 files changed

Lines changed: 754 additions & 30 deletions

File tree

.github/workflows/build.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
sudo pip3 install --system pre-commit $PIP_DEPS black flake8 pylint
1919
- name: pre-commit
2020
run: pre-commit run --all-files
21+
- name: mvn spotless:check
22+
run: mvn spotless:check -B -f bindings/jdbc/genomicsqlite-jdbc/pom.xml
2123

2224
test:
2325
runs-on: ubuntu-20.04
@@ -97,7 +99,7 @@ jobs:
9799
name: libgenomicsqlite.dylib
98100
path: libgenomicsqlite.dylib
99101

100-
combined-zip:
102+
artifacts:
101103
runs-on: ubuntu-20.04
102104
needs: [linux-so, macOS-dylib]
103105
steps:
@@ -123,3 +125,11 @@ jobs:
123125
genomicsqlite.h
124126
libgenomicsqlite.so
125127
libgenomicsqlite.dylib
128+
- name: build jar
129+
run: |
130+
cp libgenomicsqlite.so libgenomicsqlite.dylib bindings/jdbc/genomicsqlite-jdbc/src/main/resources/
131+
mvn deploy -Drevision=${{ env.GIT_REVISION }} -B -f bindings/jdbc/genomicsqlite-jdbc/pom.xml
132+
- uses: actions/upload-artifact@v2
133+
with:
134+
name: genomicsqlite-jdbc-${{ env.GIT_REVISION }}
135+
path: bindings/jdbc/genomicsqlite-jdbc/target/mvn-repo

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
5454
add_subdirectory(test)
5555
include(CTest)
5656
enable_testing()
57-
set(GENOMICSQLITE_TEST_ENV env PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/bindings/python:${PYTHONPATH} LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}:${LD_LIBRARY_PATH} GENOMICSQLITE_SYSTEM_LIBRARY=1)
57+
set(GENOMICSQLITE_TEST_ENV env PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/bindings/python:${PYTHONPATH} LIBGENOMICSQLITE=${CMAKE_BINARY_DIR}/libgenomicsqlite)
5858
add_test(NAME smoke_test COMMAND ${GENOMICSQLITE_TEST_ENV} python3 ${CMAKE_CURRENT_SOURCE_DIR}/test/genomicsqlite_smoke_test.py)
5959
add_test(NAME capi_smoke_test COMMAND ${GENOMICSQLITE_TEST_ENV} ${CMAKE_BINARY_DIR}/test/capi_smoke_test)
60+
add_test(NAME JdbcTests COMMAND ${GENOMICSQLITE_TEST_ENV} mvn test -B -f ${CMAKE_CURRENT_SOURCE_DIR}/bindings/jdbc/genomicsqlite-jdbc/pom.xml)
6061
add_test(NAME pytest COMMAND ${GENOMICSQLITE_TEST_ENV} python3 -m pytest -xv -n 4 --tb=short ${CMAKE_CURRENT_SOURCE_DIR}/test)
6162
endif()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
target/
2+
pom.xml.tag
3+
pom.xml.releaseBackup
4+
pom.xml.versionsBackup
5+
pom.xml.next
6+
release.properties
7+
dependency-reduced-pom.xml
8+
buildNumber.properties
9+
.mvn/timing.properties
10+
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
11+
.mvn/wrapper/maven-wrapper.jar
12+
src/resources/libgenomicsqlite*
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>net.mlin</groupId>
8+
<artifactId>genomicsqlite-jdbc</artifactId>
9+
<version>${revision}</version>
10+
<packaging>jar</packaging>
11+
12+
<name>genomicsqlite-jdbc</name>
13+
<url>https://github.com/mlin/GenomicSQLite</url>
14+
15+
<licenses>
16+
<license>
17+
<name>The Apache Software License, Version 2.0</name>
18+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
19+
</license>
20+
</licenses>
21+
22+
<developers>
23+
<developer>
24+
<name>Mike Lin</name>
25+
<email>dna@mlin.net</email>
26+
<organization>mlin.net LLC</organization>
27+
<organizationUrl>https://www.mlin.net</organizationUrl>
28+
</developer>
29+
</developers>
30+
31+
<scm>
32+
<connection>scm:git:git://github.com/mlin/GenomicSQLite.git</connection>
33+
<developerConnection>scm:git:ssh://github.com:mlin/GenomicSQLite.git</developerConnection>
34+
<url>https://github.com/mlin/GenomicSQLite/tree/main</url>
35+
</scm>
36+
37+
<distributionManagement>
38+
<repository>
39+
<id>internal.repo</id>
40+
<name>Temporary Staging Repository</name>
41+
<url>file://${project.build.directory}/mvn-repo</url>
42+
</repository>
43+
</distributionManagement>
44+
45+
<properties>
46+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
47+
<maven.compiler.source>1.7</maven.compiler.source>
48+
<maven.compiler.target>1.7</maven.compiler.target>
49+
</properties>
50+
51+
<dependencies>
52+
<dependency>
53+
<groupId>org.xerial</groupId>
54+
<artifactId>sqlite-jdbc</artifactId>
55+
<version>[3.31.1,)</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>junit</groupId>
59+
<artifactId>junit</artifactId>
60+
<version>4.11</version>
61+
<scope>test</scope>
62+
</dependency>
63+
</dependencies>
64+
65+
<build>
66+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
67+
<plugins>
68+
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
69+
<plugin>
70+
<artifactId>maven-clean-plugin</artifactId>
71+
<version>3.1.0</version>
72+
</plugin>
73+
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
74+
<plugin>
75+
<artifactId>maven-resources-plugin</artifactId>
76+
<version>3.0.2</version>
77+
</plugin>
78+
<plugin>
79+
<artifactId>maven-compiler-plugin</artifactId>
80+
<version>3.8.0</version>
81+
</plugin>
82+
<plugin>
83+
<artifactId>maven-surefire-plugin</artifactId>
84+
<version>2.22.2</version>
85+
<configuration>
86+
<trimStackTrace>false</trimStackTrace>
87+
</configuration>
88+
</plugin>
89+
<plugin>
90+
<artifactId>maven-jar-plugin</artifactId>
91+
<version>3.0.2</version>
92+
</plugin>
93+
<plugin>
94+
<artifactId>maven-install-plugin</artifactId>
95+
<version>2.5.2</version>
96+
</plugin>
97+
<plugin>
98+
<artifactId>maven-deploy-plugin</artifactId>
99+
<version>2.8.2</version>
100+
</plugin>
101+
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
102+
<plugin>
103+
<artifactId>maven-site-plugin</artifactId>
104+
<version>3.7.1</version>
105+
</plugin>
106+
<plugin>
107+
<artifactId>maven-project-info-reports-plugin</artifactId>
108+
<version>3.0.0</version>
109+
</plugin>
110+
<plugin>
111+
<groupId>com.diffplug.spotless</groupId>
112+
<artifactId>spotless-maven-plugin</artifactId>
113+
<version>2.3.1</version>
114+
<configuration>
115+
<java>
116+
<includes>
117+
<include>src/**/*.java</include>
118+
</includes>
119+
<importOrder/>
120+
<removeUnusedImports/>
121+
<googleJavaFormat/>
122+
</java>
123+
</configuration>
124+
</plugin>
125+
</plugins>
126+
</pluginManagement>
127+
</build>
128+
</project>
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
package net.mlin.genomicsqlite;
2+
3+
import java.sql.Connection;
4+
import java.sql.PreparedStatement;
5+
import java.sql.ResultSet;
6+
import java.sql.SQLException;
7+
import java.util.HashMap;
8+
9+
public class GenomicSQLite {
10+
public static String version(Connection conn) throws SQLException {
11+
ResultSet row = conn.createStatement().executeQuery("SELECT genomicsqlite_version()");
12+
row.next();
13+
return row.getString(1);
14+
}
15+
16+
public static String attachSQL(
17+
Connection conn, String dbFileName, String schemaName, String configJson)
18+
throws SQLException {
19+
PreparedStatement stmt = conn.prepareStatement("SELECT genomicsqlite_attach_sql(?,?,?)");
20+
stmt.setString(1, dbFileName);
21+
stmt.setString(2, schemaName);
22+
stmt.setString(3, configJson);
23+
ResultSet row = stmt.executeQuery();
24+
row.next();
25+
return row.getString(1);
26+
}
27+
28+
public static String attachSQL(Connection conn, String dbFileName, String schemaName)
29+
throws SQLException {
30+
return attachSQL(conn, dbFileName, schemaName, "{}");
31+
}
32+
33+
public static String vacuumIntoSQL(Connection conn, String destFileName, String configJson)
34+
throws SQLException {
35+
PreparedStatement stmt = conn.prepareStatement("SELECT genomicsqlite_vacuum_into_sql(?,?)");
36+
stmt.setString(1, destFileName);
37+
stmt.setString(2, configJson);
38+
ResultSet row = stmt.executeQuery();
39+
row.next();
40+
return row.getString(1);
41+
}
42+
43+
public static String vacuumIntoSQL(Connection conn, String destFileName) throws SQLException {
44+
return vacuumIntoSQL(conn, destFileName, "{}");
45+
}
46+
47+
public static String createGenomicRangeIndexSQL(
48+
Connection conn,
49+
String tableName,
50+
String rid,
51+
String beginPosition,
52+
String endPosition,
53+
int floor)
54+
throws SQLException {
55+
PreparedStatement stmt =
56+
conn.prepareStatement("SELECT create_genomic_range_index_sql(?,?,?,?,?)");
57+
stmt.setString(1, tableName);
58+
stmt.setString(2, rid);
59+
stmt.setString(3, beginPosition);
60+
stmt.setString(4, endPosition);
61+
stmt.setInt(5, floor);
62+
ResultSet row = stmt.executeQuery();
63+
row.next();
64+
return row.getString(1);
65+
}
66+
67+
public static String createGenomicRangeIndexSQL(
68+
Connection conn, String tableName, String rid, String beginPosition, String endPosition)
69+
throws SQLException {
70+
return createGenomicRangeIndexSQL(conn, tableName, rid, beginPosition, endPosition, -1);
71+
}
72+
73+
public static String putReferenceAssemblySQL(Connection conn, String assembly)
74+
throws SQLException {
75+
PreparedStatement stmt = conn.prepareStatement("SELECT put_genomic_reference_assembly_sql(?)");
76+
stmt.setString(1, assembly);
77+
ResultSet row = stmt.executeQuery();
78+
row.next();
79+
return row.getString(1);
80+
}
81+
82+
public static String putReferenceSequenceSQL(
83+
Connection conn,
84+
String name,
85+
long length,
86+
String assembly,
87+
String refget_id,
88+
String meta_json,
89+
long rid)
90+
throws SQLException {
91+
PreparedStatement stmt =
92+
conn.prepareStatement("SELECT put_genomic_reference_sequence_sql(?,?,?,?,?,?)");
93+
stmt.setString(1, name);
94+
stmt.setLong(2, length);
95+
stmt.setString(3, assembly);
96+
stmt.setString(4, refget_id);
97+
stmt.setString(5, meta_json);
98+
stmt.setLong(6, rid);
99+
ResultSet row = stmt.executeQuery();
100+
row.next();
101+
return row.getString(1);
102+
}
103+
104+
public static String putReferenceSequenceSQL(
105+
Connection conn,
106+
String name,
107+
long length,
108+
String assembly,
109+
String refget_id,
110+
String meta_json)
111+
throws SQLException {
112+
PreparedStatement stmt =
113+
conn.prepareStatement("SELECT put_genomic_reference_sequence_sql(?,?,?,?,?)");
114+
stmt.setString(1, name);
115+
stmt.setLong(2, length);
116+
if (assembly != null) stmt.setString(3, assembly);
117+
if (refget_id != null) stmt.setString(4, refget_id);
118+
if (meta_json != null) stmt.setString(5, meta_json);
119+
ResultSet row = stmt.executeQuery();
120+
row.next();
121+
return row.getString(1);
122+
}
123+
124+
public static String putReferenceSequenceSQL(
125+
Connection conn, String name, long length, String assembly, String refget_id)
126+
throws SQLException {
127+
return putReferenceSequenceSQL(conn, name, length, assembly, refget_id, null);
128+
}
129+
130+
public static String putReferenceSequenceSQL(
131+
Connection conn, String name, long length, String assembly) throws SQLException {
132+
return putReferenceSequenceSQL(conn, name, length, assembly, null, null);
133+
}
134+
135+
public static String putReferenceSequenceSQL(Connection conn, String name, long length)
136+
throws SQLException {
137+
return putReferenceSequenceSQL(conn, name, length, null, null, null);
138+
}
139+
140+
public static HashMap<Long, ReferenceSequence> getReferenceSequencesByRid(
141+
Connection conn, String assembly) throws SQLException {
142+
String sql =
143+
"SELECT _gri_rid, gri_refseq_name, gri_refseq_length, gri_assembly, gri_refget_id, gri_refseq_meta_json FROM _gri_refseq";
144+
PreparedStatement stmt;
145+
if (assembly != null) {
146+
stmt = conn.prepareStatement(sql + " WHERE gri_assembly = ?");
147+
stmt.setString(1, assembly);
148+
} else {
149+
stmt = conn.prepareStatement(sql);
150+
}
151+
ResultSet row = stmt.executeQuery();
152+
HashMap<Long, ReferenceSequence> ans = new HashMap<Long, ReferenceSequence>();
153+
while (row.next()) {
154+
ReferenceSequence grs =
155+
new ReferenceSequence(
156+
row.getLong(1),
157+
row.getString(2),
158+
row.getLong(3),
159+
row.getString(4),
160+
row.getString(5),
161+
row.getString(6));
162+
ans.put(grs.rid, grs);
163+
}
164+
return ans;
165+
}
166+
167+
public static HashMap<Long, ReferenceSequence> getReferenceSequencesByRid(Connection conn)
168+
throws SQLException {
169+
return getReferenceSequencesByRid(conn, null);
170+
}
171+
172+
public static HashMap<String, ReferenceSequence> getReferenceSequencesByName(
173+
Connection conn, String assembly) throws SQLException {
174+
HashMap<String, ReferenceSequence> ans = new HashMap<String, ReferenceSequence>();
175+
for (HashMap.Entry<Long, ReferenceSequence> entry :
176+
getReferenceSequencesByRid(conn, assembly).entrySet()) {
177+
ReferenceSequence grs = entry.getValue();
178+
if (ans.containsKey(grs.name)) {
179+
throw new RuntimeException(
180+
"GenomicSQLite.getReferenceSequencesByName: duplicate name; try filtering by assembly");
181+
}
182+
ans.put(grs.name, grs);
183+
}
184+
return ans;
185+
}
186+
187+
public static HashMap<String, ReferenceSequence> getReferenceSequencesByName(Connection conn)
188+
throws SQLException {
189+
return getReferenceSequencesByName(conn, null);
190+
}
191+
}

0 commit comments

Comments
 (0)