mirror of
https://github.com/danog/RFAMWrapper.git
synced 2024-11-30 04:19:28 +01:00
First commit
This commit is contained in:
commit
d0d9e0e5e2
73
build.xml
Normal file
73
build.xml
Normal file
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||
<!-- the Compile on Save feature is turned off for the project. -->
|
||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||
<!-- in the project's Project Properties dialog box.-->
|
||||
<project name="RFAM" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project RFAM.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar: JAR building
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="RFAM-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
</project>
|
BIN
lib/mysql-connector-java-5.1.46-bin.jar
Normal file
BIN
lib/mysql-connector-java-5.1.46-bin.jar
Normal file
Binary file not shown.
3
manifest.mf
Normal file
3
manifest.mf
Normal file
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
1420
nbproject/build-impl.xml
Normal file
1420
nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
8
nbproject/genfiles.properties
Normal file
8
nbproject/genfiles.properties
Normal file
@ -0,0 +1,8 @@
|
||||
build.xml.data.CRC32=c68b23b5
|
||||
build.xml.script.CRC32=ef345505
|
||||
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=c68b23b5
|
||||
nbproject/build-impl.xml.script.CRC32=eb5a1d57
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
|
81
nbproject/project.properties
Normal file
81
nbproject/project.properties
Normal file
@ -0,0 +1,81 @@
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
annotation.processing.run.all.processors=true
|
||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||
application.title=RFAM
|
||||
application.vendor=daniil
|
||||
build.classes.dir=${build.dir}/classes
|
||||
build.classes.excludes=**/*.java,**/*.form
|
||||
# This directory is removed when the project is cleaned:
|
||||
build.dir=build
|
||||
build.generated.dir=${build.dir}/generated
|
||||
build.generated.sources.dir=${build.dir}/generated-sources
|
||||
# Only compile against the classpath explicitly listed here:
|
||||
build.sysclasspath=ignore
|
||||
build.test.classes.dir=${build.dir}/test/classes
|
||||
build.test.results.dir=${build.dir}/test/results
|
||||
# Uncomment to specify the preferred debugger connection transport:
|
||||
#debug.transport=dt_socket
|
||||
debug.classpath=\
|
||||
${run.classpath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
# Files in build.classes.dir which should be excluded from distribution jar
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/RFAM.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
endorsed.classpath=
|
||||
excludes=
|
||||
file.reference.mysql-connector-java-5.1.46-bin.jar=/home/daniil/Downloads/mysql-connector-java-5.1.46/mysql-connector-java-5.1.46-bin.jar
|
||||
file.reference.mysql-connector-java-5.1.46-bin.jar-1=lib/mysql-connector-java-5.1.46-bin.jar
|
||||
includes=**
|
||||
jar.compress=false
|
||||
javac.classpath=\
|
||||
${file.reference.mysql-connector-java-5.1.46-bin.jar-1}
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
javac.external.vm=true
|
||||
javac.processorpath=\
|
||||
${javac.classpath}:\
|
||||
${file.reference.mysql-connector-java-5.1.46-bin.jar}
|
||||
javac.source=1.8
|
||||
javac.target=1.8
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}:\
|
||||
${file.reference.mysql-connector-java-5.1.46-bin.jar}
|
||||
javac.test.processorpath=\
|
||||
${javac.test.classpath}
|
||||
javadoc.additionalparam=
|
||||
javadoc.author=false
|
||||
javadoc.encoding=${source.encoding}
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
main.class=rfam.DB
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=false
|
||||
platform.active=default_platform
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
# Space-separated list of JVM arguments used when running the project.
|
||||
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||
run.jvmargs=
|
||||
run.test.classpath=\
|
||||
${javac.test.classpath}:\
|
||||
${build.test.classes.dir}
|
||||
source.encoding=UTF-8
|
||||
src.dir=src
|
||||
test.src.dir=test
|
15
nbproject/project.xml
Normal file
15
nbproject/project.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>RFAM</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
53
src/rfam/DB.java
Normal file
53
src/rfam/DB.java
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package rfam;
|
||||
|
||||
import rfam.RFAMWrapper.RFAMFilter;
|
||||
import rfam.RFAMWrapper.RFAMFilteredTable;
|
||||
import rfam.RFAMWrapper.RFAMTable;
|
||||
import rfam.RFAMWrapper.RFAMTableStats;
|
||||
import rfam.RFAMWrapper.RFAMColumnStats;
|
||||
import rfam.RFAMWrapper.RFAMWrapper;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import rfam.RFAMWrapper.RFAMColumnFilteredStats;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author daniil
|
||||
*/
|
||||
public class DB {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
RFAMWrapper wrapper = new RFAMWrapper();
|
||||
|
||||
RFAMTable table = new RFAMTable(wrapper, "family");
|
||||
RFAMFilteredTable filteredTable = new RFAMFilteredTable(table);
|
||||
|
||||
RFAMTableStats tableStats = new RFAMTableStats(filteredTable);
|
||||
RFAMColumnStats columnStats = new RFAMColumnStats(tableStats, "description");
|
||||
|
||||
RFAMColumnFilteredStats charStats = new RFAMColumnFilteredStats(columnStats);
|
||||
|
||||
filteredTable.applyFilter(new RFAMFilter("author").equals("Moxon SJ"));
|
||||
filteredTable.applyFilter(new RFAMFilter("description").contains(' '));
|
||||
|
||||
charStats.applyFilter(new RFAMFilter().contains('a'));
|
||||
|
||||
System.out.println(String.format("Total char count: %d", columnStats.getCharCount()));
|
||||
System.out.println(String.format("Occurences of char 'a': %d", charStats.getCharCount()));
|
||||
System.out.println(String.format("Percentage of occurences of char 'a': %f", charStats.getCharPercentage()));
|
||||
} catch (ClassNotFoundException | SQLException | IllegalAccessException | InstantiationException ex) {
|
||||
Logger.getLogger(DB.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
32
src/rfam/RFAMWrapper/RFAMColumnFilteredStats.java
Normal file
32
src/rfam/RFAMWrapper/RFAMColumnFilteredStats.java
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package rfam.RFAMWrapper;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author daniil
|
||||
*/
|
||||
public class RFAMColumnFilteredStats implements RFAMColumnStatsInterface {
|
||||
private RFAMColumnStats stats;
|
||||
private ArrayList<RFAMFilter> filters;
|
||||
|
||||
public RFAMColumnFilteredStats(RFAMColumnStats stats) {
|
||||
this.stats = stats;
|
||||
}
|
||||
|
||||
public void applyFilter(RFAMFilter filter) {
|
||||
filters.add(filter);
|
||||
}
|
||||
public int getCharCount() throws SQLException {
|
||||
return stats.getCharCount(filters);
|
||||
}
|
||||
public double getCharPercentage() throws SQLException {
|
||||
return stats.getCharCount()*100/stats.getCharCount(filters);
|
||||
}
|
||||
}
|
37
src/rfam/RFAMWrapper/RFAMColumnStats.java
Normal file
37
src/rfam/RFAMWrapper/RFAMColumnStats.java
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package rfam.RFAMWrapper;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author daniil
|
||||
*/
|
||||
public class RFAMColumnStats implements RFAMColumnStatsInterface {
|
||||
private ResultSet result;
|
||||
private String column;
|
||||
public RFAMColumnStats(RFAMTableStats stats, String column) throws SQLException {
|
||||
this.result = stats.getTable().select(column);
|
||||
this.column = column;
|
||||
}
|
||||
public int getCharCount() throws SQLException {
|
||||
return getCharCount(new ArrayList<RFAMFilter>());
|
||||
}
|
||||
public int getCharCount(ArrayList<RFAMFilter> filters) throws SQLException {
|
||||
int count = 0;
|
||||
String value;
|
||||
while ((value = result.getString(column)) != null) {
|
||||
for (RFAMFilter filter: filters) {
|
||||
count += filter.count(value);
|
||||
}
|
||||
}
|
||||
result.absolute(0);
|
||||
return count;
|
||||
}
|
||||
}
|
16
src/rfam/RFAMWrapper/RFAMColumnStatsInterface.java
Normal file
16
src/rfam/RFAMWrapper/RFAMColumnStatsInterface.java
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package rfam.RFAMWrapper;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author daniil
|
||||
*/
|
||||
public interface RFAMColumnStatsInterface {
|
||||
public int getCharCount() throws SQLException;
|
||||
}
|
107
src/rfam/RFAMWrapper/RFAMFilter.java
Normal file
107
src/rfam/RFAMWrapper/RFAMFilter.java
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package rfam.RFAMWrapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author daniil
|
||||
*/
|
||||
public class RFAMFilter {
|
||||
private String column;
|
||||
private ArrayList<String> contains;
|
||||
private ArrayList<String> equals;
|
||||
private Integer index = 0;
|
||||
|
||||
public RFAMFilter(String column) {
|
||||
this.column = column;
|
||||
}
|
||||
public RFAMFilter() {
|
||||
}
|
||||
|
||||
public RFAMFilter contains(char filter) {
|
||||
return contains(String.valueOf(filter));
|
||||
}
|
||||
public RFAMFilter contains(String filter) {
|
||||
contains.add(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RFAMFilter equals(char filter) {
|
||||
return equals(String.valueOf(filter));
|
||||
}
|
||||
public RFAMFilter equals(String filter) {
|
||||
equals.add(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getColumn() {
|
||||
return column;
|
||||
}
|
||||
public ArrayList<String> getMatchFilters() {
|
||||
return contains;
|
||||
}
|
||||
public ArrayList<String> getEqualFilters() {
|
||||
return equals;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String result = "";
|
||||
String and = "";
|
||||
if (equals.size() > 0) {
|
||||
result += column+" IN (";
|
||||
for (String equal: equals) {
|
||||
result += "?, ";
|
||||
}
|
||||
result += ")";
|
||||
if (contains.size() > 0) {
|
||||
and = " AND ";
|
||||
}
|
||||
}
|
||||
for (String match: contains) {
|
||||
result += and+column+" LIKE %?%";
|
||||
and = " AND ";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public String getNext() {
|
||||
if (index < contains.size()) {
|
||||
return contains.get(index++);
|
||||
}
|
||||
Integer newindex = index - contains.size();
|
||||
if (newindex < equals.size()) {
|
||||
index = 0;
|
||||
return null;
|
||||
}
|
||||
index++;
|
||||
return equals.get(newindex);
|
||||
}
|
||||
|
||||
|
||||
public int count(String value) {
|
||||
if (contains.size() == 0 && equals.size() == 0) {
|
||||
return value.length();
|
||||
}
|
||||
|
||||
boolean match = false;
|
||||
for (String equal: equals) {
|
||||
match = match || value.equals(equal);
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (String contain: contains) {
|
||||
count += value.split(contain).length-1;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
46
src/rfam/RFAMWrapper/RFAMFilteredTable.java
Normal file
46
src/rfam/RFAMWrapper/RFAMFilteredTable.java
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package rfam.RFAMWrapper;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author daniil
|
||||
*/
|
||||
public class RFAMFilteredTable implements RFAMTableInterface {
|
||||
private RFAMTable table;
|
||||
private ArrayList<RFAMFilter> filters;
|
||||
|
||||
public RFAMFilteredTable(RFAMTable table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
public void applyFilter(RFAMFilter filter) {
|
||||
filters.add(filter);
|
||||
}
|
||||
public ResultSet select(String field) throws SQLException {
|
||||
return select(new String[] { field });
|
||||
}
|
||||
public ResultSet select(String[] fields) throws SQLException {
|
||||
String whereClause = "";
|
||||
for (RFAMFilter filter: filters) {
|
||||
whereClause += filter;
|
||||
}
|
||||
PreparedStatement statement = table.select(fields, whereClause);
|
||||
Integer index = 0;
|
||||
String parameter;
|
||||
for (RFAMFilter filter: filters) {
|
||||
while ((parameter = filter.getNext()) != null) {
|
||||
statement.setString(index++, parameter);
|
||||
}
|
||||
}
|
||||
return statement.executeQuery();
|
||||
}
|
||||
}
|
35
src/rfam/RFAMWrapper/RFAMTable.java
Normal file
35
src/rfam/RFAMWrapper/RFAMTable.java
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package rfam.RFAMWrapper;
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author daniil
|
||||
*/
|
||||
public class RFAMTable implements RFAMTableInterface, RFAMWrapperInterface {
|
||||
private RFAMWrapper wrapper;
|
||||
private String table;
|
||||
public RFAMTable(RFAMWrapper wrapper, String table) {
|
||||
this.wrapper = wrapper;
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
public RFAMFilteredTable getFilteredTable() {
|
||||
return new RFAMFilteredTable(this);
|
||||
}
|
||||
|
||||
protected PreparedStatement select(String[] fields, String whereClause) throws SQLException {
|
||||
return wrapper.select(fields, table, whereClause);
|
||||
}
|
||||
public ResultSet select(String[] fields) throws SQLException {
|
||||
return wrapper.select(fields, table);
|
||||
}
|
||||
public ResultSet select(String field) throws SQLException {
|
||||
return wrapper.select(field, table);
|
||||
}
|
||||
|
||||
}
|
18
src/rfam/RFAMWrapper/RFAMTableInterface.java
Normal file
18
src/rfam/RFAMWrapper/RFAMTableInterface.java
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package rfam.RFAMWrapper;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author daniil
|
||||
*/
|
||||
public interface RFAMTableInterface {
|
||||
public ResultSet select(String[] fields) throws SQLException;
|
||||
public ResultSet select(String field) throws SQLException;
|
||||
}
|
25
src/rfam/RFAMWrapper/RFAMTableStats.java
Normal file
25
src/rfam/RFAMWrapper/RFAMTableStats.java
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package rfam.RFAMWrapper;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author daniil
|
||||
*/
|
||||
public class RFAMTableStats {
|
||||
private RFAMTableInterface table;
|
||||
public RFAMTableStats(RFAMTableInterface table) {
|
||||
this.table = table;
|
||||
}
|
||||
public RFAMTableInterface getTable() {
|
||||
return table;
|
||||
}
|
||||
public RFAMColumnStats getColumn(String column) throws SQLException {
|
||||
return new RFAMColumnStats(this, column);
|
||||
}
|
||||
}
|
50
src/rfam/RFAMWrapper/RFAMWrapper.java
Normal file
50
src/rfam/RFAMWrapper/RFAMWrapper.java
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package rfam.RFAMWrapper;
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author daniil
|
||||
*/
|
||||
public class RFAMWrapper implements RFAMWrapperInterface {
|
||||
private final String driver = "com.mysql.jdbc.driver";
|
||||
private final String URL = "jdbc:mysql://mysql-rfam-public.ebi.ac.uk:4497/Rfam";
|
||||
private final String username = "rfamro";
|
||||
private final String password = "";
|
||||
|
||||
private Connection connection;
|
||||
public RFAMWrapper() throws ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException {
|
||||
Class.forName(driver).newInstance();
|
||||
connection = DriverManager.getConnection(URL, username, password);
|
||||
}
|
||||
|
||||
public RFAMTable getTable(String table) {
|
||||
return new RFAMTable(this, table);
|
||||
}
|
||||
public RFAMFilteredTable getFilteredTable(String table) {
|
||||
return new RFAMFilteredTable(new RFAMTable(this, table));
|
||||
}
|
||||
|
||||
protected PreparedStatement select(String field, String fromTable, String whereClause) throws SQLException {
|
||||
return select(new String[] { field }, fromTable, whereClause);
|
||||
}
|
||||
protected PreparedStatement select(String[] fields, String fromTable, String whereClause) throws SQLException {
|
||||
String field = String.join(", ", fields);
|
||||
if (whereClause.length() > 0) {
|
||||
whereClause = " WHERE "+whereClause;
|
||||
}
|
||||
return connection.prepareStatement("SELECT "+field+" FROM "+fromTable+whereClause);
|
||||
}
|
||||
|
||||
public ResultSet select(String field, String fromTable) throws SQLException {
|
||||
return select(new String[] { field }, fromTable);
|
||||
}
|
||||
public ResultSet select(String[] fields, String fromTable) throws SQLException {
|
||||
String field = String.join(", ", fields);
|
||||
return connection.prepareStatement("SELECT "+field+" FROM "+fromTable).executeQuery();
|
||||
}
|
||||
}
|
17
src/rfam/RFAMWrapper/RFAMWrapperInterface.java
Normal file
17
src/rfam/RFAMWrapper/RFAMWrapperInterface.java
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package rfam.RFAMWrapper;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author daniil
|
||||
*/
|
||||
public interface RFAMWrapperInterface {
|
||||
}
|
Loading…
Reference in New Issue
Block a user