public static Properties loadProperties(Logger logger, File configFile) { final Properties properties = new Properties(); if (configFile.exists() && configFile.canRead()) { try (final InputStream in = new FileInputStream(configFile)) { properties.load(in); } catch (final IOException ex) { final String err = "Error loading default settings from " + configFile.getAbsolutePath() + "-file."; logger.error(ex, err); throw new RuntimeException(err, ex); } } else { logger.info( "No configuration file '" + configFile.getAbsolutePath() + "' found." ); } return properties; }
private <T> T readSilent(ResultSet rs, SqlSupplier<T> supplier, boolean fullWarning) { try { final T result = supplier.get(); if (rs.wasNull()) { return null; } else { return result; } } catch (SQLException sqle) { // ignore, just return null if (fullWarning) { LOGGER.warn(sqle, "Unable to read column metadata: " + sqle.getMessage()); } else { LOGGER.info("Metadata not supported: " + sqle.getMessage()); } } return null; }
@Override public <ENTITY> SqlStreamOptimizer<ENTITY> get(Pipeline initialPipeline, DbmsType dbmsType) { if (DEBUG.isEqualOrHigherThan(LOGGER_STREAM_OPTIMIZER.getLevel())) { LOGGER_STREAM_OPTIMIZER.debug("Evaluating %s pipeline: %s", initialPipeline.isParallel() ? "parallel" : "sequential", initialPipeline.toString()); } final SqlStreamOptimizer<ENTITY> result = getHelper(initialPipeline, dbmsType); if (DEBUG.isEqualOrHigherThan(LOGGER_STREAM_OPTIMIZER.getLevel())) { LOGGER_STREAM_OPTIMIZER.debug("Selected: %s", result.getClass().getSimpleName()); } return result; }
private void closeSilently(final AutoCloseable closeable) { actionSilently(closeable, AutoCloseable::close, "closing"); try { if (closeable != null) { closeable.close(); } } catch (Exception e) { LOGGER.error(e, "Error closing " + closeable); // Just log the error. No re-throw } }
private String readSchemaName(ResultSet rs, DbmsType dbmsType) throws SQLException { final String schemaName = rs.getString(dbmsType.getResultSetTableSchema()); String catalogName = ""; try { // This column is not there for Oracle so handle it // gracefully.... catalogName = rs.getString("TABLE_CATALOG"); } catch (final SQLException ex) { LOGGER.info("TABLE_CATALOG not in result set."); } return Optional.ofNullable(schemaName).orElse(catalogName); }
void setMaxRetainSize(int maxRetainSize) { LOGGER_CONNECTION.warn("Unsafe method called. Use configuration parameters to set this value instead"); this.maxRetainSize = maxRetainSize; } }
private void debug(String action) { LOGGER.debug("Report node " + action); } }
protected void checkDatabaseConnectivity(Injector injector) { LOGGER.debug("Checking Database Connectivity"); final Project project = injector.getOrThrow(ProjectComponent.class) .getProject(); project.dbmses().forEachOrdered(dbms -> { final DbmsHandlerComponent dbmsHandlerComponent = injector .getOrThrow(DbmsHandlerComponent.class); final DbmsType dbmsType = DatabaseUtil .dbmsTypeOf(dbmsHandlerComponent, dbms); final DbmsMetadataHandler handler = dbmsType.getMetadataHandler(); try { LOGGER.info(handler.getDbmsInfoString(dbms)); } catch (final SQLException sqle) { throw new SpeedmentException("Unable to establish initial " + "connection with the database named " + dbms.getName() + ".", sqle); } }); }
private void blockUntilAvailable() { if (closed) { throw new IllegalStateException("This connection has already been closed."); } if (!available) { LOGGER_CONNECTION.debug("Aquiring connection"); try { if (!lock.tryAcquire()) { if (blocking) { LOGGER_CONNECTION.warn("Waiting for connection to become available..."); lock.acquire(); } else { throw new SpeedmentException( "Error! No connection available. Try " + "wrapping the expression in a transaction or " + "enable the Speedment parameter " + "'connectionpool.blocking=true'."); } } } catch (final InterruptedException ex) { throw new SpeedmentException( "Interrupted while waiting for available connection.", ex); } this.counter.incrementAndGet(); available = true; } } }
public void writeToFile(TranslatorManager delegator, Path codePath, String content, boolean overwriteExisting) { requireNonNulls(codePath, content); try { if (overwriteExisting || !codePath.toFile().exists()) { final Path hashPath = codePath.getParent() .resolve(secretFolderName()) .resolve(HASH_PREFIX + codePath.getFileName().toString() + HASH_SUFFIX); write(hashPath, HashUtil.md5(content), true); write(codePath, content, false); fileCounter.incrementAndGet(); } } catch (final IOException ex) { LOGGER.error(ex, "Failed to write file " + codePath); } LOGGER.trace("*** BEGIN File:" + codePath); Stream.of(content.split(Formatting.nl())).forEachOrdered(LOGGER::trace); LOGGER.trace("*** END File:" + codePath); }
@Override public void setLevel(String path, Level level) { requireNonNulls(path, level); loggers() .filter(e -> e.getKey().startsWith(path) ) .map(Entry::getValue).forEach((Logger l) -> l.setLevel(level) ); }
private <T> void actionSilently(final T actionTarget, ThrowingConsumer<T> action, String actionLabel) { try { if (actionTarget != null) { action.accept(actionTarget); } } catch (Exception e) { LOGGER.error(e, "Error " + actionLabel + " " + actionTarget); // Just log the error. No re-throw } }
private <ENTITY> SqlStreamOptimizer<ENTITY> getHelper(Pipeline initialPipeline, DbmsType dbmsType) { @SuppressWarnings("unchecked") SqlStreamOptimizer<ENTITY> result = (SqlStreamOptimizer<ENTITY>) FALL_BACK; if (initialPipeline.isEmpty()) { return result; } Metrics metric = Metrics.empty(); for (int i = optimizers.size() - 1; i >= 0; i--) { @SuppressWarnings("unchecked") final SqlStreamOptimizer<ENTITY> candidate = (SqlStreamOptimizer<ENTITY>) optimizers.get(i); final Metrics candidateMetric = candidate.metrics(initialPipeline, dbmsType); if (DEBUG.isEqualOrHigherThan(LOGGER_STREAM_OPTIMIZER.getLevel())) { LOGGER_STREAM_OPTIMIZER.debug("Candidate: %-30s : %s ", candidate.getClass().getSimpleName(), candidateMetric); } if (METRICS_COMPARATOR.compare(candidateMetric, metric) > 0) { // if (candidateMetric.getPipelineReductions() > metric.getPipelineReductions()) { metric = candidateMetric; result = candidate; if (metric.getPipelineReductions() == Integer.MAX_VALUE) { return result; } } } return result; }
private void printStreamSupplierOrder(Injector injector) { injector.get(StreamSupplierComponent.class).ifPresent(root -> { if (root.sourceStreamSupplierComponents().findAny().isPresent()) { LOGGER.info("Current " + StreamSupplierComponent.class.getSimpleName() + " hierarchy:"); printStreamSupplierOrder(root, 0); } }); }
void setMaxAge(long maxAge) { LOGGER_CONNECTION.warn("Unsafe method called. Use configuration parameters to set this value instead"); this.maxAge = maxAge; }
protected void logOperation(Logger logger, final String sql, final List<?> values) { logger.debug("%s, values:%s", sql, values); }
protected void checkDatabaseConnectivity(Injector injector) { LOGGER.debug("Checking Database Connectivity"); final Project project = injector.getOrThrow(ProjectComponent.class) .getProject(); project.dbmses().forEachOrdered(dbms -> { final DbmsHandlerComponent dbmsHandlerComponent = injector .getOrThrow(DbmsHandlerComponent.class); final DbmsType dbmsType = DatabaseUtil .dbmsTypeOf(dbmsHandlerComponent, dbms); final DbmsMetadataHandler handler = dbmsType.getMetadataHandler(); try { LOGGER.info(handler.getDbmsInfoString(dbms)); } catch (final SQLException sqle) { throw new SpeedmentException("Unable to establish initial " + "connection with the database named " + dbms.getName() + ".", sqle); } }); }
private void blockUntilAvailable() { if (closed) { throw new IllegalStateException("This connection has already been closed."); } if (!available) { LOGGER_CONNECTION.debug("Aquiring connection"); try { if (!lock.tryAcquire()) { if (blocking) { LOGGER_CONNECTION.warn("Waiting for connection to become available..."); lock.acquire(); } else { throw new SpeedmentException( "Error! No connection available. Try " + "wrapping the expression in a transaction or " + "enable the Speedment parameter " + "'connectionpool.blocking=true'."); } } } catch (final InterruptedException ex) { throw new SpeedmentException( "Interrupted while waiting for available connection.", ex); } this.counter.incrementAndGet(); available = true; } } }