Skip to content

Commit

Permalink
Merge pull request #486 from jjgao/master
Browse files Browse the repository at this point in the history
release v0.1.1
  • Loading branch information
jjgao committed Nov 17, 2015
2 parents 8b1001e + 87f2afe commit e9a6aa5
Show file tree
Hide file tree
Showing 47 changed files with 1,029 additions and 442 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
nb-configuration.xml
nbactions-private.xml
oncotator/src/main/resources/db.properties
portal/Portal-Google-Code.ipr
portal/Portal-Google-Code.iws
Expand Down
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>0.1.0-SNAPSHOT</version>
<version>0.1.1</version>
</parent>

<!-- module metadata -->
Expand Down
6 changes: 2 additions & 4 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<!-- module meta data -->
<parent>
<artifactId>master</artifactId>
<groupId>org.mskcc.cbio</groupId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>core</artifactId>
Expand Down
122 changes: 71 additions & 51 deletions core/src/main/java/org/mskcc/cbio/portal/dao/DaoCancerStudy.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import java.sql.*;
import java.util.*;
import java.text.*;
import java.util.concurrent.ConcurrentHashMap;

/**
* Analogous to and replaces the old DaoCancerType. A CancerStudy has a NAME and
Expand All @@ -59,24 +58,31 @@ public static enum Status

private DaoCancerStudy() {}

private static final Map<String, java.util.Date> cacheDateByStableId = new ConcurrentHashMap<String, java.util.Date>();
private static final Map<Integer, java.util.Date> cacheDateByInternalId = new ConcurrentHashMap<Integer, java.util.Date>();
private static final Map<String,CancerStudy> byStableId = new ConcurrentHashMap<String,CancerStudy>();
private static final Map<Integer,CancerStudy> byInternalId = new ConcurrentHashMap<Integer,CancerStudy>();
private static final Map<String, java.util.Date> cacheDateByStableId = new HashMap<String, java.util.Date>();
private static final Map<Integer, java.util.Date> cacheDateByInternalId = new HashMap<Integer, java.util.Date>();
private static final Map<String,CancerStudy> byStableId = new HashMap<String,CancerStudy>();
private static final Map<Integer,CancerStudy> byInternalId = new HashMap<Integer,CancerStudy>();
private static long lastCached = Long.MIN_VALUE;

static {
SpringUtil.initDataSource();
reCache();
reCacheAll(System.currentTimeMillis());
}

public static void reCacheAll()
{
reCache();
DaoGeneticProfile.reCache();
DaoPatient.reCache();
DaoSample.reCache();
DaoClinicalData.reCache();
}
private static synchronized void reCacheAll(long time) {
if (lastCached >= time) {
return;
}

System.out.println("Recaching... ");
DaoCancerStudy.reCache();
DaoGeneticProfile.reCache();
DaoPatient.reCache();
DaoSample.reCache();
DaoClinicalData.reCache();
System.out.println("Finished recaching... ");
lastCached = System.currentTimeMillis();
}

private static synchronized void reCache() {
cacheDateByStableId.clear();
Expand Down Expand Up @@ -356,8 +362,10 @@ public static void addCancerStudy(CancerStudy cancerStudy, boolean overwrite) th
*/
public static CancerStudy getCancerStudyByInternalId(int internalId) throws DaoException
{
if (studyNeedsRecaching(null, internalId)) {
reCacheAll();
if (GlobalProperties.getRecacheStudyAfterUpdate()
&& studyNeedsRecaching(null, internalId)) {
System.out.print("Study with internal ID of "+internalId+" updated.");
reCacheAll(System.currentTimeMillis());
}
return byInternalId.get(internalId);
}
Expand All @@ -370,8 +378,10 @@ public static CancerStudy getCancerStudyByInternalId(int internalId) throws DaoE
*/
public static CancerStudy getCancerStudyByStableId(String stableId) throws DaoException
{
if (studyNeedsRecaching(stableId)) {
reCacheAll();
if (GlobalProperties.getRecacheStudyAfterUpdate()
&& studyNeedsRecaching(stableId)) {
System.out.print("Study "+stableId+" updated.");
reCacheAll(System.currentTimeMillis());
}
return byStableId.get(stableId);
}
Expand All @@ -383,8 +393,10 @@ public static CancerStudy getCancerStudyByStableId(String stableId) throws DaoEx
* @return true if the CancerStudy exists, otherwise false
*/
public static boolean doesCancerStudyExistByStableId(String cancerStudyStableId) {
if (studyNeedsRecaching(cancerStudyStableId)) {
reCacheAll();
if (GlobalProperties.getRecacheStudyAfterUpdate()
&& studyNeedsRecaching(cancerStudyStableId)) {
System.out.print("Study "+cancerStudyStableId+" updated.");
reCacheAll(System.currentTimeMillis());
}
return byStableId.containsKey(cancerStudyStableId);
}
Expand All @@ -397,8 +409,10 @@ public static boolean doesCancerStudyExistByStableId(String cancerStudyStableId)
* @return true if the CancerStudy exists, otherwise false
*/
public static boolean doesCancerStudyExistByInternalId(int internalCancerStudyId) {
if (studyNeedsRecaching(null, internalCancerStudyId)) {
reCacheAll();
if (GlobalProperties.getRecacheStudyAfterUpdate()
&& studyNeedsRecaching(null, internalCancerStudyId)) {
System.out.print("Study with internal ID of "+internalCancerStudyId+" updated.");
reCacheAll(System.currentTimeMillis());
}
return byInternalId.containsKey(internalCancerStudyId);
}
Expand All @@ -409,8 +423,10 @@ public static boolean doesCancerStudyExistByInternalId(int internalCancerStudyId
* @return ArrayList of all CancerStudy Objects.
*/
public static ArrayList<CancerStudy> getAllCancerStudies() {
if (cacheOutOfSyncWithDb()) {
reCacheAll();
if (GlobalProperties.getRecacheStudyAfterUpdate()
&& cacheOutOfSyncWithDb()) {
System.out.print("cache out of sync updated.");
reCacheAll(System.currentTimeMillis());
}
return new ArrayList<CancerStudy>(byStableId.values());
}
Expand All @@ -420,8 +436,10 @@ public static ArrayList<CancerStudy> getAllCancerStudies() {
* @return number of cancer studies.
*/
public static int getCount() {
if (cacheOutOfSyncWithDb()) {
reCacheAll();
if (GlobalProperties.getRecacheStudyAfterUpdate()
&& cacheOutOfSyncWithDb()) {
System.out.print("cache out of sync updated.");
reCacheAll(System.currentTimeMillis());
}
return byStableId.size();
}
Expand Down Expand Up @@ -535,7 +553,10 @@ static void deleteCancerStudy(int internalCancerStudyId) throws DaoException {
} finally {
JdbcUtil.closeAll(DaoCancerStudy.class, con, pstmt, rs);
}
reCacheAll();
System.out.print("delete a study "+internalCancerStudyId);
if (GlobalProperties.getRecacheStudyAfterUpdate()) {
reCacheAll(System.currentTimeMillis());
}
}

/**
Expand All @@ -556,30 +577,29 @@ private static CancerStudy extractCancerStudy(ResultSet rs) throws SQLException
return cancerStudy;
}

private static boolean studyNeedsRecaching(String stableId, Integer ... internalId)
{
if (cacheOutOfSyncWithDb()) {
return true;
}
try {
java.util.Date importDate = null;
java.util.Date cacheDate = null;
if (internalId.length > 0) {
importDate = getImportDate(null, internalId[0]);
cacheDate = cacheDateByInternalId.get(internalId[0]);
}
else {
if (stableId.equals(org.mskcc.cbio.portal.util.AccessControl.ALL_CANCER_STUDIES_ID)) {
return false;
}
importDate = getImportDate(stableId);
cacheDate = cacheDateByStableId.get(stableId);
}
return (importDate == null || cacheDate == null) ? true : cacheDate.before(importDate);
}
catch (ParseException e) {
return false;
}
private static boolean studyNeedsRecaching(String stableId, Integer ... internalId) {
if (cacheOutOfSyncWithDb()) {
return true;
}

try {
java.util.Date importDate = null;
java.util.Date cacheDate = null;
if (internalId.length > 0) {
importDate = getImportDate(null, internalId[0]);
cacheDate = cacheDateByInternalId.get(internalId[0]);
} else {
if (stableId.equals(org.mskcc.cbio.portal.util.AccessControl.ALL_CANCER_STUDIES_ID)) {
return false;
}
importDate = getImportDate(stableId);
cacheDate = cacheDateByStableId.get(stableId);
}

return (importDate == null || cacheDate == null) ? false : cacheDate.before(importDate);
} catch (ParseException e) {
return false;
}
catch (DaoException e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@
import org.mskcc.cbio.portal.model.*;
import org.mskcc.cbio.portal.util.InternalIdUtil;

import org.apache.commons.logging.*;
import org.apache.commons.lang.StringUtils;

import java.sql.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
* Data Access Object for `clinical` table
Expand All @@ -55,15 +53,11 @@ public final class DaoClinicalData {
private static final String SAMPLE_INSERT = "INSERT INTO " + SAMPLE_TABLE + "(`INTERAL_ID`,`ATTR_ID`,`ATTR_VALUE` VALUES(?,?,?)";
private static final String PATIENT_INSERT = "INSERT INTO " + PATIENT_TABLE + "(`INTERNAL_ID`,`ATTR_ID`,`ATTR_VALUE` VALUES(?,?,?)";

private static final Map<String, String> sampleAttributes = new ConcurrentHashMap<String, String>();
private static final Map<String, String> patientAttributes = new ConcurrentHashMap<String, String>();
private static final Map<String, String> sampleAttributes = new HashMap<String, String>();
private static final Map<String, String> patientAttributes = new HashMap<String, String>();

private DaoClinicalData() {}

static {
reCache();
}

public static synchronized void reCache()
{
clearCache();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

import java.sql.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
* Analogous to and replaces the old DaoCancerType. A CancerStudy has a NAME and
Expand All @@ -48,14 +47,10 @@
public final class DaoGeneticProfile {
private DaoGeneticProfile() {}

private static final Map<String,GeneticProfile> byStableId = new ConcurrentHashMap<String,GeneticProfile>();
private static final Map<Integer,GeneticProfile> byInternalId = new ConcurrentHashMap<Integer,GeneticProfile>();
private static final Map<Integer,List<GeneticProfile>> byStudy = new ConcurrentHashMap<Integer,List<GeneticProfile>>();

static {
reCache();
}

private static final Map<String,GeneticProfile> byStableId = new HashMap<String,GeneticProfile>();
private static final Map<Integer,GeneticProfile> byInternalId = new HashMap<Integer,GeneticProfile>();
private static final Map<Integer,List<GeneticProfile>> byStudy = new HashMap<Integer,List<GeneticProfile>>();

public static synchronized void reCache() {
byStableId.clear();
byInternalId.clear();
Expand Down
9 changes: 2 additions & 7 deletions core/src/main/java/org/mskcc/cbio/portal/dao/DaoPatient.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

import java.sql.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
* DAO to `patient`.
Expand All @@ -47,14 +46,10 @@
*/
public class DaoPatient {

private static final Map<Integer, Patient> byInternalId = new ConcurrentHashMap<Integer, Patient>();
private static final Map<Integer, Set<Patient>> byInternalCancerStudyId = new ConcurrentHashMap<Integer, Set<Patient>>();
private static final Map<Integer, Patient> byInternalId = new HashMap<Integer, Patient>();
private static final Map<Integer, Set<Patient>> byInternalCancerStudyId = new HashMap<Integer, Set<Patient>>();
private static final MultiKeyMap byCancerIdAndStablePatientId = new MultiKeyMap();

static {
reCache();
}

private static void clearCache()
{
byInternalId.clear();
Expand Down
10 changes: 3 additions & 7 deletions core/src/main/java/org/mskcc/cbio/portal/dao/DaoSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

import java.sql.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
* DAO to `sample`.
Expand All @@ -49,15 +48,11 @@ public class DaoSample {

private static final int MISSING_CANCER_STUDY_ID = -1;

private static final Map<String, Sample> byStableId = new ConcurrentHashMap<String, Sample>();
private static final Map<Integer, Sample> byInternalId = new ConcurrentHashMap<Integer, Sample>();
private static final Map<String, Sample> byStableId = new HashMap<String, Sample>();
private static final Map<Integer, Sample> byInternalId = new HashMap<Integer, Sample>();
private static final Map<Integer, Map<String, Sample>> byInternalPatientAndStableSampleId = new HashMap<Integer, Map<String, Sample>>();
private static final Map<Integer, Map<String, Sample>> byCancerStudyIdAndStableSampleId = new HashMap<Integer, Map<String, Sample>>();

static {
reCache();
}

private static void clearCache()
{
byStableId.clear();
Expand Down Expand Up @@ -204,6 +199,7 @@ public static Sample getSampleByCancerStudyAndSampleId(int cancerStudyId, String
{
Map<String, Sample> samples = byCancerStudyIdAndStableSampleId.get(cancerStudyId);
if (samples==null) {
System.err.println("Couldn't find sample "+stableSampleId+" in study "+cancerStudyId);
return null;
}

Expand Down
Loading

0 comments on commit e9a6aa5

Please sign in to comment.