You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Byron Foster <bf...@base2.cc> on 2001/12/05 19:10:42 UTC

[PATCH] Toque idbroker table setup

On Thu, 2001-11-29 at 13:02, Jason van Zyl wrote:
> On 11/29/01 2:46 PM, "John McNally" <jm...@collab.net> wrote:
> 
>> yes.  i would really like it if torque generated the sql for this,but
>> it is still a manual processu
> 
> It has setup the id tables for a long time now. There are templates
for
> creating the tables required and populating them with the initial
required
> values :-)
>  

Here is a patch that creates the necessary sql to create the idbroker
tables in standalone torque.  if the  idXMLTablXMLFile property is
defined in build.xml and the database contains at least one table that
utilizes the idbroker method then the sql generated will contain the
create for the ID_TABLE and the initialization.

Thanks,
Byron


extending the torque demo app

Posted by Rhys Dixon <rh...@dyxn.net>.
here's torque writing velocity:
this makes a page that lists all entries in a table (for each table)
it sure would be nice to have working tdk with the new torque

regards,
rhys




#set ( $quote = '"' )
#set ( $pound = '#' )
#set ( $dollar = '$' )
#set ( $ob = '{' )
#set ( $cb = '}' )


#if($data.getMessage())
Message: $data.getMessage()
#end

${pound}if ($entries)
<table>
  <tr>
    <td>
      <table cellspacing="1" cellpadding="1">
        <tr>
 #foreach ($col in $table.Columns)
      #set ( $cfc=$col.JavaName )
      #set ( $clow=$col.Name.toLowerCase() )
            ${pound}headerCell ("${cfc}")
 #end
        </tr>

        ${pound}foreach ($entry in $entries)
        <tr>
#set ($i=0)
#foreach ($col in $table.Columns)
 #if ($i>0)
    #set ( $cfc=$col.JavaName )
    #set ( $clow=$col.Name.toLowerCase() )
        ${pound}entryCell ($entry.${cfc})
 #end
#set ($i=1)
#end
#set ( $thisid = ${table.JavaName} )
          <td><a
href="${dollar}link.setPage(${quote}${table.JavaName}Edit.vm${quote}).addPat
hInfo(${quote}${table.Name}_ID${quote},
${dollar}${ob}entry.${thisid}Id${cb})">Edit</a></td>
        </tr>
        ${pound}end
      </table>
    </td>
  </tr>
</table>
${pound}end




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


extending the torque demo app

Posted by Rhys Dixon <rh...@dyxn.net>.
here's velocity generation for edit pages.
boy, i wish i had a tdk with the new torque.


regards,
rhys







## @author <a href="mailto:rhys@dyxn.net">Rhys Dixon</a>

$page.setTitle("Edit")
#set ($dollar = '$')
#set ($ob = '{')
#set ($cb = '}')
#set ($quote = '"')
#set ($pound = '#')

${pound}if(${dollar}data.getMessage())
Message: ${dollar}data.getMessage()
${pound}end

#set ($formtag = "<form method=")
#set ($formtag = $strings.concat([$formtag,${quote}]))
#set ($formtag = $strings.concat([$formtag,"post"]))
#set ($formtag = $strings.concat([$formtag,${quote}])) action="]))
#set ($formtag = $strings.concat([$formtag,${quote}]))
#set ($formtag = $strings.concat([$formtag,"$link.setPage(>"]) )
$formtag
  <div align="left">
    <table bgcolor="#ffffff" cellpadding="5">
#set ($i=0)
#foreach ($col in $table.Columns)
 #if($i > 0)
    #set ($cfc=$col.JavaName)
    #set ($clow=$col.Name.toLowerCase())
      <tr>
        #formCell ("${cfc}" "${clow}" $entry.${cfc})
      </tr>
 #end
#set ($i=1)
#end

    </table>
#set ($thisid = ${table.JavaName})
#set ($tolower=$table.Name.toLowerCase())
    <input type="hidden" name="${tolower}id"
value="${dollar}${ob}entry.${thisid}id${cb}"/>
    <input type="submit" name="eventSubmit_doInsert" value="Insert"/>
    <input type="submit" name="eventSubmit_doUpdate" value="Update"/>
    <input type="submit" name="eventSubmit_doDelete" value="Delete"/>
  </div>
</form>



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


extending the torque demo app

Posted by Rhys Dixon <rh...@dyxn.net>.
i suppose that if one listed their entries, they would want to edit them...

regards,
rhys






package ${viewlistPackage};

$license

## this is a translation of Form.java from the demo

## @author <a href="mailto:rhys@dyxn.net">Rhys Dixon</a>

/**
 *
 * This class was autogenerated by Torque : $now
 *
 * @author <a href="mailto:$email">$name</a>
 */


import java.util.Vector;

import org.apache.turbine.modules.screens.VelocitySecureScreen;
import org.apache.turbine.util.RunData;

import org.apache.turbine.util.db.Criteria;

import ${targetPackage}.${table.JavaName};
import ${targetPackage}.${table.JavaName}Peer;

import org.apache.velocity.context.Context;

public class ${table.JavaName}Edit extends VelocitySecureScreen
{
    public void doBuildTemplate( RunData data, Context context )
    {
 System.out.println("in ${table.JavaName} Edit");
        try
        {
 #set ( $idname = $table.JavaName.toUpperCase() )
            int entry_id = data.getParameters().getInt("${idname}_ID");
            Criteria criteria = new Criteria();
            criteria.add(${table.JavaName}Peer.${idname}_ID, entry_id);
            ${table.JavaName} datatype = (${table.JavaName})
${table.JavaName}Peer.doSelect(criteria).elementAt(0);
            context.put("entry", datatype);
        }
        catch (Exception e)
        {
            // log something ?
        }
    }

    protected boolean isAuthorized( RunData data ) throws Exception
    {
        System.out.println("in ${table.JavaName}List.isAuthorized");
        boolean isAuthorized = false;

        /*
         * Get acl and check security.
         */
        AccessControlList acl = data.getACL();

        if (   acl == null
                        || ! acl.hasPermission("View_${table.JavaName}")
                     )
         {
                data.addMessage("You are not authorized in this area");
    System.out.println("Unauthorized user attepted to access
${table.JavaName}: Denying");
             isAuthorized = false;
        }
        else if( acl.hasPermission("View_${table.JavaName}"))
                {
                data.addMessage("You are authorized to view an entry in
${table.JavaName}");
                System.out.println("User is authorized to view an entry in
${table.JavaName}");
                isAuthorized = true;
                }
        return isAuthorized;

    }


}



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


Re: extending the torque demo app

Posted by Rhys Dixon <rh...@dyxn.net>.
here's the java behind the list.vm that i just posted.

regards,
rhys



package ${viewlistPackage};

$license
## this is a translation of Index.java from the demo

## @author <a href="mailto:rhys@dyxn.net">Rhys Dixon</a>

/**
 *
 * This class was autogenerated by Torque : $now
 *
 * @author <a href="mailto:$email">$name</a>
 */


import java.util.Vector;

import org.apache.turbine.modules.screens.VelocitySecureScreen;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.security.AccessControlList;

import org.apache.turbine.util.db.Criteria;
import ${targetPackage}.${table.JavaName}Peer;

import org.apache.velocity.context.Context;

public class ${table.JavaName}List extends VelocitySecureScreen
{
    public void doBuildTemplate( RunData data, Context context )
    {
        context.put("entries", getEntries());
    }

    private Vector getEntries()
    {
        try
        {
  System.out.println("in ${table.JavaName} list");
            Criteria criteria = new Criteria();
            return ${table.JavaName}Peer.doSelect(criteria);
        }
        catch (Exception e)
        {
            return null;
        }
    }
    protected boolean isAuthorized( RunData data ) throws Exception
    {
        System.out.println("in ${table.JavaName}List.isAuthorized");
        boolean isAuthorized = false;

        /*
         * Get acl and check security.
         */
        AccessControlList acl = data.getACL();

        if (   acl == null
                        || ! acl.hasPermission("List_${table.JavaName}")
                     )
         {
                data.addMessage("You are not authorized in this area");
    System.out.println("Unauthorized user attepted to access
${table.JavaName}: Denying");
             isAuthorized = false;
        }
        else if( acl.hasPermission("List_${table.JavaName}"))
                {
                data.addMessage("You are authorized to list entries in ${tab
le.JavaName}");
                System.out.println("User is  authorized to list entries in
${table.JavaName}");
                isAuthorized = true;
                }
        return isAuthorized;

    }

}



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


extending the torque demo app

Posted by Rhys Dixon <rh...@dyxn.net>.
hi all,

i made a set of torque templates that generates all of the
list/view/add/edit/delete
screens, actions, velocity pages using peers, turbine and velocity pages.

this is written for the june tdk (old torque) since that's the last tdk that
worked correctly for me.

regards,
rhys

here is one file:



package ${managerPackage};

$license
## this is a translation of SQL.java from the demo

## @author <a href="mailto:rhys@dyxn.net">Rhys Dixon</a>

/**
 *
 * This class was autogenerated by Torque : $now
 *
 * @author <a href="mailto:$email">$name</a>
 */


import org.apache.velocity.context.Context;

import org.apache.turbine.util.RunData;
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.modules.actions.VelocitySecureAction;
import org.apache.turbine.services.security.TurbineSecurity;
import org.apache.turbine.util.security.AccessControlList;

import ${targetPackage}.${table.JavaName};
import ${targetPackage}.${table.JavaName}Peer;

public class ${table.JavaName}Manager extends VelocitySecureAction
{
    public void doInsert(RunData data, Context context)
        throws Exception
    {
 System.out.println("inserting new ${table.JavaName}");
        ${table.JavaName} entry = new ${table.JavaName}();
        data.getParameters().setProperties(entry);
        entry.save();
 System.out.println("after inserting new ${table.JavaName}");
    }
    /*
    public void doUpdate(RunData data, Context context)
        throws Exception
    {
 System.out.println("updating ${table.JavaName}");
        ${table.JavaName} entry = new ${table.JavaName}();
        data.getParameters().setProperties(entry);
 System.out.println("updating ${table.JavaName} with
id#"+entry.get${table.JavaName}Id());
 ${table.JavaName}Peer.doUpdate(entry);

 System.out.println("after updating ${table.JavaName}");
 }
 */

    public void doUpdate(RunData data, Context context)
        throws Exception
    {
        ${table.JavaName} entry = new ${table.JavaName}();
        data.getParameters().setProperties(entry);
        entry.setModified(true);
        entry.setNew(false);
        entry.save();
    }




    public void doDelete(RunData data, Context context)
        throws Exception
    {
 System.out.println("deleting from ${table.JavaName}");
        Criteria criteria = new Criteria();
 #set ( $idname = $table.JavaName.toUpperCase() )
        criteria.add(${table.JavaName}Peer.${idname}_ID,
data.getParameters().getInt("${table.name}id"));
        ${table.JavaName}Peer.doDelete(criteria);
 System.out.println("after deleting from ${table.JavaName}");
    }

    public void doPerform(RunData data, Context context)
        throws Exception
    {
 System.out.println("in ${table.JavaName}Manager.doPerform");
        data.setMessage("Can't find the button!<br />");
    }


    protected boolean isAuthorized( RunData data ) throws Exception
    {
        System.out.println("in ${table.JavaName}Manager.isAuthorized");
        boolean isAuthorized = false;

        /*
         * Get acl and check security.
         */
        AccessControlList acl = data.getACL();

        if (acl == null
                        || ! acl.hasPermission("Insert_${table.JavaName}")
                        || ! acl.hasPermission("Update_${table.JavaName}")
                        || ! acl.hasPermission("Delete_${table.JavaName}")
                        )
        {
                data.addMessage("You are not authorized in this area<br
/>");
  System.out.println("You are not authorized in this area<br />");
             isAuthorized = false;
        }
        else if(
data.getParameters().getString("eventSubmit_doInsert","").equals("Insert")
&&
acl.hasPermission("Insert_${table.JavaName}"))
                {
                data.addMessage("You are authorized to add to
${table.JavaName}");
                System.out.println("You are authorized to add to
${table.JavaName}<br />");
                isAuthorized = true;
                }
        else if(
data.getParameters().getString("eventSubmit_doUpdate","").equals("Update")
&&
acl.hasPermission("Update_${table.JavaName}"))
                {
                data.addMessage("You are authorized to update entries in
${table.JavaName}");
                System.out.println("You are authorized to update entries in
${table.JavaName}<br />");
                isAuthorized = true;
                }
        else if(
data.getParameters().getString("eventSubmit_doDelete","").equals("Delete")
&&
acl.hasPermission("Delete_${table.JavaName}"))
                {
                data.addMessage("You are authorized to delete from
${table.JavaName}<br />");
                System.out.println("You are authorized to delete from
${table.JavaName}");
                isAuthorized = true;
                }
        return isAuthorized;

    }




}



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


that broken link

Posted by Jakarta <ja...@dyxn.net>.
hi all,

i found the standards page. it's ok in the turbine page from "coding
specifications"
in the developer section of the menu, but not in the main site.

i suppose this means that a site commiter has to do it

navigating from the "guidelines notes" link on jakarta main page
http://jakarta.apache.org/site/guidelines.html

link to "source repositories"

http://jakarta.apache.org/site/source.html

has a link to "turbine has it's own defined conventions"

http://jakarta.apache.org/turbine/code-standards.html

should be

http://jakarta.apache.org/turbine/common/code-standards.html


well, since i found the page i was looking for, it's no longer a problem :-)

regards,

rhys






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


Re: [PATCH] Toque idbroker table setup

Posted by Byron Foster <bf...@base2.cc>.
> 
> I don't believe Ant understands the Unix idiom of ~/ as the home directory.
> You should use  ${user.home}/build.properties
> 
> 

True, I was using that as a shorthand for the email.  It is able to find
the ${user.home}/build.properties file ok.  Ultimately it can't find the
build.properties file in the rtest directory.  I will investigate and
see if I can find the problem.  

Thanks
Byron  


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


Re: [PATCH] Toque idbroker table setup

Posted by Jason van Zyl <jv...@zenplex.com>.
On 12/5/01 4:33 PM, "Byron Foster" <bf...@base2.cc> wrote:

> 
>> 
>> Did you run the testbed against your changes. If you have a test profile and
>> the tests still work than the patch is cool and we'll put it in.
>> 
>>  
> 
> I did not,  I have had some difficulty running the testbed.  I'm not
> sure what I'm doing wrong.  I get the following error:
> 
> 
> [torque-create-db] Resolver: used database.dtd from
> org.apache.torque.engine.database.transform package
>     [sql] Executing file:
> 
/home/bfoster/open/jakarta-turbine-torque/bin/test/rttest/src/sql/create-db.
sq> l
>     [sql] 2 of 2 SQL statements executed successfully
> 
> test-project-sql:
> 
> project-sql:
>    [echo] +------------------------------------------+
>    [echo] |                                          |
>    [echo] | Generating SQL for YOUR Turbine project! |
>    [echo] | Woo hoo!                                 |
>    [echo] |                                          |
>    [echo] +------------------------------------------+
> 
> BUILD FAILED
> 
> /home/bfoster/open/jakarta-turbine-torque/bin/test/rttest/build-torque.xml:72:
> Context properties file build.properties could not be found in the file system
> or on the classpath!
> 
> -===============================================
> 
> I'm using mysql.profile
> 
> To be clear: I did the following,
> 
> set torque.testProfile in ~/build.properties (The default setting are
> ok)

I don't believe Ant understands the Unix idiom of ~/ as the home directory.
You should use  ${user.home}/build.properties


> run "ant dist"
> copied over the mysql jdbc driver.
> run "ant test"
> 
> Am I missing something?
> 
> Thanks,
> Byron
> 
> 
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

-- 

jvz.

Jason van Zyl

http://tambora.zenplex.org
http://jakarta.apache.org/turbine
http://jakarta.apache.org/velocity
http://jakarta.apache.org/alexandria
http://jakarta.apache.org/commons



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


Re: [PATCH] Toque idbroker table setup

Posted by Byron Foster <bf...@base2.cc>.
> 
> Did you run the testbed against your changes. If you have a test profile and
> the tests still work than the patch is cool and we'll put it in.
> 
>  

I did not,  I have had some difficulty running the testbed.  I'm not
sure what I'm doing wrong.  I get the following error:


[torque-create-db] Resolver: used database.dtd from
org.apache.torque.engine.database.transform package 
      [sql] Executing file:
/home/bfoster/open/jakarta-turbine-torque/bin/test/rttest/src/sql/create-db.sql
      [sql] 2 of 2 SQL statements executed successfully

test-project-sql:

project-sql:
     [echo] +------------------------------------------+
     [echo] |                                          |
     [echo] | Generating SQL for YOUR Turbine project! |
     [echo] | Woo hoo!                                 |
     [echo] |                                          |
     [echo] +------------------------------------------+

BUILD FAILED

/home/bfoster/open/jakarta-turbine-torque/bin/test/rttest/build-torque.xml:72: Context properties file build.properties could not be found in the file system or on the classpath!

-===============================================

I'm using mysql.profile

To be clear: I did the following,

set torque.testProfile in ~/build.properties (The default setting are
ok)
run "ant dist"
copied over the mysql jdbc driver.
run "ant test"

Am I missing something?

Thanks,
Byron






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


Re: [PATCH] Toque idbroker table setup

Posted by Byron Foster <bf...@base2.cc>.
On Wed, 2001-12-12 at 02:11, Martin Poeschl wrote:

> i looked at it over the weekend ... but it broke the testbed and i didn't have the time to look 
> deeper :-(
> 
> 

Hmmm, I just checked out a fresh copy of Torque from CVS at the time of
this posting and applied the idbroker.patch2.txt patch and it worked
with the mysql testbed.  It also worked with the sybase testbed with the
sybase.patch.txt file I just sent. Send me a dump of the output and I
can investigate. For what database are you testing?

Thanks,
Byron





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


Re: [PATCH] Toque idbroker table setup

Posted by Martin Poeschl <mp...@marmot.at>.
i looked at it over the weekend ... but it broke the testbed and i didn't have the time to look 
deeper :-(


martin

Daniel Rall wrote:

> Anyone taking care of this?
> 
> Byron Foster <bf...@base2.cc> writes:
> 
> 
>>>>This patch makes it simpler to use.  It is smart in that if you are
>>>>using method idbroker the id table is generated into the
>>>>project-schema.xml file. Otherwise, if the method is native, no such
>>>>table is generated. One does not need to generate two sql files based on
>>>>if they are using idbroker or not. I think it earns a point in the "it
>>>>just works" category.  If the idXMLTableXMLFile property is not
>>>>specified, functionality remains as is.
>>>>
>>>Did you run the testbed against your changes. If you have a test profile and
>>>the tests still work than the patch is cool and we'll put it in.
>>>
>>>
>>Ok, I got the testbed to work and it tests ok with this patch.  I'm
>>submitting a new patch because some changes were made to the cvs
>>repository yesterday that causes conflicts with the old patch.




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


Re: [PATCH] Toque idbroker table setup

Posted by Daniel Rall <dl...@finemaltcoding.com>.
Anyone taking care of this?

Byron Foster <bf...@base2.cc> writes:

>> > This patch makes it simpler to use.  It is smart in that if you are
>> > using method idbroker the id table is generated into the
>> > project-schema.xml file. Otherwise, if the method is native, no such
>> > table is generated. One does not need to generate two sql files based on
>> > if they are using idbroker or not. I think it earns a point in the "it
>> > just works" category.  If the idXMLTableXMLFile property is not
>> > specified, functionality remains as is.
>> 
>> Did you run the testbed against your changes. If you have a test profile and
>> the tests still work than the patch is cool and we'll put it in.
>> 
>
> Ok, I got the testbed to work and it tests ok with this patch.  I'm
> submitting a new patch because some changes were made to the cvs
> repository yesterday that causes conflicts with the old patch.
>
> Index: src/conf/build.xml
> ===================================================================
> RCS file: /home/cvspublic/jakarta-turbine-torque/src/conf/build.xml,v
> retrieving revision 1.20
> diff -u -r1.20 build.xml
> --- src/conf/build.xml	2001/12/06 22:48:04	1.20
> +++ src/conf/build.xml	2001/12/07 08:48:53
> @@ -69,6 +69,7 @@
>        templatePath="${templatePath}"
>        sqldbmap="${torque.home}/${outputDirectory}/sql/sqldb.map"
>        outputFile="report.${project}.sql.generation"
> +      idTableXMLFile="${torque.home}/schema/id-table-schema.xml"
>        targetDatabase="${database}">
>        <fileset dir="${torque.home}/${schemaDirectory}">
>          <include name="*-schema.xml"/>
> @@ -395,6 +396,7 @@
>        outputFile="report.${project}.sql.generation"
>        xmlFile="${torque.home}/${schemaDirectory}/${project}-schema.xml"
>        targetDatabase="${database}"
> +      idTableXMLFile="${torque.home}/schema/id-table-schema.xml"
>      />
>  
>    </target>
> Index: src/java/org/apache/torque/adapter/IDMethod.java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/adapter/IDMethod.java,v
> retrieving revision 1.2
> diff -u -r1.2 IDMethod.java
> --- src/java/org/apache/torque/adapter/IDMethod.java	2001/10/15 16:53:10	1.2
> +++ src/java/org/apache/torque/adapter/IDMethod.java	2001/12/07 08:48:53
> @@ -82,7 +82,7 @@
>      /**
>       * Key generation via the IDBroker table.
>       */
> -    String ID_BROKER = "idbroker_table";
> +    String ID_BROKER = "idbroker";
>  
>      /**
>       * No RDBMS key generation (keys may be generated by the
> Index: src/java/org/apache/torque/engine/database/model/Database.java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Database.java,v
> retrieving revision 1.7
> diff -u -r1.7 Database.java
> --- src/java/org/apache/torque/engine/database/model/Database.java	2001/11/08 17:20:52	1.7
> +++ src/java/org/apache/torque/engine/database/model/Database.java	2001/12/07 08:48:53
> @@ -67,7 +67,9 @@
>  
>  import org.apache.torque.engine.database.model.NameGenerator;
>  
> +import org.apache.torque.adapter.IDMethod;
>  
> +
>  /**
>   * A class for holding application data structures.
>   *
> @@ -328,6 +330,28 @@
>          return (p == null ? null : p.getProperty(name));
>      }
>  
> +    /**
> +     * Determines if this database will be using the
> +     * <code>IDMethod.ID_BROKER</code> to create ids for torque OM
> +     * objects.
> +     * @return true if there is at least one table in this database that
> +     * uses the <code>IDMethod.ID_BROKER</code> method of generating
> +     * ids. returns false otherwise.
> +     */
> +    public boolean requiresIdTable()
> +    {
> +        Table table[] = getTables();
> +        for (int i=0; i<table.length; i++)
> +        {
> +            if (table[i].getIdMethod().equals(IDMethod.ID_BROKER))
> +            {
> +                return true;
> +            }
> +        }
> +        return false;
> +    }
> +
> +  
>      /**
>       * Creats a string representation of this Database.
>       * The representation is given in xml format.
> Index: src/java/org/apache/torque/engine/database/model/Table.java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Table.java,v
> retrieving revision 1.17
> diff -u -r1.17 Table.java
> --- src/java/org/apache/torque/engine/database/model/Table.java	2001/11/15 00:37:23	1.17
> +++ src/java/org/apache/torque/engine/database/model/Table.java	2001/12/07 08:48:53
> @@ -619,7 +619,7 @@
>      {
>          if (idMethod == null)
>          {
> -            return "none";
> +            return IDMethod.NO_ID_METHOD;
>          }
>          else
>          {
> Index: src/java/org/apache/torque/engine/database/transform/SQLToAppData.java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/transform/SQLToAppData.java,v
> retrieving revision 1.1.1.1
> diff -u -r1.1.1.1 SQLToAppData.java
> --- src/java/org/apache/torque/engine/database/transform/SQLToAppData.java	2001/08/02 05:08:33	1.1.1.1
> +++ src/java/org/apache/torque/engine/database/transform/SQLToAppData.java	2001/12/07 08:48:53
> @@ -69,6 +69,7 @@
>  import org.apache.torque.engine.sql.ParseException;
>  import org.apache.torque.engine.sql.SQLScanner;
>  import org.apache.torque.engine.sql.Token;
> +import org.apache.torque.adapter.IDMethod;
>  
>  /**
>   * A Class that converts an sql input file to an AppData
> @@ -190,11 +191,11 @@
>          
>          if (tbl.getPrimaryKey().size() == 1)
>          {
> -            tbl.setIdMethod("idbroker");
> +            tbl.setIdMethod(IDMethod.ID_BROKER);
>          }
>          else
>          {
> -            tbl.setIdMethod("none");
> +            tbl.setIdMethod(IDMethod.NO_ID_METHOD);
>          }
>          	
>          
> Index: src/java/org/apache/torque/task/TorqueSQLTask.java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueSQLTask.java,v
> retrieving revision 1.8
> diff -u -r1.8 TorqueSQLTask.java
> --- src/java/org/apache/torque/task/TorqueSQLTask.java	2001/11/01 00:39:49	1.8
> +++ src/java/org/apache/torque/task/TorqueSQLTask.java	2001/12/07 08:48:53
> @@ -61,7 +61,10 @@
>  import java.util.Iterator;
>  import org.apache.velocity.context.Context;
>  import org.apache.velocity.VelocityContext;
> +import org.apache.torque.engine.database.transform.XmlToAppData;
> +import org.apache.torque.engine.database.model.AppData;
>  
> +
>  /**
>   * An extended Texen task used for generating SQL source from
>   * an XML schema describing a database structure.
> @@ -88,6 +91,8 @@
>      private String database;
>      private String suffix = "";
>      
> +    private String idTableXMLFile = null;
> +    
>      public void setDatabase(String database)
>      {
>          this.database = database;
> @@ -109,6 +114,25 @@
>      }        
>  
>      /**
> +     * Set the path to the xml schema file that defines the id-table, used
> +     * by the idbroker method.
> +     * @param xml path to file.
> +     */
> +    public void setIdTableXMLFile(String idXmlFile)
> +    {
> +        idTableXMLFile = idXmlFile;
> +    }
> +
> +    /**
> +     * Gets the id-table xml schema file path.
> +     * @return Path to file.
> +     */
> +    public String getIdTableXMLFile()
> +    {
> +        return idTableXMLFile;
> +    }
> +    
> +    /**
>       * Get the current target package.
>       *
>       * @return String target database(s)
> @@ -175,6 +199,23 @@
>      }
>  
>      /**
> +     * Create the database model necessary for the IDBroker tables.
> +     * We use the model to generate the necessary SQL to create
> +     * these tables.  This method adds an AppData object containing
> +     * the model to the context under the name "idmodel".
> +     */
> +    public void loadIdBrokerModel()
> +    {
> +        // Transform the XML database schema into
> +        // data model object.
> +        XmlToAppData xmlParser = new XmlToAppData();
> +        AppData ad = xmlParser.parseFile(getIdTableXMLFile());
> +        xmlParser.parseFile(getIdTableXMLFile());
> +        ad.setName("idmodel");
> +        context.put("idmodel", ad);
> +    }
> +
> +    /**
>       * Place our target database and target platform
>       * values into the context for use in the
>       * templates.
> @@ -185,6 +226,14 @@
>          super.initControlContext();
>          context.put("targetDatabase", targetDatabase);
>          createSqlDbMap();
> +
> +        // If the load path for the id broker table xml schema is
> +        // defined then load it.
> +        if (getIdTableXMLFile() != null)
> +        {
> +            loadIdBrokerModel();
> +        }
> +        
>          return context;
>      }
>  }
> Index: src/templates/sql/base/Control.vm
> ===================================================================
> RCS file: /home/cvspublic/jakarta-turbine-torque/src/templates/sql/base/Control.vm,v
> retrieving revision 1.3
> diff -u -r1.3 Control.vm
> --- src/templates/sql/base/Control.vm	2001/11/15 00:37:52	1.3
> +++ src/templates/sql/base/Control.vm	2001/12/07 08:48:53
> @@ -2,11 +2,12 @@
>  #set ( $dbprops = $properties.load("$generator.TemplatePath/sql/base/$targetDatabase/db.props") )
>  #set ( $fname= "sql/base/$targetDatabase/table.vm" )
>  #set ( $fnamekeys= "sql/base/$targetDatabase/tablefk.vm" )
> +#set ( $idname = "sql/id-table/idtable.$targetDatabase" )
>  
>  #foreach ($dataModel in $dataModels)
>          
>    #set ( $outFile = "${dataModel.name}.sql" )
> -        
> +
>    File to be created: $outFile
>    
>    #set ( $database = $dataModel.database )
> @@ -22,4 +23,25 @@
>        $generator.parse($fnamekeys,$outFile,"tablefk",$tbl)
>      #end
>    #end    
> +
> +  #if ($idmodel)
> +
> +    Creating id-table
> +
> +    ## Generate id-table.  Little kludge, we only really expect one
> +    ## table in the database, mainly the ID-TABLE.  However, the object
> +    ## returned by Database.getTables() is an array of Table objects.
> +    ## I'm not sure how to get the first element out of the array
> +    ## without using the below work around.
> +    #foreach ($tmptable in $idmodel.database.tables)
> +      #set ($tbl = $tmptable)
> +    #end
> +    $generator.parse($fname,$outFile,"table",$tbl)
> + 
> +    ## Generate inserts into ID-TABLE for initial ids.
> +    #set ( $initialID = 1 )  
> +    $generator.parse($idname, $outFile, "tables", $database.tables)
> +
> +  #end
> +
>  #end

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


Re: [PATCH] Toque idbroker table setup

Posted by John McNally <jm...@collab.net>.
patches applied, thank you.

I modified the patch to Control.vm, so let me know if I messed it up.

john mcnally

Byron Foster wrote:
> 
> On Wed, 2001-12-05 at 13:45, Jason van Zyl wrote:
> > On 12/5/01 3:27 PM, "Byron Foster" <bf...@base2.cc> wrote:
> >
> > > On Wed, 2001-12-05 at 11:21, Jason van Zyl wrote:
> > >> On 12/5/01 1:10 PM, "Byron Foster" <bf...@base2.cc> wrote:
> > >>
> > >>> On Thu, 2001-11-29 at 13:02, Jason van Zyl wrote:
> > >>>> On 11/29/01 2:46 PM, "John McNally" <jm...@collab.net> wrote:
> > >>>>
> > >>>>> yes.  i would really like it if torque generated the sql for this,but
> > >>>>> it is still a manual processu
> > >>>>
> > >>>> It has setup the id tables for a long time now. There are templates
> > >>> for
> > >>>> creating the tables required and populating them with the initial
> > >>> required
> > >>>> values :-)
> > >>>>
> > >>>
> > >>> Here is a patch that creates the necessary sql to create the idbroker
> > >>> tables in standalone torque.  if the  idXMLTablXMLFile property is
> > >>> defined in build.xml and the database contains at least one table that
> > >>> utilizes the idbroker method then the sql generated will contain the
> > >>> create for the ID_TABLE and the initialization.
> > >>
> > >> There are already tasks to do this.
> > >>
> > >
> > > This patch makes it simpler to use.  It is smart in that if you are
> > > using method idbroker the id table is generated into the
> > > project-schema.xml file. Otherwise, if the method is native, no such
> > > table is generated. One does not need to generate two sql files based on
> > > if they are using idbroker or not. I think it earns a point in the "it
> > > just works" category.  If the idXMLTableXMLFile property is not
> > > specified, functionality remains as is.
> >
> > Did you run the testbed against your changes. If you have a test profile and
> > the tests still work than the patch is cool and we'll put it in.
> >
> 
> Ok, I got the testbed to work and it tests ok with this patch.  I'm
> submitting a new patch because some changes were made to the cvs
> repository yesterday that causes conflicts with the old patch.
> 
> Thanks,
> Byron
> 
>   ------------------------------------------------------------------------
>                           Name: idbroker.patch2.txt
>    idbroker.patch2.txt    Type: Plain Text (text/plain)
>                       Encoding: quoted-printable
> 
>   ------------------------------------------------------------------------
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

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


Re: [PATCH] Toque idbroker table setup

Posted by Byron Foster <bf...@base2.cc>.
On Wed, 2001-12-05 at 13:45, Jason van Zyl wrote:
> On 12/5/01 3:27 PM, "Byron Foster" <bf...@base2.cc> wrote:
> 
> > On Wed, 2001-12-05 at 11:21, Jason van Zyl wrote:
> >> On 12/5/01 1:10 PM, "Byron Foster" <bf...@base2.cc> wrote:
> >> 
> >>> On Thu, 2001-11-29 at 13:02, Jason van Zyl wrote:
> >>>> On 11/29/01 2:46 PM, "John McNally" <jm...@collab.net> wrote:
> >>>> 
> >>>>> yes.  i would really like it if torque generated the sql for this,but
> >>>>> it is still a manual processu
> >>>> 
> >>>> It has setup the id tables for a long time now. There are templates
> >>> for
> >>>> creating the tables required and populating them with the initial
> >>> required
> >>>> values :-)
> >>>>  
> >>> 
> >>> Here is a patch that creates the necessary sql to create the idbroker
> >>> tables in standalone torque.  if the  idXMLTablXMLFile property is
> >>> defined in build.xml and the database contains at least one table that
> >>> utilizes the idbroker method then the sql generated will contain the
> >>> create for the ID_TABLE and the initialization.
> >> 
> >> There are already tasks to do this.
> >>  
> > 
> > This patch makes it simpler to use.  It is smart in that if you are
> > using method idbroker the id table is generated into the
> > project-schema.xml file. Otherwise, if the method is native, no such
> > table is generated. One does not need to generate two sql files based on
> > if they are using idbroker or not. I think it earns a point in the "it
> > just works" category.  If the idXMLTableXMLFile property is not
> > specified, functionality remains as is.
> 
> Did you run the testbed against your changes. If you have a test profile and
> the tests still work than the patch is cool and we'll put it in.
> 

Ok, I got the testbed to work and it tests ok with this patch.  I'm
submitting a new patch because some changes were made to the cvs
repository yesterday that causes conflicts with the old patch.

Thanks,
Byron


Re: [PATCH] Toque idbroker table setup

Posted by Jason van Zyl <jv...@zenplex.com>.
On 12/5/01 3:27 PM, "Byron Foster" <bf...@base2.cc> wrote:

> On Wed, 2001-12-05 at 11:21, Jason van Zyl wrote:
>> On 12/5/01 1:10 PM, "Byron Foster" <bf...@base2.cc> wrote:
>> 
>>> On Thu, 2001-11-29 at 13:02, Jason van Zyl wrote:
>>>> On 11/29/01 2:46 PM, "John McNally" <jm...@collab.net> wrote:
>>>> 
>>>>> yes.  i would really like it if torque generated the sql for this,but
>>>>> it is still a manual processu
>>>> 
>>>> It has setup the id tables for a long time now. There are templates
>>> for
>>>> creating the tables required and populating them with the initial
>>> required
>>>> values :-)
>>>>  
>>> 
>>> Here is a patch that creates the necessary sql to create the idbroker
>>> tables in standalone torque.  if the  idXMLTablXMLFile property is
>>> defined in build.xml and the database contains at least one table that
>>> utilizes the idbroker method then the sql generated will contain the
>>> create for the ID_TABLE and the initialization.
>> 
>> There are already tasks to do this.
>>  
> 
> This patch makes it simpler to use.  It is smart in that if you are
> using method idbroker the id table is generated into the
> project-schema.xml file. Otherwise, if the method is native, no such
> table is generated. One does not need to generate two sql files based on
> if they are using idbroker or not. I think it earns a point in the "it
> just works" category.  If the idXMLTableXMLFile property is not
> specified, functionality remains as is.

Did you run the testbed against your changes. If you have a test profile and
the tests still work than the patch is cool and we'll put it in.

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

-- 

jvz.

Jason van Zyl

http://tambora.zenplex.org
http://jakarta.apache.org/turbine
http://jakarta.apache.org/velocity
http://jakarta.apache.org/alexandria
http://jakarta.apache.org/commons



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


Re: [PATCH] Toque idbroker table setup

Posted by Byron Foster <bf...@base2.cc>.
On Wed, 2001-12-05 at 11:21, Jason van Zyl wrote:
> On 12/5/01 1:10 PM, "Byron Foster" <bf...@base2.cc> wrote:
> 
> > On Thu, 2001-11-29 at 13:02, Jason van Zyl wrote:
> >> On 11/29/01 2:46 PM, "John McNally" <jm...@collab.net> wrote:
> >> 
> >>> yes.  i would really like it if torque generated the sql for this,but
> >>> it is still a manual processu
> >> 
> >> It has setup the id tables for a long time now. There are templates
> > for
> >> creating the tables required and populating them with the initial
> > required
> >> values :-)
> >>  
> > 
> > Here is a patch that creates the necessary sql to create the idbroker
> > tables in standalone torque.  if the  idXMLTablXMLFile property is
> > defined in build.xml and the database contains at least one table that
> > utilizes the idbroker method then the sql generated will contain the
> > create for the ID_TABLE and the initialization.
> 
> There are already tasks to do this.
>  

This patch makes it simpler to use.  It is smart in that if you are
using method idbroker the id table is generated into the
project-schema.xml file. Otherwise, if the method is native, no such
table is generated. One does not need to generate two sql files based on
if they are using idbroker or not. I think it earns a point in the "it
just works" category.  If the idXMLTableXMLFile property is not
specified, functionality remains as is.

Thanks,
Byron





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


Re: [PATCH] Toque idbroker table setup

Posted by Jason van Zyl <jv...@zenplex.com>.
On 12/5/01 1:10 PM, "Byron Foster" <bf...@base2.cc> wrote:

> On Thu, 2001-11-29 at 13:02, Jason van Zyl wrote:
>> On 11/29/01 2:46 PM, "John McNally" <jm...@collab.net> wrote:
>> 
>>> yes.  i would really like it if torque generated the sql for this,but
>>> it is still a manual processu
>> 
>> It has setup the id tables for a long time now. There are templates
> for
>> creating the tables required and populating them with the initial
> required
>> values :-)
>>  
> 
> Here is a patch that creates the necessary sql to create the idbroker
> tables in standalone torque.  if the  idXMLTablXMLFile property is
> defined in build.xml and the database contains at least one table that
> utilizes the idbroker method then the sql generated will contain the
> create for the ID_TABLE and the initialization.

There are already tasks to do this.
 
> Thanks,
> Byron
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

-- 

jvz.

Jason van Zyl

http://tambora.zenplex.org
http://jakarta.apache.org/turbine
http://jakarta.apache.org/velocity
http://jakarta.apache.org/alexandria
http://jakarta.apache.org/commons



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