com.arsdigita.toolbox.ui
Class StaticDataQueryBuilder

java.lang.Object
  extended bycom.arsdigita.toolbox.ui.StaticDataQueryBuilder
All Implemented Interfaces:
DataQueryBuilder, Lockable

public class StaticDataQueryBuilder
extends Object
implements DataQueryBuilder

This class is used to create an implementation of DataQueryBuilder that relies on a static DataQuery. Example:

 Page p = new Page("Data Table Page");
 // Build a data query to retrieve all users.
 String sql = "select users.user_id," +
              "person_names.given_name, " +
              "person_names.family_name, " +
              "parties.primary_email " +
         "from users, person_names, parties " +
        "where users.name_id = person_names.name_id " +
          "and users.user_id = parties.party_id";
 String cols[] = {"user_id", "given_name", "family_name", "primary_email"};
 DataQueryBuilder dqb = new StaticDataQueryBuilder(sql, cols);
 DataTable dt = new DataTable(dqb);

 dt.setEmptyView(new Label(GlobalizationUtil.globalize("toolbox.ui.no_results")));
 dt.addColumn("User ID", "user_id", true, new DefaultTableCellRenderer());
 dt.addColumn("First Name", "given_name", true, new DefaultTableCellRenderer());
 dt.addColumn("Last Name", "family_name", true, new DefaultTableCellRenderer());
 dt.addColumn("Email", "primary_email", true, new DefaultTableCellRenderer());

 // Put the table on the page and serve.
 p.add(dt);
 p.lock();
 pm.servePage(p, request, response);
 

Author:
Bryan Quinn

Field Summary
static String versionId
           
 
Constructor Summary
StaticDataQueryBuilder(DataQuery dq, String keyColumn)
          Creates a DataQueryBuilder that will always return the specified DataQuery and keyColumn.
StaticDataQueryBuilder(String sql, String[] columns)
          Create a StaticDataQueryBuilder that consists of the specified SQL query.
 
Method Summary
 String getKeyColumn()
           
 boolean isLocked()
          Return whether an object is locked and thus immutable, or can still be modified.
 void lock()
          Lock an object.
 DataQuery makeDataQuery(DataTable t, PageState s)
          Perform all neccessary database operations and return a DataQuery for the DataTable to use
 void setDataQuery(DataQuery dq)
          Update the DataQuery returned by makeDataQuery(com.arsdigita.toolbox.ui.DataTable, com.arsdigita.bebop.PageState) to the specified DataQuery.
 void setKeyColumn(String keyColumn)
          Update the key column returned by getKeyColumn() to the the specified key column.
 void update(DataQuery dq, String keyColumn)
          A convenience method to update the data query and key column with one call.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

StaticDataQueryBuilder

public StaticDataQueryBuilder(DataQuery dq,
                              String keyColumn)
Creates a DataQueryBuilder that will always return the specified DataQuery and keyColumn.

Parameters:
dq - The DataQuery to be returned byt this DataQueryBuilder.
keyColumn - The primary key column specified in the DataQuery provided.

StaticDataQueryBuilder

public StaticDataQueryBuilder(String sql,
                              String[] columns)
Create a StaticDataQueryBuilder that consists of the specified SQL query. The column array specifies what property names to map to the columns retrieved by the query in numeric order. The first entry in the column array is presumed to be primary key column.

Parameters:
sql - A SQL query.
columns - An array of column names corresponding to the the columns in the SQL query.
Method Detail

makeDataQuery

public DataQuery makeDataQuery(DataTable t,
                               PageState s)
Perform all neccessary database operations and return a DataQuery for the DataTable to use

Specified by:
makeDataQuery in interface DataQueryBuilder
Parameters:
t - the parent DataTable
s - the page state

getKeyColumn

public String getKeyColumn()
Specified by:
getKeyColumn in interface DataQueryBuilder
Returns:
the name of the column in the query that serves as the primary key for the items

setDataQuery

public void setDataQuery(DataQuery dq)
Update the DataQuery returned by makeDataQuery(com.arsdigita.toolbox.ui.DataTable, com.arsdigita.bebop.PageState) to the specified DataQuery.


setKeyColumn

public void setKeyColumn(String keyColumn)
Update the key column returned by getKeyColumn() to the the specified key column.


update

public void update(DataQuery dq,
                   String keyColumn)
A convenience method to update the data query and key column with one call.


lock

public void lock()
Description copied from interface: Lockable
Lock an object. Locked objects are to be considered immutable. Any attempt to modify them, e.g., through a setXXX method should lead to an exception.

Most lockable Bebop classes throw an IllegalStateException if an attempt is made to modify a locked instance.

Specified by:
lock in interface Lockable

isLocked

public boolean isLocked()
Description copied from interface: Lockable
Return whether an object is locked and thus immutable, or can still be modified.

Specified by:
isLocked in interface Lockable


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC