FileDocCategorySizeDatePackage
QueryPlan.javaAPI DocGlassfish v2 API9237Fri May 04 22:35:16 BST 2007com.sun.jdo.spi.persistence.support.sqlstore.sql.generator

QueryPlan

public abstract class QueryPlan extends Object
This class is used to generate SQL statements.

Fields Summary
public static final int
ACT_UPDATE
public static final int
ACT_INSERT
public static final int
ACT_DELETE
public static final int
ACT_SELECT
public static final int
ACT_NOOP
protected static final int
ST_BUILT
public ArrayList
statements
Array of Statement.
protected com.sun.jdo.spi.persistence.support.sqlstore.model.ClassDesc
config
protected int
status
Bitmask containing one of {@link QueryPlan#ST_BUILT}, {@link SelectQueryPlan#ST_C_BUILT}, {@link SelectQueryPlan#ST_OC_BUILT}, {@link SelectQueryPlan#ST_JOINED}
protected int
action
protected com.sun.jdo.spi.persistence.support.sqlstore.SQLStoreManager
store
protected ArrayList
tables
Array of QueryTable.
protected static final ResourceBundle
messages
I18N message handler.
Constructors Summary
public QueryPlan(com.sun.jdo.spi.persistence.support.sqlstore.ActionDesc desc, com.sun.jdo.spi.persistence.support.sqlstore.SQLStoreManager store)


         
        this.tables = new ArrayList();
        this.statements = new ArrayList();
        this.store = store;
        this.config = (ClassDesc) store.getPersistenceConfig(desc.getPersistenceCapableClass());
    
Methods Summary
public QueryTableaddQueryTable(com.sun.jdo.spi.persistence.support.sqlstore.model.TableDesc tableDesc)

        QueryTable table = new QueryTable(tableDesc);
        tables.add(table);
        table.setTableIndex(new TableIndex(tables.size() - 1));
        return table;
    
public QueryTableaddQueryTable(org.netbeans.modules.dbschema.TableElement tableElement, com.sun.jdo.spi.persistence.support.sqlstore.model.ClassDesc persistenceConfig)
Identifies a database table which will become part of this query plan. We will build a QueryTable object describing its use and return it. Note: No join is constructed at this point for the table added.

param
tableElement Identifies which table is being added.
param
persistenceConfig If we are adding a foreign table the persistenceConfig parameter holds the PersistenceConfig for the foreign Persistence Class.


        ClassDesc _config = (persistenceConfig == null) ? this.config : persistenceConfig;
        TableDesc tableDesc = _config.findTableDesc(tableElement);

        if (tableDesc == null) {

            if (tableElement != null) {
               throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
                        "core.configuration.classnotmappedtotable", // NOI18N
                        _config.getPersistenceCapableClass().getName(),
                        tableElement.getName().getName()));
            } else {
                throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
                         "core.configuration.classnotmapped", // NOI18N
                         _config.getPersistenceCapableClass().getName()));

            }
        }

        return addQueryTable(tableDesc);
    
public voidaddQueryTables(java.util.ArrayList queryTables)
Add all the tables from queryTables to the current query plan. Useful when transfering tables when joining query plans together.

param
queryTables Query tables from the foreign plan to be added.


        for (int i = 0; i < queryTables.size(); i++) {
            QueryTable t = (QueryTable) queryTables.get(i);

            if (tables.indexOf(t) == -1) {
                tables.add(t);
                t.getTableIndex().setValue(tables.size() - 1);
            }
        }
    
protected StatementaddStatement(QueryTable t)

		Statement s = createStatement(t);
		statements.add(s);

		return s;
    
public abstract voidbuild()

protected StatementcreateStatement(QueryTable t)

        Statement statement = newStatement();

        statement.action = action;
        statement.addQueryTable(t);

        return statement;
    
public QueryTablefindQueryTable(org.netbeans.modules.dbschema.TableElement tableElement)
Finds the QueryTable object that this query plan is using to describe the TableElement indicated by the tableElement parameter.

        for (int i = 0; i < tables.size(); i++) {
            QueryTable t = (QueryTable) tables.get(i);

            if (t.getTableDesc().getTableElement() == tableElement) {
            //if (t.getTableDesc().getTableElement().equals(tableElement)) {
                return t;
            }
        }

        return null;
    
public QueryTablefindQueryTable(com.sun.jdo.spi.persistence.support.sqlstore.model.TableDesc tableDesc)
Finds the QueryTable object that this query plan is using to describe the TableDesc indicated by the tableDesc parameter.

        for (int i = 0; i < tables.size(); i++) {
            QueryTable t = (QueryTable) tables.get(i);

            if (t.getTableDesc() == tableDesc) return t;
        }

        return null;
    
public intgetAction()

        return action;
    
public com.sun.jdo.spi.persistence.support.sqlstore.model.ClassDescgetConfig()

        return config;
    
protected StatementgetStatement(QueryTable t)

		if (t == null) return null;

        for (int i = 0; i < statements.size(); i++) {
            Statement s = (Statement) statements.get(i);

			if (s.tableList.indexOf(t) != -1)
				return s;
        }

        return null;
    
public java.util.ArrayListgetStatements()

        for (int i = 0; i < statements.size(); i++) {
            Statement s = (Statement) statements.get(i);
            //Initialize sql text of the statement
            s.getText();
        }

        return statements;
    
protected abstract StatementnewStatement()

protected voidprocessStatements()
This method goes through the statement list and tries to set up relationship between statements based on secondary table keys.

        for (int i = 0; i < statements.size(); i++) {
            Statement s = (Statement) statements.get(i);

            QueryTable qt = (QueryTable) s.getQueryTables().get(0);

            ArrayList secondaryTableKeys = qt.getTableDesc().getSecondaryTableKeys();

            if (secondaryTableKeys != null) {
                for (int j = 0; j < secondaryTableKeys.size(); j++) {
                    ReferenceKeyDesc secondaryTableKey = (ReferenceKeyDesc) secondaryTableKeys.get(j);
                    s.addSecondaryTableStatement(getStatement(findQueryTable(secondaryTableKey.getTableDesc())));
                }
            }
        }