Copyright 2009,2010, Lapetus Systems Ltd. (All rights reserved)

com.lapetus_ltd.api.db.control
Class TLptsFactoryRowSet

java.lang.Object
  extended by com.lapetus_ltd.api.db.control.TLptsFactoryRowSet

public final class TLptsFactoryRowSet
extends java.lang.Object

Class Description :

This is the workhorse of the whole db-JAPI. It processes the statements to create result sets, or related result sets
if there is a dynamic-primary relationship declared. Ok, I got you, what is dynamic-primary processing?
PRIMARY-DYNAMIC PROCESSING
Definition: The ability to relate one statement to another so that the data from one rowset be fed to another at runtime for the creation of
dynamic statements, which generate sub-rowsets to the primary rowset.
The relationships have no limit in the way of number, levels or complexity. But whatever the complexity or number of levels, there is always one
truth, and that is that there is always one top-primary statement which is found and run any time we execute any of its dynamic statements.
So, what are we saying here? Well, simply put; whenever we run a dynamic statement (a statement that takes data from a primary during runtime) then
it is never run in isolation. The db API will track down the top primary and run that, with all its sub-dynamic statements, including the one we have executed.
There is a flag called 'isExecutable' on each statement, which is inspected before running it. If this is false, the statement is not executed.
In this way we can control and set the executable only on the last statement of a relationship, so that during a creation and run scenario, the primary statements
will not be executed before all the sub-statements are ready and created.
With that said we complete our little walk down "dynamic lane". We can continue by saying that after a statement is executed, the listeners are informed of the successful creation or not.
The listeners have two functions, the first asks the application if it should continue with the processing each row of the rowset ILptsFactoryRowSetListener.processNewRowSetRows(com.lapetus_ltd.api.db.control.TLptsRowSetEvent)
or just supply the application with the rowset and end all pther processing. It goes without saying that if we are processing a primary-dynamic relationship, then we should
tell the db API to continue with the processing by replying TRUE in this function.
At that point all rows will be sent via the rowEvent function of the listener. This means that the primary and dynamic rows will be sent one at a time, with information of their
type and relation to other statements. In this manner we can create a MAP and process the hierarchy of the relationship (as in the API Data Viewer) see TLptsRowEvent for more information.

With that said about the select statements and the dynamic capabilities, we can now move onto the capability to update, delete and insert data to and from tables in data sources.
The functions executeDynamicInsert(TLptsStatement), executeDynamicUpdate(TLptsStatement) and executeDynamicDelete(TLptsStatement) allow an application to
process records from a static (programmatic) basis, from another TLptsStatement or from Stored procedures. This is known as the source and is declared in the type XLptsDBUpInsDelType
of XLptsDBStatementColumnType.getUpInsDelParameterItem() for every column that is to have the operation performed on it (INSERT,DELETE,UPDATE).
During the processing of these capabilities, the source columns are built and then used to perform the operation on the selected columns. Each XLptsDBUpInsDelType therefore
contains a relationship between one column in the target statement and one column in the source (program, other statement or stored procedure).
Please look at the examples under executeDynamicInsert(TLptsStatement), executeDynamicUpdate(TLptsStatement) and executeDynamicDelete(TLptsStatement).

$LastChangedRevision: 1227 $
$LastChangedDate:: 2010-12-07 07:56:27#$


Field Summary
static int ERROR_SQL_TYPE
           
 
Method Summary
static void addListener(ILptsFactoryRowSetListener rsl)
          Add a listener so that all resulting rows and rowsets from an execute be provided to the listener.
static void executeDynamicDelete(TLptsStatement statement)
          Deletes Rows from a Database Table.
static void executeDynamicInsert(TLptsStatement statement)
          Inserts Data to a Database Table.
static void executeDynamicUpdate(TLptsStatement statement)
          Updates a table in a DataBase.
static void executeSelectStatement(TLptsStatement stmt, int first, int noOfRecords, boolean isLimitAllRowSets)
          Executes a SELECT statement and generates one or many rowsets (depending on dynamic and primary relationships).
static void removeListener(ILptsFactoryRowSetListener rsl)
           Removes a listener from the list.
static void zI()
          Obfuscated, as it is not required by the application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_SQL_TYPE

public static final int ERROR_SQL_TYPE
See Also:
Constant Field Values
Method Detail

addListener

public static void addListener(ILptsFactoryRowSetListener rsl)
Add a listener so that all resulting rows and rowsets from an execute be provided to the listener.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : n/a

Notes : The listeners should be removed if no longer required.
Adding the same listener (same instance that is) many times has not affect as there is a check for existence before addition.
If the listener is already in the list it is not added again.

Example :

 

class RSFListener implements ILptsFactoryRowSetListener { public boolean processNewRowSetRows(TLptsRowSetEvent rowSetEvent) { return true; } public void rowEvent(TLptsRowEvent rowEvent) { rowEvent.getRowObjectList()... rowEvent.getByteValueList()... rowEvent.getColumnNameList()...etc } } TLptsFactoryRowSet.addListener(new RSFListener());

Parameters:
rsl - the ILptsFactoryRowSetListener listener

executeDynamicDelete

public static void executeDynamicDelete(TLptsStatement statement)
Deletes Rows from a Database Table.

Thread Safe : Yes

Spawns its own Thread : Yes, a new worker thread is generated.
All listener functions (rowEvent and processNewRowSetRows) are executed on the new worker thread.

May Return NULL : No

Notes :
Executes a delete statement. This statement can include static variables, stored procedures and
other Lapetus Statements.
This function does not require that a statement be created with TLptsFactoryStatement.createNewStatement(com.lapetus_ltd.api.db.control.TLptsConnection, com.lapetus_ltd._2009.xml.types.XLptsDBStatementType).
It can therefore be called directly, when the parameter TLptsStatement type has been fully set for the DELETE.

Example :

 

... private void postgressqlDynamicDelete() { TLptsConnection mssqlConnection = TLptsFactoryConnection.getConnection(connectionMSSqlId);

if(mssqlConnection == null) { TLptsLogger.logError("Could not find the Connection for MS SQL.",null); return; } // We create a SELECT statement that only selects the ID column, then we use the values from the MS SQL select // to DELETE the records in the POSTGRES statement. createStatement(mssqlConnection, "ID");

// Find the Connection to delete data from TLptsConnection connection = TLptsFactoryConnection.getConnection(connectionPostgresId);

TLptsStatement deleteStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.DELETE); deleteStatement.setXResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); deleteStatement.setXResultSetConcurrency(ResultSet.CONCUR_UPDATABLE); XLptsDBStatementTableType table = deleteStatement.getTableItemByName("testTable"); table.setSelected(true);

XLptsDBStatementColumnType col = deleteStatement.getColumnItemByName(table.getTableName(),"ID"); if (col!=null) { TLptsDBUpInsDelWhereType whereType = new TLptsDBUpInsDelWhereType(XLptsDBUpInsDelSourceType.LPTS_STATEMENT,"ID"); whereType.setOperation(TLptsFactoryStatement.OPERATION_EQUAL); whereType.setAndConnector(true); column.setUpInsDelParameterItem(whereType); }

deleteStatement.setTitle("Delete Statement"); System.out.println("SQL Statement " + deleteStatement.getTitle() + ": " + deleteStatement.getSqlStatementFormatted());

TLptsFactoryRowSet.executeDynamicDelete(deleteStatement); }

private void createStatement(TLptsConnection connection, String columnName) { TLptsStatement statement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); statement.setSqlStatementUser("SELECT [testTable].[ID] FROM [testTable] WHERE [testTable].[Occupation] <> N'ΟΙΚΙΑΚΑ'"); // a bit of Greek here. statement.setSqlStatementModified(true); statement.setTitle(columnName); System.out.println("SQL Statement " + statement.getTitle() + ": " + statement.getSqlStatementFormatted()); TLptsFactoryStatement.createNewStatement(connection,statement); } ...

private class RowSetListener implements ILptsFactoryRowSetListener { public void rowEvent(TLptsRowEvent rowEvent) { } public boolean processNewRowSetRows(TLptsRowSetEvent rowSetEvent) { if(rowSetEvent.getEventType()==TLptsRowSetEvent.EVENT_TYPE.DELETE_COMPLETE) { try { System.out.println("Statement "+ rowSetEvent.getStatement().getTitle()+ " " + ((TLptsConnection) rowSetEvent.getStatement().getConnection()).getTitle() +" delete execution complete..."); System.out.println(rowSetEvent.getRows()+" rows deleted"); if(rowSetEvent.getRowSetsNotFinished().isEmpty()) System.out.println("All row sets have finished"); else for(String rowSet : rowSetEvent.getRowSetsNotFinished()) System.out.println(rowSet + " did not finish"); if(((TLptsConnection) rowSetEvent.getStatement().getConnection()).getId().equals(connectionMSSqlId)) //PostgresSQL dynamic delete postgressqlDynamicDelete(); } catch (SQLException e) { TLptsLogger.logError("Cannot get Connection Name",e); } } return true; } }

Parameters:
statement - The delete Statement to execute
If an exception is encountered during this process, then an ERROR is logged TLptsLogger.

executeDynamicInsert

public static void executeDynamicInsert(TLptsStatement statement)
Inserts Data to a Database Table.

Thread Safe : Yes

Spawns its own Thread : Yes, a new worker thread is generated.
All listener functions (rowEvent and processNewRowSetRows) are executed on the new worker thread.

May Return NULL : No

Notes :
Executes an insert statement. This statement can include static variables, stored procedures or other Lapetus Statements.
This function does not require that a statement be created with TLptsFactoryStatement.createNewStatement(com.lapetus_ltd.api.db.control.TLptsConnection, com.lapetus_ltd._2009.xml.types.XLptsDBStatementType).
It can therefore be called directly, when the parameter TLptsStatement type has been fully set for the INSERT.

Example :

 

... private void insertData() { // **************************************** Programmatic Insert Data ********************************************** //Find the connection to add data

TLptsConnection odbcConnection = TLptsFactoryConnection.getConnection(connectionMsAccessId); if(odbcConnection == null) { TLptsLogger.logError("Cannot find the MS Access Connection.",null); return; }

createInsertStatement(odbcConnection,"testTable","windows-1253");

// *********************************Insert Data with Lapetus_Statement or Stored Procedure**************************** // *********************************Get Data From MySQL***************************************************************

TLptsConnection mySqlConnection = TLptsFactoryConnection.getConnection(connectionMySqlId); if(mySqlConnection == null) { TLptsLogger.logError("Cannot find the MySQL Connection.",null); return; }

//Create Lapetus_Statement to get data createStatement(mySqlConnection, "customers", "idcustomers"); createStatement(mySqlConnection, "customers", "Occupation"); createStatement(mySqlConnection, "customers", "Gender"); createStatement(mySqlConnection, "customers", "NumChildren");

// *********************************Add Data to MS SQL Server********************************************************* TLptsConnection msSqlConnection = TLptsFactoryConnection.getConnection(connectionMSSqlId); if(msSqlConnection == null) { TLptsLogger.logError("Cannot find the MySQL Connection.",null); return; } //Create the InsertStatement. We pass the appropriate connection and the name of the table in which we want to //insert data. createDynamicInsertStatement(msSqlConnection,"testTable","UTF-16LE");

// *********************************Add Data to PostgreSQL *********************************************************** TLptsConnection postgresConnection = TLptsFactoryConnection.getConnection(connectionPostgresId); if(postgresConnection == null) { TLptsLogger.logError("Cannot find the PostgreSQL Connection.",null); return; } //Create the InsertStatement. We pass the appropriate connection and the name of the table in which we want to //insert data. createDynamicInsertStatement(postgresConnection,"testTable",null);

// ********************************Add Data to Microsoft Office Access********************************************** //Find the connection to add data odbcConnection = TLptsFactoryConnection.getConnection(connectionMsAccessId); if(odbcConnection == null) { TLptsLogger.logError("Cannot find the MS Access Connection.",null); return; } //Create the InsertStatement. We pass the appropriate connection and the name of the table in which we want to //insert data. createDynamicInsertStatement(odbcConnection,"testTable","windows-1253"); }

private void createDynamicInsertStatement(TLptsConnection connection, String tableName,String charset) { // Create the statement and set the Type of Statement to Insert. TLptsStatement statement = new TLptsStatement(connection, XLptsDBTypeOfStatementType.INSERT); // The resultSet should be Scroll Sensitive. MS SQL does not support scroll insensitive or forward only for update data // Access supports scroll sensitive but not forward only. statement.setXResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); // ResultSet Concurrency must be concur_updatable statement.setXResultSetConcurrency(ResultSet.CONCUR_UPDATABLE); // set the table and columns for selecting XLptsDBStatementTableType table = statement.getTableItemByName(tableName); table.setSelected(true); // Then set Columns and also set the appropriate values initColumn(statement,"ID","idcustomers",table.getTableName(), XLptsDBUpInsDelSourceType.LPTS_STATEMENT,charset); initColumn(statement,"Occupation","Occupation",table.getTableName(),XLptsDBUpInsDelSourceType.LPTS_STATEMENT,charset); initColumn(statement,"Gender","Gender",table.getTableName(),XLptsDBUpInsDelSourceType.LPTS_STATEMENT,charset); initColumn(statement,"NumChildren","NumChildren",table.getTableName(),XLptsDBUpInsDelSourceType.LPTS_STATEMENT,charset); // give it a logical name statement.setTitle("Insert Statement"); System.out.println("SQL Statement " + statement.getTitle() + ": " + statement.getSqlStatementFormatted());

TLptsFactoryRowSet.executeDynamicInsert(statement); }

private void createInsertStatement(TLptsConnection connection, String tableName,String charset) { TLptsStatement statement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.INSERT); statement.setXResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); statement.setXResultSetConcurrency(ResultSet.CONCUR_UPDATABLE); XLptsDBStatementTableType table = statement.getTableItemByName(tableName); table.setSelected(true); initColumn(statement,"ID","1",table.getTableName(),XLptsDBUpInsDelSourceType.PROGRAMMATIC,charset); initColumn(statement,"Occupation","Software Developer",table.getTableName(),XLptsDBUpInsDelSourceType.PROGRAMMATIC,charset); initColumn(statement,"Gender","M",table.getTableName(),XLptsDBUpInsDelSourceType.PROGRAMMATIC,charset); initColumn(statement,"NumChildren","2",table.getTableName(),XLptsDBUpInsDelSourceType.PROGRAMMATIC,charset); statement.setTitle("Insert Statement"); System.out.println("SQL Statement " + statement.getTitle() + ": " + statement.getSqlStatementFormatted());

TLptsFactoryRowSet.executeDynamicInsert(statement); }

private void initColumn(TLptsStatement statement, String columnName, String sourceString,String tableName, XLptsDBUpInsDelSourceType sourceType,String charset) { XLptsDBStatementColumnType col = statement.getColumnItemByName(tableName,columnName);

if (col!=null) { col.setUpInsDelParameterItem(new TLptsDBUpInsDelSetType(sourceType,sourceString));

// If we want db-JAPI to handle the column as another SQL Type we can set this type to this parameters like: // col.getUpInsDelParameterItem().setSqlSubstituteType(java.sql.Types.BINARY);

// Note the following when it comes to updating STRING values in different types of data sources: // 1. Access requires the setCharset as it cannot update STRING values directly. // 2. PostgreSQL and MySQL support direct update of the string values, without setting the charset. // 3. MS SQL has two types of strings, n-type (nvarchar etc) and simple types (varchar etc.). N-types // requires the setCharset(), but the normal char does not require it. col.getUpInsDelParameterItem().setCharset(charset); } }

private void createStatement(TLptsConnection connection, String tableName, String columnName) { TLptsStatement statement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); XLptsDBStatementTableType table = statement.getTableItemByName(tableName); table.setSelected(true); statement.getColumnItemByName(tableName,columnName).setSelected(true); // we turn off the SELECT criteria processing statement.getCriteriaType().setType(XLptsDBCriteriaType.NONE); statement.setTitle(columnName);

TLptsFactoryStatement.createNewStatement(connection,statement); System.out.println("SQL Statement " + statement.getTitle() + ": " + statement.getSqlStatementFormatted()); }

...

private class RowSetListener implements ILptsFactoryRowSetListener { public void rowEvent(TLptsRowEvent rowEvent) { } public boolean processNewRowSetRows(TLptsRowSetEvent rowSetEvent) { if(rowSetEvent.getEventType()==TLptsRowSetEvent.EVENT_TYPE.INSERT_COMPLETE) { System.out.println("Statement "+ rowSetEvent.getStatement().getTitle()+" " + ((TLptsConnection) rowSetEvent.getStatement().getConnectionWE()).getTitle()+ " insert execution complete..."); System.out.println(rowSetEvent.getRows()+" rows inserted, " + rowSetEvent.getObjects() + " objects inserted"); if(rowSetEvent.getRowSetsNotFinished().isEmpty()) System.out.println("All row sets has finished"); else for(String rowSet : rowSetEvent.getRowSetsNotFinished()) System.out.println(rowSet + " did not finished"); }

if(rowSetEvent.getEventType()==TLptsRowSetEvent.EVENT_TYPE.ERROR_OCCURRED) System.out.println("The insert was not successful. We need to check the output from the logger for more information.");

// we tell the rowset factory not to process the rows and send them to us via the rowEvent. return false; } }

Parameters:
statement -
If an exception is encountered during this process, then an ERROR is logged TLptsLogger.

executeDynamicUpdate

public static void executeDynamicUpdate(TLptsStatement statement)
Updates a table in a DataBase.

Thread Safe : Yes

Spawns its own Thread : Yes, a new worker thread is generated.
All listener functions (rowEvent and processNewRowSetRows) are executed on the new worker thread.

May Return NULL : No

Notes :
Executes an update statement. This statement can include static variables, stored procedures or
other Lapetus Statements.
This function does not require that a statement be created with TLptsFactoryStatement.createNewStatement(com.lapetus_ltd.api.db.control.TLptsConnection, com.lapetus_ltd._2009.xml.types.XLptsDBStatementType).
It can therefore be called directly, when the parameter TLptsStatement type has been fully set for the UPDATE.

The first part of the example below shows a static (programmatic) update to the column "Occupation" wherever the "Gender" is Male.
It is equivalent to the SQL statement : ' UPDATE "testTable" SET "Occupation" = ? WHERE "Gender" = ? '.
In the second part there is an example of a dynamic update involving multiple TLptsStatements.
The equivalent SQL code for that is:
UPDATE [testTable]
SET [Occupation] = ( SELECT "anotherTable"."Occupation"
FROM "anotherTable" )
WHERE [ID] = ( SELECT "anotherTable"."ID"
FROM "anotherTable" );

Example :

 

... private void postgresqlSimpleUpdate(TLptsConnection connection) { //Create the statement and set the Type of Statement to Update. TLptsStatement updateStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.UPDATE); //The resultSet should be Scroll Sensitive. MS SQL does not support scroll insensitive or forward only for update //data. Access supports scroll sensitive but not forward only. updateStatement.setXResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); //ResultSet Concurrency should be concur_updatable updateStatement.setXResultSetConcurrency(ResultSet.CONCUR_UPDATABLE); // set the table and columns for selecting XLptsDBStatementTableType table = updateStatement.getTableItemByName("testTable"); //Select the table for update. Only one table can be selected per update table.setSelected(true);

// Next we have to select the columns we want to update with new values // In our Example we want to set the value in Column "Occupation" to "Software Developer", // when the value in column "Gender" is equal to "M". // Next we have to select the columns we want to update with new values TLptsDBStatementColumnType column; XLptsDBStatementColumnType colX;

colX = updateStatement.getColumnItemByName(table.getTableName(),"Occupation"); if(colX != null && colX instanceof TLptsDBStatementColumnType) { column = (TLptsDBStatementColumnType) colX; // Now we have to set the update parameters for this column // If we are going to update the row values of this column we have to set the required TLptsDBUpInsDelSetType parameters TLptsDBUpInsDelSetType setType = new TLptsDBUpInsDelSetType(XLptsDBUpInsDelSourceType.PROGRAMMATIC,"Software Developer"); // Set the parameter column.setUpInsDelParameterItem(setType);

// If we want the db-JAPI to handle the column as another SQL Type we can set this type to this parameters like: // column.getUpInsDelParameterItem().setSqlSubstituteType(java.sql.Types.BINARY);

// Note the following when it comes to updating STRING values in different types of data sources: // 1. Access requires the setCharset as it cannot update STRING values directly. // 2. PostgreSQL and MySQL support direct update of the string values, without setting the charset. // 3. MS SQL has two types of strings, n-type (nvarchar etc) and simple types (varchar etc.). N-types // requires the setCharset(), but the normal char does not require it. // column.getUpInsDelParameterItem().setCharset("windows-1253"); }

colX = updateStatement.getColumnItemByName(table.getTableName(),"Gender"); if(colX != null && colX instanceof TLptsDBStatementColumnType) { column = (TLptsDBStatementColumnType) colX; TLptsDBUpInsDelWhereType whereType = new TLptsDBUpInsDelWhereType(XLptsDBUpInsDelSourceType.PROGRAMMATIC, "M");

// Set the operation we want as ILPtsStatement.OPERATION_* whereType.setOperation(TLptsFactoryStatement.OPERATION_EQUAL); // setAndConnector for AND/OR processing of the where clauses (in this case we only have one. There is therefore no need) whereType.setAndConnector(true); column.setUpInsDelParameterItem(whereType); } updateStatement.setTitle("Update Statement"); // lets print out the statement SQL text. System.out.println("SQL Statement " + updateStatement.getTitle() + ": " + updateStatement.getSqlStatementFormatted()); // The formatted statement should be ' UPDATE "testTable" SET "Occupation" = ? WHERE "Gender" = ? ' // Finally just execute the statement. TLptsFactoryRowSet.executeDynamicUpdate(updateStatement); }

private void mssqlDynamicUpdate() { TLptsConnection postgresqlConnection = TLptsFactoryConnection.getConnection(connectionPostgresId); if(postgresqlConnection == null) return; createStatement(postgresqlConnection, "testTable", "ID"); createStatement(postgresqlConnection, "testTable", "Occupation");

TLptsConnection connection = TLptsFactoryConnection.getConnection(connectionMSSqlId); if(connection == null) return;

TLptsStatement updateStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.UPDATE); updateStatement.setXResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); updateStatement.setXResultSetConcurrency(ResultSet.CONCUR_UPDATABLE); XLptsDBStatementTableType table = updateStatement.getTableItemByName("testTable"); table.setSelected(true);

TLptsDBStatementColumnType column; XLptsDBStatementColumnType colX;

colX = updateStatement.getColumnItemByName(table.getTableName(),"Occupation"); if(colX != null && colX instanceof TLptsDBStatementColumnType) { column = (TLptsDBStatementColumnType) colX; TLptsDBUpInsDelSetType setType = new TLptsDBUpInsDelSetType(XLptsDBUpInsDelSourceType.LPTS_STATEMENT,"Occupation"); column.setUpInsDelParameterItem(setType); column.getUpInsDelParameterItem().setCharset("UTF-16LE"); }

colX = updateStatement.getColumnItemByName(table.getTableName(),"ID"); if(colX != null && colX instanceof TLptsDBStatementColumnType) { column = (TLptsDBStatementColumnType) colX; TLptsDBUpInsDelWhereType whereType = new TLptsDBUpInsDelWhereType(XLptsDBUpInsDelSourceType.LPTS_STATEMENT,"ID"); whereType.setOperation(TLptsFactoryStatement.OPERATION_EQUAL); whereType.setAndConnector(true); column.setUpInsDelParameterItem(whereType); } updateStatement.setTitle("Update Statement"); System.out.println("SQL Statement " + updateStatement.getTitle() + ": " + updateStatement.getSqlStatementFormatted());

TLptsFactoryRowSet.executeDynamicUpdate(updateStatement); }

private void createStatement(TLptsConnection connection, String tableName, String columnName) { TLptsStatement statement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); // set the table and columns for selecting XLptsDBStatementTableType table = statement.getTableItemByName(tableName); table.setSelected(true);

statement.getCriteriaType().setType(XLptsDBCriteriaType.NONE); // Set the name of the statement to the name of the column so that it makes sense statement.setTitle(columnName); TLptsFactoryStatement.createNewStatement(connection,statement); }

private class RowSetListener implements ILptsFactoryRowSetListener { public void rowEvent(TLptsRowEvent rowEvent) { } public boolean processNewRowSetRows(TLptsRowSetEvent rowSetEvent) { if(rowSetEvent.getEventType()==TLptsRowSetEvent.EVENT_TYPE.UPDATE_COMPLETE) { try { System.out.println("Statement "+ rowSetEvent.getStatement().getTitle()+ " " + ((TLptsConnection) rowSetEvent.getStatement().getConnection()).getTitle() +" update execution complete..."); System.out.println(rowSetEvent.getRows()+" rows updated, " + rowSetEvent.getObjects() + " objects updated"); if(rowSetEvent.getRowSetsNotFinished().isEmpty()) System.out.println("All row sets has finished"); else for(String rowSet : rowSetEvent.getRowSetsNotFinished()) System.out.println(rowSet + " did not finish"); // this is special case where we feed the new updated data in the progress db to the MS SQL db. if(((TLptsConnection) rowSetEvent.getStatement().getConnection()).getId().equals(connectionPostgresId)) mssqlDynamicUpdate(); } catch (Exception e) { TLptsLogger.logError("Cannot get Connection Name",e); } }

return true; } }

Parameters:
statement - The update Statement to execute.
If an exception is encountered during this process, then an ERROR is logged TLptsLogger.

executeSelectStatement

public static void executeSelectStatement(TLptsStatement stmt,
                                          int first,
                                          int noOfRecords,
                                          boolean isLimitAllRowSets)
Executes a SELECT statement and generates one or many rowsets (depending on dynamic and primary relationships).

Thread Safe : Yes.

Spawns its own Thread : Yes, a new worker thread is generated.
All listener functions (rowEvent and processNewRowSetRows) are therefore executed on the new worker thread.

May Return NULL : n/a

Notes :
If the statement is dynamic and is related to a primary rowset, then the parent of all the related statements is found and
executed, with the related statements executed in a tree-like fashion, as stipulated by their relationships.
We are able to specify which rows are to be processes, by using the parameters first and noOfRecords.

The best place to execute a statement is in the statement factory listener, as soon as the statement is created successfully. ILptsFactoryStatementListener.newStatementCreated(TLptsConnection, TLptsStatement)

All statements and rowset are closed automatically at the end of processing (after TLptsRowEvent.EVENT_TYPE.PROCESSING_COMPLETE or on error or on interruption.
Example :

 

TLptsFactoryStatement.addListener(new ILptsFactoryStatementListener() { public void newStatementProcessStarted(TLptsConnection connection) { } public void newStatementCreated(TLptsConnection connection, TLptsStatement statement) { TLptsFactoryRowSet.executeSelectStatement(statement,1,0,false); } public void newStatementFailed(TLptsConnection connection) { } public void removedAndClosedStatement(TLptsConnection connection, TLptsStatement statement) { } });

TLptsFactoryRowSet.addListener( new ILptsFactoryRowSetListener() { public boolean processNewRowSetRows(TLptsRowSetEvent rowSetEvent) { return true; } public void rowEvent(TLptsRowEvent rowEvent) { rowEvent.getRowObjectList()... rowEvent.getByteValueList()... rowEvent.getColumnNameList()...etc } });

Parameters:
stmt - The statement to be executed, which may not actually be executed first if it is dynamic.
first - The first record to be processes, with a one base (1=first, 2=second, 3=third ...)
noOfRecords - The number of records to process. 0 indicates all records.
isLimitAllRowSets - Specify whether to limit only the primary or all sub-rowsets to the number of records specified above. If this is false then only the primary records are limited, with all the dynamic sets not being limited to the noOfRecords.

removeListener

public static void removeListener(ILptsFactoryRowSetListener rsl)

Removes a listener from the list.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : N/A

Notes :

Example :

 

class RSFListener implements ILptsFactoryRowSetListener { public boolean processNewRowSetRows(TLptsRowSetEvent rowSetEvent) { return true; } public void rowEvent(TLptsRowEvent rowEvent) { rowEvent.getRowObjectList()... rowEvent.getByteValueList()... rowEvent.getColumnNameList()...etc } }

RSFListener rsf = new RSFListener() TLptsFactoryRowSet.addListener(rsf); ... // When the program exits. TLptsFactoryRowSet.removeListener(rsf);

Parameters:
rsl -

zI

public static void zI()
Obfuscated, as it is not required by the application.



Copyright 2009,2010, Lapetus Systems Ltd. (All rights reserved)