You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by Thomas Fischer <fi...@seitenbau.net> on 2010/09/25 22:54:20 UTC

please enlighten me... attributes "abstract" and "alias" on tables

What is the attribute "abstract" used for? I'm curious because it does not
seem to work currently. In Torque 3.3, the following snippet is in the base
peer template:
    public static Class getOMClass()
        throws TorqueException
    {
    public static Class getOMClass()
        throws TorqueException
    {
#if ($table.isAbstract())
        String error = "You must implement the getOMClass method in your";
               error += " Peer object in order for things to work
properly.";
               error += " This method should return the proper Class that";
               error += " represents the Peer's Business Object.";
        throw new TorqueException (error);
#else
        return CLASS_DEFAULT;
#end
    }
As far as I know, static methods are bound at compile time and cannot be
overridden (i.e the BasePeer code will always access this implementation
and thus always fail).

I'm equally curious about he "alias" attribute. If it is set, some methods
are not generated in Torque 3.3 but I do not see why nor a use case. Does
anybody have one ?

     Thanks in advance for any light on this,

         Thomas


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Re: please enlighten me... attributes "abstract" and "alias" on tables

Posted by Thomas Fischer <fi...@seitenbau.net>.
> ...
>
> > Or did I musunderstand what you were saying ?
>
> Probably. What happens in our case is that the call always goes to
> TablePeer.getOMClass(). If that does not exist,
> BaseTablePeer.getOMClass() gets called. If this didn't work, we could
> never use TablePeer.doSelect() because the method is in fact in
> BaseTablePeer. If you add a static method getOMClass() to TablePeer,
> this will get called. This is not exactly an "override" but works as
> such. Torque has many places where this behavior is employed.

Shame on me. How have I been committer to Torque for such a long time and
not grasp this?
Thanks for explaining.

    Thomas


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Re: please enlighten me... attributes "abstract" and "alias" on tables

Posted by Thomas Vandahl <tv...@apache.org>.
On 27.09.10 21:43, Thomas Fischer wrote:
> You cannot override a static method. Ecample:
> 
> // Base.java
> public class Base
> {
>   public static String getOmClass()
>   {
>       return "BASE";
>   }
> 
>   public static void printOmClass()
>   {
>       System.out.println(getOmClass());
The example is System.out.println(Inherited.getOmClass()) here.

>   }
> }
> 
> // Inherited.java
> public class Inherited extends Base
> {
>     public static String getOmClass()
>     {
>         return "INHERITED";
>     }
> 
>     public static void main(String[] argv)
>     {
>         printOmClass();
>     }
> }

> Or did I musunderstand what you were saying ?

Probably. What happens in our case is that the call always goes to
TablePeer.getOMClass(). If that does not exist,
BaseTablePeer.getOMClass() gets called. If this didn't work, we could
never use TablePeer.doSelect() because the method is in fact in
BaseTablePeer. If you add a static method getOMClass() to TablePeer,
this will get called. This is not exactly an "override" but works as
such. Torque has many places where this behavior is employed.

> Go ahead, should not be difficult to implement. I can help, if you have any
> questions.

Well, I'd rather concentrate myself on the runtime... :-)

Bye, Thomas.

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Re: please enlighten me... attributes "abstract" and "alias" on tables

Posted by Thomas Fischer <fi...@seitenbau.net>.
> > As far as I know, static methods are bound at compile time and cannot
be
> > overridden (i.e the BasePeer code will always access this
implementation
> > and thus always fail).
>
> AFAICT, no runtime code ever calls getOMClass(). The generated peer
> classes call TablePeer.getOMClass() and thus overriding this method
> *will* work. It looks like you can define another class that is used in
> row2Object(). Don't know if that could be useful.

Sorry I do not understand:

In the Torque 3 test project:

AuthorPeer:
    /** A class that can be returned by this peer. */
    protected static final String CLASSNAME_DEFAULT =
        "org.apache.torque.test.Author";

    /** A class that can be returned by this peer. */
    protected static final Class CLASS_DEFAULT = initClass(
CLASSNAME_DEFAULT);

    /**
     * Class object initialization method.
     *
     * @param className name of the class to initialize
     * @return the initialized class
     */
    private static Class initClass(String className)
    {
        Class c = null;
        try
        {
            c = Class.forName(className);
        }
        catch (Throwable t)
        {
            ...
        }
        return c;
    }
    public static Class getOMClass()
        throws TorqueException
    {
        return CLASS_DEFAULT;
    }

so getOmClass() will always return Author.class

getOmClass() is called in Runtime code:

    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(AuthorPeer.row2Object(row, 1,
                AuthorPeer.getOMClass()));
        }
        return results;
    }

You cannot override a static method. Ecample:

// Base.java
public class Base
{
  public static String getOmClass()
  {
      return "BASE";
  }

  public static void printOmClass()
  {
      System.out.println(getOmClass());
  }
}

// Inherited.java
public class Inherited extends Base
{
    public static String getOmClass()
    {
        return "INHERITED";
    }

    public static void main(String[] argv)
    {
        printOmClass();
    }
}

Running Inheried will output:
BASE

because the call getOmClass() in printOmClass() is bound at compile time.

Because of this, populateObjects(...) will always fail classes marked as
abstract.

Or did I musunderstand what you were saying ?

....

> As we are at it, sometimes in a schema the equivalent to "skipSql" for
> the OM classes "skipJava" could be useful.

Go ahead, should not be difficult to implement. I can help, if you have any
questions.

    Thomas


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Re: please enlighten me... attributes "abstract" and "alias" on tables

Posted by Thomas Vandahl <tv...@apache.org>.
On 25.09.10 22:54, Thomas Fischer wrote:
> As far as I know, static methods are bound at compile time and cannot be
> overridden (i.e the BasePeer code will always access this implementation
> and thus always fail).

AFAICT, no runtime code ever calls getOMClass(). The generated peer
classes call TablePeer.getOMClass() and thus overriding this method
*will* work. It looks like you can define another class that is used in
row2Object(). Don't know if that could be useful.

> 
> I'm equally curious about he "alias" attribute. If it is set, some methods
> are not generated in Torque 3.3 but I do not see why nor a use case. Does
> anybody have one ?

I have no idea about his one.

As we are at it, sometimes in a schema the equivalent to "skipSql" for
the OM classes "skipJava" could be useful.

Bye, Thomas.

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


RE: please enlighten me... attributes "abstract" and "alias" on tables

Posted by Greg Monroe <Gr...@dukece.com>.
I had a vague memory that these were related to Turbine user management.
Some googling these scraps of info (from 2001-ish) about alias:

http://www.mail-archive.com/turbine-user@jakarta.apache.org/msg03870.html

http://wiki.apache.org/db-torque/PostgreSQLFAQ#What_other_issues_are_there.3F

The latter seems to indicate that alias is not needed after Turbine 2.3. 
There are hints in the former thread that alias might also perform the 
same function as the nosql attribute.

I seem to remember that abstract might have been designed for people
who wanted to build/supply their own Torque objects rather than use 
the generated ones.  This might have been related to doing custom
Turbine user management object.  But I'm not sure.

My guess is that we could drop them and nobody would miss them.  Especially
since they have not been documented well for years.


> -----Original Message-----
> From: Thomas Fischer [mailto:fischer@seitenbau.net]
> Sent: Saturday, September 25, 2010 4:54 PM
> To: Apache Torque Developers List
> Subject: please enlighten me... attributes "abstract" and "alias" on
> tables
> 
> 
> What is the attribute "abstract" used for? I'm curious because it does
> not
> seem to work currently. In Torque 3.3, the following snippet is in the
> base
> peer template:
>     public static Class getOMClass()
>         throws TorqueException
>     {
>     public static Class getOMClass()
>         throws TorqueException
>     {
> #if ($table.isAbstract())
>         String error = "You must implement the getOMClass method in
> your";
>                error += " Peer object in order for things to work
> properly.";
>                error += " This method should return the proper Class
> that";
>                error += " represents the Peer's Business Object.";
>         throw new TorqueException (error);
> #else
>         return CLASS_DEFAULT;
> #end
>     }
> As far as I know, static methods are bound at compile time and cannot be
> overridden (i.e the BasePeer code will always access this implementation
> and thus always fail).
> 
> I'm equally curious about he "alias" attribute. If it is set, some
> methods
> are not generated in Torque 3.3 but I do not see why nor a use case. Does
> anybody have one ?
> 
>      Thanks in advance for any light on this,
> 
>          Thomas
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-dev-help@db.apache.org

DukeCE Privacy Statement:
Please be advised that this e-mail and any files transmitted with
it are confidential communication or may otherwise be privileged or
confidential and are intended solely for the individual or entity
to whom they are addressed. If you are not the intended recipient
you may not rely on the contents of this email or any attachments,
and we ask that you please not read, copy or retransmit this
communication, but reply to the sender and destroy the email, its
contents, and all copies thereof immediately. Any unauthorized
dissemination, distribution or copying of this communication is
strictly prohibited.

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org