-
My objective is to reuse DB connection specially from existing DB connection pool. Why does Clover requires DB connection object to implement IConnection?
-
I removed the Connection element from my graph file. In my Java code I instantiated a DBConnection object with DB properties.
// build the DBConnection
Properties p = new Properties();
p.setProperty(“user”, DBUser);
p.setProperty(“password”, DBPassword
p.setProperty(“dbDriver”, “oracle.jdbc.OracleDriver”);
p.setProperty(“name”, “oracleConn”);
p.setProperty(“passwordEncrypted”,“false”);
p.setProperty(“dbURL”, DBServer);
dbconn = new DBConnection (“conn3”, p);
dbconn.setThreadSafeConnections(false);
My graphfile has XLS Data Reader which reads an XLS file of 3 sheets, data of each sheet is process sequentially by a Reformat component and inserted into a DB Table.
//java code loops to process the 3 sheets using the same graph, but with a different sheetname.
Properties p2 = new Properties();
for (int i = 0; i < f.getNumsheets(); ++i) {
String sheetName = f.sheetNames[i];
p2.setProperty(“sheetname”, sheetName);
TransformationGraph graph = null;
TransformationGraphXMLReaderWriter graphReader = new TransformationGraphXMLReaderWriter(p2); <— pass property with new sheetname
try {
graph = graphReader.read(new FileInputStream(graphFile)); ← read the XML Graph file
graph.addConnection(dbconn); <---- pass dbconn to graph file
// dump the graph
graph.dumpGraphConfiguration();
//prepare runtime parameters - JMX is turned off
GraphRuntimeContext runtimeContext = new GraphRuntimeContext();
runtimeContext.setUseJMX(false);
GraphExecutor executor = new GraphExecutor();
GraphExecutor.initGraph(graph);
executor.runGraph(graph, runtimeContext);
} catch (Exception e) {
logger.error("Exception occurred: ", e);
logger.error(“Failed graph execution!\n” + e.getMessage());
return;
}
}
The code loops 3 times on the for-loop. However only the data from the LAST Sheet file was inserted to DB?
Do you know why this is happening? what happen to the first 2 sheets?
- If I include the Connection element into my Graph file, and remove the graph.addConnection(dbconn) from my Java code. Data from all 3 sheets of the XLS file are processed and inserted into the DB table. Doing this way requires a new DB connection for each execution of a graph file. As you may know, instantiating, opening and closing for each DB connection takes time specially for XLS files with large data and more sheets per file. Is there a better way to re-use DB connections in multiple graph executions?