/** * TODO: what about the JDBC driver class name? */ @Override public Connection getConnection() throws SQLException { return LocalJDBCConnectionUtils.createConnection(settings); } }
/** * Keeps a permanent connection to the DB (if enabled in the settings). * * Needed by some in-memory DBs (such as H2). * */ public boolean connect() throws OntopConnectionException { try { if (localConnection != null && !localConnection.isClosed()) { return true; } if (settings.isPermanentDBConnectionEnabled()) { localConnection = LocalJDBCConnectionUtils.createConnection(settings); return localConnection != null; } } catch (SQLException e) { throw new OntopConnectionException(e); } return true; }
/** * Keeps a permanent connection to the DB (if enabled in the settings). * * Needed by some in-memory DBs (such as H2). * */ public boolean connect() throws OntopConnectionException { try { if (localConnection != null && !localConnection.isClosed()) { return true; } if (settings.isPermanentDBConnectionEnabled()) { localConnection = LocalJDBCConnectionUtils.createConnection(settings); return localConnection != null; } } catch (SQLException e) { throw new OntopConnectionException(e); } return true; }
/*** * extract mappings from given datasource, and insert them into the pre-processed mapping * * Duplicate Exception may happen, * since mapping id is generated randomly and same id may occur */ private SQLPPMapping bootstrapMappings(SQLPPMapping ppMapping) throws SQLException, DuplicateMappingException { if (ppMapping == null) { throw new IllegalArgumentException("Model should not be null"); } try (Connection conn = LocalJDBCConnectionUtils.createConnection(settings)) { RDBMetadata metadata = RDBMetadataExtractionTools.createMetadata(conn, typeFactory, jdbcTypeMapper); // this operation is EXPENSIVE RDBMetadataExtractionTools.loadMetadata(metadata, conn, null); return bootstrapMappings(metadata, ppMapping); } }
/*** * extract mappings from given datasource, and insert them into the pre-processed mapping * * Duplicate Exception may happen, * since mapping id is generated randomly and same id may occur */ private SQLPPMapping bootstrapMappings(SQLPPMapping ppMapping) throws SQLException, DuplicateMappingException { if (ppMapping == null) { throw new IllegalArgumentException("Model should not be null"); } try (Connection conn = LocalJDBCConnectionUtils.createConnection(settings)) { RDBMetadata metadata = RDBMetadataExtractionTools.createMetadata(conn); // this operation is EXPENSIVE RDBMetadataExtractionTools.loadMetadata(metadata, conn, null); return bootstrapMappings(metadata, ppMapping); } }
/** * Makes use of the DB connection */ private RDBMetadata extractDBMetadata(SQLPPMapping ppMapping, Optional<RDBMetadata> optionalDBMetadata, OBDASpecInput specInput) throws DBMetadataExtractionException { boolean isDBMetadataProvided = optionalDBMetadata.isPresent(); /* * Metadata extraction can be disabled when DBMetadata is already provided */ if (isDBMetadataProvided && (!settings.isProvidedDBMetadataCompletionEnabled())) return optionalDBMetadata.get(); try (Connection localConnection = LocalJDBCConnectionUtils.createConnection(settings)) { return isDBMetadataProvided ? dbMetadataExtractor.extract(ppMapping, localConnection, optionalDBMetadata.get(), specInput.getConstraintFile()) : dbMetadataExtractor.extract(ppMapping, localConnection, specInput.getConstraintFile()); } /* * Problem while creating the connection */ catch (SQLException e) { throw new DBMetadataExtractionException(e.getMessage()); } }
/** * Makes use of the DB connection */ private RDBMetadata extractDBMetadata(final SQLPPMapping ppMapping, Optional<RDBMetadata> optionalDBMetadata, OBDASpecInput specInput) throws DBMetadataExtractionException, MetaMappingExpansionException { boolean isDBMetadataProvided = optionalDBMetadata.isPresent(); /* * Metadata extraction can be disabled when DBMetadata is already provided */ if (isDBMetadataProvided && (!settings.isProvidedDBMetadataCompletionEnabled())) return optionalDBMetadata.get(); try (Connection localConnection = LocalJDBCConnectionUtils.createConnection(settings)) { return isDBMetadataProvided ? dbMetadataExtractor.extract(ppMapping, localConnection, optionalDBMetadata.get(), specInput.getConstraintFile()) : dbMetadataExtractor.extract(ppMapping, localConnection, specInput.getConstraintFile()); } /* * Problem while creating the connection */ catch (SQLException e) { throw new DBMetadataExtractionException(e.getMessage()); } }
protected SQLPPMapping expandPPMapping(SQLPPMapping ppMapping, OntopMappingSQLSettings settings, RDBMetadata dbMetadata) throws MetaMappingExpansionException { MetaMappingExpander expander = new MetaMappingExpander(ppMapping.getTripleMaps()); final ImmutableList<SQLPPTriplesMap> expandedMappingAxioms; if (expander.hasMappingsToBeExpanded()) { try (Connection connection = LocalJDBCConnectionUtils.createConnection(settings)) { expandedMappingAxioms = expander.getExpandedMappings(connection, dbMetadata); } // Problem while creating the connection catch (SQLException e) { throw new MetaMappingExpansionException(e.getMessage()); } } else expandedMappingAxioms = expander.getNonExpandableMappings(); try { return new SQLPPMappingImpl(expandedMappingAxioms, ppMapping.getMetadata()); } catch (DuplicateMappingException e) { // Internal bug throw new IllegalStateException(e); } }
protected SQLPPMapping expandPPMapping(SQLPPMapping ppMapping, OntopMappingSQLSettings settings, RDBMetadata dbMetadata) throws MetaMappingExpansionException { MetaMappingExpander expander = new MetaMappingExpander(ppMapping.getTripleMaps(), termFactory, substitutionFactory); final ImmutableList<SQLPPTriplesMap> expandedMappingAxioms; if (expander.hasMappingsToBeExpanded()) { try (Connection connection = LocalJDBCConnectionUtils.createConnection(settings)) { expandedMappingAxioms = expander.getExpandedMappings(connection, dbMetadata); } // Problem while creating the connection catch (SQLException e) { throw new MetaMappingExpansionException(e.getMessage()); } } else expandedMappingAxioms = expander.getNonExpandableMappings(); try { return new SQLPPMappingImpl(expandedMappingAxioms, ppMapping.getMetadata()); } catch (DuplicateMappingException e) { // Internal bug throw new IllegalStateException(e); } }