com.ptc.windchill.upgrade.util
Class ConditionalPagedTableIterator

java.lang.Object
  extended bycom.ptc.windchill.upgrade.util.ConditionalPagedTableIterator
All Implemented Interfaces:
Iterator

public class ConditionalPagedTableIterator
extends Object
implements Iterator

ConditionalPagedTableIterator determines which Paging mechanism to use depending upon what is available. The PDS paging API is available to release 6.0 and later versions of Windchill. For earlier release, use a simplied version of paging provided by this tool. In addition to this, ConditionalPagedTableIterator also hides the fact that paging is occuring, i.e. the program using this class acts as though it is iterating through a simple ResultSet without bothering with the details of paging.


Field Summary
private  StandardACProcessor acp_
           
(package private)  Connection conn
           
private static boolean DEVELOPER_MODE
           
(package private)  int offset
           
(package private)  int pageSize
           
private  PersistentObjectManager pom_
           
(package private)  QuerySpec querySpec
           
private  boolean RELEASE_5
           
(package private)  QueryResult result
           
(package private)  Exception savedException
           
(package private)  long sessionId
           
static String TEMP_INSERT_STR
           
static String TEMP_SELECT_STR
           
private static String TEMP_TABLE__CLASS_NAME
           
private static String TEMP_TABLE_NAME
           
private static String TEMP_TABLE_OID
           
private static String TEMP_TABLE_ROW_ORDER
           
private static String TEMP_TABLE_SESSION_ID
           
(package private)  int totalSize
           
 
Constructor Summary
private ConditionalPagedTableIterator(PersistentObjectManager pom)
           
 
Method Summary
private  QuerySpec addWhereToQuerySpec(String class_name, QuerySpec select)
           
 void cleanup()
           
private  void closePagingSession()
           
private  void createTempTable()
           
private  void dropTempTable()
           
private  int executeStatement(String statement)
           
private  QueryResult fetchPagingSession(int offset, int page_size, long session_id)
          Returns the next object in the ResultSet.
private  String getPrimaryTableName(String class_name)
           
 long getSessionId()
          The initial query stores OIDs in a temp table.
static String getTableAlias()
          Returns alias of the table defined in the FROM clause.
static int getTableIndex()
          Returns index of table used in SearchConditions.
static int getTempIndex()
          Returns index of the temp table used in SearchConditions.
 int getTotalSize()
          Returns the number of rows in the temp table for this session id.
 boolean hasNext()
          Returns true if the iteration has more elements.
private  void init(int page_size)
           
private  void init(long session_id, int page_size, String class_name)
           
private  void init(long session_id, int page_size, String class_name, String[] attr_list, String[] column_list, String insert_stmt)
           
private  void init(long session_id, String class_name)
           
private  QuerySpec initPageQuerySpec(String class_name)
           
private  QuerySpec initPageQuerySpec(String class_name, String[] attr_list, String[] column_list)
           
private  QuerySpec initQuerySpec(String class_name, boolean selectable)
           
private  int initTempTable(long session_id, String id_col, String class_name)
           
private  int initTempTable(String insert_stmt)
           
private  boolean isRelease5()
           
static ConditionalPagedTableIterator newPagingIterator(int page_size, PersistentObjectManager pom)
          Instantiates and initializes a ConditionalPagedTableIterator.
static ConditionalPagedTableIterator newPagingIterator(long session_id, int page_size, String class_name, PersistentObjectManager pom)
          Instantiates and initializes a ConditionalPagedTableIterator.
static ConditionalPagedTableIterator newPagingIterator(long session_id, int page_size, String class_name, String[] attr_list, String[] column_list, String insert_stmt, PersistentObjectManager pom)
          Instantiates and initializes a ConditionalPagedTableIterator.
 Object next()
          Returns the next element in the iteration.
private  void openPagingSession(String class_name)
          Returns the next object in the ResultSet.
private  void openPagingSession(String class_name, String[] attr_list, String[] column_list, String insert_stmt)
          Returns the next object in the ResultSet.
 void remove()
          Removes from the underlying collection the last element returned by the iterator (optional operation).
private  void reportException(Exception e)
           
 void resetQuery(long session_id, String class_name)
          Clears out the previous query and starts a new paging query with the given QuerySpec.
private  void setRelease5(String release_level)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEVELOPER_MODE

private static final boolean DEVELOPER_MODE
See Also:
Constant Field Values

TEMP_TABLE_NAME

private static String TEMP_TABLE_NAME

TEMP_TABLE_OID

private static String TEMP_TABLE_OID

TEMP_TABLE_ROW_ORDER

private static String TEMP_TABLE_ROW_ORDER

TEMP_TABLE_SESSION_ID

private static String TEMP_TABLE_SESSION_ID

TEMP_TABLE__CLASS_NAME

private static String TEMP_TABLE__CLASS_NAME

TEMP_INSERT_STR

public static final String TEMP_INSERT_STR

TEMP_SELECT_STR

public static final String TEMP_SELECT_STR
See Also:
Constant Field Values

sessionId

long sessionId

totalSize

int totalSize

result

QueryResult result

pageSize

int pageSize

offset

int offset

querySpec

QuerySpec querySpec

savedException

Exception savedException

conn

Connection conn

RELEASE_5

private boolean RELEASE_5

pom_

private PersistentObjectManager pom_

acp_

private StandardACProcessor acp_
Constructor Detail

ConditionalPagedTableIterator

private ConditionalPagedTableIterator(PersistentObjectManager pom)
Method Detail

newPagingIterator

public static ConditionalPagedTableIterator newPagingIterator(int page_size,
                                                              PersistentObjectManager pom)
                                                       throws WTException
Instantiates and initializes a ConditionalPagedTableIterator.

Throws:
WTException

newPagingIterator

public static ConditionalPagedTableIterator newPagingIterator(long session_id,
                                                              int page_size,
                                                              String class_name,
                                                              PersistentObjectManager pom)
                                                       throws WTException
Instantiates and initializes a ConditionalPagedTableIterator.

Throws:
WTException

newPagingIterator

public static ConditionalPagedTableIterator newPagingIterator(long session_id,
                                                              int page_size,
                                                              String class_name,
                                                              String[] attr_list,
                                                              String[] column_list,
                                                              String insert_stmt,
                                                              PersistentObjectManager pom)
                                                       throws WTException
Instantiates and initializes a ConditionalPagedTableIterator. This constructor allows an array of String to be applied to the select statement to restrict the number of columns/attributes that are returned session_id : uniquely identifies this particular query. page_size : the number of rows retrieved on each fetch class_name : name of the class to be joined with the temp table for fetches attr_list : list of attributes to be returned column_list: list of column names to be returned insert_stmt: free form jdbc used to limit the number of rows in the temp table. Always use the constant TEMP_INSERT_STR to start this string. Usage: String[] attr_list = new String[1]; attr_list[0] = "name"; column_list = null; //This is used for columns no longer in the model insert_stmt = ConditionalPagedTableIterator.TEMP_INSERT_STR + "MY_TABLE" + "WHERE columnA < 4000 ORDER BY IDA3B5"; pom = (PersistentObjectManager)(context.getPomHandler().getPom()); iterator = ConditionalPagedTableIterator.newPagingIterator(session_id, page_size, class_name, attr_list, column_list, insert_stmt, pom);

Throws:
WTException

hasNext

public boolean hasNext()
Returns true if the iteration has more elements.

Specified by:
hasNext in interface Iterator

next

public Object next()
Returns the next element in the iteration.

Specified by:
next in interface Iterator

remove

public void remove()
Removes from the underlying collection the last element returned by the iterator (optional operation). Not implemented yet

Specified by:
remove in interface Iterator

getTotalSize

public int getTotalSize()
Returns the number of rows in the temp table for this session id.


getSessionId

public long getSessionId()
The initial query stores OIDs in a temp table. The session id distinguishes this query's data from another session's.


resetQuery

public void resetQuery(long session_id,
                       String class_name)
                throws WTException
Clears out the previous query and starts a new paging query with the given QuerySpec.

Throws:
WTException

getTableIndex

public static int getTableIndex()
Returns index of table used in SearchConditions.


getTempIndex

public static int getTempIndex()
Returns index of the temp table used in SearchConditions.


getTableAlias

public static String getTableAlias()
Returns alias of the table defined in the FROM clause.


init

private void init(int page_size)
           throws WTException
Throws:
WTException

init

private void init(long session_id,
                  int page_size,
                  String class_name)
           throws WTException
Throws:
WTException

init

private void init(long session_id,
                  String class_name)
           throws WTException
Throws:
WTException

init

private void init(long session_id,
                  int page_size,
                  String class_name,
                  String[] attr_list,
                  String[] column_list,
                  String insert_stmt)
           throws WTException
Throws:
WTException

cleanup

public void cleanup()
             throws WTException
Throws:
WTException

createTempTable

private void createTempTable()
                      throws WTException
Throws:
WTException

dropTempTable

private void dropTempTable()
                    throws WTException
Throws:
WTException

initTempTable

private int initTempTable(long session_id,
                          String id_col,
                          String class_name)
                   throws WTException
Throws:
WTException

initTempTable

private int initTempTable(String insert_stmt)
                   throws WTException
Throws:
WTException

getPrimaryTableName

private String getPrimaryTableName(String class_name)
                            throws WTException
Throws:
WTException

initQuerySpec

private QuerySpec initQuerySpec(String class_name,
                                boolean selectable)
                         throws QueryException,
                                WTException
Throws:
QueryException
WTException

initPageQuerySpec

private QuerySpec initPageQuerySpec(String class_name,
                                    String[] attr_list,
                                    String[] column_list)
                             throws QueryException,
                                    WTException
Throws:
QueryException
WTException

initPageQuerySpec

private QuerySpec initPageQuerySpec(String class_name)
                             throws QueryException,
                                    WTException
Throws:
QueryException
WTException

addWhereToQuerySpec

private QuerySpec addWhereToQuerySpec(String class_name,
                                      QuerySpec select)
                               throws QueryException,
                                      WTException
Throws:
QueryException
WTException

openPagingSession

private void openPagingSession(String class_name)
                        throws WTException
Returns the next object in the ResultSet. Takes care of any paging that may be necessary.

Throws:
WTException

openPagingSession

private void openPagingSession(String class_name,
                               String[] attr_list,
                               String[] column_list,
                               String insert_stmt)
                        throws WTException
Returns the next object in the ResultSet. Takes care of any paging that may be necessary.

Throws:
WTException

fetchPagingSession

private QueryResult fetchPagingSession(int offset,
                                       int page_size,
                                       long session_id)
                                throws WTException
Returns the next object in the ResultSet. Takes care of any paging that may be necessary.

Throws:
WTException

closePagingSession

private void closePagingSession()
                         throws WTException
Throws:
WTException

reportException

private void reportException(Exception e)

executeStatement

private int executeStatement(String statement)
                      throws Exception
Throws:
Exception

isRelease5

private boolean isRelease5()

setRelease5

private void setRelease5(String release_level)