|
SilverStream Application Server 3.5 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
A low-level API for accessing and updating row-based data sources within data source triggered business objects. Normally clients will use the higher-level AgiRowCursor and AgiRowSetManager interfaces.
The AgiDataSource interface is used internally by SilverStream row-set managers (such as TableDataStore), and is documented with the intent of allowing 3rd parties to write data sources that can supplement the DataSet-based data sources used in the SilverStream Server. The intent is that this interface can be implemented using direct calls, HTTP requests, or CORBA.
An application will rarely or never call an object that implements AgiDataSource directly. Instead, a data source business object will create and return an AgiDataSource object that the programmer has implemented, and the internal SilverStream row-management classes will use it to obtain data from the external data source.
AgiDataRow
,
AgiDataUpdateRequest
Method Summary | |
void |
checkException()
Check to see whether there's a bufferred-up exception on the specified data source. |
void |
close()
Close the data source and free any resources associated with the current query. |
AgiBandDescriptor |
getBandDescriptor()
Get a "band description" for this data source, describing the contents of the data rows used in it. |
Enumeration |
getNextRows(int count)
Get the next chunk of rows from the result set of this data source. |
AgiDataUpdateRequest |
prepareUpdateRequest()
Prepare an update request to be executed against this data source. |
boolean |
readOnly()
Return true if and only if the data source is marked as "read-only" -- no updates are allowed. |
void |
reQuery()
Re-execute the current query on the data source, closing the query if any. |
void |
reQueryIfClosed()
Re-execute the current query on the data source if and only if the previous query has been closed. |
void |
setDataRowFactory(AgiDataRowFactory rowFactory)
Set the row factory to be used by this data source for constructing data rows. |
void |
startNewQuery(String queryString,
String orderBy,
int fetchAheadCount)
Start a new query on the data source, closing the old query if any. |
Method Detail |
public void setDataRowFactory(AgiDataRowFactory rowFactory)
rowFactory
- Factory object to be used for constructing rowsMost implementations will simply save the supplied row factory in a class-private variable for later use.
public void setDataRowFactory(AgiDataRowFactory rowFactory) { m_rowFactory = rowFactory; }
public void close()
close
method should protect itself against the possibility
that it might be called more than once.
The data source can still be restarted by a AgiDataSource.reQueryIfClosed()
.
public void close() { if (m_resultSet != null) { try { m_resultSet.close(); } catch (SQLException ex) {} m_resultSet = null; } if (m_statement != null) { try { m_statement.close(); } catch (SQLException ex) {} m_statement = null; } if (m_conn != null) { m_db.releaseConnection(m_conn); m_conn = null; } }
public void startNewQuery(String queryString, String orderBy, int fetchAheadCount) throws AgoApiException
queryString
- the new query string; may be null to mean "use
previous query". Supply an empty query string to mean "no user-defined
query terms". This is typically an expression in the SilverStream
expression syntax.orderBy
- The new order-by string; may be null to mean "use
previous order". Supply an empty order-by string to mean "no user-defined
order terms". This is typically an expression in the SilverStream
expression syntax.fetchAheadCount
- Number of rows server is to fetch ahead; -1 to
mean "use server default" (may be 0)
In this example, we assume the query and order-by arguments are SQL
where
and order by
clauses.
public void startNewQuery(String queryString, String orderBy, int fetchAheadCount) throws AgoApiException { if (queryString != null) m_queryString = queryString; if (orderBy != null) m_orderBy = orderBy; reQuery(); }
public void reQuery() throws AgoApiException
public void reQuery() throws AgoApiException { try { close(); String query = "select ID, Name from Names"; if (m_queryString != null && m_queryString.length() > 0) query += " where " + m_queryString; if (m_orderBy != null && m_orderBy.length() > 0) query += " order by " + m_orderBy; m_conn = m_db.getConnection(true); m_statement = m_conn.prepareStatement(query); m_resultSet = m_statement.executeQuery(); } catch (SQLException ex) { throw new AgoSystemDatabaseException(ex, "Query failed"); } }
public void reQueryIfClosed() throws AgoApiException
public void reQueryIfClosed() throws AgoApiException { if (m_resultSet == null) { reQuery(); }
public AgiBandDescriptor getBandDescriptor()
public AgiBandDescriptor getBandDescriptor() { return new MyBandDescriptor(); }
public boolean readOnly() throws AgoApiException
public boolean readOnly() throws AgoApiException { return false; }
public Enumeration getNextRows(int count) throws AgoEndOfRowsException, AgoApiException
count
- number of rows to be returnedreQueryIfClosed()
first to do that
if needed.
The rows are constructed by calling the data row factory
specified by the call to setDataRowFactory()
.
Note that this call can return an empty enumeration, indicating that no more rows are currently available but that more rows may be available later.
In this example, we return at most one row, irrespective of how many the caller asks for. The row enumeration class is not shown.
public Enumeration getNextRows(int count) throws AgoEndOfRowsException, AgoApiException { ASSERT(m_rowFactory != null); if (m_resultSet == null) throw new AgoEndOfRowsException(null); try { if (!m_resultSet.next()) { close(); return null; } AgiDataRow row = m_rowFactory.createDataRow(null); row.setData(0, m_resultSet.getObject(1)); row.setData(1, m_resultSet.getObject(2)); return new SingleRowEnumeration(row); } catch (SQLException ex) { throw new AgoSystemDatabaseException(ex, "Error getting next row"); } }
public AgiDataUpdateRequest prepareUpdateRequest() throws AgoApiException
public AgiDataUpdateRequest prepareUpdateRequest() throws AgoApiException { return new MyDataUpdateRequest(m_db, m_rowFactory); }
public void checkException() throws AgoApiException
public void checkException() throws AgoApiException { if (m_bufferredException != null) throw m_bufferredException; }
|
SilverStream Application Server 3.5 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |