From: <rv...@us...> - 2009-11-18 12:41:44
|
Revision: 280 http://treebase.svn.sourceforge.net/treebase/?rev=280&view=rev Author: rvos Date: 2009-11-18 12:41:37 +0000 (Wed, 18 Nov 2009) Log Message: ----------- Changed nexus file contents type from Clob (which we used under DB2) to Text (which we use under postgres), which is mapped onto a string by hibernate. Modified Paths: -------------- trunk/treebase-core/src/main/java/org/cipres/treebase/TreebaseUtil.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Study.java trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/StudyServiceImpl.java trunk/treebase-core/src/main/java/org/cipres/treebase/util/RawNexusImporter.java trunk/treebase-core/src/main/java/org/cipres/treebase/util/RebuildNexusFiletable.java trunk/treebase-core/src/main/java/org/cipres/treebase/util/RepatriateData.java trunk/treebase-core/src/test/java/org/cipres/treebase/dao/study/StudyDAOTest.java trunk/treebase-core/src/test/java/org/cipres/treebase/service/study/StudyServiceImplTest.java trunk/treebase-core/src/test/java/org/cipres/treebase/service/study/SubmissionServiceImplTest.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusFileController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/NexusFilesController.java Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/TreebaseUtil.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/TreebaseUtil.java 2009-11-18 12:25:46 UTC (rev 279) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/TreebaseUtil.java 2009-11-18 12:41:37 UTC (rev 280) @@ -1,6 +1,10 @@ package org.cipres.treebase; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Arrays; @@ -136,7 +140,42 @@ return buf.toString(); } + + /** + * Reads the contents of a file into a string + * @param file + * @return file contents as string + */ + public static String readFileToString(File file) { + StringBuilder contents = new StringBuilder(); + try { + //use buffering, reading one line at a time + //FileReader always assumes default encoding is OK! + BufferedReader input = new BufferedReader(new FileReader(file)); + try { + String line = null; //not declared within while loop + /* + * readLine is a bit quirky : + * it returns the content of a line MINUS the newline. + * it returns null only for the END of the stream. + * it returns an empty String if two newlines appear in a row. + */ + while (( line = input.readLine()) != null){ + contents.append(line); + contents.append(System.getProperty("line.separator")); + } + } + finally { + input.close(); + } + } + catch (IOException ex){ + ex.printStackTrace(); + } + return contents.toString(); + } + /** * For Testing use. Output the content of the array to a string. If the all element parameter is * false, output only the first 10 elements. Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Study.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Study.java 2009-11-18 12:25:46 UTC (rev 279) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Study.java 2009-11-18 12:41:37 UTC (rev 280) @@ -1,6 +1,5 @@ package org.cipres.treebase.domain.study; -import java.sql.Clob; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -72,7 +71,7 @@ private List<Analysis> mAnalyses = new ArrayList<Analysis>(); private Set<TaxonLabelSet> mTaxonLabelSets = new HashSet<TaxonLabelSet>(); - private Map<String, Clob> mNexusFiles = new HashMap<String, Clob>(); + private Map<String, String> mNexusFiles = new HashMap<String, String>(); // transient fields private String mTransientDescription; @@ -318,14 +317,14 @@ // @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN) // @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "studyCache") // @Transient - public Map<String, Clob> getNexusFiles() { + public Map<String, String> getNexusFiles() { return mNexusFiles; } /** * Set the NexusFiles field. */ - public void setNexusFiles(Map<String, Clob> pNewNexusFiles) { + public void setNexusFiles(Map<String, String> pNewNexusFiles) { mNexusFiles = pNewNexusFiles; } @@ -415,9 +414,9 @@ * Creation date: Feb 22, 2006 12:06:25 PM * * @param pFileName - * @param pNexusFile Clob + * @param pNexusFile */ - public void addNexusFile(String pFileName, Clob pNexusFile) { + public void addNexusFile(String pFileName, String pNexusFile) { if (TreebaseUtil.isEmpty(pFileName)) { if (pNexusFile == null) { return; Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/StudyServiceImpl.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/StudyServiceImpl.java 2009-11-18 12:25:46 UTC (rev 279) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/StudyServiceImpl.java 2009-11-18 12:41:37 UTC (rev 280) @@ -1,9 +1,11 @@ package org.cipres.treebase.service.study; +import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; +import java.io.IOException; import java.sql.Clob; import java.util.Collection; import java.util.Iterator; @@ -353,23 +355,11 @@ Study s = update(pStudy); Iterator<File> fileIter = pNexusFiles.iterator(); - try { - while (fileIter.hasNext()) { - File element = (File) fileIter.next(); - - String fileName = element.getName(); - FileReader reader; - reader = new FileReader(element); - - int fileLength = (int) (element.length()); - Clob nexus = Hibernate.createClob(reader, fileLength); - s.addNexusFile(fileName, nexus); - - } - } catch (FileNotFoundException ex) { - LOGGER.error(ex.getMessage()); + while (fileIter.hasNext()) { + File element = (File) fileIter.next(); + String fileName = element.getName(); + s.addNexusFile(fileName, TreebaseUtil.readFileToString(element)); } - } /** Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/util/RawNexusImporter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/util/RawNexusImporter.java 2009-11-18 12:25:46 UTC (rev 279) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/util/RawNexusImporter.java 2009-11-18 12:41:37 UTC (rev 280) @@ -15,6 +15,7 @@ import java.util.Set; import org.cipres.treebase.ContextManager; +import org.cipres.treebase.TreebaseUtil; import org.cipres.treebase.domain.matrix.Matrix; import org.cipres.treebase.domain.matrix.MatrixHome; import org.cipres.treebase.domain.study.Study; @@ -121,20 +122,8 @@ return false; } - Clob clob; - try { - clob = buildClob(file); - } catch (FileNotFoundException e) { - err.println(fileName + ": file not found"); - return false; - } catch (UnsupportedEncodingException e) { - throw e; - } catch (IOException e) { - err.println(fileName + ": I/O error; skipping"); - return false; - } - - if (clob == null) return false; + String fileContents = TreebaseUtil.readFileToString(file); + if (fileContents == null) return false; Set<Study> studies = new HashSet<Study> (); studies.addAll(handleMatricesInFile(file)); @@ -142,7 +131,7 @@ for (Study s : studies) { if (liveMode()) - s.getNexusFiles().put(fileName, clob); + s.getNexusFiles().put(fileName, fileContents); verbose("Study S" + s.getId() + " now linked to nexus file " + fileName); } return true; Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/util/RebuildNexusFiletable.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/util/RebuildNexusFiletable.java 2009-11-18 12:25:46 UTC (rev 279) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/util/RebuildNexusFiletable.java 2009-11-18 12:41:37 UTC (rev 280) @@ -23,7 +23,7 @@ for (TBPersistable obj : ContextManager.getStudyHome().findAll(Study.class)) { Study s = (Study) obj; - Map<String,Clob> studyNexusFile = s.getNexusFiles(); + Map<String,String> studyNexusFile = s.getNexusFiles(); for (String fileName : studyNexusFile.keySet()) { if (nexusFileStudy.containsKey(fileName)) { nexusFileStudy.remove(fileName); Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/util/RepatriateData.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/util/RepatriateData.java 2009-11-18 12:25:46 UTC (rev 279) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/util/RepatriateData.java 2009-11-18 12:41:37 UTC (rev 280) @@ -74,8 +74,8 @@ if (m.getStudy() != s) { String nexusFileName = m.getNexusFileName(); - Map<String,Clob> nexusMap = m.getStudy().getNexusFiles(); - Clob nexusFile = nexusMap.remove(nexusFileName); + Map<String,String> nexusMap = m.getStudy().getNexusFiles(); + String nexusFile = nexusMap.remove(nexusFileName); s.getNexusFiles().put(nexusFileName, nexusFile); m.setStudy(s); } @@ -93,8 +93,8 @@ + " to study " + s.getId() + " submission " + sub.getId()); if (t.getStudy() != s) { String nexusFileName = t.getNexusFileName(); - Map<String,Clob> nexusMap = t.getStudy().getNexusFiles(); - Clob nexusFile = nexusMap.remove(nexusFileName); + Map<String,String> nexusMap = t.getStudy().getNexusFiles(); + String nexusFile = nexusMap.remove(nexusFileName); s.getNexusFiles().put(nexusFileName, nexusFile); t.setStudy(s); } Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/dao/study/StudyDAOTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/dao/study/StudyDAOTest.java 2009-11-18 12:25:46 UTC (rev 279) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/dao/study/StudyDAOTest.java 2009-11-18 12:41:37 UTC (rev 280) @@ -243,8 +243,10 @@ + "f ctgactgctgaggagaaggctgccgtcaccgccttttggggcaaggtgaaagtggatgaagttggtggtgag gccctgggcaggctgctggttgtctacccctggactcagaggttctttgagtcctttggggacttgtccact gctgatgctgttatgaacaaccctaaggtgaaggcccatggcaagaaggtgctagattcctttagtaatggc atgaagcatctcgatgacctcaagggcacctttgctgcgctgagtgagctgcactgtgataagctgcatgtg gatcctgagaacttcaagctcctgggcaacgtgctagtggttgtgctggctcgcaattttggcaaggaattc accccggtgctgcaggctgactttcagaaggtggtggctggtgtggccaatgccctggcccacagatatcat\n" + "g ctgtccgatgcggtcaacgctgccgtcaccgccttttggggcaaggtgaaagtggatcaagttggtggtgag gccctgggcaggccgctggttgtctaccgctggactcagaggtgctatgagtcctttggagacttgtccact gctgatgctgttatgaacaaccctaaggtgaaggcccatggcaagaaggtgctagattcctttagtaatggc atgaagcatctcgatgacctcaagggcacctttgctgcgctgagtgagctgcactgtgataagctgcatgtg gatcctgagaacttcaagctcctgggcaacgtgctagtggttgtgctggctcgcaattttggcaaggaattc accccggtgctgcaggctgactttcagaaggtggtggctggtgtggccaatgccctggcccacagatatcat\n"; - Clob nexusC = Hibernate.createClob(nexus); - s.addNexusFile(fileName, nexusC); + //XXX rav 18/11/09 - we no longer use Clobs, we use text for nexus strings + //Clob nexusC = Hibernate.createClob(nexus); + //s.addNexusFile(fileName, nexusC); + s.addNexusFile(fileName, nexus); getFixture().store(s); Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/service/study/StudyServiceImplTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/service/study/StudyServiceImplTest.java 2009-11-18 12:25:46 UTC (rev 279) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/service/study/StudyServiceImplTest.java 2009-11-18 12:41:37 UTC (rev 280) @@ -362,10 +362,10 @@ + "f ctgactgctgaggagaaggctgccgtcaccgccttttggggcaaggtgaaagtggatgaagttggtggtgag gccctgggcaggctgctggttgtctacccctggactcagaggttctttgagtcctttggggacttgtccact gctgatgctgttatgaacaaccctaaggtgaaggcccatggcaagaaggtgctagattcctttagtaatggc atgaagcatctcgatgacctcaagggcacctttgctgcgctgagtgagctgcactgtgataagctgcatgtg gatcctgagaacttcaagctcctgggcaacgtgctagtggttgtgctggctcgcaattttggcaaggaattc accccggtgctgcaggctgactttcagaaggtggtggctggtgtggccaatgccctggcccacagatatcat\n" + "g ctgtccgatgcggtcaacgctgccgtcaccgccttttggggcaaggtgaaagtggatcaagttggtggtgag gccctgggcaggccgctggttgtctaccgctggactcagaggtgctatgagtcctttggagacttgtccact gctgatgctgttatgaacaaccctaaggtgaaggcccatggcaagaaggtgctagattcctttagtaatggc atgaagcatctcgatgacctcaagggcacctttgctgcgctgagtgagctgcactgtgataagctgcatgtg gatcctgagaacttcaagctcctgggcaacgtgctagtggttgtgctggctcgcaattttggcaaggaattc accccggtgctgcaggctgactttcagaaggtggtggctggtgtggccaatgccctggcccacagatatcat\n"; - Clob nexusC = Hibernate.createClob(nexus); + //Clob nexusC = Hibernate.createClob(nexus); getStudyHome().refresh(s); - s.addNexusFile(fileName, nexusC); + s.addNexusFile(fileName, nexus); // force commit immeidately, important: setComplete(); @@ -377,14 +377,14 @@ assertTrue(countNexus == 1); startNewTransaction(); - Clob nexusClob = s.getNexusFiles().values().iterator().next(); - int clobLength = (int) nexusClob.length(); + String nexusString = s.getNexusFiles().values().iterator().next(); + int nexusLength = (int) nexusString.length(); // String clobStr = nexusClob.getSubString(0, 200); - char[] clobchars = new char[clobLength]; - nexusClob.getCharacterStream().read(clobchars); - logger.info("test clob: length=" + clobLength + "content = " + new String(clobchars)); - assertTrue(clobLength > 0); + //char[] clobchars = new char[clobLength]; + //nexusClob.getCharacterStream().read(clobchars); + logger.info("test clob: length=" + nexusLength + "content = " + nexusString); + assertTrue(nexusLength > 0); setComplete(); endTransaction(); Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/service/study/SubmissionServiceImplTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/service/study/SubmissionServiceImplTest.java 2009-11-18 12:25:46 UTC (rev 279) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/service/study/SubmissionServiceImplTest.java 2009-11-18 12:41:37 UTC (rev 280) @@ -472,13 +472,10 @@ Study study2 = (Study) hibernateTemplate.load(Study.class, sub.getStudy().getId()); // hibernateTemplate.refresh(sub); - Clob nexusClob = study2.getNexusFiles().values().iterator().next(); - int clobLength = (int) nexusClob.length(); - char[] clobchars = new char[clobLength]; - nexusClob.getCharacterStream().read(clobchars); - String clobStr = new String(clobchars); - logger.info("test clob: length=" + clobLength + "content = " + clobStr); - assertTrue(clobLength > 0); + String nexusString = study2.getNexusFiles().values().iterator().next(); + int nexusStringLength = (int) nexusString.length(); + logger.info("test clob: length=" + nexusStringLength + "content = " + nexusString); + assertTrue(nexusStringLength > 0); // 4. delete: delete submission: // after add Nexus files, sub is outdated: @@ -569,13 +566,10 @@ // verify clob: hibernateTemplate.refresh(sub); - Clob nexusClob = sub.getStudy().getNexusFiles().values().iterator().next(); - int clobLength = (int) nexusClob.length(); - char[] clobchars = new char[clobLength]; - nexusClob.getCharacterStream().read(clobchars); - String clobStr = new String(clobchars); - logger.info("test clob: length=" + clobLength + "content = " + clobStr); - assertTrue(clobLength > 0); + String nexusString = sub.getStudy().getNexusFiles().values().iterator().next(); + int nexusStringLength = (int) nexusString.length(); + logger.info("test clob: length=" + nexusStringLength + "content = " + nexusString); + assertTrue(nexusStringLength > 0); // 4. delete: delete submission: // after add Nexus files, sub is outdated: Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusFileController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusFileController.java 2009-11-18 12:25:46 UTC (rev 279) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusFileController.java 2009-11-18 12:41:37 UTC (rev 280) @@ -135,20 +135,11 @@ return null; } Study study = ControllerUtil.findStudy(req, mStudyService); - Map<String, Clob> nexusMap = study.getNexusFiles(); - Clob clob = nexusMap.get(nexusFileName); - String clobStr = "File Not Found. File Name is: " + nexusFileName; - if (clob != null) { - try { - int clobLength = (int) clob.length(); - char[] clobchars = new char[clobLength]; - clob.getCharacterStream().read(clobchars); - clobStr = new String(clobchars); - } catch ( Exception e ) { - e.printStackTrace(); - } - } - return clobStr; + Map<String, String> nexusMap = study.getNexusFiles(); + String nexusString = nexusMap.get(nexusFileName); + return nexusString != null + ? nexusString + : "File Not Found. File Name is: " + nexusFileName; } } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/NexusFilesController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/NexusFilesController.java 2009-11-18 12:25:46 UTC (rev 279) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/NexusFilesController.java 2009-11-18 12:41:37 UTC (rev 280) @@ -51,7 +51,7 @@ throws Exception { Study study = ControllerUtil.findStudy(pRequest, mStudyService); - Map<String, Clob> nexusFilesMap = study.getNexusFiles(); + Map<String, String> nexusFilesMap = study.getNexusFiles(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("MAP SIZE IS: " + nexusFilesMap.size()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |