com.xj.anylogic.engine.connectivity
Class Query

java.lang.Object
  extended by com.xj.anylogic.engine.connectivity.Query
All Implemented Interfaces:
java.io.Serializable

public class Query
extends java.lang.Object

Query object for database connectivity
Works in 2 modes:


This object is only available in the AnyLogic Professional

Author:
XJ Technologies Company Ltd. www.anylogic.com
See Also:
Serialized Form

Constructor Summary
Query(java.lang.String name, Database database, boolean selectFromTable, java.lang.String tableNameOrQueryText)
          Creates new Query for work only with execute() method
Query(java.lang.String name, Database database, boolean selectFromTable, java.lang.String tableNameOrQueryText, java.lang.String[][] mapping)
          Creates new Query for work in the Mapping mode (executeAndMap() method)
Note the execute() method is still available for this object
 
Method Summary
 java.lang.Object createNewRowElementInstance()
          Extension-point for element creation
In the Mapping mode, this method should be overridden to create specifical element and return it
 void destroy()
          Releases resources acquired by this object
Also destroys all not destroyed contributors associated with this object

Doest nothing if object is already destroyed
 ResultSet execute()
          Executes query in the database and returns single ResultSet
If any error occurs, throws RuntimeException
Connects Database if it is not connected.
 int executeAndMap()
          This method fills underlying collection or Replicated Active Object (created Active Objects are started automatically) with elements created from rows of database Query result
This method works only in the Mapping mode
 int executeAndMap(boolean startActiveObjects)
          This method fills underlying collection or Replicated Active Object with elements created from rows of database Query result
This method works only in the Mapping mode
 java.lang.String getName()
          Returns the name of this object
 void registerNewRowElement(java.lang.Object element, boolean startActiveObjects)
          Extension-point for element creation
In the Mapping mode, this method should be overridden to start given element (previously created by createNewRowElementInstance() and parametrized) add it to the underlying collection and return it
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Query

public Query(java.lang.String name,
             Database database,
             boolean selectFromTable,
             java.lang.String tableNameOrQueryText)
Creates new Query for work only with execute() method

Parameters:
name - object name (decoration purpose)
database -
selectFromTable -
tableNameOrQueryText -

Query

public Query(java.lang.String name,
             Database database,
             boolean selectFromTable,
             java.lang.String tableNameOrQueryText,
             java.lang.String[][] mapping)
Creates new Query for work in the Mapping mode (executeAndMap() method)
Note the execute() method is still available for this object

Parameters:
name - object name (decoration purpose)
database - database to connect to
selectFromTable - flag indicating what value is contained in parameter tableNameOrQueryText
tableNameOrQueryText -
  • the table name to select data from, - if selectFromTable is true
  • SQL query text, otherwise
mapping - mappings array with dimensions N x 2 like:
 new String[][] { { "fieldName0", "columnLabel0" },
                { "fieldName1", "columnLabel1" },
 // ...
 }
 
where
  • fieldName is name of field in the created collection element or ActiveObject
  • columnLabel is column's title which is used in printouts and displays. This title is usually specified by the SQL AS clause. If a SQL AS is not specified, the table column name is assumed
Method Detail

createNewRowElementInstance

public java.lang.Object createNewRowElementInstance()
Extension-point for element creation
In the Mapping mode, this method should be overridden to create specifical element and return it

Returns:
new element instance created for each row

registerNewRowElement

public void registerNewRowElement(java.lang.Object element,
                                  boolean startActiveObjects)
Extension-point for element creation
In the Mapping mode, this method should be overridden to start given element (previously created by createNewRowElementInstance() and parametrized) add it to the underlying collection and return it

Parameters:
startActiveObjects - defines either created Active Objects are started or not
overridden method should call start() method on active object only if this parameter is true

execute

public final ResultSet execute()
Executes query in the database and returns single ResultSet
If any error occurs, throws RuntimeException
Connects Database if it is not connected. After this method call Database remains connected.

Returns:
new ResultSet object; never null
Please call ResultSet.close() method after all needed operations are completed

executeAndMap

public final int executeAndMap()
This method fills underlying collection or Replicated Active Object (created Active Objects are started automatically) with elements created from rows of database Query result
This method works only in the Mapping mode

Returns:
number of created objects

executeAndMap

public final int executeAndMap(boolean startActiveObjects)
This method fills underlying collection or Replicated Active Object with elements created from rows of database Query result
This method works only in the Mapping mode

Parameters:
startActiveObjects - defines either created Active Objects are started or not
Returns:
number of created objects

toString

public java.lang.String toString()

getName

public final java.lang.String getName()
Returns the name of this object

Returns:
the name of this object

destroy

public final void destroy()
Releases resources acquired by this object
Also destroys all not destroyed contributors associated with this object

Doest nothing if object is already destroyed



Copyright © 1991-2008 XJ Technlogies. All Rights Reserved.