private static boolean stringNotEmpty(final String value) { return !stringIsEmpty(value); }
protected void loadDriver() { if (stringIsEmpty(connection_driver)) return; log.debug("Registering JDBC Driver named '%s'", connection_driver); try { Class.forName(connection_driver); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("JDBC Driver required for JDBC_PING " + " protocol could not be loaded: '" + connection_driver + "'"); } }
protected void verifyConfigurationParameters() { // Skip if datasource is already provided via integration code (e.g. WildFly) if (dataSource == null) { if (stringIsEmpty(this.connection_url) || stringIsEmpty(this.connection_driver) || stringIsEmpty(this.connection_username)) { if (stringIsEmpty(this.datasource_jndi_name)) { throw new IllegalArgumentException("Either the 4 configuration properties starting with 'connection_' or the datasource_jndi_name must be set"); } } if (stringNotEmpty(this.connection_url) || stringNotEmpty(this.connection_driver) || stringNotEmpty(this.connection_username)) { if (stringNotEmpty(this.datasource_jndi_name)) { throw new IllegalArgumentException("When using the 'datasource_jndi_name' configuration property, all properties starting with 'connection_' must not be set"); } } } if (stringIsEmpty(this.insert_single_sql)) { throw new IllegalArgumentException("The insert_single_sql configuration property is mandatory"); } if (stringIsEmpty(this.delete_single_sql)) { throw new IllegalArgumentException("The delete_single_sql configuration property is mandatory"); } if (stringIsEmpty(this.select_all_pingdata_sql)) { throw new IllegalArgumentException("The select_all_pingdata_sql configuration property is mandatory"); } }
@Override public void init() throws Exception { super.init(); verifyConfigurationParameters(); // If dataSource is already set, skip loading driver or JNDI lookup if (dataSource == null) { if (stringIsEmpty(datasource_jndi_name)) { loadDriver(); } else { dataSource = getDataSourceFromJNDI(datasource_jndi_name.trim()); } } attemptSchemaInitialization(); }
protected void attemptSchemaInitialization() { if(stringIsEmpty(initialize_sql)) { log.debug("Table creation step skipped: initialize_sql property is missing"); return; } Connection connection=getConnection(); if(connection == null) return; try(PreparedStatement ps=connection.prepareStatement(initialize_sql)) { if(log.isTraceEnabled()) log.trace("SQL for initializing schema: %s", ps); ps.execute(); log.debug("Table created for JDBC_PING Discovery Protocol"); } catch(SQLException e) { log.debug("Could not execute initialize_sql statement; not necessarily an error, we always attempt to create the schema. " + "To suppress this message, set initialize_sql to an empty value. Cause: %s", e.getMessage()); } finally { try { connection.close(); } catch(SQLException e) { log.error(Util.getMessage("ErrorClosingConnection"), e); } } }
private static boolean stringNotEmpty(final String value) { return !stringIsEmpty(value); }
protected void loadDriver() { if (stringIsEmpty(connection_driver)) return; log.debug("Registering JDBC Driver named '%s'", connection_driver); try { Class.forName(connection_driver); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("JDBC Driver required for JDBC_PING " + " protocol could not be loaded: '" + connection_driver + "'"); } }
protected void verifyConfigurationParameters() { // Skip if datasource is already provided via integration code (e.g. WildFly) if (dataSource == null) { if (stringIsEmpty(this.connection_url) || stringIsEmpty(this.connection_driver) || stringIsEmpty(this.connection_username)) { if (stringIsEmpty(this.datasource_jndi_name)) { throw new IllegalArgumentException("Either the 4 configuration properties starting with 'connection_' or the datasource_jndi_name must be set"); } } if (stringNotEmpty(this.connection_url) || stringNotEmpty(this.connection_driver) || stringNotEmpty(this.connection_username)) { if (stringNotEmpty(this.datasource_jndi_name)) { throw new IllegalArgumentException("When using the 'datasource_jndi_name' configuration property, all properties starting with 'connection_' must not be set"); } } } if (stringIsEmpty(this.insert_single_sql)) { throw new IllegalArgumentException("The insert_single_sql configuration property is mandatory"); } if (stringIsEmpty(this.delete_single_sql)) { throw new IllegalArgumentException("The delete_single_sql configuration property is mandatory"); } if (stringIsEmpty(this.select_all_pingdata_sql)) { throw new IllegalArgumentException("The select_all_pingdata_sql configuration property is mandatory"); } }
@Override public void init() throws Exception { super.init(); verifyConfigurationParameters(); // If dataSource is already set, skip loading driver or JNDI lookup if (dataSource == null) { if (stringIsEmpty(datasource_jndi_name)) { loadDriver(); } else { dataSource = getDataSourceFromJNDI(datasource_jndi_name.trim()); } } attemptSchemaInitialization(); }
protected void attemptSchemaInitialization() { if(stringIsEmpty(initialize_sql)) { log.debug("Table creation step skipped: initialize_sql property is missing"); return; } Connection connection=getConnection(); if(connection == null) return; try(PreparedStatement ps=connection.prepareStatement(initialize_sql)) { if(log.isTraceEnabled()) log.trace("SQL for initializing schema: %s", ps); ps.execute(); log.debug("Table created for JDBC_PING Discovery Protocol"); } catch(SQLException e) { log.debug("Could not execute initialize_sql statement; not necessarily an error, we always attempt to create the schema. " + "To suppress this message, set initialize_sql to an empty value. Cause: %s", e.getMessage()); } finally { try { connection.close(); } catch(SQLException e) { log.error(Util.getMessage("ErrorClosingConnection"), e); } } }