You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Jason Kary <jk...@cisco.com> on 2002/05/31 17:12:07 UTC

Torque Question?

Hi,

Appologies for the simple question.  I am using torque-3.0-b2 and I 
can't seem to get save() to work?  I would like to enable log4j to print 
messages however I can't seem to get the properties in Torque.properties 
setup?  I am basically stuck and need some help from the experts. :)  

When I run some basic junit tests on my code, I am seeing the primary 
key being set, however no data is persisted?

Here are the particulars:

Torque.props:

#
# Adding some stuff to see if I can enable logging.
#
torque.applicationRoot.log=c:/
log4j.rootCategory= debug, default,org.apache.torque,sql


# This first category is required and the category
# must be named 'default'. This is used for all logging
# where an explicit category is not specified.

log4j.category.default = ALL, default
log4j.appender.default = org.apache.log4j.FileAppender
log4j.appender.default.file = c:/torque.log
log4j.appender.default.layout = org.apache.log4j.PatternLayout
log4j.appender.default.layout.conversionPattern = %d [%t] %-5p %c - %m%n
log4j.appender.default.append = false

log4j.category.org.apache.torque = ALL, org.apache.torque
log4j.appender.org.apache.torque = org.apache.log4j.FileAppender
log4j.appender.org.apache.torque.file = c:/turbine.log
log4j.appender.org.apache.torque.layout = org.apache.log4j.PatternLayout
log4j.appender.org.apache.torque.layout.conversionPattern = %d [%t] %-5p 
%c - %m%n
log4j.appender.org.apache.torque.append = false

# This category is used in the BasePeer class. All
# SQL generated will be logged if the category
# priority is set to DEBUG

log4j.category.sql = DEBUG, sql
log4j.appender.sql = org.apache.log4j.FileAppender
log4j.appender.sql.file = c:/sql.log
log4j.appender.sql.layout = org.apache.log4j.PatternLayout
log4j.appender.sql.layout.conversionPattern = %d [%t] %-5p %c - %m%n
log4j.appender.sql.append = false


Torque Class:

public class TPrincipal extends com.cisco.gseit.security.BaseTPrincipal 
implements Persistent, java.security.Principal {
    /**
     *  Torque implementation of Principal. This class will persist any 
Prinicpal
     * object you wish by using the torque infrastructure. A typical 
usage of this
     * class by subclassing this object for identification of the type 
of principal. <P>
     * A name property is provided for convenience adn also allows specific
     * subsets of a partticular principal, HOWEVER it is STRONGLY 
discouraged as
     * the java.security.acl architecture seems to lend itself better to 
the subclass model. <P>
     * Alternatively, the name property can contian the DATA you are 
protecting...
     *@param  name           Description of Parameter
     *@exception  Exception  Description of Exception
     */

    /**
     *  Convenience consrtuctor. By passing in a name, we will create a 
new row or
     * lookup an existing row in the database based on the name attribute.
     *@param  name           Description of Parameter
     *@exception  Exception  Description of Exception
     */
    public TPrincipal(String aName) throws Exception {
        super();
        System.out.println("In constructor");
        this.setName(aName);
    }

    /** Bean Constructor */
    public TPrincipal() {
        super();
    }

    public void setName(String aName) {
        try {
            System.out.println("In setting name");
            super.setName(aName);
            //this.checkName();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void checkName() throws Exception {
        Criteria crit = new Criteria();
        List myList = null;
        //crit.add(TPrincipalPeer.NAME, super.getName());
        System.out.println("Just before do select.");
        myList = TPrincipalPeer.doSelect(crit);
        System.out.println("After the do select.");
        System.out.println("Size of rows returned = " + myList.size());
        this.setModified(true);
        this.save();
        System.out.println("Principal:" + this.getName() + " exists and 
Primary Key is : " + this.getPrimaryKey());

/*        if (myList.size() > 0) {
            this.setPrimaryKey(((com.cisco.gseit.security.TPrincipal) 
myList.iterator().next()).getPrimaryKey());
            System.out.println("Principal:" + this.getName() + " exists 
and Primary Key is : " + this.getPrimaryKey());
        } else {
            this.save();
        }
  */
    }

    /**
     *  Description of the Method
     *@param  par1  Description of Parameter
     *@return       Description of the Returned Value public boolean 
equals(Object par1) { boolean retVal = false;
     * if (par1 instanceof TPrincipal) { if 
(this.getName().equals(((TPrincipal) par1).getName())) {
     * retVal = true; } } return retVal; }
     */

    /**
     *  return the name of the class and the data
     *@return    Description of the Returned Value
     */
    public String toString() {
        return TPrincipal.class.getName() + "( " + this.getName() + " ) ";
    }

    /**
     *  Return the primary key id for the hashcode. You MUST ensure the 
record is SAVED.  There is no way for this
     * signature to throw an exception.
     *@return    Primary key for the principal.
     */
    public int hashCode() {
        return this.getId().getBigDecimal().intValue();
    }
}


AND Finally here is STDOUT:

In constructor
In setting name
In constructor
In setting name
Just before do select.
After the do select.
Size of rows returned = 0
Principal:TestPrincipal exists and Primary Key is : 12

Any help is appreciated!
Take Care
Jason Kary




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>