public Connection openConnection() throws SQLException { if (this.conn == null) { try { this.conn = DBUtility.getLocalConnection( databaseUser, databaseName, databasePassword, databaseDriver, databaseURL, "R2ORunner"); } catch (SQLException e) { String errorMessage = "Error loading database, error message = " + e.getMessage(); logger.error(errorMessage); // e.printStackTrace(); throw e; } } return this.conn; }
private void readConfigurationFile(String configurationDir) throws Exception { this.noOfDatabase = this.readInteger(Constants.NO_OF_DATABASE_NAME_PROP_NAME(), 0); if (this.noOfDatabase != 0 && this.noOfDatabase != 1) { throw new InvalidConfigurationPropertiesException("Only zero or one database is supported."); } this.conn = null; for (int i = 0; i < noOfDatabase; i++) { String propertyDatabaseDriver = Constants.DATABASE_DRIVER_PROP_NAME() + "[" + i + "]"; this.databaseDriver = this.getProperty(propertyDatabaseDriver); String propertyDatabaseURL = Constants.DATABASE_URL_PROP_NAME() + "[" + i + "]"; this.databaseURL = this.getProperty(propertyDatabaseURL); String propertyDatabaseName = Constants.DATABASE_NAME_PROP_NAME() + "[" + i + "]"; this.databaseName = this.getProperty(propertyDatabaseName); String propertyDatabaseUser = Constants.DATABASE_USER_PROP_NAME() + "[" + i + "]"; this.databaseUser = this.getProperty(propertyDatabaseUser); String propertyDatabasePassword = Constants.DATABASE_PWD_PROP_NAME() + "[" + i + "]"; this.databasePassword = this.getProperty(propertyDatabasePassword); String propertyDatabaseType = Constants.DATABASE_TYPE_PROP_NAME() + "[" + i + "]"; this.databaseType = this.getProperty(propertyDatabaseType); String propertyDatabaseTimeout = Constants.DATABASE_TIMEOUT_PROP_NAME() + "[" + i + "]"; String timeoutPropertyString = this.getProperty(propertyDatabaseTimeout); if (timeoutPropertyString != null && !timeoutPropertyString.equals("")) { this.databaseTimeout = Integer.parseInt(timeoutPropertyString.trim()); } logger.info("Obtaining database connection..."); try { this.conn = DBUtility.getLocalConnection( databaseUser, databaseName, databasePassword, databaseDriver, databaseURL, "Configuration Properties"); if (this.conn != null) { logger.info("Connection obtained."); } } catch (SQLException e) { this.conn = null; String errorMessage = "Error loading database, error message = " + e.getMessage(); logger.error(errorMessage); // e.printStackTrace(); } } this.mappingDocumentFilePath = this.readString(Constants.MAPPINGDOCUMENT_FILE_PATH(), null); if (this.mappingDocumentFilePath != null) { boolean isNetResourceMapping = ODEMapsterUtility.isNetResource(this.mappingDocumentFilePath); if (!isNetResourceMapping && configurationDir != null) { this.mappingDocumentFilePath = configurationDir + mappingDocumentFilePath; } } this.queryFilePath = this.getProperty(Constants.QUERYFILE_PROP_NAME()); boolean isNetResourceQuery = ODEMapsterUtility.isNetResource(this.queryFilePath); if (!isNetResourceQuery && configurationDir != null) { if (this.queryFilePath != null && !this.queryFilePath.equals("")) { this.queryFilePath = configurationDir + queryFilePath; } } this.ontologyFilePath = this.getProperty(Constants.ONTOFILE_PROP_NAME()); this.outputFilePath = this.getProperty(Constants.OUTPUTFILE_PROP_NAME()); if (configurationDir != null) { this.outputFilePath = configurationDir + outputFilePath; if (this.ontologyFilePath != null && !this.ontologyFilePath.equals("")) { this.ontologyFilePath = configurationDir + ontologyFilePath; } } this.rdfLanguage = this.readString(Constants.OUTPUTFILE_RDF_LANGUAGE(), Constants.OUTPUT_FORMAT_NTRIPLE()); logger.debug("rdf language = " + this.rdfLanguage); this.jenaMode = this.readString(Constants.JENA_MODE_TYPE(), Constants.JENA_MODE_TYPE_MEMORY()); logger.debug("Jena mode = " + jenaMode); this.selfJoinElimination = this.readBoolean(Constants.OPTIMIZE_TB(), true); logger.debug("Self join elimination = " + this.selfJoinElimination); this.reorderSTG = this.readBoolean(Constants.REORDER_STG(), true); logger.debug("Reorder STG = " + this.reorderSTG); this.subQueryElimination = this.readBoolean(Constants.SUBQUERY_ELIMINATION(), true); logger.debug("Subquery elimination = " + this.subQueryElimination); this.transJoinSubQueryElimination = this.readBoolean(Constants.TRANSJOIN_SUBQUERY_ELIMINATION(), true); logger.debug("Trans join subquery elimination = " + this.transJoinSubQueryElimination); this.transSTGSubQueryElimination = this.readBoolean(Constants.TRANSSTG_SUBQUERY_ELIMINATION(), true); logger.debug("Trans stg subquery elimination = " + this.transSTGSubQueryElimination); this.subQueryAsView = this.readBoolean(Constants.SUBQUERY_AS_VIEW(), false); logger.debug("Subquery as view = " + this.subQueryAsView); this.queryTranslatorClassName = this.readString(Constants.QUERY_TRANSLATOR_CLASSNAME(), null); this.queryEvaluatorClassName = this.readString(Constants.DATASOURCE_READER_CLASSNAME(), null); this.queryResultWriterClassName = this.readString(Constants.QUERY_RESULT_WRITER_CLASSNAME(), null); this.literalRemoveStrangeChars = this.readBoolean(Constants.REMOVE_STRANGE_CHARS_FROM_LITERAL(), true); logger.debug("Remove Strange Chars From Literal Column = " + this.literalRemoveStrangeChars); this.encodeUnsafeChars = this.readBoolean(Constants.ENCODE_UNSAFE_CHARS_IN_URI_COLUMN(), true); logger.debug("Encode Unsafe Chars From URI Column = " + this.encodeUnsafeChars); this.encodeReservedChars = this.readBoolean(Constants.ENCODE_RESERVED_CHARS_IN_URI_COLUMN(), true); logger.debug("Encode Reserved Chars From URI Column = " + this.encodeReservedChars); }