/* 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.awt.Color; import java.util.Date; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import org.clothocore.api.data.Feature; import org.clothocore.api.data.Feature.FeatureDatum; import org.clothocore.api.data.ObjBase; import org.clothocore.api.data.ObjBase.ObjBaseDatum; import org.clothocore.api.data.ObjType; import org.clothocad.hibernate.hibernateDatum; import org.clothocad.hibernate.HibernateConnection; /** * FeatureTable generated by hbm2java */ public class FeatureTable implements java.io.Serializable, hibernateDatum { public static ObjType getType( Enum field ) { if ( field.getDeclaringClass() != Feature.Fields.class ) { return null; } Feature.Fields f = (Feature.Fields) field; switch ( f ) { case AUTHOR: return ObjType.PERSON; case SEQUENCE: return ObjType.NUCSEQ; case ANNOTATIONS: return ObjType.ANNOTATION; default: return null; } } public FeatureTable( Feature f ) { this.idFeature = f.getUUID(); this.name = f.getName(); this.dateCreated = f.getDateCreated(); this.lastModified = f.getLastModified(); this.riskGroup = (short) f.getRiskGroup(); this.genbankId = f.getGenbankId(); // this.swissprotId = f.getSwissProtId(); this field is no longer supported // this.pdbId = f.getPdbId(); this field is no longer supported this.isCds = f.isCDS(); if ( f.getForwardColor() != null ) { this.forColor = f.getForwardColor().getRGB(); } if ( f.getReverseColor() != null ) { this.revColor = f.getReverseColor().getRGB(); } if ( f.getAuthorUUID() != null ) { this.personTable = new PersonTable( f.getAuthorUUID() ); } if ( f.getSeq() != null ) { this.nucseqTable = new NucseqTable( f.getSeq().getUUID() ); } // this.featureData = f.getFeatureData(); this field is not implemented in current Clotho if(!f.isInDatabase()) { needsSecondaryProcessing = true; return; } HashSet<String> existingLinks = new HashSet<String>(); //Remove old Note:Feature links String query = "from FeatureNoteXref where featureId='" + idFeature + "'"; Iterator xrefs = HibernateConnection.connection.query( query ); while ( xrefs.hasNext() ) { FeatureNoteXref cx = (FeatureNoteXref) xrefs.next(); String uuid = cx.getId().getNoteId(); existingLinks.add( uuid ); if ( !f.getNoteLinks().contains( uuid ) ) { HibernateConnection.connection.deleteDatum( cx ); } } //Save all the new Xrefs for notes for ( String uuid : f.getNoteLinks() ) { if ( !existingLinks.contains( uuid ) ) { FeatureNoteXrefId cxi = new FeatureNoteXrefId( uuid, idFeature ); FeatureNoteXref cxr = new FeatureNoteXref( cxi, new FeatureTable( idFeature ), new NoteTable( uuid ) ); featureNoteXrefs.add( cxr ); HibernateConnection.connection.saveDatum( cxr ); } } existingLinks = new HashSet<String>(); //Remove old Family:Feature links query = "from FeatureFamilyXref where featureId='" + idFeature + "'"; xrefs = HibernateConnection.connection.query( query ); while ( xrefs.hasNext() ) { FeatureFamilyXref cx = (FeatureFamilyXref) xrefs.next(); String uuid = cx.getId().getFamilyId(); existingLinks.add( uuid ); if ( !f.getFamilyLinks().contains( uuid ) ) { HibernateConnection.connection.deleteDatum( cx ); } } //Save all the new Xrefs for familys for ( String uuid : f.getFamilyLinks() ) { if ( !existingLinks.contains( uuid ) ) { FeatureFamilyXrefId cxi = new FeatureFamilyXrefId( uuid, idFeature ); FeatureFamilyXref cxr = new FeatureFamilyXref( cxi, new FeatureTable( idFeature ), new FamilyTable( uuid ) ); featureFamilyXrefs.add( cxr ); HibernateConnection.connection.saveDatum( cxr ); } } } @Override public void runSecondaryProcessing(ObjBase obj) { Feature f = (Feature) obj; //Save all the new Xrefs for notes for ( String uuid : f.getNoteLinks() ) { FeatureNoteXrefId cxi = new FeatureNoteXrefId( uuid, idFeature ); FeatureNoteXref cxr = new FeatureNoteXref( cxi, new FeatureTable( idFeature ), new NoteTable( uuid ) ); featureNoteXrefs.add( cxr ); HibernateConnection.connection.saveDatum( cxr ); } //Save all the new Xrefs for familys for ( String uuid : f.getFamilyLinks() ) { FeatureFamilyXrefId cxi = new FeatureFamilyXrefId( uuid, idFeature ); FeatureFamilyXref cxr = new FeatureFamilyXref( cxi, new FeatureTable( idFeature ), new FamilyTable( uuid ) ); featureFamilyXrefs.add( cxr ); HibernateConnection.connection.saveDatum( cxr ); } needsSecondaryProcessing = false; } @Override public boolean needsSecondaryProcessing() { return needsSecondaryProcessing; } @Override public ObjBase getObject() { Feature.FeatureDatum d = (FeatureDatum) getObjBaseDatum(); Feature f = new Feature( d ); return f; } @Override public ObjBaseDatum getObjBaseDatum() { String authorUUID = null, nucSeqUUID = null; if ( personTable != null ) { authorUUID = personTable.getUUID(); } if ( nucseqTable != null ) { nucSeqUUID = nucseqTable.getUUID(); } //find all the note links HashSet<String> noteLinks = new HashSet<String>(); Iterator<hibernateDatum> objs = this.featureNoteXrefs.iterator(); while ( objs.hasNext() ) { FeatureNoteXref cx = (FeatureNoteXref) objs.next(); String uuid = cx.getId().getNoteId(); noteLinks.add( uuid ); } //find all the Family links HashSet<String> familyLinks = new HashSet<String>(); objs = this.featureFamilyXrefs.iterator(); while ( objs.hasNext() ) { FeatureFamilyXref cx = (FeatureFamilyXref) objs.next(); String uuid = cx.getId().getFamilyId(); familyLinks.add( uuid ); } Feature.FeatureDatum d = new Feature.FeatureDatum(); d.uuid = idFeature; d.name = name; d.dateCreated = dateCreated; d.lastModified = lastModified; d.forwardColor = new Color( forColor ); d.reverseColor = new Color( revColor ); d._riskGroup = riskGroup; d._GenbankId = genbankId; d._authorUUID = authorUUID; d._seqID = nucSeqUUID; d._noteLinks = noteLinks; d._familyLinks = familyLinks; if(isCds!=null) { d._isCDS = isCds; } else { d._isCDS = false; } return d; } @Override public String getUUID() { return idFeature; } public static String translate( Enum field ) { if ( field.getDeclaringClass() != Feature.Fields.class ) { return null; } Feature.Fields f = (Feature.Fields) field; switch ( f ) { case NAME: return "name"; case DATE_CREATED: return "dateCreated"; case LAST_MODIFIED: return "lastModifed"; case FORWARD_COLOR: return "forColor"; case REVERSE_COLOR: return "revColor"; case GENBANK_ID: return "genbankId"; case RISK_GROUP: return "riskGroup"; case DATA: return "featureData"; case AUTHOR: return "personTable"; case SEQUENCE: return "nucseqTable"; case ANNOTATIONS: return "nucseqAnnotations"; default: return null; } } private boolean needsSecondaryProcessing = false; /***** AUTO-GENERATED CODE *****/ private String idFeature; private PersonTable personTable; private NucseqTable nucseqTable; private String name; private Short riskGroup; private String genbankId; private String swissprotId; private String pdbId; private Integer forColor; private Integer revColor; private Date dateCreated; private Date lastModified; private String featureData; private Boolean isCds; private Set featureTraitXrefs = new HashSet(0); private Set featureFamilyXrefs = new HashSet(0); private Set nucseqAnnotations = new HashSet(0); private Set featureNoteXrefs = new HashSet(0); public FeatureTable() { } public FeatureTable(String idFeature) { this.idFeature = idFeature; } public FeatureTable(String idFeature, PersonTable personTable, NucseqTable nucseqTable, String name, Short riskGroup, String genbankId, String swissprotId, String pdbId, Integer forColor, Integer revColor, Date dateCreated, Date lastModified, String featureData, Boolean isCds, Set featureTraitXrefs, Set featureFamilyXrefs, Set nucseqAnnotations, Set featureNoteXrefs) { this.idFeature = idFeature; this.personTable = personTable; this.nucseqTable = nucseqTable; this.name = name; this.riskGroup = riskGroup; this.genbankId = genbankId; this.swissprotId = swissprotId; this.pdbId = pdbId; this.forColor = forColor; this.revColor = revColor; this.dateCreated = dateCreated; this.lastModified = lastModified; this.featureData = featureData; this.isCds = isCds; this.featureTraitXrefs = featureTraitXrefs; this.featureFamilyXrefs = featureFamilyXrefs; this.nucseqAnnotations = nucseqAnnotations; this.featureNoteXrefs = featureNoteXrefs; } public String getIdFeature() { return this.idFeature; } public void setIdFeature(String idFeature) { this.idFeature = idFeature; } public PersonTable getPersonTable() { return this.personTable; } public void setPersonTable(PersonTable personTable) { this.personTable = personTable; } public NucseqTable getNucseqTable() { return this.nucseqTable; } public void setNucseqTable(NucseqTable nucseqTable) { this.nucseqTable = nucseqTable; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public Short getRiskGroup() { return this.riskGroup; } public void setRiskGroup(Short riskGroup) { this.riskGroup = riskGroup; } public String getGenbankId() { return this.genbankId; } public void setGenbankId(String genbankId) { this.genbankId = genbankId; } public String getSwissprotId() { return this.swissprotId; } public void setSwissprotId(String swissprotId) { this.swissprotId = swissprotId; } public String getPdbId() { return this.pdbId; } public void setPdbId(String pdbId) { this.pdbId = pdbId; } public Integer getForColor() { return this.forColor; } public void setForColor(Integer forColor) { this.forColor = forColor; } public Integer getRevColor() { return this.revColor; } public void setRevColor(Integer revColor) { this.revColor = revColor; } 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 String getFeatureData() { return this.featureData; } public void setFeatureData(String featureData) { this.featureData = featureData; } public Boolean getIsCds() { return this.isCds; } public void setIsCds(Boolean isCds) { this.isCds = isCds; } public Set getFeatureTraitXrefs() { return this.featureTraitXrefs; } public void setFeatureTraitXrefs(Set featureTraitXrefs) { this.featureTraitXrefs = featureTraitXrefs; } public Set getFeatureFamilyXrefs() { return this.featureFamilyXrefs; } public void setFeatureFamilyXrefs(Set featureFamilyXrefs) { this.featureFamilyXrefs = featureFamilyXrefs; } public Set getNucseqAnnotations() { return this.nucseqAnnotations; } public void setNucseqAnnotations(Set nucseqAnnotations) { this.nucseqAnnotations = nucseqAnnotations; } public Set getFeatureNoteXrefs() { return this.featureNoteXrefs; } public void setFeatureNoteXrefs(Set featureNoteXrefs) { this.featureNoteXrefs = featureNoteXrefs; } }