org.apache.torque.om
Class BaseObject

java.lang.Object
  extended by org.apache.torque.om.BaseObject
All Implemented Interfaces:
java.io.Serializable, Persistent

public abstract class BaseObject
extends java.lang.Object
implements Persistent, java.io.Serializable

This class contains attributes and methods that are used by all business objects within the system.

Version:
$Id: BaseObject.java 516325 2007-03-09 08:03:53Z seade $
Author:
Frank Y. Kim, John D. McNally
See Also:
Serialized Form

Field Summary
static int NEW_ID
          The constant denoting an unset numeric database identifier.
 
Constructor Summary
BaseObject()
           
 
Method Summary
 boolean equals(BaseObject bo)
          Compares the primary key of this instance with the key of another.
 boolean equals(java.lang.Object obj)
          Compares this with another BaseObject instance.
 java.lang.Object getByName(java.lang.String field)
          Retrieves a field from the object by name.
 java.lang.Object getByPeerName(java.lang.String name)
          Retrieves a field from the object by name passed in as a String.
 java.lang.Object getByPosition(int pos)
          Retrieves a field from the object by position as specified in a database schema for example.
protected  org.apache.commons.logging.Log getLog()
          gets a commons-logging Log based on class name.
 ObjectKey getPrimaryKey()
          getter for the object primaryKey.
 TableMap getTableMap()
          Retrieves the TableMap object related to this Table data.
 int hashCode()
          If the primary key is not null, return the hashcode of the primary key.
 boolean isModified()
          Returns whether the object has been modified.
 boolean isNew()
          Returns whether the object has ever been saved.
 void resetModified()
          Sets the modified state for the object to be false.
abstract  void save()
          Saves the object.
abstract  void save(java.sql.Connection con)
          Stores the object in the database.
abstract  void save(java.lang.String dbName)
          Stores the object in the database.
 boolean setByName(java.lang.String name, java.lang.Object value)
          Set a field in the object by field (Java) name.
 boolean setByPeerName(java.lang.String name, java.lang.Object value)
          Set field values by Peer Field Name
 boolean setByPosition(int position, java.lang.Object value)
          Set field values by it's position (zero based) in the XML schema.
 void setModified(boolean m)
          Sets the modified state for the object.
 void setNew(boolean b)
          Setter for the isNew attribute.
 void setPrimaryKey(ObjectKey primaryKey)
          Sets the PrimaryKey for the object as an Object.
 void setPrimaryKey(SimpleKey[] primaryKey)
          Sets the PrimaryKey for the object as an Object.
 void setPrimaryKey(java.lang.String primaryKey)
          Sets the PrimaryKey for the object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEW_ID

public static final int NEW_ID
The constant denoting an unset numeric database identifier.

See Also:
Constant Field Values
Constructor Detail

BaseObject

public BaseObject()
Method Detail

getPrimaryKey

public ObjectKey getPrimaryKey()
getter for the object primaryKey.

Specified by:
getPrimaryKey in interface Persistent
Returns:
the object primaryKey as an Object

isModified

public boolean isModified()
Returns whether the object has been modified.

Specified by:
isModified in interface Persistent
Returns:
True if the object has been modified.

isNew

public boolean isNew()
Returns whether the object has ever been saved. This will be false, if the object was retrieved from storage or was created and then saved.

Specified by:
isNew in interface Persistent
Returns:
true, if the object has never been persisted.

setNew

public void setNew(boolean b)
Setter for the isNew attribute. This method will be called by Torque-generated children and Peers.

Specified by:
setNew in interface Persistent
Parameters:
b - the state of the object.

setPrimaryKey

public void setPrimaryKey(java.lang.String primaryKey)
                   throws TorqueException
Sets the PrimaryKey for the object.

Specified by:
setPrimaryKey in interface Persistent
Parameters:
primaryKey - The new PrimaryKey for the object.
Throws:
TorqueException - This method will not throw any exceptions but this allows for children to override the method more easily

setPrimaryKey

public void setPrimaryKey(SimpleKey[] primaryKey)
                   throws TorqueException
Sets the PrimaryKey for the object as an Object.

Parameters:
primaryKey - The new PrimaryKey for the object.
Throws:
TorqueException - This method will not throw any exceptions but this allows for children to override the method more easily

setPrimaryKey

public void setPrimaryKey(ObjectKey primaryKey)
                   throws TorqueException
Sets the PrimaryKey for the object as an Object.

Specified by:
setPrimaryKey in interface Persistent
Parameters:
primaryKey - The new PrimaryKey for the object.
Throws:
TorqueException - This method will not throw any exceptions but this allows for children to override the method more easily

setModified

public void setModified(boolean m)
Sets the modified state for the object.

Specified by:
setModified in interface Persistent
Parameters:
m - The new modified state for the object.

resetModified

public void resetModified()
Sets the modified state for the object to be false.


getByName

public java.lang.Object getByName(java.lang.String field)
Retrieves a field from the object by name. Must be overridden if called. BaseObject's implementation will throw an Error.

Parameters:
field - The name of the field to retrieve.
Returns:
The retrieved field value

setByName

public boolean setByName(java.lang.String name,
                         java.lang.Object value)
                  throws TorqueException
Set a field in the object by field (Java) name.

Parameters:
name - field name
value - field value
Returns:
True if value was set, false if not (invalid name / protected field).
Throws:
java.lang.IllegalArgumentException - if object type of value does not match field object type.
TorqueException - If a problem occurs with the set[Field] method.

getByPeerName

public java.lang.Object getByPeerName(java.lang.String name)
Retrieves a field from the object by name passed in as a String. Must be overridden if called. BaseObject's implementation will throw an Error.

Parameters:
name - field name
Returns:
value of the field

setByPeerName

public boolean setByPeerName(java.lang.String name,
                             java.lang.Object value)
                      throws TorqueException
Set field values by Peer Field Name

Parameters:
name - field name
value - field value
Returns:
True if value was set, false if not (invalid name / protected field).
Throws:
java.lang.IllegalArgumentException - if object type of value does not match field object type.
TorqueException - If a problem occurs with the set[Field] method.

getByPosition

public java.lang.Object getByPosition(int pos)
Retrieves a field from the object by position as specified in a database schema for example. Must be overridden if called. BaseObject's implementation will throw an Error.

Parameters:
pos - field position
Returns:
value of the field

setByPosition

public boolean setByPosition(int position,
                             java.lang.Object value)
                      throws TorqueException
Set field values by it's position (zero based) in the XML schema.

Parameters:
position - The field position
value - field value
Returns:
True if value was set, false if not (invalid position / protected field).
Throws:
java.lang.IllegalArgumentException - if object type of value does not match field object type.
TorqueException - If a problem occurs with the set[Field] method.

equals

public boolean equals(java.lang.Object obj)
Compares this with another BaseObject instance. If obj is an instance of BaseObject, delegates to equals(BaseObject). Otherwise, returns false.

Overrides:
equals in class java.lang.Object
Parameters:
obj - The object to compare to.
Returns:
Whether equal to the object specified.

equals

public boolean equals(BaseObject bo)
Compares the primary key of this instance with the key of another.

Parameters:
bo - The object to compare to.
Returns:
Whether the primary keys are equal and the object have the same class.

hashCode

public int hashCode()
If the primary key is not null, return the hashcode of the primary key. Otherwise calls Object.hashCode().

Overrides:
hashCode in class java.lang.Object
Returns:
an int value

getLog

protected org.apache.commons.logging.Log getLog()
gets a commons-logging Log based on class name.

Returns:
a Log to write log to.

save

public abstract void save()
                   throws java.lang.Exception
Description copied from interface: Persistent
Saves the object.

Specified by:
save in interface Persistent
Throws:
java.lang.Exception - This method might throw an exception
See Also:
Persistent.save()

save

public abstract void save(java.lang.String dbName)
                   throws java.lang.Exception
Description copied from interface: Persistent
Stores the object in the database. If the object is new, it inserts it; otherwise an update is performed.

Specified by:
save in interface Persistent
Parameters:
dbName - the name of the database
Throws:
java.lang.Exception - This method might throw an exception
See Also:
Persistent.save(String)

save

public abstract void save(java.sql.Connection con)
                   throws java.lang.Exception
Description copied from interface: Persistent
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

Specified by:
save in interface Persistent
Parameters:
con - the Connection used to store the object
Throws:
java.lang.Exception - This method might throw an exception
See Also:
Persistent.save(Connection)

getTableMap

public TableMap getTableMap()
                     throws TorqueException
Retrieves the TableMap object related to this Table data. Must be overridden in generated classes. If BaseObject's implementation is called it will throw an Error.

Returns:
The associated TableMap object.
Throws:
TorqueException


Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.