The IlvDB2DataSource class is an IlvMapDataSource for reading georeferenced
objects from a DB2® spatial
database. It wraps up all operations (connecting to database,
reading features, rendering them to graphic objects) in a
convenient way.
To read a map stored in an DB2 spatial
database:
-
Create a connection to the DB2 Spatial database:
IlvDB2ConnectionInfo theDB2Connection=new IlvDB2ConnectionInfo(); theDB2Connection.setHostName("server_hostname"); theDB2Connection.setHostPort("50001"); theDB2Connection.setUser("a_db2_user"); theDB2Connection.setPassword("password"); theDB2Connection.setDatabaseName("database_name")
-
Create a data source with this connection as a parameter:
// we want to fetch layer "A_DB2_USER.FLOODZONES.LOCATION.SRID=100002" String layerName="A_DB2_USER.FLOODZONES.LOCATION.SRID=100002"; IlvDB2DataSource dataSource=new IlvDB2DataSource(DB2Connection, layerName);
To obtain a list of layers, see Getting a list of layers -
Set parameters on this data source to use load-on-demand, if needed:
boolean useTiling = true; int rowCount = 5; int columnCount = 5; dataSource.setTilingParameters(useTiling, rowCount, columnCount);
-
Connect this data source to the manager of the view:
dataSource.setManager(getView().getManager());
-
Insert the data source map layer into the layer tree (You first need to retrieve the layer model from the property of the manager):
IlvMapLayerTreeModel mltm = IlvMapLayerTreeProperty.GetMapLayerTreeModel(v.getManager()); mltm.addChild(null, dataSource.getInsertionLayer());
-
Insert the data source into the data source tree. You first need to retrieve the data source model from the property of the manager:
IlvMapDataSourceModel dataSourceModel = IlvMapDataSourceProperty.GetMapDataSourceModel(manager); dataSourceModel.insert(dataSource);
-
Finally, start the data source (or the whole model, if you have more than one data source):
dataSource.start();