db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <fisc...@seitenbau.net>
Subject Re: please enlighten me... attributes "abstract" and "alias" on tables
Date Mon, 27 Sep 2010 19:43:09 GMT
> > 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


Mime
View raw message