/*
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.Hashtable;
import java.util.Iterator;
import java.util.Set;
import org.clothocore.api.data.Collection;
import org.clothocore.api.data.Collection.CollectionDatum;
import org.clothocore.api.data.ObjBase;
import org.clothocore.api.data.ObjType;
import org.clothocad.hibernate.hibernateDatum;
import org.clothocad.hibernate.HibernateConnection;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import org.clothocore.api.data.ObjBase.ObjBaseDatum;
/**
* CollectionTable generated by hbm2java
*/
public class CollectionTable implements java.io.Serializable, hibernateDatum {
public static ObjType getType( Enum field ) {
if ( field.getDeclaringClass() != Collection.Fields.class ) {
return null;
}
Collection.Fields f = (Collection.Fields) field;
switch ( f ) {
case AUTHOR:
return ObjType.PERSON;
default:
return null;
}
}
public CollectionTable( Collection c ) {
this.idCollection = c.getUUID();
this.name = c.getName();
this.description = c.getDescription();
this.personTable = new PersonTable( c.getAuthor().getUUID() );
this.dateCreated = c.getDateCreated();
this.lastModified = c.getLastModified();
HashSet<String> existingLinks = new HashSet<String>();
//Remove old CollectionXRef links
String query = "from Collectionxref where collectionId='" + idCollection + "'";
Iterator xrefs = HibernateConnection.connection.query( query );
while ( xrefs.hasNext() ) {
Collectionxref cx = (Collectionxref) xrefs.next();
String uuid = cx.getId().getObjectId();
existingLinks.add( uuid );
if ( !c.getUUIDTypeHash().containsKey( uuid ) ) {
HibernateConnection.connection.deleteDatum( cx );
}
}
//Save all the new Xrefs
for ( String uuid : c.getUUIDTypeHash().keySet() ) {
if ( !existingLinks.contains( uuid ) ) {
CollectionxrefId cxi = new CollectionxrefId( idCollection, uuid );
Collectionxref cxr = new Collectionxref( cxi, this, personTable, c.getUUIDTypeHash().get( uuid ).toString(), dateCreated, lastModified );
collectionXrefs.add( cxr );
HibernateConnection.connection.saveDatum( cxr );
}
}
}
@Override
public void runSecondaryProcessing(ObjBase obj) {
}
@Override
public boolean needsSecondaryProcessing() {
return false;
}
@Override
public ObjBase getObject() {
Collection.CollectionDatum d = (CollectionDatum) getObjBaseDatum();
Collection c = new Collection( d );
return c;
}
@Override
public ObjBaseDatum getObjBaseDatum() {
Hashtable<String, ObjType> uuidTypeHash = new Hashtable<String, ObjType>();
Hashtable<ObjType, HashSet<String>> typeUUIDHash = new Hashtable<ObjType, HashSet<String>>();
Iterator<hibernateDatum> objs = this.collectionXrefs.iterator();
while ( objs.hasNext() ) {
Collectionxref cx = (Collectionxref) objs.next();
String uuid = cx.getId().getObjectId();
ObjType type = ObjType.valueOf( cx.getObjectType() );
uuidTypeHash.put( uuid, type );
HashSet<String> listy;
if ( typeUUIDHash.containsKey( type ) ) {
listy = typeUUIDHash.get( type );
} else {
listy = new HashSet<String>();
typeUUIDHash.put( type, listy );
}
listy.add( uuid );
}
Collection.CollectionDatum d = new Collection.CollectionDatum();
d.uuid = idCollection;
d.name = name;
d._description = description;
d._authorUUID = personTable.getIdPerson();
d.uuidTypeHash = uuidTypeHash;
d.typeUUIDHash = typeUUIDHash;
d.dateCreated = dateCreated;
d.lastModified = lastModified;
return d;
}
public static String translate( Enum field ) {
if ( field.getDeclaringClass() != Collection.Fields.class ) {
return null;
}
Collection.Fields f = (Collection.Fields) field;
switch ( f ) {
case NAME:
return "name";
case DATE_CREATED:
return "dateCreated";
case LAST_MODIFIED:
return "lastModified";
case DESCRIPTION:
return "description";
case AUTHOR:
return "personTable";
default:
return null;
}
}
@Override
public String getUUID() {
return idCollection;
}
/***** AUTO-GENERATED CODE *****/
private String idCollection;
private PersonTable personTable;
private String name;
private String description;
private Date dateCreated;
private Date lastModified;
private Set personTables = new HashSet( 0 );
private Set collectionXrefs = new HashSet( 0 );
public CollectionTable() {
}
public CollectionTable( String idCollection ) {
this.idCollection = idCollection;
}
public CollectionTable( String idCollection, PersonTable personTable, String name, String description, Date dateCreated, Date lastModified, Set personTables, Set collectionXrefs ) {
this.idCollection = idCollection;
this.personTable = personTable;
this.name = name;
this.description = description;
this.dateCreated = dateCreated;
this.lastModified = lastModified;
this.personTables = personTables;
this.collectionXrefs = collectionXrefs;
}
public String getIdCollection() {
return this.idCollection;
}
public void setIdCollection( String idCollection ) {
this.idCollection = idCollection;
}
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 getDescription() {
return this.description;
}
public void setDescription( String description ) {
this.description = description;
}
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 getPersonTables() {
return this.personTables;
}
public void setPersonTables( Set personTables ) {
this.personTables = personTables;
}
public Set getCollectionXrefs() {
return this.collectionXrefs;
}
public void setCollectionXrefs( Set collectionXrefs ) {
this.collectionXrefs = collectionXrefs;
}
}