/* Copyright (c) 2009 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.. */ package org.clothocad.hibernate.data; // Generated Jun 1, 2010 8:47:54 PM by Hibernate Tools 3.2.1.GA import java.util.Date; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import org.clothocore.api.data.ObjBase; import org.clothocore.api.data.ObjBase.ObjBaseDatum; import org.clothocore.api.data.ObjType; import org.clothocore.api.data.OligoSample; import org.clothocore.api.data.OligoSample.OligoSampleDatum; import org.clothocore.api.data.PlasmidSample; import org.clothocore.api.data.PlasmidSample.PlasmidSampleDatum; import org.clothocore.api.data.Sample; import org.clothocore.api.data.Sample.SampleDatum; import org.clothocore.api.data.StrainSample; import org.clothocore.api.data.StrainSample.StrainSampleDatum; import org.clothocad.hibernate.hibernateDatum; import org.clothocad.hibernate.HibernateConnection; /** * SampleTable generated by hbm2java */ public class SampleTable implements java.io.Serializable, hibernateDatum { public static ObjType getType( Enum field ) { throw new UnsupportedOperationException( "Not yet implemented" ); } public SampleTable(Sample s) { this.idSample = s.getUUID(); this.dateCreated = s.getDateCreated(); this.lastModified = s.getLastModified(); this.dateLastUsed = s.getDateLastUsed(); this.volume = s.getVolume(); this.concentration = s.getConcentration(); this.quality = s.getQuality(); this.sampleType = s.getSampleType().toString(); this.name = s.getName(); if(s.getAuthor() != null) { this.personTable = new PersonTable(s.getAuthor().getUUID()); } if(s.getContainer() != null) { this.containerTable = new ContainerTable(s.getContainer().getUUID()); } Sample.sampleType type = s.getSampleType(); HashSet<String> existingLinks = new HashSet<String>(); String query = "from SampleDataXref where sampleId='" + idSample + "'" ; Iterator xrefs = HibernateConnection.connection.query(query); while (xrefs.hasNext()) { SampleDataXref cx = (SampleDataXref) xrefs.next(); String uuid = cx.getId().getSampleDataId(); existingLinks.add(uuid); if(!s.getDataLinks().contains(uuid)) { HibernateConnection.connection.deleteDatum(cx); } } //Save all the Xrefs for data for(String uuid: s.getDataLinks()) { if(!existingLinks.contains(uuid)) { SampleDataXrefId cxi = new SampleDataXrefId( idSample, uuid ); SampleDataXref cxr = new SampleDataXref(cxi, new SampleTable(idSample), new SampleDataTable(uuid)); sampleDataXrefs.add( cxr ); HibernateConnection.connection.saveDatum( cxr ); } } switch(type) { case PLASMID_SAMPLE: PlasmidSample ps = (PlasmidSample) s; if(ps.getPlasmid() != null) { this.plasmidTable = new PlasmidTable(ps.getPlasmid().getUUID()); } if(ps.getSourceStrain() != null) { this.strainTable = new StrainTable(ps.getSourceStrain().getUUID()); } break; case CELL_SAMPLE: StrainSample cs = (StrainSample) s; if(cs.getStrain() != null) { this.strainTable = new StrainTable(cs.getStrain().getUUID()); } break; case OLIGO_SAMPLE: OligoSample os = (OligoSample) s; if(os.getOligo() != null) { this.oligoTable = new OligoTable(os.getOligo().getUUID()); } break; default: break; } } @Override public ObjBase getObject() { Sample.sampleType type = Sample.sampleType.valueOf(sampleType); Sample.SampleDatum d = (SampleDatum) getObjBaseDatum(); switch(type) { case PLASMID_SAMPLE: return new PlasmidSample((PlasmidSampleDatum) d); case OLIGO_SAMPLE: return new OligoSample((OligoSampleDatum) d); case CELL_SAMPLE: return new StrainSample((StrainSampleDatum) d); default: return null; } } @Override public void runSecondaryProcessing(ObjBase obj) { } @Override public boolean needsSecondaryProcessing() { return false; } @Override public ObjBaseDatum getObjBaseDatum() { Sample.sampleType type = Sample.sampleType.valueOf(sampleType); Sample.SampleDatum d = null; switch(type) { case PLASMID_SAMPLE: PlasmidSample.PlasmidSampleDatum psd = new PlasmidSample.PlasmidSampleDatum(); psd._plasmidUUID = this.plasmidTable.getIdPlasmid(); psd._sourceStrainUUID = this.strainTable.getIdStrain(); d = psd; break; case OLIGO_SAMPLE: OligoSample.OligoSampleDatum osd = new OligoSample.OligoSampleDatum(); osd._oligoUUID = this.oligoTable.getIdOligo(); d = osd; break; case CELL_SAMPLE: StrainSample.StrainSampleDatum ssd = new StrainSample.StrainSampleDatum(); ssd._strainUUID = this.strainTable.getIdStrain(); d = ssd; break; default: return null; } d.uuid = this.idSample; d.name = name; d.dateCreated = dateCreated; d.lastModified = lastModified; d._authorUUID = this.personTable.getIdPerson(); d._concentration = this.concentration; d._containerUUID = this.containerTable.getIdContainer(); d._lastUsed = this.dateLastUsed; d._quality = this.quality; d._volume = this.volume; //d._parentSamples; Iterator<hibernateDatum> objs = this.sampleDataXrefs.iterator(); while (objs.hasNext()) { SampleDataXref cx = (SampleDataXref) objs.next(); String uuid = cx.getId().getSampleDataId(); d.sampleDataLinks.add(uuid); } return d; } @Override public String getUUID() { return idSample; } public static String translate( Enum field ) { if(field.getDeclaringClass() != Sample.Fields.class) { return null; } Sample.Fields f = (Sample.Fields) field; switch(f) { case NAME: return "name"; case DATE_CREATED: return "dateCreated"; case LAST_MODIFIED: return "lastModifed"; case CONCENTRATION: return "concentration"; case QUALITY: return "quality"; case VOLUME: return "volume"; case LAST_USED: return "dateLastUsed"; default: return null; } } /***** AUTO-GENERATED CODE *****/ private String idSample; private PersonTable personTable; private PlasmidTable plasmidTable; private OligoTable oligoTable; private StrainTable strainTable; private ContainerTable containerTable; private String name; private String sampleType; private Short quality; private Double concentration; private Double volume; private Date dateLastUsed; private Date dateCreated; private Date lastModified; private Set sampleDataXrefs = new HashSet(0); public SampleTable() { } public SampleTable(String idSample) { this.idSample = idSample; } public SampleTable(String idSample, String sampleType, PersonTable personTable, PlasmidTable plasmidTable, OligoTable oligoTable, StrainTable strainTable, ContainerTable containerTable, String name, Short quality, Double concentration, Double volume, Date dateLastUsed, Date dateCreated, Date lastModified, Set sampleDataXrefs) { this.idSample = idSample; this.personTable = personTable; this.plasmidTable = plasmidTable; this.oligoTable = oligoTable; this.strainTable = strainTable; this.containerTable = containerTable; this.name = name; this.sampleType = sampleType; this.quality = quality; this.concentration = concentration; this.volume = volume; this.dateLastUsed = dateLastUsed; this.dateCreated = dateCreated; this.lastModified = lastModified; this.sampleDataXrefs = sampleDataXrefs; } public String getIdSample() { return this.idSample; } public void setIdSample(String idSample) { this.idSample = idSample; } public PersonTable getPersonTable() { return this.personTable; } public void setPersonTable(PersonTable personTable) { this.personTable = personTable; } public PlasmidTable getPlasmidTable() { return this.plasmidTable; } public void setPlasmidTable(PlasmidTable plasmidTable) { this.plasmidTable = plasmidTable; } public OligoTable getOligoTable() { return this.oligoTable; } public void setOligoTable(OligoTable oligoTable) { this.oligoTable = oligoTable; } public StrainTable getStrainTable() { return this.strainTable; } public void setStrainTable(StrainTable strainTable) { this.strainTable = strainTable; } public ContainerTable getContainerTable() { return this.containerTable; } public void setContainerTable(ContainerTable containerTable) { this.containerTable = containerTable; } public String getSampleType() { return this.sampleType; } public void setSampleType(String name) { this.sampleType = name; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public Short getQuality() { return this.quality; } public void setQuality(Short quality) { this.quality = quality; } public Double getConcentration() { return this.concentration; } public void setConcentration(Double concentration) { this.concentration = concentration; } public Double getVolume() { return this.volume; } public void setVolume(Double volume) { this.volume = volume; } public Date getDateLastUsed() { return this.dateLastUsed; } public void setDateLastUsed(Date dateLastUsed) { this.dateLastUsed = dateLastUsed; } public Date getDateCreated() { return this.dateCreated; } public void setDateCreated(Date dateCreated) { this.dateCreated = dateCreated; } public Date getLastModified() { return this.lastModified; } public void setLastModified(Date lastModified) { this.lastModified = lastModified; } public Set getSampleDataXrefs() { return this.sampleDataXrefs; } public void setSampleDataXrefs(Set sampleDataXrefs) { this.sampleDataXrefs = sampleDataXrefs; } }