Skip to content

Commit

Permalink
Merge pull request #2414 from jjgao/release-1.6.0
Browse files Browse the repository at this point in the history
Release 1.6.0
  • Loading branch information
jjgao authored May 8, 2017
2 parents 641ace4 + 1c75fc0 commit 512e49f
Show file tree
Hide file tree
Showing 151 changed files with 3,226 additions and 2,410 deletions.
2 changes: 1 addition & 1 deletion business/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>master</artifactId>
<groupId>org.mskcc.cbio</groupId>
<version>1.5.2</version>
<version>1.6.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>business</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>master</artifactId>
<groupId>org.mskcc.cbio</groupId>
<version>1.5.2</version>
<version>1.6.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ public static void deleteCancerStudy(int internalCancerStudyId) throws DaoExcept
"DELETE FROM sample_profile WHERE GENETIC_PROFILE_ID IN (SELECT GENETIC_PROFILE_ID FROM genetic_profile WHERE CANCER_STUDY_ID=?)",
"DELETE FROM mutation WHERE GENETIC_PROFILE_ID IN (SELECT GENETIC_PROFILE_ID FROM genetic_profile WHERE CANCER_STUDY_ID=?)",
"DELETE FROM mutation_count WHERE GENETIC_PROFILE_ID IN (SELECT GENETIC_PROFILE_ID FROM genetic_profile WHERE CANCER_STUDY_ID=?)",
"DELETE FROM mutation_count_by_keyword WHERE GENETIC_PROFILE_ID IN (SELECT GENETIC_PROFILE_ID FROM genetic_profile WHERE CANCER_STUDY_ID=?)",
"DELETE FROM clinical_attribute_meta WHERE CANCER_STUDY_ID=?",
"DELETE FROM clinical_event_data WHERE CLINICAL_EVENT_ID IN (SELECT CLINICAL_EVENT_ID FROM clinical_event WHERE PATIENT_ID IN (SELECT INTERNAL_ID FROM patient WHERE CANCER_STUDY_ID=?))",
"DELETE FROM clinical_event WHERE PATIENT_ID IN (SELECT INTERNAL_ID FROM patient WHERE CANCER_STUDY_ID=?)",
Expand Down
28 changes: 28 additions & 0 deletions core/src/main/java/org/mskcc/cbio/portal/dao/DaoMutation.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,34 @@ public static int calculateMutationCount (int profileId) throws DaoException {
JdbcUtil.closeAll(DaoMutation.class, con, pstmt, rs);
}
}

public static int calculateMutationCountByKeyword(int profileId) throws DaoException {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoMutation.class);
pstmt = con.prepareStatement(
"INSERT INTO mutation_count_by_keyword " +
"SELECT g2.`GENETIC_PROFILE_ID`, mutation_event.`KEYWORD`, m2.`ENTREZ_GENE_ID`, " +
"IF(mutation_event.`KEYWORD` IS NULL, 0, COUNT(*)) AS KEYWORD_COUNT, (SELECT COUNT(*) " +
"FROM `mutation` AS m1 , `genetic_profile` AS g1 " +
"WHERE m1.`GENETIC_PROFILE_ID` = g1.`GENETIC_PROFILE_ID` " +
"AND g1.`GENETIC_PROFILE_ID`= g2.`GENETIC_PROFILE_ID` AND m1.`ENTREZ_GENE_ID` = m2.`ENTREZ_GENE_ID` " +
"GROUP BY g1.`GENETIC_PROFILE_ID` , m1.`ENTREZ_GENE_ID`) AS GENE_COUNT " +
"FROM `mutation` AS m2 , `genetic_profile` AS g2 , `mutation_event` " +
"WHERE m2.`GENETIC_PROFILE_ID` = g2.`GENETIC_PROFILE_ID` " +
"AND m2.`MUTATION_EVENT_ID` = mutation_event.`MUTATION_EVENT_ID` " +
"AND g2.`GENETIC_PROFILE_ID`=? " +
"GROUP BY g2.`GENETIC_PROFILE_ID` , mutation_event.`KEYWORD` , m2.`ENTREZ_GENE_ID`;");
pstmt.setInt(1, profileId);
return pstmt.executeUpdate();
} catch (SQLException e) {
throw new DaoException(e);
} finally {
JdbcUtil.closeAll(DaoMutation.class, con, pstmt, rs);
}
}

/**
* @deprecated We believe that this method is no longer called by any part of the codebase, and it will soon be deleted.
Expand Down
101 changes: 46 additions & 55 deletions core/src/main/java/org/mskcc/cbio/portal/dao/JdbcUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Memorial Sloan-Kettering Cancer Center.
* Copyright (c) 2015 - 2017 Memorial Sloan-Kettering Cancer Center.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
Expand Down Expand Up @@ -32,14 +32,12 @@

package org.mskcc.cbio.portal.dao;

import org.mskcc.cbio.portal.util.*;

import org.apache.commons.logging.*;

import java.sql.*;
import java.util.*;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.logging.*;
import org.mskcc.cbio.portal.util.*;

/**
* Connection Utility for JDBC.
Expand All @@ -48,90 +46,83 @@
* @author Ersin Ciftci
*/
public class JdbcUtil {
private static DataSource ds;
private static DataSource dataSource;
private static Map<String,Integer> activeConnectionCount = new HashMap<String,Integer>(); // keep track of the number of active connection per class/requester
private static final Log LOG = LogFactory.getLog(JdbcUtil.class);

/**
* Gets the data source
* @return the data source
*/
public static DataSource getDataSource() {
if (ds==null) ds = initDataSource();
return ds;
if (dataSource == null) {
dataSource = initDataSource();
}
return dataSource;
}

/**
* Sets the data source
* @param value the data source
*/
public static void setDataSource(DataSource value) {
ds = value;
dataSource = value;
}

private static DataSource initDataSource() {
DatabaseProperties dbProperties = DatabaseProperties.getInstance();
String host = dbProperties.getDbHost();
String userName = dbProperties.getDbUser();
String password = dbProperties.getDbPassword();
String database = dbProperties.getDbName();

String url ="jdbc:mysql://" + host + "/" + database +
"?user=" + userName + "&password=" + password +
"&zeroDateTimeBehavior=convertToNull";

// Set up poolable data source
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName("com.mysql.jdbc.Driver");
ds.setUsername(userName);
ds.setPassword(password);
ds.setUrl(url);

BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUsername(userName);
dataSource.setPassword(password);
dataSource.setUrl(url);
// By pooling/reusing PreparedStatements, we get a major performance gain
ds.setPoolPreparedStatements(true);
ds.setMaxActive(100);

dataSource.setPoolPreparedStatements(true);
dataSource.setMaxActive(100);
activeConnectionCount = new HashMap<String,Integer>();

return ds;
return dataSource;
}

/**
* Gets Connection to the Database.
*
*
* @param clazz class
* @return Live Connection to Database.
* @throws java.sql.SQLException Error Connecting to Database.
*/
public static Connection getDbConnection(Class clazz) throws SQLException {
return getDbConnection(clazz.getName());
}

/**
* Gets Connection to the Database.
*
*
* @param requester name
* @return Live Connection to Database.
* @throws java.sql.SQLException Error Connecting to Database.
*/
private static Connection getDbConnection(String requester) throws SQLException {
// this method should be syncronized
// but may slow the speed?

Connection con;
try {
con = getDataSource().getConnection();
}
catch (Exception e) {
} catch (Exception e) {
logMessage(e.getMessage());
throw new SQLException(e);
}

if (requester!=null) {
if (requester != null) {
Integer count = activeConnectionCount.get(requester);
activeConnectionCount.put(requester, count==null ? 1 : (count+1));
activeConnectionCount.put(requester, count == null ? 1 : (count + 1));
}

return con;
}

Expand All @@ -143,19 +134,17 @@ private static Connection getDbConnection(String requester) throws SQLException
public static void closeConnection(Class clazz, Connection con) {
closeConnection(clazz.getName(), con);
}

private static void closeConnection(String requester, Connection con) {
try {
if (con != null && !con.isClosed()) {
con.close();

if (requester!=null) {
int count = activeConnectionCount.get(requester)-1;
if (count<0) {
int count = activeConnectionCount.get(requester) - 1;
if (count < 0) {
// since adding connection is not synchronized, the count may not be the real one
count = 0;
}

activeConnectionCount.put(requester, count);
}
}
Expand All @@ -171,8 +160,8 @@ private static void closeConnection(String requester, Connection con) {
* @param rs ResultSet Object.
*/
public static void closeAll(ResultSet rs) {
JdbcUtil.closeAll((String)null, null, null, rs);
}
JdbcUtil.closeAll((String)null, null, null, rs);
}

/**
* Frees Database Connection.
Expand All @@ -181,8 +170,7 @@ public static void closeAll(ResultSet rs) {
* @param ps Prepared Statement Object.
* @param rs ResultSet Object.
*/
public static void closeAll(Class clazz, Connection con, PreparedStatement ps,
ResultSet rs) {
public static void closeAll(Class clazz, Connection con, PreparedStatement ps, ResultSet rs) {
closeAll(clazz.getName(), con, ps, rs);
}

Expand All @@ -192,23 +180,26 @@ public static void closeAll(Class clazz, Connection con, PreparedStatement ps,
* @param con Connection Object.
* @param rs ResultSet Object.
*/
private static void closeAll(String requester, Connection con, PreparedStatement ps,
ResultSet rs) {
private static void closeAll(String requester, Connection con, PreparedStatement ps, ResultSet rs) {
if (rs != null) {
try {
rs.close();
if (!rs.isClosed()) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
if (ps != null) {
try {
ps.close();
if (!ps.isClosed()) {
ps.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
closeConnection(requester, con);
closeConnection(requester, con);
}

/**
Expand All @@ -223,7 +214,9 @@ public static void closeAll(Class clazz, Connection con, ResultSet rs) {
closeConnection(requester, con);
if (rs != null) {
try {
rs.close();
if (!rs.isClosed()) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
Expand All @@ -236,18 +229,18 @@ private static void logMessage(String message) {
}
System.err.println(message);
}

// is it good to put the two methods below here?
static Integer readIntegerFromResultSet(ResultSet rs, String column) throws SQLException {
int i = rs.getInt(column);
return rs.wasNull() ? null : i;
}

static Long readLongFromResultSet(ResultSet rs, String column) throws SQLException {
long l = rs.getInt(column);
return rs.wasNull() ? null : l;
}

static Double readDoubleFromResultSet(ResultSet rs, String column) throws SQLException {
double d = rs.getDouble(column);
return rs.wasNull() ? null : d;
Expand All @@ -261,7 +254,6 @@ static Double readDoubleFromResultSet(ResultSet rs, String column) throws SQLExc
* @throws SQLException
*/
public static void disableForeignKeyCheck(Connection con) throws SQLException {

Statement stmt = con.createStatement();
stmt.execute("SET FOREIGN_KEY_CHECKS=0");
stmt.close();
Expand All @@ -273,7 +265,6 @@ public static void disableForeignKeyCheck(Connection con) throws SQLException {
* @throws SQLException
*/
public static void enableForeignKeyCheck(Connection con) throws SQLException {

Statement stmt = con.createStatement();
stmt.execute("SET FOREIGN_KEY_CHECKS=1");
stmt.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ public void importData() throws IOException, DaoException {

// calculate mutation count for every sample
DaoMutation.calculateMutationCount(geneticProfileId);
DaoMutation.calculateMutationCountByKeyword(geneticProfileId);

if (entriesSkipped > 0) {
ProgressMonitor.setCurrentMessage(" --> total number of data entries skipped (see table below): " + entriesSkipped);
Expand Down
Loading

0 comments on commit 512e49f

Please sign in to comment.