Skip to content

Commit

Permalink
Release 1.0.2. Adding convenience.
Browse files Browse the repository at this point in the history
  • Loading branch information
khituras committed Apr 27, 2018
1 parent ff20f15 commit 69aa784
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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>
<artifactId>costosys</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.2</version>
<name>Corpus Storage System</name>
<description>A utility for managing documents stored in a PostgreSQL database. The documents are imported into a
PostgreSQL DB as full texts with the goal to be able to retrieve the documents by their PubMedID efficiently.
Expand Down
53 changes: 42 additions & 11 deletions src/main/java/de/julielab/xmlData/dataBase/DataBaseConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import de.julielab.xmlData.dataBase.util.TableSchemaMismatchException;
import de.julielab.xmlData.dataBase.util.UnobtainableConnectionException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -326,7 +328,7 @@ public Connection getConn() {
if (null == dataSource) {
LOG.debug("Setting up connection pool data source");
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setPoolName("costosys-"+System.nanoTime());
hikariConfig.setPoolName("costosys-" + System.nanoTime());
hikariConfig.setJdbcUrl(dbURL);
hikariConfig.setUsername(user);
hikariConfig.setPassword(password);
Expand Down Expand Up @@ -1254,6 +1256,20 @@ public String getNextDataTable(String referencingTable) throws SQLException {
return referencedTable;
}

/**
* Determines the first data table on the reference path <code>referencingTable -> table1 -> table2 -> ... -> lastTable -> null</code>
* referenced from <code>referencingTable</code>. This means that <code>referencingTable</code> is returned itself
* if it is a data table.
* @param referencingTable The start point table for the path for which the first data table is to be returned.
* @return The first data table on the foreign-key path beginning with <code>referencingTable</code> itself.
* @throws SQLException If a database operation fails.
*/
public String getNextOrThisDataTable(String referencingTable) throws SQLException {
if (isDataTable(referencingTable))
return referencingTable;
return getNextDataTable(referencingTable);
}

/**
* <p>
* Checks if the given table is a subset table.
Expand Down Expand Up @@ -3274,26 +3290,33 @@ public void close() {
return null;
}

public List<Object> getNumColumnsAndFields(boolean joined, String[] tables, String[] schemaNames) {
List<Object> numColumnsAndFields = new ArrayList<Object>();
/**
* Helper method to determine the columns that are returned in case of a joining operation. Returns the number of
* returned fields and the according field definitions. If <code>joined</code> is set to <code>false</code>, only the
* first table and the first schema is taken into account.
*
* @param joined Whether the data is joined.
* @param schemaNames The names of the table schemas of the tables that are read. From the respective table schemas,
* the columns that are marked to be retrieved, are extracted.
* @return A pair holding the number of retrieved columns and those columns themselves.
*/
public Pair<Integer, List<Map<String, String>>> getNumColumnsAndFields(boolean joined, String[] schemaNames) {
int numColumns = 0;
List<Map<String, String>> fields = new ArrayList<Map<String, String>>();
List<Map<String, String>> fields = new ArrayList<>();
if (!joined) {
FieldConfig fieldConfig = fieldConfigs.get(schemaNames[0]);
numColumns = fieldConfig.getColumnsToRetrieve().length;
fields = fieldConfig.getFields();
} else {
for (int i = 0; i < tables.length; i++) {
for (int i = 0; i < schemaNames.length; i++) {
FieldConfig fieldConfig = fieldConfigs.get(schemaNames[i]);
int num = fieldConfig.getColumnsToRetrieve().length;
numColumns = numColumns + num;
List<Map<String, String>> fieldsPartly = fieldConfig.getFieldsToRetrieve();
fields.addAll(fieldsPartly);
}
}
numColumnsAndFields.add(numColumns);
numColumnsAndFields.add(fields);
return numColumnsAndFields;
return new ImmutablePair<>(numColumns, fields);
}

/**
Expand Down Expand Up @@ -3491,8 +3514,8 @@ public FieldConfig getFieldConfiguration(String schemaName) {
}

/**
* @param tableName
* @return
* Checks whether the given table matches the active table schema.
* @param tableName The table to check.
* @see #checkTableDefinition(String, String)
*/
public void checkTableDefinition(String tableName) throws TableSchemaMismatchException {
Expand All @@ -3509,6 +3532,8 @@ public void checkTableDefinition(String tableName) throws TableSchemaMismatchExc
* @param tableName - table to check
*/
public void checkTableDefinition(String tableName, String schemaName) throws TableSchemaMismatchException {
if (!tableExists(tableName))
throw new IllegalArgumentException("The table '" + tableName + "' does not exist.");
FieldConfig fieldConfig = fieldConfigs.get(schemaName);

List<String> actualColumns = new ArrayList<>();
Expand Down Expand Up @@ -3810,7 +3835,13 @@ public synchronized FieldConfig addXmiAnnotationFieldConfiguration(List<Map<Stri
String fieldConfigName = StringUtils.join(pkNames, "-") + "-xmi-annotations-autogenerated";
FieldConfig ret;
if (!fieldConfigs.containsKey(fieldConfigName)) {
List<Map<String, String>> fields = new ArrayList<>(primaryKey);
List<Map<String, String>> fields = new ArrayList<>();
// Important: For the annotation tables we don't want to return their primary key. They are used
// as AdditionalTable parameter to the XmiDBReader and the primary key is already returned from the
// data table schema.
// We make a copy of the primary key fields so we can change them without manipulating the given key.
primaryKey.stream().map(HashMap::new).forEach(fields::add);
fields.forEach(pkField -> pkField.put(JulieXMLConstants.RETRIEVE, "false"));
FieldConfig xmiConfig = fieldConfigs.get(doGzip ? "xmi_annotation_gzip" : "xmi_annotation");
HashSet<Integer> xmiConfigPkIndices = new HashSet<>(xmiConfig.getPrimaryKeyFieldNumbers());
// Add those fields to the new configuration that are not the primary key fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.julielab.xml.JulieXMLTools;
import de.julielab.xmlData.config.FieldConfig;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -102,21 +103,19 @@ private class ArrayResToListThread extends Thread {
private Exchanger<ResultSet> resExchanger = new Exchanger<ResultSet>();
private ResultSet currentRes;
private ArrayList<byte[][]> currentList;
private String[] table;
private String[] schemaName;
private boolean joined = false;
private volatile boolean end = false;

ArrayResToListThread(Exchanger<List<byte[][]>> listExchanger, List<Object[]> keyList, String[] table,
ArrayResToListThread(Exchanger<List<byte[][]>> listExchanger, List<Object[]> keyList, String[] tables,
String whereClause, String[] schemaName) {
this.listExchanger = listExchanger;
this.table = table;
this.schemaName = schemaName;
if (table.length > 1 && schemaName.length > 1) {
if (tables.length > 1) {
this.joined = true;
}
// start the thread that is actually querying the database
arrayFromDBThread = new ArrayFromDBThread(resExchanger, keyList, table, whereClause, schemaName);
arrayFromDBThread = new ArrayFromDBThread(resExchanger, keyList, tables, whereClause, schemaName);
try {
// retrieve the first result without yet running the thread;
// when we have the result, we begin to create the result list
Expand All @@ -132,9 +131,9 @@ private class ArrayResToListThread extends Thread {

@SuppressWarnings("unchecked")
public void run() {
List<Object> numColumnsAndFields = dbc.getNumColumnsAndFields(joined, table, schemaName);
int numColumns = (Integer) numColumnsAndFields.get(0);
List<Map<String, String>> fields = (List<Map<String, String>>) numColumnsAndFields.get(1);
Pair<Integer, List<Map<String, String>>> numColumnsAndFields = dbc.getNumColumnsAndFields(joined, schemaName);
int numColumns = numColumnsAndFields.getLeft();
List<Map<String, String>> fields = numColumnsAndFields.getRight();
int i = 0;
byte[][] retrievedData = null;
try {
Expand Down

0 comments on commit 69aa784

Please sign in to comment.