Hi,
I'm experimenting a simple form, adding a group (3 fields) to a simple, one
group table database, following some examples from the Struts book by James
Turner. All classes built (with Torque and mysql) and deployed. I couldn't
bring up the form and kept getting the error below. I think something is
wrong w/ my struts setup. Attached are struts config, my jsp, and some
simple java files. Could someone help me on this ? I really appreciate it.
-Frank
Error: 500
Location: /infolink/users/edit_group.jsp
Internal Servlet Error:
javax.servlet.ServletException: No getter method for property group_name of
bean org.apache.struts.taglib.html.BEAN
at
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImp
l.java:460)
at users.edit_group_1._jspService(edit_group_1.java:550)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:91
7)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at
org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10I
nterceptor.java:176)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:516)
at java.lang.Thread.run(Thread.java:536)
Root cause:
javax.servlet.jsp.JspException: No getter method for property group_name of
bean org.apache.struts.taglib.html.BEAN
at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:742)
at
org.apache.struts.taglib.html.BaseFieldTag.doStartTag(BaseFieldTag.java:193)
at users.edit_group_1._jspService(edit_group_1.java:241)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:91
7)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at
org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10I
nterceptor.java:176)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:516)
at java.lang.Thread.run(Thread.java:536)
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<!--
This is the Struts configuration file for the "Group!" sample application
-->
<struts-config>
<!-- ======== Form Bean Definitions =================================== -->
<form-beans>
<form-bean name="GroupForm" type="infolink.users.GroupForm"/>
<form-property name="group_name" type="java.lang.String"/>
</form-beans>
<!-- ========== Action Mapping Definitions ============================== -->
<action-mappings>
<!-- Say Hello! -->
<action path = "/Group"
type = "infolink.users.GroupAction"
name = "GroupForm"
scope = "request"
validate = "true"
input = "/edit_group.jsp"
>
<forward name="home" path="/view_groups.jsp" />
</action>
</action-mappings>
<!-- ========== Message Resources Definitions =========================== -->
<message-resources parameter="infolink.users.ApplicationResources"/>
</struts-config>
package infolink.users;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.Action;
import org.apache.torque.*;
/**
* stocktrack.struts.action.NewUserAction class.
* this class used by Struts Framework process the
* stocktrack.struts.form.NewUserForm form.
* - method invoked by HTTP request is perform(....)
* - form name is newUserForm
* - input page is newUser.jsp
* - scope name is request
* - path for this action is /newuser
*
* struts-config declaration:
* <action name="newUserForm"
* path="/newuser"
* type="stocktrack.struts.action.NewUserAction"
* input="newUser.jsp"
* scope="request"
* validate="true" >
* <!-- yours forwards -->
* </action>
*
* @see org.apache.struts.action.Action org.apache.struts.action.Action
* Generated by StrutsWizard.
*/
public class GroupAction extends org.apache.struts.action.Action {
public ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
GroupForm gf = (GroupForm) form;
try {
Group g = Group.findGroupByName(gf.getGroupName());
if (g != null) {
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("group.newgroup.duplicate.group"));
this.saveErrors(request, errors);
return mapping.getInputForward();
}
g = new Group();
g.setGroupName(gf.getGroupName());
g.setGroupDesc(gf.getGroupDesc());
g.setGroupStatus(gf.getGroupStatus());
g.save();
request.getSession().setAttribute(Constants.GROUP_KEY, g);
return mapping.findForward("home");
}
catch (Exception ex) {
ex.printStackTrace();
return mapping.findForward("error");
}
}
}
package infolink.users;
import javax.servlet.http.*;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.torque.*;
public final class GroupForm extends ActionForm
{
/**
* The value for the group_id field
*/
private int group_id;
/**
* The value for the group_name field
*/
private String group_name;
/**
* The value for the group_desc field
*/
private String group_desc;
/**
* The value for the group_status field
*/
private int group_status;
public void reset(ActionMapping mapping, HttpServletRequest request)
{
this.group_id = 0;
this.group_name = "";
this.group_desc = "";;
this.group_status = 0;
}
/**
* Validate the properties posted in this request. If validation errors are
* found, return an <code>ActionErrors</code> object containing the errors.
* If no validation errors occur, return <code>null</code> or an empty
* <code>ActionErrors</code> object.
*
* @param mapping The current mapping (from struts-config.xml)
* @param request The servlet request object
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if ((group_name == null) || (group_name.length() < 1))
errors.add("group_name", new ActionError("infolink.group.no.name.error"));
return errors;
}
/**
* Get the GroupId
*
* @return int
*/
public int getGroupId()
{
return group_id;
}
/**
* Set the value of GroupId
*
* @param v new value
*/
public void setGroupId(int v)
{
if (this.group_id != v)
{
this.group_id = v;
}
}
/**
* Get the GroupName
*
* @return String
*/
public String getGroupName()
{
return group_name;
}
/**
* Set the value of GroupName
*
* @param v new value
*/
public void setGroupName(String v)
{
this.group_name = v;
}
/**
* Get the GroupDesc
*
* @return String
*/
public String getGroupDesc()
{
return group_desc;
}
/**
* Set the value of GroupDesc
*
* @param v new value
*/
public void setGroupDesc(String v)
{
this.group_desc = v;
}
/**
* Get the GroupStatus
*
* @return int
*/
public int getGroupStatus()
{
return group_status;
}
/**
* Set the value of GroupStatus
*
* @param v new value
*/
public void setGroupStatus(int v)
{
if (this.group_status != v)
{
this.group_status = v;
}
}
}
package org.apache.torque;
import java.util.List;
import org.apache.torque.*;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
/**
* The skeleton for this class was autogenerated by Torque on:
*
* [Thu Jan 15 16:11:08 PST 2004]
*
* 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 Group
extends org.apache.torque.BaseGroup
implements Persistent
{
public static Group findGroupByName (String name)
{
try {
Criteria c = new Criteria();
c.add (GroupPeer.GROUP_NAME, name);
List l = GroupPeer.doSelect(c);
if ((l == null) || (l.size() == 0))
return null;
return (Group)l.get(0);
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
package org.apache.torque;
/**
* The skeleton for this class was autogenerated by Torque on:
*
* [Thu Jan 15 16:11:08 PST 2004]
*
* 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 GroupPeer
extends org.apache.torque.BaseGroupPeer
{
}
package org.apache.torque;
import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;
/**
* This class was autogenerated by Torque on:
*
* [Thu Jan 22 07:47:19 PST 2004]
*
* You should not use this class directly. It should not even be
* extended all references should be to Group
*/
public abstract class BaseGroup extends BaseObject
{
/** The Peer class */
private static final GroupPeer peer =
new GroupPeer();
/**
* The value for the group_id field
*/
private NumberKey group_id;
/**
* The value for the group_name field
*/
private String group_name;
/**
* The value for the group_desc field
*/
private String group_desc;
/**
* The value for the group_status field
*/
private int group_status;
/**
* Get the GroupId
*
* @return NumberKey
*/
public NumberKey getGroupId()
{
return group_id;
}
/**
* Set the value of GroupId
*
* @param v new value
*/
public void setGroupId(NumberKey v)
{
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;
}
if (!ObjectUtils.equals(this.group_id, v))
{
this.group_id = v;
setModified(true);
}
}
/**
* Set the value of GroupId as a string.
*
* @param v new value
*/
public void setGroupId(String v)
{
setGroupId(new NumberKey(v));
}
/**
* Get the GroupName
*
* @return String
*/
public String getGroupName()
{
return group_name;
}
/**
* Set the value of GroupName
*
* @param v new value
*/
public void setGroupName(String v)
{
if (!ObjectUtils.equals(this.group_name, v))
{
this.group_name = v;
setModified(true);
}
}
/**
* Get the GroupDesc
*
* @return String
*/
public String getGroupDesc()
{
return group_desc;
}
/**
* Set the value of GroupDesc
*
* @param v new value
*/
public void setGroupDesc(String v)
{
if (!ObjectUtils.equals(this.group_desc, v))
{
this.group_desc = v;
setModified(true);
}
}
/**
* Get the GroupStatus
*
* @return int
*/
public int getGroupStatus()
{
return group_status;
}
/**
* Set the value of GroupStatus
*
* @param v new value
*/
public void setGroupStatus(int v)
{
if (this.group_status != v)
{
this.group_status = v;
setModified(true);
}
}
private static List fieldNames = null;
/**
* Generate a list of field names.
*/
public static synchronized List getFieldNames()
{
if (fieldNames == null)
{
fieldNames = new ArrayList();
fieldNames.add("GroupId");
fieldNames.add("GroupName");
fieldNames.add("GroupDesc");
fieldNames.add("GroupStatus");
fieldNames = Collections.unmodifiableList(fieldNames);
}
return fieldNames;
}
/**
* Retrieves a field from the object by name passed in
* as a String.
*/
public Object getByName(String name)
{
if (name.equals("GroupId"))
{
return getGroupId();
}
if (name.equals("GroupName"))
{
return getGroupName();
}
if (name.equals("GroupDesc"))
{
return getGroupDesc();
}
if (name.equals("GroupStatus"))
{
return new Integer(getGroupStatus());
}
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(GroupPeer.GROUP_ID ))
{
return getGroupId();
}
if (name.equals(GroupPeer.GROUP_NAME ))
{
return getGroupName();
}
if (name.equals(GroupPeer.GROUP_DESC ))
{
return getGroupDesc();
}
if (name.equals(GroupPeer.GROUP_STATUS ))
{
return new Integer(getGroupStatus());
}
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 getGroupId();
}
if (pos == 1)
{
return getGroupName();
}
if (pos == 2)
{
return getGroupDesc();
}
if (pos == 3)
{
return new Integer(getGroupStatus());
}
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(GroupPeer.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 TorqueException
{
Connection con = null;
try
{
con = Transaction.begin(dbName);
save(con);
Transaction.commit(con);
}
catch(TorqueException e)
{
Transaction.safeRollback(con);
throw e;
}
}
/** 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(Connection con) throws TorqueException
{
if (!alreadyInSave)
{
alreadyInSave = true;
// If this object has been modified, then save it to the database.
if (isModified())
{
if (isNew())
{
GroupPeer.doInsert((Group) this, con);
setNew(false);
}
else
{
GroupPeer.doUpdate((Group) this, con);
}
}
alreadyInSave = false;
}
}
/**
* Set the PrimaryKey using ObjectKey.
*
* @param group_id ObjectKey
*/
public void setPrimaryKey(ObjectKey group_id)
{
setGroupId((NumberKey)group_id);
}
/**
* Set the PrimaryKey using a String.
*/
public void setPrimaryKey(String key)
{
setGroupId(new NumberKey(key) );
}
/**
* returns an id that differentiates this object from others
* of its class.
*/
public ObjectKey getPrimaryKey()
{
return getGroupId();
}
/**
* 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 Group copy() throws TorqueException
{
return copyInto(new Group());
}
protected Group copyInto(Group copyObj) throws TorqueException
{
copyObj.setGroupId(group_id);
copyObj.setGroupName(group_name);
copyObj.setGroupDesc(group_desc);
copyObj.setGroupStatus(group_status);
copyObj.setNew(false);
copyObj.setNew(true);
copyObj.setGroupId((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 GroupPeer getPeer()
{
return peer;
}
}
package org.apache.torque;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.apache.torque.Torque;
import org.apache.torque.TorqueException;
import org.apache.torque.map.MapBuilder;
import org.apache.torque.map.TableMap;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.util.BasePeer;
import org.apache.torque.util.Criteria;
import com.workingdogs.village.DataSetException;
import com.workingdogs.village.QueryDataSet;
import com.workingdogs.village.Record;
// Local classes
import org.apache.torque.map.*;
/**
* This class was autogenerated by Torque on:
*
* [Thu Jan 22 07:47:19 PST 2004]
*
*/
public abstract class BaseGroupPeer
extends BasePeer
{
/** the default database name for this class */
public static final String DATABASE_NAME = "infolink";
/** the table name for this class */
public static final String TABLE_NAME = "group";
/**
* @return the map builder for this peer
*/
public static MapBuilder getMapBuilder()
throws TorqueException
{
return getMapBuilder(GroupMapBuilder.CLASS_NAME);
}
/** the column name for the GROUP_ID field */
public static final String GROUP_ID;
/** the column name for the GROUP_NAME field */
public static final String GROUP_NAME;
/** the column name for the GROUP_DESC field */
public static final String GROUP_DESC;
/** the column name for the GROUP_STATUS field */
public static final String GROUP_STATUS;
static
{
GROUP_ID = "group.GROUP_ID";
GROUP_NAME = "group.GROUP_NAME";
GROUP_DESC = "group.GROUP_DESC";
GROUP_STATUS = "group.GROUP_STATUS";
if (Torque.isInit())
{
try
{
getMapBuilder();
}
catch (Exception e)
{
category.error("Could not initialize Peer", e);
}
}
else
{
Torque.registerMapBuilder(GroupMapBuilder.CLASS_NAME);
}
}
/** number of columns for this peer */
public static final int numColumns = 4;
/** A class that can be returned by this peer. */
protected static final String CLASSNAME_DEFAULT =
"org.apache.torque.Group";
/** 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 <[EMAIL PROTECTED]> " +
"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 List resultSet2Objects(java.sql.ResultSet results)
throws TorqueException
{
try
{
QueryDataSet qds = null;
List rows = null;
try
{
qds = new QueryDataSet(results);
rows = getSelectResults(qds);
}
finally
{
if (qds != null)
{
qds.close();
}
}
return populateObjects(rows);
}
catch (SQLException e)
{
throw new TorqueException(e);
}
catch (DataSetException e)
{
throw new TorqueException(e);
}
}
/**
* Method to do inserts
*/
public static ObjectKey doInsert(Criteria criteria)
throws TorqueException
{
return BaseGroupPeer
.doInsert(criteria, (Connection) 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, Connection con)
throws TorqueException
{
// 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);
}
if (con == null)
{
return BasePeer.doInsert(criteria);
}
else
{
return BasePeer.doInsert(criteria, con);
}
}
/** Add all the columns needed to create a new object */
public static void addSelectColumns(Criteria criteria)
throws TorqueException
{
criteria.addSelectColumn(GROUP_ID);
criteria.addSelectColumn(GROUP_NAME);
criteria.addSelectColumn(GROUP_DESC);
criteria.addSelectColumn(GROUP_STATUS);
}
/**
* 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 Group row2Object(Record row,
int offset,
Class cls)
throws TorqueException
{
try
{
Group obj = (Group) cls.newInstance();
populateObject(row, offset, obj);
obj.setModified(false);
obj.setNew(false);
return obj;
}
catch (InstantiationException e)
{
throw new TorqueException(e);
}
catch (IllegalAccessException e)
{
throw new TorqueException(e);
}
}
/**
* 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,
Group obj)
throws TorqueException
{
try
{
if (row.getValue(offset + 0).asBigDecimal() instanceof Object)
{
if (null == row.getValue(offset + 0).asBigDecimal())
{
obj.setGroupId((NumberKey) null);
}
else
{
obj.setGroupId(
new NumberKey(row.getValue(offset + 0).asBigDecimal()));
}
}
obj.setGroupName(row.getValue(offset + 1).asString());
obj.setGroupDesc(row.getValue(offset + 2).asString());
obj.setGroupStatus(row.getValue(offset + 3).asInt());
}
catch (DataSetException e)
{
throw new TorqueException(e);
}
}
/** Method to do selects */
public static List doSelect(Criteria criteria) throws TorqueException
{
return populateObjects(doSelectVillageRecords(criteria));
}
/** Method to do selects within a transaction */
public static List doSelect(Criteria criteria, Connection con)
throws TorqueException
{
return populateObjects(doSelectVillageRecords(criteria, con));
}
/**
* 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 List doSelectVillageRecords(Criteria criteria)
throws TorqueException
{
return BaseGroupPeer
.doSelectVillageRecords(criteria, (Connection) null);
}
/**
* Grabs the raw Village records to be formed into objects.
* This method should be used for transactions
*/
public static List doSelectVillageRecords(Criteria criteria, Connection con)
throws TorqueException
{
if (criteria.getSelectColumns().size() == 0)
{
addSelectColumns(criteria);
}
// 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 returns a List of Value (Village) arrays. The array
// order follows the order columns were placed in the Select clause.
if (con == null)
{
return BasePeer.doSelect(criteria);
}
else
{
return BasePeer.doSelect(criteria, con);
}
}
/**
* The returned List will contain objects of the default type or
* objects that inherit from the default.
*/
public static List populateObjects(List records)
throws TorqueException
{
List results = new ArrayList(records.size());
// populate the object(s)
for (int i = 0; i < records.size(); i++)
{
Record row = (Record) records.get(i);
results.add(GroupPeer.row2Object(row, 1,
GroupPeer.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 TorqueException
{
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 TorqueException
{
BaseGroupPeer
.doUpdate(criteria, (Connection) 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.
* @param dbCon the connection to use
*/
public static void doUpdate(Criteria criteria, Connection con)
throws TorqueException
{
Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
selectCriteria.put(GROUP_ID, criteria.remove(GROUP_ID));
// 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);
}
if (con == null)
{
BasePeer.doUpdate(selectCriteria, criteria);
}
else
{
BasePeer.doUpdate(selectCriteria, criteria, con);
}
}
/**
* Method to do deletes.
*
* @param criteria object containing data that is used DELETE from database.
*/
public static void doDelete(Criteria criteria) throws TorqueException
{
BaseGroupPeer
.doDelete(criteria, (Connection) 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.
* @param dbCon the connection to use
*/
public static void doDelete(Criteria criteria, Connection con)
throws TorqueException
{
// 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);
}
if (con == null)
{
BasePeer.doDelete(criteria);
}
else
{
BasePeer.doDelete(criteria, con);
}
}
/** Method to do selects */
public static List doSelect(Group obj) throws TorqueException
{
return doSelect(buildCriteria(obj));
}
/** Method to do inserts */
public static void doInsert(Group obj) throws TorqueException
{
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(Group obj) throws TorqueException
{
doUpdate(buildCriteria(obj));
obj.setModified(false);
}
/**
* @param obj the data object to delete in the database.
*/
public static void doDelete(Group obj) throws TorqueException
{
doDelete(buildCriteria(obj));
}
/**
* Method to do inserts. This method is to be used during a transaction,
* otherwise use the doInsert(Group) method. It will take
* care of the connection details internally.
*
* @param obj the data object to insert into the database.
*/
public static void doInsert(Group obj, Connection con)
throws TorqueException
{
obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
obj.setNew(false);
obj.setModified(false);
}
/**
* Method to do update. This method is to be used during a transaction,
* otherwise use the doUpdate(Group) method. It will take
* care of the connection details internally.
*
* @param obj the data object to update in the database.
*/
public static void doUpdate(Group obj, Connection con)
throws TorqueException
{
doUpdate(buildCriteria(obj), con);
obj.setModified(false);
}
/**
* Method to delete. This method is to be used during a transaction,
* otherwise use the doDelete(Group) method. It will take
* care of the connection details internally.
*
* @param obj the data object to delete in the database.
*/
public static void doDelete(Group obj, Connection con)
throws TorqueException
{
doDelete(buildCriteria(obj), con);
}
/** Build a Criteria object from the data object for this peer */
public static Criteria buildCriteria( Group obj )
{
Criteria criteria = new Criteria(DATABASE_NAME);
if (!obj.isNew())
criteria.add(GROUP_ID, obj.getGroupId());
criteria.add(GROUP_NAME, obj.getGroupName());
criteria.add(GROUP_DESC, obj.getGroupDesc());
criteria.add(GROUP_STATUS, obj.getGroupStatus());
return criteria;
}
/**
* Retrieve a single object by pk
*
* @param pk the primary key
*/
public static Group retrieveByPK(ObjectKey pk)
throws TorqueException
{
Connection db = null;
Group retVal = null;
try
{
db = Torque.getConnection(DATABASE_NAME);
retVal = retrieveByPK(pk, db);
}
finally
{
Torque.closeConnection(db);
}
return(retVal);
}
/**
* Retrieve a single object by pk
*
* @param pk the primary key
* @param con the connection to use
*/
public static Group retrieveByPK(ObjectKey pk, Connection con)
throws TorqueException
{
Criteria criteria = new Criteria();
criteria.add(GROUP_ID, pk);
List v = doSelect(criteria, con);
if (v.size() != 1)
{
throw new TorqueException("Failed to select one and only one row.");
}
else
{
return (Group)v.get(0);
}
}
/**
* Retrieve a multiple objects by pk
*
* @param pks List of primary keys
*/
public static List retrieveByPKs(List pks)
throws TorqueException
{
Connection db = null;
List retVal = null;
try
{
db = Torque.getConnection(DATABASE_NAME);
retVal = retrieveByPKs(pks, db);
}
finally
{
Torque.closeConnection(db);
}
return(retVal);
}
/**
* Retrieve a multiple objects by pk
*
* @param pks List of primary keys
* @param dbcon the connection to use
*/
public static List retrieveByPKs( List pks, Connection dbcon )
throws TorqueException
{
List objs = null;
if (pks == null || pks.size() == 0)
{
objs = new LinkedList();
}
else
{
Criteria criteria = new Criteria();
criteria.addIn( GROUP_ID, pks );
objs = doSelect(criteria, dbcon);
}
return objs;
}
/**
* 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 TorqueException
{
return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]