Event Callbacks


Add an event callback to SqlDataManager object.

This feature is only available for Professional and Enterprise editions of screen-scraper.

Before adding an event to the SqlDataManager, you must build the schema of any tables you will use because events are related to table operations such as inserting data


  • schema Case insensitive schema (table) name
  • when The event assiciated with the schema that should trigger the callback
    • onCreate Triggered whenever the DataManager creates a new DataNode, such as the first addData since the last commit
    • onAddData Triggered after dm.addData is called
    • onWrite Triggered immediately before the DataNode is written (DataWriter.write). Applies to both inserts and updates
    • onInsert Triggered immediately before the data is going to be inserted as a new row in the database as opposed to updating an existing row
    • onUpdate Triggered immediately before existing database values are going to be updated as opposed to inserted as a new row
    • onWriteError Triggered if an exception was thrown when trying to write to the database
    • afterWrite Triggered immediately after the DataNode is written. At this point any values written are in the DataNode, including autogenerated keys
  • listener A callback interface that must be implemented by the client. There is a single method public void handleEvent(DataManagerEvent event) that needs to be implemented. The DataManagerEvent has a method getDataNode() to retrieve the relevant DataNode.

Return Values

Returns a DataManagerEventListener. The same DataManagerEventListener object that was passed in

Change Log

Version Description
5.5 Available for professional and enterprise editions.

Class Locations

  • com.screenscraper.datamanager.DataManager
  • com.screenscraper.datamanager.DataManagerEventListener
  • com.screenscraper.datamanager.DataManagerEventSource.EventFireTime


Register a callback to log out database write errors to 'person' table to the web interface

import com.screenscraper.datamanager.*;
import com.screenscraper.datamanager.sql.SqlDataManager;
import org.apache.commons.dbcp.BasicDataSource;

// BasicDataSource
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName( "com.mysql.jdbc.Driver" );
ds.setUsername( "user" );
ds.setPassword( "psswrd" );
ds.setUrl( "jdbc:mysql://" );
ds.setMaxActive( 10 );

// Create Data Manager
dm = new SqlDataManager( ds, session );
_session = session;

//This will log out any write errors to the 'person' table to the screen-scraper web interface
dm.addEventListener("person", DataManagerEventSource.EventFireTime.onWriteError,
  new DataManagerEventListener() {
    public void handleEvent(DataManagerEvent event) {
      DataNode n = event.getDataNode();
      _session.webError("Database Write Error",n.getObjectMap());