Rafael Kitover > Template-Plugin-Java-0.4 > Template::Plugin::JavaSQL

Download:
Template-Plugin-Java-0.4.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

Template::Plugin::JavaSQL - Help generate Java from database schemas.

SYNOPSES ^

Within an XML file processed by the Java plugin:

        <sql:
                query="select foo as f, bar as b from some_table"
        >

        or

        <sql:
                table="some_table"
        >

Via a template such as:

        [% USE Java %]
        [% Use JavaSQL %]
        ...
        String query =
        "select [% JavaSQL.columnNames.join(", ") %] from [% JavaSQL.tables.join(", ") %]";
        [% IF JavaSQL.where %]
        query += " where [% JavaSQL.where %] ";
        [% ELSE %]
        query += " where 0=0 ";
        [% END %]
        [% FOREACH JavaSQL.columns %]
        if (${varName}Set) { query += " and $name = ?"; }
        [% END %]
        [% IF JavaSQL.order %]
        query += "order by [% JavaSQL.order %]";
        [% END %]
        stmt = myConnection.prepareStatement(query);

Just use the DBClass.template from the distribution for fully functional database classes.

DESCRIPTION ^

In addition to methods that refer to parts of a SQL query, any columns resultant from the query or table will be added as java variables to the variables hash, with close-as-possible mapped types.

METHODS ^

new

Constructor. If given one parameter of type Template::Context, will use that as a context. Then process the contents of "sql:" within the stash. This is what typically happens inside a template when a [% USE JavaSQL %] directive is encountered.

context

Returns Template::Context this instance has, if any.

query

The complete query, either supplied at instantiation or inferred from other arguments.

where

The "where" portion of the SQL query, excluding the word "where" itself.

tables

A list of tables used by the query.

tableCount

Number of tables used by query.

updatable

Whether the query used can be used to update the table.

order

An ORDER BY clause, if one was used.

columnNames

A list of column names used in the query.

isColumn

Check whether a variable name is a column.

varToColumn

Gives the column name mapping of the Java variable name.

columnToVar

Gives the Java variable name mapping of the column name.

columnCount

Number of columns returned from query.

columns

Intended to be used as [% FOREACH JavaSQL.columns %] ... See "SYNOPSYS".

parseQuery

Used internally to parse a SQL query and set the appropriate state variables.

ENVIRONMENT ^

DBI_DSN

DBI Data Source Name, for example, the data source for MySQL and database name "test" it would be: dbi:mysql:database=test

DBI_USER

User name to connect to the database as.

DBI_PASS

Password for database, can be blank for no password.

AUTHOR ^

Rafael Kitover (caelum@debian.org) The concept and related templates are based on Andrew Lanthier's dbgen framework (an unreleased development utility).

COPYRIGHT ^

This program is Copyright (c) 2000 by Rafael Kitover. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

BUGS ^

Probably many.

TODO ^

A very great deal.

SEE ALSO ^

perl(1), Template(3), Template::Plugin::Java::Utils(3), Template::Plugin::Java::Constants(3),

syntax highlighting: