@Test(expectedExceptions = IOException.class) public void testSpecSearch() throws Exception { FlowSpecSearchObject flowSpecSearchObject = FlowSpecSearchObject.builder().build(); MysqlSpecStore.createGetPreparedStatement(flowSpecSearchObject, "table"); }
static String createGetPreparedStatement(FlowSpecSearchObject flowSpecSearchObject, String tableName) throws IOException { String baseStatement = String.format(GET_STATEMENT, tableName); List<String> conditions = new ArrayList<>(); if (flowSpecSearchObject.getFlowSpecUri() != null) { conditions.add("spec_uri = ?"); } if (flowSpecSearchObject.getFlowGroup() != null) { conditions.add("flow_group = ?"); } if (flowSpecSearchObject.getFlowName() != null) { conditions.add("flow_name = ?"); } if (flowSpecSearchObject.getTemplateURI() != null) { conditions.add("template_uri = ?"); } if (flowSpecSearchObject.getUserToProxy() != null) { conditions.add("user_to_proxy = ?"); } if (flowSpecSearchObject.getSourceIdentifier() != null) { conditions.add("source_identifier = ?"); } if (flowSpecSearchObject.getDestinationIdentifier() != null) { conditions.add("destination_identifier = ?"); } if (flowSpecSearchObject.getSchedule() != null) { conditions.add("schedule = ?"); } if (flowSpecSearchObject.getModifiedTimestamp() != null) { conditions.add("modified_time = ?"); } if (flowSpecSearchObject.getIsRunImmediately() != null) { conditions.add("isRunImmediately = ?"); } if (flowSpecSearchObject.getOwningGroup() != null) { conditions.add("owning_group = ?"); } if (flowSpecSearchObject.getPropertyFilter() != null) { String propertyFilter = flowSpecSearchObject.getPropertyFilter(); Splitter commaSplitter = Splitter.on(",").trimResults().omitEmptyStrings(); for (String property : commaSplitter.splitToList(propertyFilter)) { if (property.contains("=")) { String[] keyValue = property.split("="); if (keyValue.length != 2) { log.error("Incorrect flow config search query"); continue; } conditions.add("spec_json->'$.configAsProperties.\"" + keyValue[0] + "\"' like " + "'%" + keyValue[1] + "%'"); } else { conditions.add("spec_json->'$.configAsProperties.\"" + property + "\"' is not null"); } } } if (conditions.size() == 0) { throw new IOException("At least one condition is required to query flow configs."); } return baseStatement + String.join(" AND ", conditions); }
MysqlSpecStore extends InstrumentedSpecStore { static String createGetPreparedStatement(FlowSpecSearchObject flowSpecSearchObject, String tableName) throws IOException { String baseStatement = String.format(GET_STATEMENT, tableName); List<String> conditions = new ArrayList<>(); if (flowSpecSearchObject.getFlowSpecUri() != null) { conditions.add("spec_uri = ?"); } if (flowSpecSearchObject.getFlowGroup() != null) { conditions.add("flow_group = ?"); } if (flowSpecSearchObject.getFlowName() != null) { conditions.add("flow_name = ?"); } if (flowSpecSearchObject.getTemplateURI() != null) { conditions.add("template_uri = ?"); } if (flowSpecSearchObject.getUserToProxy() != null) { conditions.add("user_to_proxy = ?"); } if (flowSpecSearchObject.getSourceIdentifier() != null) { conditions.add("source_identifier = ?"); } if (flowSpecSearchObject.getDestinationIdentifier() != null) { conditions.add("destination_identifier = ?"); } if (flowSpecSearchObject.getSchedule() != null) { conditions.add("schedule = ?"); } if (flowSpecSearchObject.getModifiedTimestamp() != null) { conditions.add("modified_time = ?"); } if (flowSpecSearchObject.getIsRunImmediately() != null) { conditions.add("isRunImmediately = ?"); } if (flowSpecSearchObject.getOwningGroup() != null) { conditions.add("owning_group = ?"); } if (flowSpecSearchObject.getPropertyFilter() != null) { String propertyFilter = flowSpecSearchObject.getPropertyFilter(); Splitter commaSplitter = Splitter.on(",").trimResults().omitEmptyStrings(); for (String property : commaSplitter.splitToList(propertyFilter)) { if (property.contains("=")) { String[] keyValue = property.split("="); if (keyValue.length != 2) { log.error("Incorrect flow config search query"); continue; } conditions.add("spec_json->'$.configAsProperties.\"" + keyValue[0] + "\"' like " + "'%" + keyValue[1] + "%'"); } else { conditions.add("spec_json->'$.configAsProperties.\"" + property + "\"' is not null"); } } } if (conditions.size() == 0) { throw new IOException("At least one condition is required to query flow configs."); } return baseStatement + String.join(" AND ", conditions); } }
MysqlSpecStore extends InstrumentedSpecStore { static String createGetPreparedStatement(FlowSpecSearchObject flowSpecSearchObject, String tableName) throws IOException { String baseStatement = String.format(GET_STATEMENT, tableName); List<String> conditions = new ArrayList<>(); if (flowSpecSearchObject.getFlowSpecUri() != null) { conditions.add("spec_uri = ?"); } if (flowSpecSearchObject.getFlowGroup() != null) { conditions.add("flow_group = ?"); } if (flowSpecSearchObject.getFlowName() != null) { conditions.add("flow_name = ?"); } if (flowSpecSearchObject.getTemplateURI() != null) { conditions.add("template_uri = ?"); } if (flowSpecSearchObject.getUserToProxy() != null) { conditions.add("user_to_proxy = ?"); } if (flowSpecSearchObject.getSourceIdentifier() != null) { conditions.add("source_identifier = ?"); } if (flowSpecSearchObject.getDestinationIdentifier() != null) { conditions.add("destination_identifier = ?"); } if (flowSpecSearchObject.getSchedule() != null) { conditions.add("schedule = ?"); } if (flowSpecSearchObject.getModifiedTimestamp() != null) { conditions.add("modified_time = ?"); } if (flowSpecSearchObject.getIsRunImmediately() != null) { conditions.add("isRunImmediately = ?"); } if (flowSpecSearchObject.getOwningGroup() != null) { conditions.add("owning_group = ?"); } if (flowSpecSearchObject.getPropertyFilter() != null) { String propertyFilter = flowSpecSearchObject.getPropertyFilter(); Splitter commaSplitter = Splitter.on(",").trimResults().omitEmptyStrings(); for (String property : commaSplitter.splitToList(propertyFilter)) { if (property.contains("=")) { String[] keyValue = property.split("="); if (keyValue.length != 2) { log.error("Incorrect flow config search query"); continue; } conditions.add("spec_json->'$.configAsProperties.\"" + keyValue[0] + "\"' like " + "'%" + keyValue[1] + "%'"); } else { conditions.add("spec_json->'$.configAsProperties.\"" + property + "\"' is not null"); } } } if (conditions.size() == 0) { throw new IOException("At least one condition is required to query flow configs."); } return baseStatement + String.join(" AND ", conditions); } MysqlSpecStore(Config config, SpecSerDe specSerDe); }
MysqlSpecStore extends InstrumentedSpecStore { static String createGetPreparedStatement(FlowSpecSearchObject flowSpecSearchObject, String tableName) throws IOException { String baseStatement = String.format(GET_STATEMENT, tableName); List<String> conditions = new ArrayList<>(); if (flowSpecSearchObject.getFlowSpecUri() != null) { conditions.add("spec_uri = ?"); } if (flowSpecSearchObject.getFlowGroup() != null) { conditions.add("flow_group = ?"); } if (flowSpecSearchObject.getFlowName() != null) { conditions.add("flow_name = ?"); } if (flowSpecSearchObject.getTemplateURI() != null) { conditions.add("template_uri = ?"); } if (flowSpecSearchObject.getUserToProxy() != null) { conditions.add("user_to_proxy = ?"); } if (flowSpecSearchObject.getSourceIdentifier() != null) { conditions.add("source_identifier = ?"); } if (flowSpecSearchObject.getDestinationIdentifier() != null) { conditions.add("destination_identifier = ?"); } if (flowSpecSearchObject.getSchedule() != null) { conditions.add("schedule = ?"); } if (flowSpecSearchObject.getModifiedTimestamp() != null) { conditions.add("modified_time = ?"); } if (flowSpecSearchObject.getIsRunImmediately() != null) { conditions.add("isRunImmediately = ?"); } if (flowSpecSearchObject.getOwningGroup() != null) { conditions.add("owning_group = ?"); } if (flowSpecSearchObject.getPropertyFilter() != null) { String propertyFilter = flowSpecSearchObject.getPropertyFilter(); Splitter commaSplitter = Splitter.on(",").trimResults().omitEmptyStrings(); for (String property : commaSplitter.splitToList(propertyFilter)) { if (property.contains("=")) { String[] keyValue = property.split("="); if (keyValue.length != 2) { log.error("Incorrect flow config search query"); continue; } conditions.add("spec_json->'$.configAsProperties.\"" + keyValue[0] + "\"' like " + "'%" + keyValue[1] + "%'"); } else { conditions.add("spec_json->'$.configAsProperties.\"" + property + "\"' is not null"); } } } if (conditions.size() == 0) { throw new IOException("At least one condition is required to query flow configs."); } return baseStatement + String.join(" AND ", conditions); } MysqlSpecStore(Config config, SpecSerDe specSerDe); @Override boolean existsImpl(URI specUri); @Override void addSpecImpl(Spec spec); void addSpec(Spec spec, String tagValue); @Override boolean deleteSpec(Spec spec); @Override boolean deleteSpecImpl(URI specUri); @Override boolean deleteSpec(URI specUri, String version); @Override // TODO : this method is not doing what the contract is in the SpecStore interface Spec updateSpecImpl(Spec spec); @Override Spec getSpecImpl(URI specUri); Collection<Spec> getSpecsImpl(SpecSearchObject specSearchObject); @Override Spec getSpec(URI specUri, String version); @Override Collection<Spec> getAllVersionsOfSpec(URI specUri); @Override Collection<Spec> getSpecsImpl(); @Override Iterator<URI> getSpecURIsImpl(); @Override Iterator<URI> getSpecURIsWithTag(String tag); @Override Optional<URI> getSpecStoreURI(); }
MysqlSpecStore extends InstrumentedSpecStore { static String createGetPreparedStatement(FlowSpecSearchObject flowSpecSearchObject, String tableName) throws IOException { String baseStatement = String.format(GET_STATEMENT, tableName); List<String> conditions = new ArrayList<>(); if (flowSpecSearchObject.getFlowSpecUri() != null) { conditions.add("spec_uri = ?"); } if (flowSpecSearchObject.getFlowGroup() != null) { conditions.add("flow_group = ?"); } if (flowSpecSearchObject.getFlowName() != null) { conditions.add("flow_name = ?"); } if (flowSpecSearchObject.getTemplateURI() != null) { conditions.add("template_uri = ?"); } if (flowSpecSearchObject.getUserToProxy() != null) { conditions.add("user_to_proxy = ?"); } if (flowSpecSearchObject.getSourceIdentifier() != null) { conditions.add("source_identifier = ?"); } if (flowSpecSearchObject.getDestinationIdentifier() != null) { conditions.add("destination_identifier = ?"); } if (flowSpecSearchObject.getSchedule() != null) { conditions.add("schedule = ?"); } if (flowSpecSearchObject.getModifiedTimestamp() != null) { conditions.add("modified_time = ?"); } if (flowSpecSearchObject.getIsRunImmediately() != null) { conditions.add("isRunImmediately = ?"); } if (flowSpecSearchObject.getOwningGroup() != null) { conditions.add("owning_group = ?"); } if (flowSpecSearchObject.getPropertyFilter() != null) { String propertyFilter = flowSpecSearchObject.getPropertyFilter(); Splitter commaSplitter = Splitter.on(",").trimResults().omitEmptyStrings(); for (String property : commaSplitter.splitToList(propertyFilter)) { if (property.contains("=")) { String[] keyValue = property.split("="); if (keyValue.length != 2) { log.error("Incorrect flow config search query"); continue; } conditions.add("spec_json->'$.configAsProperties.\"" + keyValue[0] + "\"' like " + "'%" + keyValue[1] + "%'"); } else { conditions.add("spec_json->'$.configAsProperties.\"" + property + "\"' is not null"); } } } if (conditions.size() == 0) { throw new IOException("At least one condition is required to query flow configs."); } return baseStatement + String.join(" AND ", conditions); } MysqlSpecStore(Config config, SpecSerDe specSerDe); @Override boolean existsImpl(URI specUri); @Override void addSpecImpl(Spec spec); void addSpec(Spec spec, String tagValue); @Override boolean deleteSpec(Spec spec); @Override boolean deleteSpecImpl(URI specUri); @Override boolean deleteSpec(URI specUri, String version); @Override // TODO : this method is not doing what the contract is in the SpecStore interface Spec updateSpecImpl(Spec spec); @Override Spec getSpecImpl(URI specUri); Collection<Spec> getSpecsImpl(SpecSearchObject specSearchObject); @Override Spec getSpec(URI specUri, String version); @Override Collection<Spec> getAllVersionsOfSpec(URI specUri); @Override Collection<Spec> getSpecsImpl(); @Override Iterator<URI> getSpecURIsImpl(); @Override Iterator<URI> getSpecURIsWithTag(String tag); @Override Optional<URI> getSpecStoreURI(); static final String CONFIG_PREFIX; static final String DEFAULT_TAG_VALUE; }