/*
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.UUID;
import org.clothocore.api.core.Collector;
import org.clothocore.api.data.ObjBase;
import org.clothocad.hibernate.HibernateConnection;
/**
* SearchtagTable generated by hbm2java
*/
public class SearchtagTable implements java.io.Serializable {
/**
* JCA added: this is relayed from Datum classes during save to prune out old
* searchTags and put in new ones during each Datum's save method.
* @param datum
*/
public static void updateSearchTags(ObjBase obj) {
HashSet<String> existingTags = new HashSet<String>();
//Remove old searchTags
String aquery = "from SearchtagTable where objectId='" + obj.getUUID() + "'" ;
Iterator ixrefs = HibernateConnection.connection.query(aquery);
while (ixrefs.hasNext()) {
SearchtagTable cx = (SearchtagTable) ixrefs.next();
String tag = cx.getName();
existingTags.add(tag);
if(!obj.getSearchTags().contains(tag)) {
HibernateConnection.connection.deleteDatum(cx);
}
}
//Save all the new searchTags
for(String atag: obj.getSearchTags()) {
if(!existingTags.contains(atag)) {
String taglineid = UUID.randomUUID().toString();
PersonTable persontable = new PersonTable(Collector.getCurrentUser());
SearchtagTable stt = new SearchtagTable( taglineid, persontable, atag, obj.getUUID(), obj.getType().toString(), new Date(), new Date());
HibernateConnection.connection.saveDatum( stt );
}
}
}
/**
* JCA added: this is relayed from Datum classes during save to prune out old
* searchTags and put in new ones during each Datum's save method.
* @param datum
*/
public static void pullSearchTags(ObjBase obj) {
//Remove old searchTags
String aquery = "from SearchtagTable where objectId='" + obj.getUUID() + "'" ;
Iterator ixrefs = HibernateConnection.connection.query(aquery);
while (ixrefs.hasNext()) {
SearchtagTable cx = (SearchtagTable) ixrefs.next();
String tag = cx.getName();
obj.getSearchTags().add(tag);
}
}
/***** AUTO-GENERATED CODE *****/
private String idSearchtag;
private PersonTable personTable;
private String name;
private String objectId;
private String objectType;
private Date dateCreated;
private Date lastModified;
public SearchtagTable() {
}
public SearchtagTable(String idSearchtag) {
this.idSearchtag = idSearchtag;
}
public SearchtagTable(String idSearchtag, PersonTable personTable, String name, String objectId, String objectType, Date dateCreated, Date lastModified) {
this.idSearchtag = idSearchtag;
this.personTable = personTable;
this.name = name;
this.objectId = objectId;
this.objectType = objectType;
this.dateCreated = dateCreated;
this.lastModified = lastModified;
}
public String getIdSearchtag() {
return this.idSearchtag;
}
public void setIdSearchtag(String idSearchtag) {
this.idSearchtag = idSearchtag;
}
public PersonTable getPersonTable() {
return this.personTable;
}
public void setPersonTable(PersonTable personTable) {
this.personTable = personTable;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getObjectId() {
return this.objectId;
}
public void setObjectId(String objectId) {
this.objectId = objectId;
}
public String getObjectType() {
return this.objectType;
}
public void setObjectType(String objectType) {
this.objectType = objectType;
}
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;
}
}