11package com .ibm .opl .customdatasource ;
22
33import ilog .opl .IloCustomOplDataSource ;
4+ import ilog .opl .IloCustomOplPostProcessListener ;
45import ilog .opl .IloOplDataHandler ;
56import ilog .opl .IloOplElement ;
67import ilog .opl .IloOplElementDefinition ;
2021import java .util .Enumeration ;
2122import java .util .Properties ;
2223
24+
25+
2326/**
2427 * An custom data source reading data using JDBC.
2528 *
@@ -28,6 +31,30 @@ public class JdbcCustomDataSource extends IloCustomOplDataSource {
2831 private JdbcConfiguration _configuration ;
2932 private IloOplModelDefinition _def ;
3033
34+ /**
35+ * A post process listener to write output
36+ */
37+ private static class JdbcCustomDataSourcePublisher extends IloCustomOplPostProcessListener {
38+ IloOplModel _model ;
39+ JdbcConfiguration _config ;
40+
41+
42+ JdbcCustomDataSourcePublisher (IloOplFactory factory , IloOplModel model , JdbcConfiguration config ) {
43+ super (factory );
44+ _model = model ;
45+ _config = config ;
46+ }
47+
48+ @ Override
49+ public void customStartPostProcess () {
50+ }
51+
52+ @ Override
53+ public void customEndPostProcess () {
54+ JdbcWriter .writeOutput (_config , _model );
55+ }
56+ }
57+
3158 /**
3259 * Adds a custom data source to a model.
3360 *
@@ -41,6 +68,7 @@ public static void addDataSourceXMLConfig(String xmlFile, IloOplModel model) thr
4168 IloOplModelDefinition definition = model .getModelDefinition ();
4269 JdbcCustomDataSource source = new JdbcCustomDataSource (config , factory , definition );
4370 model .addDataSource (source );
71+ model .registerPostProcessListener (new JdbcCustomDataSourcePublisher (factory , model , config ));
4472 }
4573
4674 /**
@@ -54,6 +82,7 @@ public static void addDataSource(JdbcConfiguration config, IloOplModel model) {
5482 IloOplModelDefinition definition = model .getModelDefinition ();
5583 JdbcCustomDataSource source = new JdbcCustomDataSource (config , factory , definition );
5684 model .addDataSource (source );
85+ model .registerPostProcessListener (new JdbcCustomDataSourcePublisher (factory , model , config ));
5786 }
5887
5988 /**
0 commit comments