[Nmrshiftdb-devel] CVS: nmrshiftdb/src/java/org/openscience/nmrshiftdb Atoms.java,NONE,1.1 AtomsPeer
Brought to you by:
steinbeck
Update of /cvsroot/nmrshiftdb/nmrshiftdb/src/java/org/openscience/nmrshiftdb
In directory usw-pr-cvs1:/tmp/cvs-serv25278
Added Files:
Atoms.java AtomsPeer.java BaseAtoms.java BaseAtomsPeer.java
BaseBonds.java BaseBondsAtoms.java BaseBondsAtomsPeer.java
BaseBondsPeer.java BaseCanonicalName.java
BaseCanonicalNamePeer.java BaseChemicalName.java
BaseChemicalNamePeer.java BaseMeasurementConditions.java
BaseMeasurementConditionsPeer.java BaseMolecule.java
BaseMoleculePeer.java BaseMoleculeTurbineUser.java
BaseMoleculeTurbineUserPeer.java BaseSignal.java
BaseSignalAtoms.java BaseSignalAtomsPeer.java
BaseSignalPeer.java BaseSpectrum.java BaseSpectrumPeer.java
BaseSpectrumType.java BaseSpectrumTypePeer.java
BaseTurbineUser.java BaseTurbineUserPeer.java Bonds.java
BondsAtoms.java BondsAtomsPeer.java BondsPeer.java
CanonicalName.java CanonicalNamePeer.java ChemicalName.java
ChemicalNamePeer.java MeasurementConditions.java
MeasurementConditionsPeer.java Molecule.java MoleculePeer.java
MoleculeTurbineUser.java MoleculeTurbineUserPeer.java
Signal.java SignalAtoms.java SignalAtomsPeer.java
SignalPeer.java Spectrum.java SpectrumPeer.java
SpectrumType.java SpectrumTypePeer.java TurbineUser.java
TurbineUserPeer.java
Log Message:
added torque source files
--- NEW FILE: Atoms.java ---
package org.openscience.nmrshiftdb;
import org.apache.torque.om.Persistent;
/**
* The skeleton for this class was autogenerated by Torque on:
*
* [Wed Jan 30 20:42:04 CET 2002]
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*/
public class Atoms
extends org.openscience.nmrshiftdb.BaseAtoms
implements Persistent
{
}
--- NEW FILE: AtomsPeer.java ---
package org.openscience.nmrshiftdb;
import java.util.*;
import com.workingdogs.village.*;
import org.apache.torque.map.*;
import org.apache.torque.pool.DBConnection;
// Local classes
import org.openscience.nmrshiftdb.map.*;
/**
* The skeleton for this class was autogenerated by Torque on:
*
* [Wed Jan 30 20:42:04 CET 2002]
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*/
public class AtomsPeer
extends org.openscience.nmrshiftdb.BaseAtomsPeer
{
}
--- NEW FILE: BaseAtoms.java ---
package org.openscience.nmrshiftdb;
import java.util.*;
import java.math.*;
import org.apache.torque.Torque;
import org.apache.torque.om.*;
import org.apache.torque.util.BasePeer;
import org.apache.torque.util.Criteria;
import org.apache.torque.pool.DBConnection;
import org.apache.commons.util.ObjectUtils;
/**
* This class was autogenerated by Torque on:
*
* [Tue Feb 12 14:17:43 CET 2002]
*
* You should not use this class directly. It should not even be
* extended all references should be to Atoms
*/
public abstract class BaseAtoms extends BaseObject
{
/** The Peer class */
private static final AtomsPeer peer =
new AtomsPeer();
/**
* The value for the atoms_id field
*/
private NumberKey atoms_id;
/**
* The value for the symbol field
*/
private String symbol;
/**
* The value for the molecule_id field
*/
private NumberKey molecule_id;
/**
* Get the AtomsId
* @return NumberKey
*/
public NumberKey getAtomsId()
{
return atoms_id;
}
/**
* Set the value of AtomsId
*/
public void setAtomsId(NumberKey v ) throws Exception
{
if (v != null && v.getValue() == null)
{
// If this is an Objectkey than this set method is
// probably storing the id of this object or some
// associated object. If the objectKey value is null
// then we convert the parameter to null so that this
// property is consistently null to indicate that no
// object is associated or defined.
v = null;
}
// update associated SignalAtoms
if (collSignalAtomss != null )
{
for (int i=0; i<collSignalAtomss.size(); i++)
{
((SignalAtoms)collSignalAtomss.get(i))
.setAtomsId(v);
}
}
// update associated BondsAtoms
if (collBondsAtomss != null )
{
for (int i=0; i<collBondsAtomss.size(); i++)
{
((BondsAtoms)collBondsAtomss.get(i))
.setAtomsId(v);
}
}
if ( !ObjectUtils.equals(this.atoms_id, v) )
{
this.atoms_id = v;
setModified(true);
}
}
/**
* Set the value of AtomsId as a string.
*/
public void setAtomsId(String v ) throws Exception
{
setAtomsId(new NumberKey(v));
}
/**
* Get the Symbol
* @return String
*/
public String getSymbol()
{
return symbol;
}
/**
* Set the value of Symbol
*/
public void setSymbol(String v )
{
if ( !ObjectUtils.equals(this.symbol, v) )
{
this.symbol = v;
setModified(true);
}
}
/**
* Get the MoleculeId
* @return NumberKey
*/
public NumberKey getMoleculeId()
{
return molecule_id;
}
/**
* Set the value of MoleculeId
*/
public void setMoleculeId(NumberKey v ) throws Exception
{
if (v != null && v.getValue() == null)
{
// If this is an Objectkey than this set method is
// probably storing the id of this object or some
// associated object. If the objectKey value is null
// then we convert the parameter to null so that this
// property is consistently null to indicate that no
// object is associated or defined.
v = null;
}
aMolecule = null;
if ( !ObjectUtils.equals(this.molecule_id, v) )
{
this.molecule_id = v;
setModified(true);
}
}
/**
* Set the value of MoleculeId as a string.
*/
public void setMoleculeId(String v ) throws Exception
{
setMoleculeId(new NumberKey(v));
}
private Molecule aMolecule;
/**
* Declares an association between this object and a Molecule object
*
* @param Molecule v
*/
public void setMolecule(Molecule v) throws Exception
{
setMoleculeId(v.getMoleculeId());
aMolecule = v;
}
public Molecule getMolecule() throws Exception
{
if ( aMolecule==null && (!ObjectUtils.equals(this.molecule_id, null)) )
{
aMolecule = MoleculePeer.retrieveByPK(this.molecule_id);
/* The following can be used instead of the line above to
guarantee the related object contains a reference
to this object, but this level of coupling
may be undesirable in many circumstances.
As it can lead to a db query with many results that may
never be used.
Molecule obj = MoleculePeer.retrieveByPK(this.molecule_id);
obj.addAtomss(this);
*/
}
return aMolecule;
}
/**
* Provides convenient way to set a relationship based on a
* ObjectKey. e.g.
* <code>bar.setFooKey(foo.getPrimaryKey())</code>
*
*/
public void setMoleculeKey(ObjectKey key) throws Exception
{
setMoleculeId((NumberKey)key);
}
/**
* Collection to store aggregation of collSignalAtomss
*/
protected Vector collSignalAtomss;
/**
* Temporary storage of collSignalAtomss to save a possible db hit in
* the event objects are add to the collection, but the
* complete collection is never requested.
*/
protected void initSignalAtomss()
{
if (collSignalAtomss == null)
{
collSignalAtomss = new Vector();
}
}
/**
* Method called to associate a SignalAtoms object to this object
* through the SignalAtoms foreign key attribute
*
* @param SignalAtoms l
*/
public void addSignalAtoms(SignalAtoms l) throws Exception
{
getSignalAtomss().add(l);
l.setAtoms((Atoms)this);
}
/**
* The criteria used to select the current contents of collSignalAtomss
*/
private Criteria lastSignalAtomssCriteria = null;
/**
* If this collection has already been initialized, returns
* the collection. Otherwise returns the results of
* getSignalAtomss(new Criteria())
*/
public Vector getSignalAtomss() throws Exception
{
if (collSignalAtomss == null)
{
collSignalAtomss = getSignalAtomss(new Criteria(10));
}
return collSignalAtomss;
}
/**
* If this collection has already been initialized with
* an identical criteria, it returns the collection.
* Otherwise if this Atoms has previously
* been saved, it will retrieve related SignalAtomss from storage.
* If this Atoms is new, it will return
* an empty collection or the current collection, the criteria
* is ignored on a new object.
*/
public Vector getSignalAtomss(Criteria criteria) throws Exception
{
if (collSignalAtomss == null)
{
if ( isNew() )
{
collSignalAtomss = new Vector();
}
else
{
criteria.add(SignalAtomsPeer.ATOMS_ID, getAtomsId() );
collSignalAtomss = SignalAtomsPeer.doSelect(criteria);
}
}
else
{
// criteria has no effect for a new object
if ( !isNew() )
{
// the following code is to determine if a new query is
// called for. If the criteria is the same as the last
// one, just return the collection.
criteria.add(SignalAtomsPeer.ATOMS_ID, getAtomsId() );
if ( !lastSignalAtomssCriteria.equals(criteria) )
{
collSignalAtomss = SignalAtomsPeer.doSelect(criteria);
}
}
}
lastSignalAtomssCriteria = criteria;
return collSignalAtomss;
}
/**
* If this collection has already been initialized with
* an identical criteria, it returns the collection.
* Otherwise if this Atoms is new, it will return
* an empty collection; or if this Atoms has previously
* been saved, it will retrieve related SignalAtomss from storage.
*
* This method is protected by default in order to keep the public
* api reasonable. You can provide public methods for those you
* actually need in Atoms.
*/
protected Vector getSignalAtomssJoinSignal(Criteria criteria)
throws Exception
{
if (collSignalAtomss == null)
{
if ( isNew() )
{
collSignalAtomss = new Vector();
}
else
{
criteria.add(SignalAtomsPeer.ATOMS_ID, getAtomsId() );
collSignalAtomss = SignalAtomsPeer.doSelectJoinSignal(criteria);
}
}
else
{
// the following code is to determine if a new query is
// called for. If the criteria is the same as the last
// one, just return the collection.
boolean newCriteria = true;
criteria.add(SignalAtomsPeer.ATOMS_ID, getAtomsId() );
if ( !lastSignalAtomssCriteria.equals(criteria) )
{
collSignalAtomss = SignalAtomsPeer.doSelectJoinSignal(criteria);
}
}
lastSignalAtomssCriteria = criteria;
return collSignalAtomss;
}
/**
* Collection to store aggregation of collBondsAtomss
*/
protected Vector collBondsAtomss;
/**
* Temporary storage of collBondsAtomss to save a possible db hit in
* the event objects are add to the collection, but the
* complete collection is never requested.
*/
protected void initBondsAtomss()
{
if (collBondsAtomss == null)
{
collBondsAtomss = new Vector();
}
}
/**
* Method called to associate a BondsAtoms object to this object
* through the BondsAtoms foreign key attribute
*
* @param BondsAtoms l
*/
public void addBondsAtoms(BondsAtoms l) throws Exception
{
getBondsAtomss().add(l);
l.setAtoms((Atoms)this);
}
/**
* The criteria used to select the current contents of collBondsAtomss
*/
private Criteria lastBondsAtomssCriteria = null;
/**
* If this collection has already been initialized, returns
* the collection. Otherwise returns the results of
* getBondsAtomss(new Criteria())
*/
public Vector getBondsAtomss() throws Exception
{
if (collBondsAtomss == null)
{
collBondsAtomss = getBondsAtomss(new Criteria(10));
}
return collBondsAtomss;
}
/**
* If this collection has already been initialized with
* an identical criteria, it returns the collection.
* Otherwise if this Atoms has previously
* been saved, it will retrieve related BondsAtomss from storage.
* If this Atoms is new, it will return
* an empty collection or the current collection, the criteria
* is ignored on a new object.
*/
public Vector getBondsAtomss(Criteria criteria) throws Exception
{
if (collBondsAtomss == null)
{
if ( isNew() )
{
collBondsAtomss = new Vector();
}
else
{
criteria.add(BondsAtomsPeer.ATOMS_ID, getAtomsId() );
collBondsAtomss = BondsAtomsPeer.doSelect(criteria);
}
}
else
{
// criteria has no effect for a new object
if ( !isNew() )
{
// the following code is to determine if a new query is
// called for. If the criteria is the same as the last
// one, just return the collection.
criteria.add(BondsAtomsPeer.ATOMS_ID, getAtomsId() );
if ( !lastBondsAtomssCriteria.equals(criteria) )
{
collBondsAtomss = BondsAtomsPeer.doSelect(criteria);
}
}
}
lastBondsAtomssCriteria = criteria;
return collBondsAtomss;
}
/**
* If this collection has already been initialized with
* an identical criteria, it returns the collection.
* Otherwise if this Atoms is new, it will return
* an empty collection; or if this Atoms has previously
* been saved, it will retrieve related BondsAtomss from storage.
*
* This method is protected by default in order to keep the public
* api reasonable. You can provide public methods for those you
* actually need in Atoms.
*/
protected Vector getBondsAtomssJoinBonds(Criteria criteria)
throws Exception
{
if (collBondsAtomss == null)
{
if ( isNew() )
{
collBondsAtomss = new Vector();
}
else
{
criteria.add(BondsAtomsPeer.ATOMS_ID, getAtomsId() );
collBondsAtomss = BondsAtomsPeer.doSelectJoinBonds(criteria);
}
}
else
{
// the following code is to determine if a new query is
// called for. If the criteria is the same as the last
// one, just return the collection.
boolean newCriteria = true;
criteria.add(BondsAtomsPeer.ATOMS_ID, getAtomsId() );
if ( !lastBondsAtomssCriteria.equals(criteria) )
{
collBondsAtomss = BondsAtomsPeer.doSelectJoinBonds(criteria);
}
}
lastBondsAtomssCriteria = criteria;
return collBondsAtomss;
}
private static Vector fieldNames_ = null;
/**
* Generate a list of field names.
*/
public static synchronized List getFieldNames()
{
if (fieldNames_ == null)
{
fieldNames_ = new Vector();
fieldNames_.add("AtomsId");
fieldNames_.add("Symbol");
fieldNames_.add("MoleculeId");
}
return fieldNames_;
}
/**
* Retrieves a field from the object by name passed in
* as a String.
*/
public Object getByName(String name)
{
if (name.equals("AtomsId"))
{
return getAtomsId();
}
if (name.equals("Symbol"))
{
return getSymbol();
}
if (name.equals("MoleculeId"))
{
return getMoleculeId();
}
return null;
}
/**
* Retrieves a field from the object by name passed in
* as a String. The String must be one of the static
* Strings defined in this Class' Peer.
*/
public Object getByPeerName(String name)
{
if (name.equals(AtomsPeer.ATOMS_ID ))
{
return getAtomsId();
}
if (name.equals(AtomsPeer.SYMBOL ))
{
return getSymbol();
}
if (name.equals(AtomsPeer.MOLECULE_ID ))
{
return getMoleculeId();
}
return null;
}
/**
* Retrieves a field from the object by Position as specified
* in the xml schema. Zero-based.
*/
public Object getByPosition(int pos)
{
if ( pos == 0 )
{
return getAtomsId();
}
if ( pos == 1 )
{
return getSymbol();
}
if ( pos == 2 )
{
return getMoleculeId();
}
return null;
}
/**
* Stores the object in the database. If the object is new,
* it inserts it; otherwise an update is performed.
*/
public void save() throws Exception
{
save(AtomsPeer.getMapBuilder()
.getDatabaseMap().getName());
}
/**
* Stores the object in the database. If the object is new,
* it inserts it; otherwise an update is performed.
* Note: this code is here because the method body is
* auto-generated conditionally and therefore needs to be
* in this file instead of in the super class, BaseObject.
*/
public void save(String dbName) throws Exception
{
DBConnection dbCon = null;
try
{
dbCon = BasePeer.beginTransaction(dbName);
save(dbCon);
}
catch(Exception e)
{
BasePeer.rollBackTransaction(dbCon);
throw e;
}
BasePeer.commitTransaction(dbCon);
}
/** flag to prevent endless save loop, if this object is referenced
by another object which falls in this transaction. */
private boolean alreadyInSave = false;
/**
* Stores the object in the database. If the object is new,
* it inserts it; otherwise an update is performed. This method
* is meant to be used as part of a transaction, otherwise use
* the save() method and the connection details will be handled
* internally
*/
public void save(DBConnection dbCon) throws Exception
{
if (!alreadyInSave)
{
alreadyInSave = true;
// If this object has been modified, then save it to the database.
if (isModified())
{
if (isNew())
{
AtomsPeer.doInsert((Atoms)this, dbCon);
setNew(false);
}
else
{
AtomsPeer.doUpdate((Atoms)this, dbCon);
}
}
if (collSignalAtomss != null )
{
for (int i=0; i<collSignalAtomss.size(); i++)
{
((SignalAtoms)collSignalAtomss.get(i)).save(dbCon);
}
}
if (collBondsAtomss != null )
{
for (int i=0; i<collBondsAtomss.size(); i++)
{
((BondsAtoms)collBondsAtomss.get(i)).save(dbCon);
}
}
alreadyInSave = false;
}
}
/**
* Set the PrimaryKey using ObjectKey.
*
* @param ObjectKey atoms_id
*/
public void setPrimaryKey(ObjectKey atoms_id)
throws Exception {
setAtomsId((NumberKey)atoms_id);
}
/**
* Set the PrimaryKey using a String.
*/
public void setPrimaryKey(String key) throws Exception
{
setAtomsId(new NumberKey(key) );
}
/**
* returns an id that differentiates this object from others
* of its class.
*/
public ObjectKey getPrimaryKey()
{
return getAtomsId();
}
/**
* Makes a copy of this object.
* It creates a new object filling in the simple attributes.
* It then fills all the association collections and sets the
* related objects to isNew=true.
*/
public Atoms copy() throws Exception
{
Atoms copyObj = new Atoms();
copyObj.setAtomsId(atoms_id);
copyObj.setSymbol(symbol);
copyObj.setMoleculeId(molecule_id);
copyObj.setNew(false);
List v = getSignalAtomss();
for (int i=0; i<v.size(); i++)
{
SignalAtoms obj = (SignalAtoms) v.get(i);
copyObj.addSignalAtoms(obj.copy());
((Persistent)v.get(i)).setNew(true);
}
v = getBondsAtomss();
for (int i=0; i<v.size(); i++)
{
BondsAtoms obj = (BondsAtoms) v.get(i);
copyObj.addBondsAtoms(obj.copy());
((Persistent)v.get(i)).setNew(true);
}
copyObj.setNew(true);
copyObj.setAtomsId((NumberKey)null);
return copyObj;
}
/**
* returns a peer instance associated with this om. Since Peer classes
* are not to have any instance attributes, this method returns the
* same instance for all member of this class. The method could therefore
* be static, but this would prevent one from overriding the behavior.
*/
public AtomsPeer getPeer()
{
return peer;
}
}
--- NEW FILE: BaseAtomsPeer.java ---
package org.openscience.nmrshiftdb;
import java.util.*;
import java.math.*;
import java.sql.*;
import com.workingdogs.village.*;
import org.apache.torque.Torque;
import org.apache.torque.util.BasePeer;
import org.apache.torque.om.*;
import org.apache.torque.util.*;
import org.apache.torque.map.*;
import org.apache.torque.pool.DBConnection;
import org.apache.torque.TorqueException;
// Local classes
import org.openscience.nmrshiftdb.map.*;
/**
* This class was autogenerated by Torque on:
*
* [Tue Feb 12 14:17:43 CET 2002]
*
*/
public abstract class BaseAtomsPeer
extends BasePeer
{
/** the default database name for this class */
public static final String DATABASE_NAME = "nmrshiftdb";
/** the table name for this class */
public static final String TABLE_NAME = "ATOMS";
/**
* @returns the map builder for this peer
*/
public static MapBuilder getMapBuilder()
throws Exception
{
return getMapBuilder(AtomsMapBuilder.CLASS_NAME);
}
/** the column name for the ATOMS_ID field */
public static final String ATOMS_ID;
/** the column name for the SYMBOL field */
public static final String SYMBOL;
/** the column name for the MOLECULE_ID field */
public static final String MOLECULE_ID;
static
{
ATOMS_ID = "ATOMS.ATOMS_ID";
SYMBOL = "ATOMS.SYMBOL";
MOLECULE_ID = "ATOMS.MOLECULE_ID";
if (Torque.isInit())
{
try
{
getMapBuilder();
}
catch (Exception e)
{
category.error("Could not initialize Peer", e);
}
}
else
{
Torque.registerMapBuilder(AtomsMapBuilder.CLASS_NAME);
}
}
/** number of columns for this peer */
public static final int numColumns = 3;
/** A class that can be returned by this peer. */
protected static final String CLASSNAME_DEFAULT =
"org.openscience.nmrshiftdb.Atoms";
/** A class that can be returned by this peer. */
protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
/** Class object initialization method. */
private static Class initClass(String className)
{
Class c = null;
try
{
c = Class.forName(className);
}
catch (Throwable t)
{
category.error("A FATAL ERROR has occurred which should not " +
"have happened under any circumstance. Please notify " +
"the Turbine developers <tur...@ja...> " +
"and give as many details as possible (including the error " +
"stack trace).", t);
// Error objects should always be propogated.
if (t instanceof Error)
{
throw (Error) t.fillInStackTrace();
}
}
return c;
}
/**
* Get the list of objects for a ResultSet. Please not that your
* resultset MUST return columns in the right order. You can use
* getFieldNames() in BaseObject to get the correct sequence.
*/
public static Vector resultSet2Objects (java.sql.ResultSet results) throws Exception
{
QueryDataSet qds = null;
Vector rows = null;
try
{
qds = new QueryDataSet( results );
rows = getSelectResults( qds );
}
finally
{
if (qds != null) qds.close();
}
return populateObjects (rows);
}
/**
* Method to do inserts
*/
public static ObjectKey doInsert( Criteria criteria ) throws Exception
{
return BaseAtomsPeer
.doInsert( criteria, (DBConnection) null );
}
/**
* Method to do inserts. This method is to be used during a transaction,
* otherwise use the doInsert(Criteria) method. It will take care of
* the connection details internally.
*/
public static ObjectKey doInsert( Criteria criteria, DBConnection dbCon )
throws Exception
{
if ( dbCon == null )
{
// Set the correct dbName if it has not been overridden
// criteria.getDbName will return the same object if not set to
// another value so == check is okay and faster
if ( criteria.getDbName() == Torque.getDefaultDB() )
{
criteria.setDbName(DATABASE_NAME);
}
return BasePeer.doInsert( criteria );
}
else
{
return BasePeer.doInsert( criteria, dbCon );
}
}
/** Add all the columns needed to create a new object */
public static void addSelectColumns (Criteria criteria) throws Exception
{
criteria.addSelectColumn( ATOMS_ID );
criteria.addSelectColumn( SYMBOL );
criteria.addSelectColumn( MOLECULE_ID );
}
/**
* Create a new object of type cls from a resultset row starting
* from a specified offset. This is done so that you can select
* other rows than just those needed for this object. You may
* for example want to create two objects from the same row.
*/
public static Atoms row2Object (Record row,
int offset,
Class cls )
throws Exception
{
Atoms obj = (Atoms)cls.newInstance();
populateObject(row, offset, obj);
obj.setModified(false);
obj.setNew(false);
return obj;
}
/**
* Populates an object from a resultset row starting
* from a specified offset. This is done so that you can select
* other rows than just those needed for this object. You may
* for example want to create two objects from the same row.
*/
public static void populateObject (Record row,
int offset,
Atoms obj )
throws Exception
{
obj.setAtomsId(
new NumberKey(row.getValue(offset+0).asBigDecimal()));
obj.setSymbol(row.getValue(offset+1).asString());
obj.setMoleculeId(
new NumberKey(row.getValue(offset+2).asBigDecimal()));
}
/** Method to do selects */
public static Vector doSelect( Criteria criteria ) throws Exception
{
return populateObjects( doSelectVillageRecords(criteria) );
}
/** Method to do selects within a transaction */
public static Vector doSelect( Criteria criteria,
DBConnection dbCon )
throws Exception
{
return populateObjects( doSelectVillageRecords(criteria, dbCon) );
}
/**
* Grabs the raw Village records to be formed into objects.
* This method handles connections internally. The Record objects
* returned by this method should be considered readonly. Do not
* alter the data and call save(), your results may vary, but are
* certainly likely to result in hard to track MT bugs.
*/
public static Vector doSelectVillageRecords( Criteria criteria )
throws Exception
{
return BaseAtomsPeer
.doSelectVillageRecords(criteria, (DBConnection) null);
}
/**
* Grabs the raw Village records to be formed into objects.
* This method should be used for transactions
*/
public static Vector doSelectVillageRecords( Criteria criteria,
DBConnection dbCon )
throws Exception
{
if (criteria.getSelectColumns().size() == 0)
{
addSelectColumns ( criteria );
}
// BasePeer returns a Vector of Value (Village) arrays. The array
// order follows the order columns were placed in the Select clause.
if ( dbCon == null)
{
// Set the correct dbName if it has not been overridden
// criteria.getDbName will return the same object if not set to
// another value so == check is okay and faster
if ( criteria.getDbName() == Torque.getDefaultDB() )
{
criteria.setDbName(DATABASE_NAME);
}
return BasePeer.doSelect(criteria);
}
else
{
return BasePeer.doSelect(criteria, dbCon);
}
}
/**
* The returned vector will contain objects of the default type or
* objects that inherit from the default.
*/
public static Vector populateObjects(Vector records)
throws Exception
{
Vector results = new Vector(records.size());
// populate the object(s)
for ( int i=0; i<records.size(); i++ )
{
Record row = (Record)records.elementAt(i);
results.add(AtomsPeer.row2Object(row, 1,
AtomsPeer.getOMClass()));
}
return results;
}
/**
* The class that the Peer will make instances of.
* If the BO is abstract then you must implement this method
* in the BO.
*/
public static Class getOMClass()
throws Exception
{
return CLASS_DEFAULT;
}
/**
* Method to do updates.
*
* @param Criteria object containing data that is used to create the UPDATE statement.
*/
public static void doUpdate(Criteria criteria) throws Exception
{
BaseAtomsPeer
.doUpdate( criteria, (DBConnection) null );
}
/**
* Method to do updates. This method is to be used during a transaction,
* otherwise use the doUpdate(Criteria) method. It will take care of
* the connection details internally.
*
* @param Criteria object containing data that is used to create the UPDATE statement.
*/
public static void doUpdate(Criteria criteria, DBConnection dbCon) throws Exception
{
Criteria selectCriteria = new
Criteria(DATABASE_NAME, 2);
selectCriteria.put( ATOMS_ID, criteria.remove(ATOMS_ID) );
if ( dbCon == null )
{
// Set the correct dbName if it has not been overridden
// criteria.getDbName will return the same object if not set to
// another value so == check is okay and faster
if ( criteria.getDbName() == Torque.getDefaultDB() )
{
criteria.setDbName(DATABASE_NAME);
}
BasePeer.doUpdate( selectCriteria, criteria );
}
else
{
BasePeer.doUpdate( selectCriteria, criteria, dbCon );
}
}
/**
* Method to do deletes.
*
* @param Criteria object containing data that is used DELETE from database.
*/
public static void doDelete(Criteria criteria) throws Exception
{
BaseAtomsPeer
.doDelete ( criteria, (DBConnection) null );
}
/**
* Method to do deletes. This method is to be used during a transaction,
* otherwise use the doDelete(Criteria) method. It will take care of
* the connection details internally.
*
* @param Criteria object containing data that is used DELETE from database.
*/
public static void doDelete(Criteria criteria, DBConnection dbCon)
throws Exception
{
if ( dbCon == null )
{
// Set the correct dbName if it has not been overridden
// criteria.getDbName will return the same object if not set to
// another value so == check is okay and faster
if ( criteria.getDbName() == Torque.getDefaultDB() )
{
criteria.setDbName(DATABASE_NAME);
}
BasePeer.doDelete ( criteria );
}
else
{
BasePeer.doDelete ( criteria, dbCon );
}
}
/** Method to do selects */
public static Vector doSelect(Atoms obj) throws Exception
{
return doSelect(buildCriteria(obj));
}
/** Method to do inserts */
public static void doInsert( Atoms obj ) throws Exception
{
obj.setPrimaryKey(doInsert(buildCriteria(obj)));
obj.setNew(false);
obj.setModified(false);
}
/**
* @param obj the data object to update in the database.
*/
public static void doUpdate(Atoms obj) throws Exception
{
doUpdate(buildCriteria(obj));
}
/**
* @param obj the data object to delete in the database.
*/
public static void doDelete(Atoms obj) throws Exception
{
doDelete(buildCriteria(obj));
}
/**
* Method to do inserts. This method is to be used during a transaction,
* otherwise use the doInsert(Atoms) method. It will take
* care of the connection details internally.
*
* @param obj the data object to insert into the database.
*/
public static void doInsert( Atoms obj, DBConnection dbCon)
throws Exception
{
obj.setPrimaryKey(doInsert(buildCriteria(obj), dbCon));
obj.setNew(false);
obj.setModified(false);
}
/**
* Method to do update. This method is to be used during a transaction,
* otherwise use the doUpdate(Atoms) method. It will take
* care of the connection details internally.
*
* @param obj the data object to update in the database.
*/
public static void doUpdate(Atoms obj, DBConnection dbCon)
throws Exception
{
doUpdate(buildCriteria(obj), dbCon);
}
/**
* Method to delete. This method is to be used during a transaction,
* otherwise use the doDelete(Atoms) method. It will take
* care of the connection details internally.
*
* @param obj the data object to delete in the database.
*/
public static void doDelete(Atoms obj, DBConnection dbCon)
throws Exception
{
doDelete(buildCriteria(obj), dbCon);
}
/** Build a Criteria object from the data object for this peer */
public static Criteria buildCriteria( Atoms obj )
{
Criteria criteria = new Criteria();
if ( !obj.isNew() )
criteria.add( ATOMS_ID, obj.getAtomsId() );
criteria.add( SYMBOL, obj.getSymbol() );
criteria.add( MOLECULE_ID, obj.getMoleculeId() );
return criteria;
}
/**
* Retrieve a single object by pk
*
* @param ObjectKey pk
*/
public static Atoms retrieveByPK( ObjectKey pk )
throws Exception
{
DBConnection db = null;
Atoms retVal = null;
try
{
db = Torque.getConnection( DATABASE_NAME );
retVal = retrieveByPK( pk, db );
}
finally
{
if (db != null)
Torque.releaseConnection(db);
}
return(retVal);
}
/**
* Retrieve a single object by pk
*
* @param ObjectKey pk
* @param DBConnection dbcon
*/
public static Atoms retrieveByPK( ObjectKey pk, DBConnection dbcon )
throws Exception
{
Criteria criteria = new Criteria();
criteria.add( ATOMS_ID, pk );
Vector v = doSelect(criteria, dbcon);
if ( v.size() != 1)
{
throw new Exception("Failed to select one and only one row.");
}
else
{
return (Atoms)v.firstElement();
}
}
/**
* selects a collection of Atoms objects pre-filled with their
* Molecule objects.
*
* This method is protected by default in order to keep the public
* api reasonable. You can provide public methods for those you
* actually need in AtomsPeer.
*/
protected static Vector doSelectJoinMolecule(Criteria c)
throws Exception
{
// Set the correct dbName if it has not been overridden
// c.getDbName will return the same object if not set to
// another value so == check is okay and faster
if ( c.getDbName() == Torque.getDefaultDB() )
{
c.setDbName(DATABASE_NAME);
}
AtomsPeer.addSelectColumns(c);
int offset = numColumns + 1;
MoleculePeer.addSelectColumns(c);
c.addJoin(AtomsPeer.MOLECULE_ID,
MoleculePeer.MOLECULE_ID);
Vector rows = BasePeer.doSelect(c);
Vector results = new Vector();
for (int i=0; i<rows.size(); i++)
{
Record row = (Record)rows.elementAt(i);
Class omClass = AtomsPeer.getOMClass();
Atoms obj1 = (Atoms)AtomsPeer
.row2Object( row, 1, omClass);
omClass = MoleculePeer.getOMClass();
Molecule obj2 = (Molecule)MoleculePeer
.row2Object(row, offset, omClass);
boolean newObject = true;
for (int j=0; j<results.size(); j++)
{
Atoms temp_obj1 = (Atoms)results.elementAt(j);
Molecule temp_obj2 = temp_obj1.getMolecule();
if ( temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey() ) )
{
newObject = false;
temp_obj2.addAtoms(obj1);
break;
}
}
if (newObject)
{
obj2.initAtomss();
obj2.addAtoms(obj1);
}
results.add(obj1);
}
return results;
}
/**
* Returns the TableMap related to this peer. This method is not
* needed for general use but a specific application could have a
* need.
*/
protected static TableMap getTableMap()
throws Exception
{
return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
}
}
--- NEW FILE: BaseBonds.java ---
package org.openscience.nmrshiftdb;
import java.util.*;
import java.math.*;
import org.apache.torque.Torque;
import org.apache.torque.om.*;
import org.apache.torque.util.BasePeer;
import org.apache.torque.util.Criteria;
import org.apache.torque.pool.DBConnection;
import org.apache.commons.util.ObjectUtils;
/**
* This class was autogenerated by Torque on:
*
* [Tue Feb 12 14:17:43 CET 2002]
*
* You should not use this class directly. It should not even be
* extended all references should be to Bonds
*/
public abstract class BaseBonds extends BaseObject
{
/** The Peer class */
private static final BondsPeer peer =
new BondsPeer();
/**
* The value for the bonds_id field
*/
private NumberKey bonds_id;
/**
* The value for the degree field
*/
private int degree;
/**
* The value for the molecule_id field
*/
private NumberKey molecule_id;
/**
* Get the BondsId
* @return NumberKey
*/
public NumberKey getBondsId()
{
return bonds_id;
}
/**
* Set the value of BondsId
*/
public void setBondsId(NumberKey v ) throws Exception
{
if (v != null && v.getValue() == null)
{
// If this is an Objectkey than this set method is
// probably storing the id of this object or some
// associated object. If the objectKey value is null
// then we convert the parameter to null so that this
// property is consistently null to indicate that no
// object is associated or defined.
v = null;
}
// update associated BondsAtoms
if (collBondsAtomss != null )
{
for (int i=0; i<collBondsAtomss.size(); i++)
{
((BondsAtoms)collBondsAtomss.get(i))
.setBondsId(v);
}
}
if ( !ObjectUtils.equals(this.bonds_id, v) )
{
this.bonds_id = v;
setModified(true);
}
}
/**
* Set the value of BondsId as a string.
*/
public void setBondsId(String v ) throws Exception
{
setBondsId(new NumberKey(v));
}
/**
* Get the Degree
* @return int
*/
public int getDegree()
{
return degree;
}
/**
* Set the value of Degree
*/
public void setDegree(int v )
{
if (this.degree != v)
{
this.degree = v;
setModified(true);
}
}
/**
* Get the MoleculeId
* @return NumberKey
*/
public NumberKey getMoleculeId()
{
return molecule_id;
}
/**
* Set the value of MoleculeId
*/
public void setMoleculeId(NumberKey v ) throws Exception
{
if (v != null && v.getValue() == null)
{
// If this is an Objectkey than this set method is
// probably storing the id of this object or some
// associated object. If the objectKey value is null
// then we convert the parameter to null so that this
// property is consistently null to indicate that no
// object is associated or defined.
v = null;
}
aMolecule = null;
if ( !ObjectUtils.equals(this.molecule_id, v) )
{
this.molecule_id = v;
setModified(true);
}
}
/**
* Set the value of MoleculeId as a string.
*/
public void setMoleculeId(String v ) throws Exception
{
setMoleculeId(new NumberKey(v));
}
private Molecule aMolecule;
/**
* Declares an association between this object and a Molecule object
*
* @param Molecule v
*/
public void setMolecule(Molecule v) throws Exception
{
setMoleculeId(v.getMoleculeId());
aMolecule = v;
}
public Molecule getMolecule() throws Exception
{
if ( aMolecule==null && (!ObjectUtils.equals(this.molecule_id, null)) )
{
aMolecule = MoleculePeer.retrieveByPK(this.molecule_id);
/* The following can be used instead of the line above to
guarantee the related object contains a reference
to this object, but this level of coupling
may be undesirable in many circumstances.
As it can lead to a db query with many results that may
never be used.
Molecule obj = MoleculePeer.retrieveByPK(this.molecule_id);
obj.addBondss(this);
*/
}
return aMolecule;
}
/**
* Provides convenient way to set a relationship based on a
* ObjectKey. e.g.
* <code>bar.setFooKey(foo.getPrimaryKey())</code>
*
*/
public void setMoleculeKey(ObjectKey key) throws Exception
{
setMoleculeId((NumberKey)key);
}
/**
* Collection to store aggregation of collBondsAtomss
*/
protected Vector collBondsAtomss;
/**
* Temporary storage of collBondsAtomss to save a possible db hit in
* the event objects are add to the collection, but the
* complete collection is never requested.
*/
protected void initBondsAtomss()
{
if (collBondsAtomss == null)
{
collBondsAtomss = new Vector();
}
}
/**
* Method called to associate a BondsAtoms object to this object
* through the BondsAtoms foreign key attribute
*
* @param BondsAtoms l
*/
public void addBondsAtoms(BondsAtoms l) throws Exception
{
getBondsAtomss().add(l);
l.setBonds((Bonds)this);
}
/**
* The criteria used to select the current contents of collBondsAtomss
*/
private Criteria lastBondsAtomssCriteria = null;
/**
* If this collection has already been initialized, returns
* the collection. Otherwise returns the results of
* getBondsAtomss(new Criteria())
*/
public Vector getBondsAtomss() throws Exception
{
if (collBondsAtomss == null)
{
collBondsAtomss = getBondsAtomss(new Criteria(10));
}
return collBondsAtomss;
}
/**
* If this collection has already been initialized with
* an identical criteria, it returns the collection.
* Otherwise if this Bonds has previously
* been saved, it will retrieve related BondsAtomss from storage.
* If this Bonds is new, it will return
* an empty collection or the current collection, the criteria
* is ignored on a new object.
*/
public Vector getBondsAtomss(Criteria criteria) throws Exception
{
if (collBondsAtomss == null)
{
if ( isNew() )
{
collBondsAtomss = new Vector();
}
else
{
criteria.add(BondsAtomsPeer.BONDS_ID, getBondsId() );
collBondsAtomss = BondsAtomsPeer.doSelect(criteria);
}
}
else
{
// criteria has no effect for a new object
if ( !isNew() )
{
// the following code is to determine if a new query is
// called for. If the criteria is the same as the last
// one, just return the collection.
criteria.add(BondsAtomsPeer.BONDS_ID, getBondsId() );
if ( !lastBondsAtomssCriteria.equals(criteria) )
{
collBondsAtomss = BondsAtomsPeer.doSelect(criteria);
}
}
}
lastBondsAtomssCriteria = criteria;
return collBondsAtomss;
}
/**
* If this collection has already been initialized with
* an identical criteria, it returns the collection.
* Otherwise if this Bonds is new, it will return
* an empty collection; or if this Bonds has previously
* been saved, it will retrieve related BondsAtomss from storage.
*
* This method is protected by default in order to keep the public
* api reasonable. You can provide public methods for those you
* actually need in Bonds.
*/
protected Vector getBondsAtomssJoinAtoms(Criteria criteria)
throws Exception
{
if (collBondsAtomss == null)
{
if ( isNew() )
{
collBondsAtomss = new Vector();
}
else
{
criteria.add(BondsAtomsPeer.BONDS_ID, getBondsId() );
collBondsAtomss = BondsAtomsPeer.doSelectJoinAtoms(criteria);
}
}
else
{
// the following code is to determine if a new query is
// called for. If the criteria is the same as the last
// one, just return the collection.
boolean newCriteria = true;
criteria.add(BondsAtomsPeer.BONDS_ID, getBondsId() );
if ( !lastBondsAtomssCriteria.equals(criteria) )
{
collBondsAtomss = BondsAtomsPeer.doSelectJoinAtoms(criteria);
}
}
lastBondsAtomssCriteria = criteria;
return collBondsAtomss;
}
private static Vector fieldNames_ = null;
/**
* Generate a list of field names.
*/
public static synchronized List getFieldNames()
{
if (fieldNames_ == null)
{
fieldNames_ = new Vector();
fieldNames_.add("BondsId");
fieldNames_.add("Degree");
fieldNames_.add("MoleculeId");
}
return fieldNames_;
}
/**
* Retrieves a field from the object by name passed in
* as a String.
*/
public Object getByName(String name)
{
if (name.equals("BondsId"))
{
return getBondsId();
}
if (name.equals("Degree"))
{
return new Integer(getDegree());
}
if (name.equals("MoleculeId"))
{
return getMoleculeId();
}
return null;
}
/**
* Retrieves a field from the object by name passed in
* as a String. The String must be one of the static
* Strings defined in this Class' Peer.
*/
public Object getByPeerName(String name)
{
if (name.equals(BondsPeer.BONDS_ID ))
{
return getBondsId();
}
if (name.equals(BondsPeer.DEGREE ))
{
return new Integer(getDegree());
}
if (name.equals(BondsPeer.MOLECULE_ID ))
{
return getMoleculeId();
}
return null;
}
/**
* Retrieves a field from the object by Position as specified
* in the xml schema. Zero-based.
*/
public Object getByPosition(int pos)
{
if ( pos == 0 )
{
return getBondsId();
}
if ( pos == 1 )
{
return new Integer(getDegree());
}
if ( pos == 2 )
{
return getMoleculeId();
}
return null;
}
/**
* Stores the object in the database. If the object is new,
* it inserts it; otherwise an update is performed.
*/
public void save() throws Exception
{
save(BondsPeer.getMapBuilder()
.getDatabaseMap().getName());
}
/**
* Stores the object in the database. If the object is new,
* it inserts it; otherwise an update is performed.
* Note: this code is here because the method body is
* auto-generated conditionally and therefore needs to be
* in this file instead of in the super class, BaseObject.
*/
public void save(String dbName) throws Exception
{
DBConnection dbCon = null;
try
{
dbCon = BasePeer.beginTransaction(dbName);
save(dbCon);
}
catch(Exception e)
{
BasePeer.rollBackTransaction(dbCon);
throw e;
}
BasePeer.commitTransaction(dbCon);
}
/** flag to prevent endless save loop, if this object is referenced
by another object which falls in this transaction. */
private boolean alreadyInSave = false;
/**
* Stores the object in the database. If the object is new,
* it inserts it; otherwise an update is performed. This method
* is meant to be used as part of a transaction, otherwise use
* the save() method and the connection details will be handled
* internally
*/
public void save(DBConnection dbCon) throws Exception
{
if (!alreadyInSave)
{
alreadyInSave = true;
// If this object has been modified, then save it to the database.
if (isModified())
{
if (isNew())
{
BondsPeer.doInsert((Bonds)this, dbCon);
setNew(false);
}
else
{
BondsPeer.doUpdate((Bonds)this, dbCon);
}
}
if (collBondsAtomss != null )
{
for (int i=0; i<collBondsAtomss.size(); i++)
{
((BondsAtoms)collBondsAtomss.get(i)).save(dbCon);
}
}
alreadyInSave = false;
}
}
/**
* Set the PrimaryKey using ObjectKey.
*
* @param ObjectKey bonds_id
*/
public void setPrimaryKey(ObjectKey bonds_id)
throws Exception {
setBondsId((NumberKey)bonds_id);
}
/**
* Set the PrimaryKey using a String.
*/
public void setPrimaryKey(String key) throws Exception
{
setBondsId(new NumberKey(key) );
}
/**
* returns an id that differentiates this object from others
* of its class.
*/
public ObjectKey getPrimaryKey()
{
return getBondsId();
}
/**
* Makes a copy of this object.
* It creates a new object filling in the simple attributes.
* It then fills all the association collections and sets the
* related objects to isNew=true.
*/
public Bonds copy() throws Exception
{
Bonds copyObj = new Bonds();
copyObj.setBondsId(bonds_id);
copyObj.setDegree(degree);
copyObj.setMoleculeId(molecule_id);
copyObj.setNew(false);
List v = getBondsAtomss();
for (int i=0; i<v.size(); i++)
{
BondsAtoms obj = (BondsAtoms) v.get(i);
copyObj.addBondsAtoms(obj.copy());
((Persistent)v.get(i)).setNew(true);
}
copyObj.setNew(true);
copyObj.setBondsId((NumberKey)null);
return copyObj;
}
/**
* returns a peer instance associated with this om. Since Peer classes
* are not to have any instance attributes, this method returns the
* same instance for all member of this class. The method could therefore
* be static, but this would prevent one from overriding the behavior.
*/
public BondsPeer getPeer()
{
return peer;
}
}
--- NEW FILE: BaseBondsAtoms.java ---
package org.openscience.nmrshiftdb;
import java.util.*;
import java.math.*;
import org.apache.torque.Torque;
import org.apache.torque.om.*;
import org.apache.torque.util.BasePeer;
import org.apache.torque.util.Criteria;
import org.apache.torque.pool.DBConnection;
import org.apache.commons.util.ObjectUtils;
/**
* This class was autogenerated by Torque on:
*
* [Tue Feb 12 14...
[truncated message content] |