Skip to content

Commit 896f3d7

Browse files
committed
use autoincrement rather than dao.findLargest
1 parent 6f69e54 commit 896f3d7

8 files changed

Lines changed: 16 additions & 80 deletions

src/main/java/org/mskcc/cbio/portal/dao/DaoClinicalEvent.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,6 @@ private static ClinicalEvent extractClinicalEvent(ResultSet rs) throws SQLExcept
140140
return clinicalEvent;
141141
}
142142

143-
public static long getLargestClinicalEventId() throws DaoException {
144-
Connection con = null;
145-
PreparedStatement pstmt = null;
146-
ResultSet rs = null;
147-
try {
148-
con = JdbcUtil.getDbConnection(DaoClinicalEvent.class);
149-
pstmt = con.prepareStatement
150-
("SELECT max(`clinical_event_id`) FROM `clinical_event`");
151-
rs = pstmt.executeQuery();
152-
return rs.next() ? rs.getLong(1) : 0;
153-
} catch (SQLException e) {
154-
throw new DaoException(e);
155-
} finally {
156-
JdbcUtil.closeAll(DaoClinicalEvent.class, con, pstmt, rs);
157-
}
158-
}
159-
160143
/**
161144
*
162145
* @param cancerStudyId

src/main/java/org/mskcc/cbio/portal/dao/DaoCopyNumberSegment.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,6 @@ public static void createFractionGenomeAlteredClinicalData(int cancerStudyId, Se
140140
}
141141
}
142142

143-
public static long getLargestId() throws DaoException {
144-
Connection con = null;
145-
PreparedStatement pstmt = null;
146-
ResultSet rs = null;
147-
try {
148-
con = JdbcUtil.getDbConnection(DaoMutation.class);
149-
pstmt = con.prepareStatement
150-
("SELECT max(`seg_id`) FROM `copy_number_seg`");
151-
rs = pstmt.executeQuery();
152-
return rs.next() ? rs.getLong(1) : 0;
153-
} catch (SQLException e) {
154-
throw new DaoException(e);
155-
} finally {
156-
JdbcUtil.closeAll(DaoMutation.class, con, pstmt, rs);
157-
}
158-
}
159-
160143
public static List<CopyNumberSegment> getSegmentForASample(
161144
int sampleId, int cancerStudyId) throws DaoException {
162145
return getSegmentForSamples(Collections.singleton(sampleId),cancerStudyId);

src/main/java/org/mskcc/cbio/portal/dao/DaoMutation.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -650,22 +650,6 @@ public static Set<ExtendedMutation.MutationEvent> getAllMutationEvents() throws
650650
return events;
651651
}
652652

653-
public static long getLargestMutationEventId() throws DaoException {
654-
Connection con = null;
655-
PreparedStatement pstmt = null;
656-
ResultSet rs = null;
657-
try {
658-
con = JdbcUtil.getDbConnection(DaoMutation.class);
659-
pstmt = con.prepareStatement("SELECT max(`mutation_event_id`) FROM `mutation_event`");
660-
rs = pstmt.executeQuery();
661-
return rs.next() ? rs.getLong(1) : 0;
662-
} catch (SQLException e) {
663-
throw new DaoException(e);
664-
} finally {
665-
JdbcUtil.closeAll(DaoMutation.class, con, pstmt, rs);
666-
}
667-
}
668-
669653
private static ExtendedMutation extractMutation(ResultSet rs) throws SQLException, DaoException {
670654
try {
671655
ExtendedMutation mutation = new ExtendedMutation(extractMutationEvent(rs));

src/main/java/org/mskcc/cbio/portal/dao/DaoStructuralVariant.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,22 +179,6 @@ public static void deleteStructuralVariants(int geneticProfileId, Set<Integer> s
179179
}
180180
}
181181

182-
public static long getLargestInternalId() throws DaoException {
183-
Connection con = null;
184-
PreparedStatement pstmt = null;
185-
ResultSet rs = null;
186-
try {
187-
con = JdbcUtil.getDbConnection(DaoMutation.class);
188-
pstmt = con.prepareStatement("SELECT max(`internal_id`) FROM `structural_variant`");
189-
rs = pstmt.executeQuery();
190-
return rs.next() ? rs.getLong(1) : 0;
191-
} catch (SQLException e) {
192-
throw new DaoException(e);
193-
} finally {
194-
JdbcUtil.closeAll(DaoMutation.class, con, pstmt, rs);
195-
}
196-
}
197-
198182
/**
199183
* Return all structural variants in the database.
200184
* @return

src/main/java/org/mskcc/cbio/portal/scripts/ImportCopyNumberSegmentData.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.math.BigDecimal;
3737
import java.util.*;
3838
import joptsimple.OptionSet;
39+
import org.mskcc.cbio.portal.dao.ClickHouseAutoIncrement;
3940
import org.mskcc.cbio.portal.dao.ClickHouseBulkLoader;
4041
import org.mskcc.cbio.portal.dao.ClickHouseOptimizer;
4142
import org.mskcc.cbio.portal.dao.DaoCancerStudy;
@@ -63,12 +64,13 @@ public class ImportCopyNumberSegmentData extends ConsoleRunnable {
6364
private boolean isIncrementalUpdateMode;
6465
private Set<Integer> processedSampleIds;
6566

67+
private static final String COPY_NUMBER_SEG_SEQUENCE = "seq_copy_number_seg";
68+
6669
private void importData(File file, int cancerStudyId) throws IOException, DaoException {
6770
FileReader reader = new FileReader(file);
6871
BufferedReader buf = new BufferedReader(reader);
6972
try {
7073
String line = buf.readLine(); // skip header line
71-
long segId = DaoCopyNumberSegment.getLargestId();
7274
processedSampleIds = new HashSet<>();
7375
while ((line=buf.readLine()) != null) {
7476
ProgressMonitor.incrementCurValue();
@@ -107,7 +109,7 @@ private void importData(File file, int cancerStudyId) throws IOException, DaoExc
107109
}
108110
}
109111
CopyNumberSegment cns = new CopyNumberSegment(cancerStudyId, s.getInternalId(), chrom, start, end, numProbes, segMean);
110-
cns.setSegId(++segId);
112+
cns.setSegId(ClickHouseAutoIncrement.nextId(COPY_NUMBER_SEG_SEQUENCE)); // TODO : relocate this to dao code layer
111113
DaoCopyNumberSegment.addCopyNumberSegment(cns);
112114
processedSampleIds.add(s.getInternalId());
113115
}

src/main/java/org/mskcc/cbio/portal/scripts/ImportExtendedMutationData.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.commons.lang3.StringUtils;
3939
import org.mskcc.cbio.maf.MafRecord;
4040
import org.mskcc.cbio.maf.MafUtil;
41+
import org.mskcc.cbio.portal.dao.ClickHouseAutoIncrement;
4142
import org.mskcc.cbio.portal.dao.ClickHouseBulkLoader;
4243
import org.mskcc.cbio.portal.dao.DaoAlleleSpecificCopyNumber;
4344
import org.mskcc.cbio.portal.dao.DaoCancerStudy;
@@ -95,6 +96,8 @@ public class ImportExtendedMutationData {
9596

9697
private final boolean overwriteExisting;
9798

99+
private static final String MUTATION_EVENT_SEQUENCE = "seq_mutation_event";
100+
98101
/**
99102
* construct an ImportExtendedMutationData.
100103
* Filter mutations according to the no argument MutationFilter().
@@ -133,22 +136,16 @@ public void setSwissprotIsAccession(boolean swissprotIsAccession) {
133136

134137
public void importData() throws IOException, DaoException {
135138
ClickHouseBulkLoader.bulkLoadOn();
136-
137139
HashSet <String> sequencedCaseSet = new HashSet<String>();
138-
139140
Map<MutationEvent,MutationEvent> existingEvents = new HashMap<MutationEvent,MutationEvent>();
140141
ProgressMonitor.setCurrentMessage("Starting to load existing mutation events...");
141142
for(MutationEvent mutationEvent: DaoMutation.getAllMutationEvents()) {
142143
existingEvents.put(mutationEvent, mutationEvent);
143144
}
144145
ProgressMonitor.setCurrentMessage("Loaded " + existingEvents.size() + " existing mutation events.");
145146
Set<MutationEvent> newEvents = new HashSet<MutationEvent>();
146-
147147
Map<ExtendedMutation,ExtendedMutation> mutations = new HashMap<ExtendedMutation,ExtendedMutation>();
148-
long mutationEventId = DaoMutation.getLargestMutationEventId();
149-
150148
List<AlleleSpecificCopyNumber> ascnRecords = new ArrayList<AlleleSpecificCopyNumber>();
151-
152149
DaoGeneOptimized daoGene = DaoGeneOptimized.getInstance();
153150

154151
try (FileReader reader = new FileReader(mutationFile);
@@ -435,7 +432,7 @@ public void importData() throws IOException, DaoException {
435432
if (event!=null) {
436433
mutation.setEvent(event);
437434
} else {
438-
mutation.setMutationEventId(++mutationEventId);
435+
mutation.setMutationEventId(ClickHouseAutoIncrement.nextId(MUTATION_EVENT_SEQUENCE)); // TODO : relocate this to dao code layer
439436
existingEvents.put(mutation.getEvent(), mutation.getEvent());
440437
newEvents.add(mutation.getEvent());
441438
}

src/main/java/org/mskcc/cbio/portal/scripts/ImportStructuralVariantData.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.io.*;
2727
import java.util.*;
2828
import org.mskcc.cbio.maf.TabDelimitedFileUtil;
29+
import org.mskcc.cbio.portal.dao.ClickHouseAutoIncrement;
2930
import org.mskcc.cbio.portal.dao.ClickHouseBulkLoader;
3031
import org.mskcc.cbio.portal.dao.DaoException;
3132
import org.mskcc.cbio.portal.dao.DaoGeneOptimized;
@@ -59,6 +60,8 @@ public class ImportStructuralVariantData {
5960

6061
private final boolean isIncrementalUpdateMode;
6162

63+
private static final String STRUCTURAL_VARIANT_SEQUENCE = "seq_structural_variant";
64+
6265
public ImportStructuralVariantData(
6366
File structuralVariantFile,
6467
int geneticProfileId,
@@ -85,7 +88,6 @@ public void importData() throws IOException, DaoException {
8588
// Genetic profile is read in first
8689
GeneticProfile geneticProfile = DaoGeneticProfile.getGeneticProfileById(geneticProfileId);
8790
Set<Integer> sampleIds = new HashSet<>();
88-
long id = DaoStructuralVariant.getLargestInternalId();
8991
Set<String> uniqueSVs = new HashSet<>();
9092
while ((line = buf.readLine()) != null) {
9193
ProgressMonitor.incrementCurValue();
@@ -94,7 +96,7 @@ public void importData() throws IOException, DaoException {
9496
recordCount++;
9597
String parts[] = TsvUtil.splitTsvLine(line);
9698
StructuralVariant structuralVariant = structuralVariantUtil.parseStructuralVariantRecord(parts);
97-
structuralVariant.setInternalId(++id);
99+
structuralVariant.setInternalId(ClickHouseAutoIncrement.nextId(STRUCTURAL_VARIANT_SEQUENCE)); // TODO : relocate this to dao code layer
98100
structuralVariant.setGeneticProfileId(geneticProfileId);
99101
if (!structuralVariantUtil.hasRequiredStructuralVariantFields(structuralVariant)) {
100102
ProgressMonitor.logWarning(

src/main/java/org/mskcc/cbio/portal/scripts/ImportTimelineData.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.io.*;
3636
import java.util.*;
3737
import joptsimple.OptionSet;
38+
import org.mskcc.cbio.portal.dao.ClickHouseAutoIncrement;
3839
import org.mskcc.cbio.portal.dao.ClickHouseBulkLoader;
3940
import org.mskcc.cbio.portal.dao.DaoClinicalEvent;
4041
import org.mskcc.cbio.portal.dao.DaoException;
@@ -51,6 +52,8 @@
5152
*/
5253
public class ImportTimelineData extends ConsoleRunnable {
5354

55+
private static final String CLINICAL_EVENT_SEQUENCE = "seq_clinical_event";
56+
5457
private static void importData(String dataFile, int cancerStudyId, boolean overwriteExisting) throws IOException, DaoException {
5558
ClickHouseBulkLoader.bulkLoadOn();
5659

@@ -75,9 +78,7 @@ private static void importData(String dataFile, int cancerStudyId, boolean overw
7578
+ "PATIENT_ID\tSTART_DATE\tSTOP_DATE\tEVENT_TYPE");
7679
}
7780

78-
long clinicalEventId = DaoClinicalEvent.getLargestClinicalEventId();
7981
Set<Integer> processedPatientIds = new HashSet<>();
80-
8182
while ((line = buff.readLine()) != null) {
8283
line = line.trim();
8384

@@ -97,7 +98,7 @@ private static void importData(String dataFile, int cancerStudyId, boolean overw
9798
DaoClinicalEvent.deleteByPatientId(patient.getInternalId());
9899
}
99100
ClinicalEvent event = new ClinicalEvent();
100-
event.setClinicalEventId(++clinicalEventId);
101+
event.setClinicalEventId(ClickHouseAutoIncrement.nextId(CLINICAL_EVENT_SEQUENCE)); // TODO : relocate this to dao code layer
101102
event.setPatientId(patient.getInternalId());
102103
event.setStartDate(Long.valueOf(fields[1]));
103104
if (indexCategorySpecificField != 3 && !fields[2].isEmpty()) {

0 commit comments

Comments
 (0)