private void generateRDF(String wkname, String query, List<KR2RMLRDFWriter> writers, R2RMLMappingIdentifier id, String baseURI)
throws IOException, JSONException, KarmaException, SQLException, ClassNotFoundException{
logger.debug("Generating RDF...");
WorksheetR2RMLJenaModelParser parserTest = new WorksheetR2RMLJenaModelParser(id);
KR2RMLMapping mapping = parserTest.parse();
for (KR2RMLRDFWriter writer : writers) {
if (writer instanceof BloomFilterKR2RMLRDFWriter) {
BloomFilterKR2RMLRDFWriter t = (BloomFilterKR2RMLRDFWriter)writer;
t.setR2RMLMappingIdentifier(id);
}
}
AbstractJDBCUtil dbUtil = JDBCUtilFactory.getInstance(dbType);
Connection conn = dbUtil.getConnection(hostname, portnumber, username, password, dBorSIDName);
conn.setAutoCommit(false);
java.sql.Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(DATABASE_TABLE_FETCH_SIZE);
ResultSet r = stmt.executeQuery(query);
ResultSetMetaData meta = r.getMetaData();;
// Get the column names
List<String> columnNames = new ArrayList<>();
for (int i = 1; i <= meta.getColumnCount(); i++) {
columnNames.add(meta.getColumnName(i));
}
// Prepare required Karma objects
Workspace workspace = initializeWorkspace();
RepFactory factory = workspace.getFactory();
Worksheet wk = factory.createWorksheet(wkname, workspace, encoding);
List<String> headersList = addHeaders(wk, columnNames, factory);
int counter = 0;
ArrayList<String> rowValues = null;
while ((rowValues = dbUtil.parseResultSetRow(r)) != null) {
// Generate RDF and create a new worksheet for every DATABASE_TABLE_FETCH_SIZE rows
if(counter%DATABASE_TABLE_FETCH_SIZE == 0 && counter != 0) {
generateRDFFromWorksheet(wk, workspace, mapping, writers, baseURI);
logger.debug("Done for " + counter + " rows ..." );
removeWorkspace(workspace);
parserTest = new WorksheetR2RMLJenaModelParser(id);
mapping = parserTest.parse();
workspace = initializeWorkspace();
factory = workspace.getFactory();
wk = factory.createWorksheet(wkname, workspace, encoding);
headersList = addHeaders(wk, columnNames, factory);