Skip to content

Commit

Permalink
Import of original WhiteRabbit application, to be modified
Browse files Browse the repository at this point in the history
  • Loading branch information
schuemie committed May 20, 2014
1 parent 7bcd0be commit 3a75227
Show file tree
Hide file tree
Showing 116 changed files with 21,821 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/jtds-1.3.0.jar"/>
<classpathentry kind="lib" path="lib/ojdbc5.jar"/>
<classpathentry kind="lib" path="lib/ojdbc6.jar"/>
<classpathentry kind="lib" path="lib/postgresql-9.3-1101.jdbc41.jar"/>
<classpathentry kind="lib" path="lib/sqljdbc4.jar"/>
<classpathentry kind="lib" path="lib/mysql-connector-java-5.1.30-bin.jar"/>
<classpathentry kind="lib" path="lib/dom4j-1.6.1.jar"/>
<classpathentry kind="lib" path="lib/poi-3.9-20121203.jar"/>
<classpathentry kind="lib" path="lib/poi-excelant-3.9-20121203.jar"/>
<classpathentry kind="lib" path="lib/poi-ooxml-3.9-20121203.jar"/>
<classpathentry kind="lib" path="lib/poi-ooxml-schemas-3.9-20121203.jar"/>
<classpathentry kind="lib" path="lib/stax-api-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/xmlbeans-2.3.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>WhiteRabbit</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
41 changes: 41 additions & 0 deletions .settings/com.wdev91.eclipse.copyright.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" ?>
<project>
<owner></owner>
<copyright><![CDATA[Copyright 2014 Observational Health Data Sciences and Informatics
This file is part of WhiteRabbit
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
@author Observational Health Data Sciences and Informatics
@author Martijn Schuemie]]></copyright>
<header contentId="org.eclipse.ant.core.antBuildFile" excluded="true" />
<header contentId="org.eclipse.jdt.core.JARManifest" excluded="true" />
<header contentId="org.eclipse.jdt.core.javaSource" postBlankLines="0" lineFormat="false" preserveFirstLine="false">
<beginLine><![CDATA[/*******************************************************************************]]></beginLine>
<linePrefix><![CDATA[ * ]]></linePrefix>
<endLine><![CDATA[ ******************************************************************************/]]></endLine>
</header>
<header contentId="org.eclipse.core.runtime.text" postBlankLines="0" lineFormat="true" preserveFirstLine="false">
<beginLine><![CDATA[#-------------------------------------------------------------------------------]]></beginLine>
<linePrefix><![CDATA[# ]]></linePrefix>
<endLine><![CDATA[#-------------------------------------------------------------------------------]]></endLine>
</header>
<header contentId="org.eclipse.ui.views.log.log" excluded="true" />
<header contentId="org.eclipse.core.runtime.xml" postBlankLines="0" lineFormat="false" preserveFirstLine="true">
<beginLine><![CDATA[<!--]]></beginLine>
<linePrefix><![CDATA[ ]]></linePrefix>
<endLine><![CDATA[-->]]></endLine>
<firstLinePattern><![CDATA[<\?xml version=.*\?>]]></firstLinePattern>
</header>
</project>
11 changes: 11 additions & 0 deletions jarDesc/WhiteRabbit.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Manifest-Version: 1.0
Class-Path: . WhiteRabbit_lib/jtds-1.3.0.jar WhiteRabbit_lib/ojdbc5.ja
r WhiteRabbit_lib/ojdbc6.jar WhiteRabbit_lib/postgresql-9.3-1101.jdbc
41.jar WhiteRabbit_lib/sqljdbc4.jar WhiteRabbit_lib/mysql-connector-j
ava-5.1.30-bin.jar WhiteRabbit_lib/dom4j-1.6.1.jar WhiteRabbit_lib/po
i-3.9-20121203.jar WhiteRabbit_lib/poi-excelant-3.9-20121203.jar Whit
eRabbit_lib/poi-ooxml-3.9-20121203.jar WhiteRabbit_lib/poi-ooxml-sche
mas-3.9-20121203.jar WhiteRabbit_lib/stax-api-1.0.1.jar WhiteRabbit_l
ib/xmlbeans-2.3.0.jar
Main-Class: org.ohdsi.whiteRabbit.interactiveMapping.RabbitInAHat

22 changes: 22 additions & 0 deletions jarDesc/WhiteRabbit.jardesc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="WINDOWS-1252" standalone="no"?>
<jardesc>
<jar path="C:/home/Software/WhiteRabbit/WhiteRabbit.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/WhiteRabbit/jarDesc/WhiteRabbit.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="true" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>
<manifest generateManifest="false" mainClassHandleIdentifier="=WhiteRabbit/src&lt;org.ohdsi.whiteRabbit{WhiteRabbitMain.java[WhiteRabbitMain" manifestLocation="/WhiteRabbit/jarDesc/WhiteRabbit.MF" manifestVersion="1.0" reuseManifest="false" saveManifest="true" usesManifest="true">
<sealing sealJar="false">
<packagesToSeal/>
<packagesToUnSeal/>
</sealing>
</manifest>
<selectedElements exportClassFiles="true" exportJavaFiles="true" exportOutputFolder="false">
<file path="/WhiteRabbit/LICENSE"/>
<file path="/WhiteRabbit/.gitignore"/>
<file path="/WhiteRabbit/README.md"/>
<folder path="/WhiteRabbit/jarDesc"/>
<file path="/WhiteRabbit/.classpath"/>
<file path="/WhiteRabbit/.project"/>
<javaElement handleIdentifier="=WhiteRabbit/src"/>
</selectedElements>
</jardesc>
Binary file added lib/dom4j-1.6.1.jar
Binary file not shown.
Binary file added lib/jtds-1.3.0.jar
Binary file not shown.
Binary file added lib/mysql-connector-java-5.1.30-bin.jar
Binary file not shown.
Binary file added lib/ojdbc5.jar
Binary file not shown.
Binary file added lib/ojdbc6.jar
Binary file not shown.
Binary file added lib/poi-3.9-20121203.jar
Binary file not shown.
Binary file added lib/poi-excelant-3.9-20121203.jar
Binary file not shown.
Binary file added lib/poi-ooxml-3.9-20121203.jar
Binary file not shown.
Binary file added lib/poi-ooxml-schemas-3.9-20121203.jar
Binary file not shown.
Binary file added lib/postgresql-9.3-1101.jdbc41.jar
Binary file not shown.
Binary file added lib/sqljdbc4.jar
Binary file not shown.
Binary file added lib/stax-api-1.0.1.jar
Binary file not shown.
Binary file added lib/xmlbeans-2.3.0.jar
Binary file not shown.
45 changes: 45 additions & 0 deletions src/org/ohdsi/databases/DbType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
*
* This file is part of WhiteRabbit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Observational Health Data Sciences and Informatics
* @author Martijn Schuemie
******************************************************************************/
package org.ohdsi.databases;

public class DbType {
public static DbType MYSQL = new DbType("mysql");
public static DbType MSSQL = new DbType("mssql");
public static DbType ORACLE = new DbType("oracle");
public static DbType POSTGRESQL = new DbType("postgresql");

private enum Type {
MYSQL, MSSQL, ORACLE, POSTGRESQL
};

private Type type;

public DbType(String type) {
this.type = Type.valueOf(type.toUpperCase());
}

public boolean equals(Object other) {
if (other instanceof DbType && ((DbType) other).type == type)
return true;
else
return false;
}
}
151 changes: 151 additions & 0 deletions src/org/ohdsi/databases/QueryDB.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
*
* This file is part of WhiteRabbit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Observational Health Data Sciences and Informatics
* @author Martijn Schuemie
******************************************************************************/
package org.ohdsi.databases;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;
import java.util.Map;

import org.ohdsi.utilities.files.ReadTextFile;
import org.ohdsi.utilities.files.Row;

public class QueryDB implements Iterable<Row>{
private String sql;
private Connection connection;

public QueryDB(InputStream sqlStream, Connection connection){
this(sqlStream,null,connection);
}

public QueryDB(InputStream sqlStream, Map<String, String> parameterToValue, Connection connection){
this.connection = connection;
sql = loadSQL(sqlStream);
if (parameterToValue != null)
for (String parameter : parameterToValue.keySet())
sql = sql.replaceAll(parameter, parameterToValue.get(parameter));
trimSQL();
}

public QueryDB(String sql, Connection connection){
this.connection = connection;
this.sql = sql;
trimSQL();
}

private void trimSQL() {
sql = sql.trim();
if (sql.endsWith(";"))
sql = sql.substring(0,sql.length()-1);
}

private String loadSQL(InputStream sqlStream) {
StringBuilder sql = new StringBuilder();
for (String line : new ReadTextFile(sqlStream)){
sql.append(line.trim());
sql.append('\n');
}
return sql.substring(0, sql.lastIndexOf(";"));
}

public boolean execute(){
boolean result = false;
for (String subQuery : sql.split(";"))
try {
Statement statement = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
result = statement.execute(subQuery.toString());
} catch (SQLException e) {
if (e.getMessage().contains("ORA-00942") && sql.toUpperCase().startsWith("DROP"))
System.out.println("Tried dropping non-existing table");
else {
System.err.println("SQL: " + subQuery);
e.printStackTrace();
}
}
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
return result;
}

@Override
public Iterator<Row> iterator() {
return new DBRowIterator(sql);
}
public class DBRowIterator implements Iterator<Row>{

private ResultSet resultSet;

private boolean hasNext;

public DBRowIterator(String sql) {
try {
Statement statement = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
resultSet = statement.executeQuery(sql.toString());
hasNext = resultSet.next();
if (!hasNext)
connection.close();
} catch (SQLException e){
System.err.println(sql.toString());
System.err.println(e.getMessage());
throw new RuntimeException(e);
}
}

@Override
public boolean hasNext() {
return hasNext;
}

@Override
public Row next() {
try {
Row row = new Row();
ResultSetMetaData metaData;
metaData = resultSet.getMetaData();
for (int i = 1; i < metaData.getColumnCount()+1; i++) {
String columnName = metaData.getColumnName(i);
String value = resultSet.getString(i);
if (value == null)
value = "";
row.add(columnName, value.replace(" 00:00:00", ""));
}
hasNext = resultSet.next();
if (!hasNext)
connection.close();
return row;
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}

@Override
public void remove() {
}
}
}
40 changes: 40 additions & 0 deletions src/org/ohdsi/databases/QueryParameters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
*
* This file is part of WhiteRabbit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Observational Health Data Sciences and Informatics
* @author Martijn Schuemie
******************************************************************************/
package org.ohdsi.databases;

import java.util.HashMap;
import java.util.Map;

public class QueryParameters {
private Map<String, String> key2Value = new HashMap<String, String>();
public void set(String key, String value){
key2Value.put(key, value);
}

public void set(String key, int value){
key2Value.put(key, Integer.toString(value));
}

protected Map<String, String> getMap() {
return key2Value;
}

}
Loading

0 comments on commit 3a75227

Please sign in to comment.