public UploadFileResult addNexusFilesJDBC(
Submission pSubmission,
Collection<File> pNexusFiles,
ProgressionListener pListener) {
UploadFileResult result = new UploadFileResult();
if (pSubmission == null) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("processNexusFiles() - Submission is null"); //$NON-NLS-1$
}
return result;
}
if (!checkFiles(pNexusFiles)) {
return result;
}
int fileCount = pNexusFiles.size();
int processedCount = 0;
long timeStart = System.currentTimeMillis();
int matrixCount = 0;
int treeCount = 0;
// Process one file at a time:
for (File file : pNexusFiles) {
long timeFile = System.currentTimeMillis();
NexusDataSet dataSet = null;
try {
// first start a transaction, use Hibernate to add and persist most of the data
dataSet = addNexusFile(pSubmission, file);
NexusDataSetJDBC dataJDBC = dataSet.getDataJDBC();
// Next use direct JDBC to batch insert data, for performance reason.
// getDomainHome().refreshAll(dataJDBC.getAllMatrices());
// TODO: create a new method:
Connection conn = getSubmissionHome().getConnection();
for (MatrixJDBC matrixJDBC : dataJDBC.getMatrixJDBCList()) {
matrixJDBC.batchInsertColumn(conn);
matrixJDBC.prepElementBatchInsert(conn);
matrixJDBC.processMatrixElements(conn);
// MesquiteMatrixConverter converter = matrixJDBC.getMesqMatrixConverter();
// converter.processMatrixElements(matrixJDBC, conn);
matrixJDBC.batchInsertCompoundElements(conn);
matrixCount ++;
}
treeCount += dataSet.getTotalTreeCount();
// ALERT: Do not use. will get connection closed exception!
// try {
// conn.close();
// } catch (SQLException ex) {
// throw new CleanupFailureDataAccessException("Failed to close connection.", ex);
// }
} finally {
// Dispose the mesquite project after all usage:
if (dataSet != null && dataSet.getMesqProject()!=null) dataSet.getMesqProject().dispose();
}
for (Matrix m : dataSet.getMatrices()) {
getMatrixHome().refresh(m);
m.setDimensions();
getMatrixHome().merge(m);
}
// TODO: if pListener is not null, launch a thread to do the parsing.
processedCount++;
if (pListener != null) {
pListener.updateProgress(processedCount, fileCount);
}
if (LOGGER.isDebugEnabled()) {
long timeFileEnd = System.currentTimeMillis();
LOGGER.debug("one file time=" + (timeFileEnd - timeFile) / 1000); //$NON-NLS-1$
}
}
// Third start a new transaction, use Hibernate to store the original nexus files.
Study study = pSubmission.getStudy();
getStudyService().addNexusFiles(study, pNexusFiles);
if (LOGGER.isDebugEnabled()) {
long timeEnd = System.currentTimeMillis();
LOGGER.debug("total time=" + (timeEnd - timeStart) / 1000); //$NON-NLS-1$
LOGGER.debug("total matrix=" + matrixCount + " treeCount =" + treeCount); //$NON-NLS-1$
}
result.setMatrixCount(matrixCount);
result.setTreeCount(treeCount);
return result;
}