[Bugfix] fixed PostgreSqlQueryVisitor due to querying orders in resource

This only happened when the query had a ParameterSelection
This commit is contained in:
Robert von Burg 2014-12-03 18:12:41 +01:00
parent 1844a4aee6
commit d1a1b89194
2 changed files with 160 additions and 15 deletions

View File

@ -220,8 +220,9 @@ public abstract class PostgreSqlQueryVisitor implements StrolchRootElementSelect
}
private void xpath(String bagKey, String paramKey, String paramValue) {
String xpath = "cast(xpath('//Resource/ParameterBag[@Id=\"${bagKey}\"]/Parameter[@Id=\"${paramKey}\" and @Value=\"${paramValue}\"]', asxml) as text[]) != '{}'\n";
String xpath = "cast(xpath('//${className}/ParameterBag[@Id=\"${bagKey}\"]/Parameter[@Id=\"${paramKey}\" and @Value=\"${paramValue}\"]', asxml) as text[]) != '{}'\n";
this.sb.append(this.indent);
xpath = xpath.replace("${className}", getClassName());
xpath = xpath.replace("${bagKey}", bagKey);
xpath = xpath.replace("${paramKey}", paramKey);
xpath = xpath.replace("${paramValue}", paramValue);
@ -232,7 +233,8 @@ public abstract class PostgreSqlQueryVisitor implements StrolchRootElementSelect
public void visit(StringParameterSelection selection) {
String value = selection.getValue();
String xpath = "xpath('//Resource/ParameterBag[@Id=\"${bagKey}\"]/Parameter[@Id=\"${paramKey}\"]/@Value', asxml))::TEXT AS content";
String xpath = "xpath('//${className}/ParameterBag[@Id=\"${bagKey}\"]/Parameter[@Id=\"${paramKey}\"]/@Value', asxml))::TEXT AS content";
xpath = xpath.replace("${className}", getClassName());
xpath = xpath.replace("${bagKey}", selection.getBagKey());
xpath = xpath.replace("${paramKey}", selection.getParamKey());
@ -310,8 +312,9 @@ public abstract class PostgreSqlQueryVisitor implements StrolchRootElementSelect
@Override
public void visit(NullParameterSelection selection) {
String xpath = "cast(xpath('//Resource/ParameterBag[@Id=\"${bagKey}\"]/Parameter[@Id=\"${paramKey}\"]', asxml) as text[]) = '{}'\n";
String xpath = "cast(xpath('//${className}/ParameterBag[@Id=\"${bagKey}\"]/Parameter[@Id=\"${paramKey}\"]', asxml) as text[]) = '{}'\n";
this.sb.append(this.indent);
xpath = xpath.replace("${className}", getClassName());
xpath = xpath.replace("${bagKey}", selection.getBagKey());
xpath = xpath.replace("${paramKey}", selection.getParamKey());
this.sb.append(xpath);
@ -319,16 +322,18 @@ public abstract class PostgreSqlQueryVisitor implements StrolchRootElementSelect
@Override
public void visit(ParameterBagSelection selection) {
String xpath = "cast(xpath('//Resource/ParameterBag[@Id=\"${bagKey}\"]', asxml) as text[]) != '{}'\n";
String xpath = "cast(xpath('//${className}/ParameterBag[@Id=\"${bagKey}\"]', asxml) as text[]) != '{}'\n";
this.sb.append(this.indent);
xpath = xpath.replace("${className}", getClassName());
xpath = xpath.replace("${bagKey}", selection.getBagKey());
this.sb.append(xpath);
}
@Override
public void visit(NullParameterBagSelection selection) {
String xpath = "cast(xpath('//Resource/ParameterBag[@Id=\"${bagKey}\"]', asxml) as text[]) = '{}'\n";
String xpath = "cast(xpath('//${className}/ParameterBag[@Id=\"${bagKey}\"]', asxml) as text[]) = '{}'\n";
this.sb.append(this.indent);
xpath = xpath.replace("${className}", getClassName());
xpath = xpath.replace("${bagKey}", selection.getBagKey());
this.sb.append(xpath);
}

View File

@ -233,6 +233,156 @@ public class QueryTest {
new NameSelection("order 1", StringMatchMode.EQUALS_CASE_SENSITIVE));
performOrderQuery(query, Arrays.asList("@1", "@2"));
}
@Test
public void shouldQueryOrderByBooleParam() throws SQLException {
OrderQuery query = new OrderQuery(new StrolchTypeNavigation("MyType1"));
query.and().with(ParameterSelection.booleanSelection("@bag01", "@param1", true));
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
}
@Test
public void shouldQueryOrderByFloagParam() throws SQLException {
OrderQuery query = new OrderQuery(new StrolchTypeNavigation("MyType1"));
query.and().with(ParameterSelection.floatSelection("@bag01", "@param2", 44.3));
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
}
@Test
public void shouldQueryOrderByIntegerParam() throws SQLException {
OrderQuery query = new OrderQuery(new StrolchTypeNavigation("MyType1"));
query.and().with(ParameterSelection.integerSelection("@bag01", "@param3", 77));
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
}
@Test
public void shouldQueryOrderByLongParam() throws SQLException {
OrderQuery query = new OrderQuery(new StrolchTypeNavigation("MyType2"));
query.and().with(ParameterSelection.longSelection("@bag01", "@param4", 4453234566L));
performOrderQuery(query, Arrays.asList("@4", "@5", "@6"));
}
@Test
public void shouldQueryOrderByStringParam() throws SQLException {
List<String> expected = Arrays.asList("@1", "@2", "@3");
OrderQuery query = new OrderQuery(new StrolchTypeNavigation("MyType1"));
query.and().with(
ParameterSelection.stringSelection("@bag01", "@param5", "Strolch",
StringMatchMode.EQUALS_CASE_SENSITIVE));
performOrderQuery(query, expected);
query = new OrderQuery(new StrolchTypeNavigation("MyType1"));
query.and().with(
ParameterSelection.stringSelection("@bag01", "@param5", "strolch",
StringMatchMode.EQUALS_CASE_SENSITIVE));
performOrderQuery(query, Arrays.<String> asList());
query = new OrderQuery(new StrolchTypeNavigation("MyType1"));
query.and().with(
ParameterSelection.stringSelection("@bag01", "@param5", "strolch",
StringMatchMode.EQUALS_CASE_INSENSITIVE));
performOrderQuery(query, expected);
query = new OrderQuery(new StrolchTypeNavigation("MyType1"));
query.and().with(
ParameterSelection.stringSelection("@bag01", "@param5", "olch",
StringMatchMode.CONTAINS_CASE_INSENSITIVE));
performOrderQuery(query, expected);
}
@Test
public void shouldQueryOrderByDateParam() throws SQLException {
OrderQuery query = new OrderQuery(new StrolchTypeNavigation("MyType1"));
query.and().with(ParameterSelection.dateSelection("@bag01", "@param6", new Date(1354295525628L)));
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
}
@Test
public void shouldQueryOrderByDurationParam() throws SQLException {
OrderQuery query = new OrderQuery(new StrolchTypeNavigation("MyType1"));
query.and().with(ParameterSelection.durationSelection("@bag01", "@param8", "P1D"));
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
}
@Test
public void shouldQueryOrderByNullParam1() throws SQLException {
OrderQuery query = new OrderQuery(new StrolchTypeNavigation("MyType1"));
query.and().with(ParameterSelection.nullSelection("@bag01", "@param6"));
performOrderQuery(query, Arrays.<String> asList());
}
@Test
public void shouldQueryOrderByNullParam2() throws SQLException {
OrderQuery query = new OrderQuery(new StrolchTypeNavigation("MyType1"));
query.and().with(ParameterSelection.nullSelection("@bag01", "@param"));
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
}
@Test
public void shouldQueryOrderByBag() throws SQLException {
OrderQuery query = new OrderQuery(new StrolchTypeNavigation("MyType1"));
query.and().with(new ParameterBagSelection("@bag01"));
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
}
@Test
public void shouldQueryOrderByNullBag() throws SQLException {
OrderQuery query = new OrderQuery(new StrolchTypeNavigation("MyType1"));
query.and().with(new NullParameterBagSelection("@bag01"));
performOrderQuery(query, Arrays.<String> asList());
}
@Test
public void shouldQueryResource1() throws SQLException {
@ -255,16 +405,6 @@ public class QueryTest {
@Test
public void shouldQueryResourceByBooleParam() throws SQLException {
// select id, name, type, asxml
// from
// resources
// where
// type = 'MyType1' and
// (
// cast(xpath('//Resource/ParameterBag/Parameter[@Id="@param1" and @Value="true"]', asxml) as text[]) != '{}'
// )
ResourceQuery query = new ResourceQuery(new StrolchTypeNavigation("MyType1"));
query.and().with(ParameterSelection.booleanSelection("@bag01", "@param1", true));
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));